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.
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;
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")