From 2d10a72798da5489363088dfbe02ccbc5942cfcd Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 16 Apr 2017 12:01:42 +0200 Subject: [PATCH] run: Improve error diagnostics for chdir(2) failure. 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 | 8 +++++++- file.c | 13 ------------- file.h | 1 - 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/dss.c b/dss.c index 8547f24..5e2ef46 100644 --- 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 8494408..d606c16 100644 --- 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 c462b10..140a505 100644 --- 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); /** -- 2.39.5