URL: https://github.com/SSSD/sssd/pull/982 Author: miztake Title: #982: monitor: Fix check process about multiple starts of sssd when pidfile… Action: opened
PR body: """ … remains If PIDFile is invalid in sssd.service, pidfile remains if sssd terminates abnormally. Also, if /var/run is not tmpfs, the pidfile will remain when the OS is forcibly stopped. In check process about multiple starts of sssd, only the existence of pidfile is checked. Fix not only to check if pidfile exists, but also to check if PID exists. """ To pull the PR as Git branch: git remote add ghsssd https://github.com/SSSD/sssd git fetch ghsssd pull/982/head:pr982 git checkout pr982
From e252509613ddff82f5fd879c63733d282c5aca07 Mon Sep 17 00:00:00 2001 From: MIZUTA Takeshi <mizuta.take...@fujitsu.com> Date: Wed, 5 Feb 2020 17:39:53 +0900 Subject: [PATCH] monitor: Fix check process about multiple starts of sssd when pidfile remains If PIDFile is invalid in sssd.service, pidfile remains if sssd terminates abnormally. Also, if /var/run is not tmpfs, the pidfile will remain when the OS is forcibly stopped. In check process about multiple starts of sssd, only the existence of pidfile is checked. Fix not only to check if pidfile exists, but also to check if PID exists. --- src/monitor/monitor.c | 11 +++++++---- src/util/server.c | 20 +++++++++++++++++--- src/util/util.h | 1 + 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c index a97a528ae7..ec6110582b 100644 --- a/src/monitor/monitor.c +++ b/src/monitor/monitor.c @@ -2509,10 +2509,13 @@ int main(int argc, const char *argv[]) if (opt_genconf == 0) { ret = check_file(SSSD_PIDFILE, 0, 0, S_IFREG|0600, 0, NULL, false); if (ret == EOK) { - DEBUG(SSSDBG_FATAL_FAILURE, - "pidfile exists at %s\n", SSSD_PIDFILE); - ERROR("SSSD is already running\n"); - return 2; + ret = check_pidfile(SSSD_PIDFILE); + if (ret != EOK) { + DEBUG(SSSDBG_FATAL_FAILURE, + "pidfile exists at %s\n", SSSD_PIDFILE); + ERROR("SSSD is already running\n"); + return 2; + } } /* Warn if nscd seems to be running */ diff --git a/src/util/server.c b/src/util/server.c index e607bf6e24..b27cbc1559 100644 --- a/src/util/server.c +++ b/src/util/server.c @@ -136,15 +136,13 @@ static void become_daemon(void) close_low_fds(); } -int pidfile(const char *file) +int check_pidfile(const char *file) { char pid_str[32]; pid_t pid; int fd; int ret, err; ssize_t len; - size_t size; - ssize_t written; ssize_t pidlen = sizeof(pid_str) - 1; fd = open(file, O_RDONLY, 0644); @@ -193,6 +191,22 @@ int pidfile(const char *file) } } + return 0; +} + +int pidfile(const char *file) +{ + char pid_str[32]; + int fd; + int ret, err; + size_t size; + ssize_t written; + + ret = check_pidfile(file); + if (ret != EOK) { + return ret; + } + fd = open(file, O_CREAT | O_WRONLY | O_EXCL, 0644); err = errno; if (fd == -1) { diff --git a/src/util/util.h b/src/util/util.h index c13faf5843..0369a5b247 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -183,6 +183,7 @@ struct main_context { errno_t server_common_rotate_logs(struct confdb_ctx *confdb, const char *conf_entry); int die_if_parent_died(void); +int check_pidfile(const char *file); int pidfile(const char *file); int server_setup(const char *name, int flags, uid_t uid, gid_t gid,
_______________________________________________ sssd-devel mailing list -- sssd-devel@lists.fedorahosted.org To unsubscribe send an email to sssd-devel-le...@lists.fedorahosted.org Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedorahosted.org/archives/list/sssd-devel@lists.fedorahosted.org