summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Eden <sven.eden@prydeworx.com>2018-11-12 08:43:36 +0100
committerSven Eden <sven.eden@prydeworx.com>2018-11-12 08:43:36 +0100
commit59e70b352f9b61ecd881f15485c607a670f9b32a (patch)
treeb9307e21c3be625d63a9074d3d12ee88fac540c7
parent9f54ff0832237f4040ee9f13679a62425a78a86e (diff)
Prep v239.2: Check process name of possibly stale PID file (#94)
-rw-r--r--src/login/elogind.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/login/elogind.c b/src/login/elogind.c
index edcf312..7762248 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;