]> git.tue.mpg.de Git - dss.git/commitdiff
run: Improve error message if dss is already running.
authorAndre Noll <maan@tuebingen.mpg.de>
Fri, 17 Jun 2016 07:29:12 +0000 (09:29 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Thu, 13 Jul 2017 20:54:03 +0000 (22:54 +0200)
The current error message, "child terminated unexpectedly", is not
very comprehensive.

The most likely reason for the child to terminate is that it could not
obtain the semaphore lock because another dss process is running. This
commit adds a test to com_run() that check this condition in the
parent before the child process is born. This way, if another process
is holding the lock, we can fail with a nice error message that also
includes the pid of the process that holds the lock.

dss.c
err.h

diff --git a/dss.c b/dss.c
index 6f0d759db4a71084f04967f7f32aa65ea68dd394..8547f24a55e6c218d76fe002f7c76baa6c81e958 100644 (file)
--- a/dss.c
+++ b/dss.c
@@ -1511,11 +1511,20 @@ static void lock_dss_or_die(void)
 static int com_run(void)
 {
        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)) {
                fd = daemon_init();
                daemonized = true;
diff --git a/err.h b/err.h
index fc1ef19a272e9e4bee8b3e8e870cfd548d16951d..3d4e136f208473fb2de31cb645a868f33995bbaa 100644 (file)
--- a/err.h
+++ b/err.h
@@ -56,6 +56,7 @@ static inline char *dss_strerror(int num)
        DSS_ERROR(SIGNAL, "caught terminating signal"), \
        DSS_ERROR(BUG, "values of beta might cause dom!"), \
        DSS_ERROR(NOT_RUNNING, "dss not running"), \
+       DSS_ERROR(ALREADY_RUNNING, "dss already running"), \
        DSS_ERROR(TOO_MANY_RSYNC_ERRORS, "too many consecutive rsync errors"), \
        DSS_ERROR(LOPSUB, "lopsub error")