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@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:
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@v3.sk --- Changes since v1: - Remove the pid file upon startup if we're not running. Otherwise we'd fail to override it.
teamd/teamd.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/teamd/teamd.c b/teamd/teamd.c index ed5ff1a..4885b14 100644 --- a/teamd/teamd.c +++ b/teamd/teamd.c @@ -1458,7 +1458,9 @@ 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) + daemon_pid_file_remove(); + if (pid > 0) { teamd_log_err("Daemon already running on PID %u.", pid); return -EEXIST; } @@ -1729,14 +1731,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:
Mon, Nov 03, 2014 at 06:36:53PM CET, lkundrak@v3.sk wrote:
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@v3.sk
applied, thanks!
libteam@lists.fedorahosted.org