From 59e70b352f9b61ecd881f15485c607a670f9b32a Mon Sep 17 00:00:00 2001 From: Sven Eden Date: Mon, 12 Nov 2018 08:43:36 +0100 Subject: Prep v239.2: Check process name of possibly stale PID file (#94) --- src/login/elogind.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/login/elogind.c') diff --git a/src/login/elogind.c b/src/login/elogind.c index edcf312d4..77622483a 100644 --- a/src/login/elogind.c +++ b/src/login/elogind.c @@ -156,7 +156,7 @@ static int elogind_daemonize(void) { /// Simple tool to see, if elogind is already running static pid_t elogind_is_already_running(bool need_pid_file) { - _cleanup_free_ char *s = NULL; + _cleanup_free_ char *s = NULL, *comm = NULL; pid_t pid; int r; @@ -170,8 +170,17 @@ static pid_t elogind_is_already_running(bool need_pid_file) { if (r < 0) goto we_are_alone; - if ( (pid != getpid_cached()) && pid_is_alive(pid)) - return pid; + if ( (pid != getpid_cached()) && pid_is_alive(pid)) { + /* If the old elogind process currently running was forked into + * background, its name will be "elogind-daemon", while this + * process will be "elogind". + * Therefore check comm with startswith(). + */ + get_process_comm(pid, &comm); + if (NULL == startswith(strna(comm), program_invocation_short_name)) + goto we_are_alone; + } + return pid; we_are_alone: @@ -372,7 +381,7 @@ void elogind_manager_free(Manager* m) { /// Add-On for manager_new() int elogind_manager_new(Manager* m) { - int r = 0, e = 0; + int r = 0; m->cgroups_agent_fd = -1; m->pin_cgroupfs_fd = -1; -- cgit v1.2.3