run: Improve error diagnostics for chdir(2) failure.
authorAndre Noll <maan@tuebingen.mpg.de>
Sun, 16 Apr 2017 10:01:42 +0000 (12:01 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Thu, 13 Jul 2017 20:54:03 +0000 (22:54 +0200)
In run mode, if the destination directory does not exist, dss prints
"No such file or directory" and exits, without telling the user (a)
it was a failed chdir(2) call that caused the error, and (b) the name
of the directory. This patch adds an error message containing this
information.

Since there is only one caller of dss_chdir(), let's get rid
of this public function in file.c and call chdir() directly from
change_to_dest_dir() of dss.c.

dss.c
file.c
file.h

diff --git a/dss.c b/dss.c
index 8547f24a55e6c218d76fe002f7c76baa6c81e958..5e2ef46f71251c6a157f2f9df02900c8e534a3a9 100644 (file)
--- a/dss.c
+++ b/dss.c
@@ -1055,9 +1055,15 @@ static int handle_sigchld(void)
 
 static int change_to_dest_dir(void)
 {
+       int ret;
        const char *dd = OPT_STRING_VAL(DSS, DEST_DIR);
+
        DSS_INFO_LOG(("changing cwd to %s\n", dd));
-       return dss_chdir(dd);
+       if (chdir(dd) >= 0)
+               return 1;
+       ret = -ERRNO_TO_DSS_ERROR(errno);
+       DSS_ERROR_LOG(("could not change cwd to %s\n", dd));
+       return ret;
 }
 
 static int check_config(const struct lls_command *cmd)
diff --git a/file.c b/file.c
index 84944082960055e272e942aa40a760b5709eb875..d606c16e15242a4ed9069cd1929428ec42bbcd02 100644 (file)
--- a/file.c
+++ b/file.c
@@ -69,19 +69,6 @@ out:
        closedir(dir);
        return ret;
 }
-/**
- * Wrapper for chdir(2).
- *
- * \param path The specified directory.
- *
- * \return Standard.
- */
-int dss_chdir(const char *path)
-{
-       if (chdir(path) >= 0)
-               return 1;
-       return -ERRNO_TO_DSS_ERROR(errno);
-}
 
 /**
  * Set a file descriptor to non-blocking mode.
diff --git a/file.h b/file.h
index c462b1084cdd77cbb7f14c47b3066559d2a52019..140a505ba01b1fe3adb3614e118103517a722384 100644 (file)
--- a/file.h
+++ b/file.h
@@ -3,7 +3,6 @@
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
-int dss_chdir(const char *path);
 int for_each_subdir(int (*func)(const char *, void *), void *private_data);
 __must_check int mark_fd_nonblocking(int fd);
 /**