From 25b4f1983a3804353f5fc879f93ecde978a90aaf Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Fri, 17 Jun 2016 09:29:12 +0200 Subject: [PATCH] run: Improve error message if dss is already running. 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 | 9 +++++++++ err.h | 1 + 2 files changed, 10 insertions(+) diff --git a/dss.c b/dss.c index 6f0d759..8547f24 100644 --- 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 --- 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") -- 2.39.2