]> git.tuebingen.mpg.de Git - dss.git/blobdiff - dss.c
run: Improve error diagnostics for chdir(2) failure.
[dss.git] / dss.c
diff --git a/dss.c b/dss.c
index d0dab0dc3f688254163d9d138069a48dd77ccd5b..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)
@@ -1510,14 +1516,23 @@ static void lock_dss_or_die(void)
 
 static int com_run(void)
 {
-       int ret;
+       int ret, fd = -1;
+       char *config_file;
+       pid_t pid;
 
        if (OPT_GIVEN(DSS, DRY_RUN)) {
                DSS_ERROR_LOG(("dry run not supported by this command\n"));
                return -E_SYNTAX;
        }
+       config_file = get_config_file_name();
+       ret = get_dss_pid(config_file, &pid);
+       free(config_file);
+       if (ret >= 0) {
+               DSS_ERROR_LOG(("pid %d\n", (int)pid));
+               return -E_ALREADY_RUNNING;
+       }
        if (OPT_GIVEN(RUN, DAEMON)) {
-               daemon_init();
+               fd = daemon_init();
                daemonized = true;
                logfile = open_log(OPT_STRING_VAL(RUN, LOGFILE));
        }
@@ -1526,6 +1541,16 @@ static int com_run(void)
        ret = install_sighandler(SIGHUP);
        if (ret < 0)
                return ret;
+       if (fd >= 0) {
+               ret = write(fd, "\0", 1);
+               if (ret != 1) {
+                       DSS_ERROR_LOG(("write to daemon pipe returned %d\n",
+                               ret));
+                       if (ret < 0)
+                               return -ERRNO_TO_DSS_ERROR(errno);
+                       return -E_BUG;
+               }
+       }
        ret = select_loop();
        if (ret >= 0) /* impossible */
                ret = -E_BUG;