From eb2ab82ff7ed51eb5b744c3ea21b51f793116809 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 11 Jan 2023 11:50:15 +0100 Subject: Fix session id detection on newer systemd --- src/userlist.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/userlist.c b/src/userlist.c index 1f65eb5..7a4a348 100644 --- a/src/userlist.c +++ b/src/userlist.c @@ -183,8 +183,9 @@ static void getSessionData( struct user * user ) char sessionName[40] = ""; while ( fgets( buffer, sizeof(buffer), fh ) != NULL ) { const char *p = strstr( buffer, ":name=systemd:" ); - if ( p == NULL ) - continue; + if ( p == NULL ) { + p = buffer; + } p = strstr( p + 14, "/session-" ); if ( p == NULL ) continue; @@ -192,6 +193,10 @@ static void getSessionData( struct user * user ) break; } fclose( fh ); + if ( sessionName[0] == '\0' ) { + fprintf( stderr, "getSessionData: Cannot get logind session id from %d cgroup file.\n", (int)user->sessionLeader ); + return; + } // Extract session leader pid from loginctl - it's often different from what utmp says int fds[2]; if ( pipe( fds ) == -1 ) { -- cgit v1.2.3-55-g7522