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 6f0d759..8547f24 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 fc1ef19..3d4e136 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")