From: Thorsten Kukuk Date: Tue, 6 Jun 2023 12:52:22 +0000 (+0200) Subject: sd-login: add sd_session_get_leader interface X-Git-Tag: v254-rc1~271 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=403082602d4230c224529c46e2d8a392f3a50e49;p=thirdparty%2Fsystemd.git sd-login: add sd_session_get_leader interface --- diff --git a/man/sd_session_is_active.xml b/man/sd_session_is_active.xml index a3cc9befe8d..8639599eccc 100644 --- a/man/sd_session_is_active.xml +++ b/man/sd_session_is_active.xml @@ -33,6 +33,7 @@ sd_session_get_vt sd_session_get_remote_host sd_session_get_remote_user + sd_session_get_leader Determine state of a specific session @@ -110,6 +111,12 @@ char **display + + int sd_session_get_leader + const char *session + pid_t *leader + + int sd_session_get_remote_host const char *session @@ -236,6 +243,10 @@ free3 call after use. + sd_session_get_leader() may be used to + determine the PID of the leader of the session identified by the + specified session identifier. + sd_session_get_remote_host() may be used to determine the remote hostname of the session identified by the specified session identifier. The returned string needs to be @@ -284,6 +295,7 @@ sd_session_get_type(), sd_session_get_class(), sd_session_get_display(), + sd_session_get_leader(), sd_session_get_remote_user(), sd_session_get_remote_host() and sd_session_get_tty() return 0 or diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym index 936a3577f54..ea13e02719b 100644 --- a/src/libsystemd/libsystemd.sym +++ b/src/libsystemd/libsystemd.sym @@ -826,4 +826,5 @@ global: sd_pid_notify_barrier; sd_event_source_leave_ratelimit; sd_journal_step_one; + sd_session_get_leader; } LIBSYSTEMD_253; diff --git a/src/libsystemd/sd-login/sd-login.c b/src/libsystemd/sd-login/sd-login.c index c5d54bbf74d..4d09b156536 100644 --- a/src/libsystemd/sd-login/sd-login.c +++ b/src/libsystemd/sd-login/sd-login.c @@ -870,6 +870,25 @@ _public_ int sd_session_get_remote_host(const char *session, char **remote_host) return session_get_string(session, "REMOTE_HOST", remote_host); } +_public_ int sd_session_get_leader(const char *session, pid_t *leader) { + _cleanup_free_ char *leader_string = NULL; + pid_t pid; + int r; + + assert_return(leader, -EINVAL); + + r = session_get_string(session, "LEADER", &leader_string); + if (r < 0) + return r; + + r = parse_pid(leader_string, &pid); + if (r < 0) + return r; + + *leader = pid; + return 0; +} + _public_ int sd_seat_get_active(const char *seat, char **session, uid_t *uid) { _cleanup_free_ char *p = NULL, *s = NULL, *t = NULL; int r; diff --git a/src/systemd/sd-login.h b/src/systemd/sd-login.h index 7246d9f472a..4700a76441a 100644 --- a/src/systemd/sd-login.h +++ b/src/systemd/sd-login.h @@ -184,6 +184,9 @@ int sd_session_get_desktop(const char *session, char **desktop); /* Determine the X11 display of this session. */ int sd_session_get_display(const char *session, char **display); +/* Determine the leader process of this session. */ +int sd_session_get_leader(const char *session, pid_t *leader); + /* Determine the remote host of this session. */ int sd_session_get_remote_host(const char *session, char **remote_host);