It's a suicide. daemon_pid_file_is_running() may return 0 in case a PID file
exists but is empty. It's safe to assume the daemon is not running -- it either
lost race while dying between opening and writing a PID file, or the system
crashed.
Signed-off-by: Lubomir Rintel <lkundrak(a)v3.sk>
---
teamd/teamd.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/teamd/teamd.c b/teamd/teamd.c
index ed5ff1a..c680bb4 100644
--- a/teamd/teamd.c
+++ b/teamd/teamd.c
@@ -1458,7 +1458,7 @@ static int teamd_start(struct teamd_context *ctx, enum
teamd_exit_code *p_ret)
}
pid = daemon_pid_file_is_running();
- if (pid >= 0) {
+ if (pid > 0) {
teamd_log_err("Daemon already running on PID %u.", pid);
return -EEXIST;
}
@@ -1729,14 +1729,18 @@ int main(int argc, char **argv)
case DAEMON_CMD_VERSION:
break;
case DAEMON_CMD_KILL:
- err = daemon_pid_file_kill_wait(SIGTERM, 5);
- if (err)
- teamd_log_warn("Failed to kill daemon: %s", strerror(errno));
- else
- ret = TEAMD_EXIT_SUCCESS;
+ if (daemon_pid_file_is_running() > 0) {
+ err = daemon_pid_file_kill_wait(SIGTERM, 5);
+ if (err)
+ teamd_log_warn("Failed to kill daemon: %s", strerror(errno));
+ else
+ ret = TEAMD_EXIT_SUCCESS;
+ } else {
+ teamd_log_warn("Daemon not running");
+ }
break;
case DAEMON_CMD_CHECK:
- ret = (daemon_pid_file_is_running() >= 0) ? TEAMD_EXIT_SUCCESS :
+ ret = (daemon_pid_file_is_running() > 0) ? TEAMD_EXIT_SUCCESS :
TEAMD_EXIT_FAILURE;
break;
case DAEMON_CMD_RUN:
--
1.9.3
Show replies by date