From: Martin Mares Date: Wed, 18 Jul 2012 08:36:07 +0000 (+0200) Subject: Daemon: daemon_control() finished X-Git-Tag: v5.99~153 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=244c4fe7e6cf5ae78cbe6343fe7f9b6dfc29b11a;p=libucw.git Daemon: daemon_control() finished --- diff --git a/ucw/daemon.c b/ucw/daemon.c index b0ea4767..9f3273df 100644 --- a/ucw/daemon.c +++ b/ucw/daemon.c @@ -191,7 +191,7 @@ daemon_control_err(struct daemon_control_params *dc, char *msg, ...) } static int -daemon_read_pid(struct daemon_control_params *dc) +daemon_read_pid(struct daemon_control_params *dc, int will_wait) { int pid_fd = open(dc->pid_file, O_RDONLY); if (pid_fd < 0) @@ -202,7 +202,7 @@ daemon_read_pid(struct daemon_control_params *dc) return -1; } - if (flock(pid_fd, LOCK_EX | LOCK_NB) >= 0) + if (flock(pid_fd, LOCK_EX | (will_wait ? 0 : LOCK_NB)) >= 0) { // The lock file is stale close(pid_fd); @@ -254,7 +254,7 @@ daemon_control(struct daemon_control_params *dc) return daemon_control_err(dc, "Cannot lock guard file `%s': %m", dc->guard_file); // Read the PID file - int pid = daemon_read_pid(dc); + int pid = daemon_read_pid(dc, 0); if (pid < 0) goto done; @@ -302,7 +302,7 @@ daemon_control(struct daemon_control_params *dc) daemon_control_err(dc, "Daemon %s", ecmsg); goto done; } - pid = daemon_read_pid(dc); + pid = daemon_read_pid(dc, 0); if (!pid) daemon_control_err(dc, "Daemon failed to write the PID file `%s'", dc->pid_file); else @@ -318,7 +318,10 @@ daemon_control(struct daemon_control_params *dc) daemon_control_err(dc, "Cannot send signal %d: %m", dc->signal); goto done; } - // FIXME: Wait for the daemon to exit, possibly with a timeout + pid = daemon_read_pid(dc, 1); + ASSERT(pid <= 0); + if (!pid) + st = DAEMON_STATUS_OK; break; case DAEMON_CONTROL_SIGNAL: if (!pid) diff --git a/ucw/daemon.h b/ucw/daemon.h index 561a4015..dc2fd746 100644 --- a/ucw/daemon.h +++ b/ucw/daemon.h @@ -85,7 +85,7 @@ enum daemon_control_action { * * `DAEMON_STATUS_ALREADY_DONE` if the daemon is already in the requested state * * `DAEMON_STATUS_NOT_RUNNING` if the action failed, because the daemon is not running * * `DAEMON_STATUS_ERROR` if the action failed for some other reason (in this case, - * the error_msg field contains a full error message) + * `dc->error_msg` contains a full error message) **/ enum daemon_control_status daemon_control(struct daemon_control_params *dc);