diff --git a/man/sd_session_is_active.xml b/man/sd_session_is_active.xml
index a3cc9befe8..8639599ecc 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 936a3577f5..ea13e02719 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 c5d54bbf74..4d09b15653 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 7246d9f472..4700a76441 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);