sd-login: add sd_session_get_leader interface

This commit is contained in:
Thorsten Kukuk
2023-06-06 14:52:22 +02:00
committed by Luca Boccassi
parent 3fa3d612a2
commit 403082602d
4 changed files with 35 additions and 0 deletions

View File

@@ -33,6 +33,7 @@
<refname>sd_session_get_vt</refname>
<refname>sd_session_get_remote_host</refname>
<refname>sd_session_get_remote_user</refname>
<refname>sd_session_get_leader</refname>
<refpurpose>Determine state of a specific session</refpurpose>
</refnamediv>
@@ -110,6 +111,12 @@
<paramdef>char **<parameter>display</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>sd_session_get_leader</function></funcdef>
<paramdef>const char *<parameter>session</parameter></paramdef>
<paramdef>pid_t *<parameter>leader</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>sd_session_get_remote_host</function></funcdef>
<paramdef>const char *<parameter>session</parameter></paramdef>
@@ -236,6 +243,10 @@
<citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
call after use.</para>
<para><function>sd_session_get_leader()</function> may be used to
determine the PID of the leader of the session identified by the
specified session identifier.</para>
<para><function>sd_session_get_remote_host()</function> 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 @@
<function>sd_session_get_type()</function>,
<function>sd_session_get_class()</function>,
<function>sd_session_get_display()</function>,
<function>sd_session_get_leader()</function>,
<function>sd_session_get_remote_user()</function>,
<function>sd_session_get_remote_host()</function> and
<function>sd_session_get_tty()</function> return 0 or

View File

@@ -826,4 +826,5 @@ global:
sd_pid_notify_barrier;
sd_event_source_leave_ratelimit;
sd_journal_step_one;
sd_session_get_leader;
} LIBSYSTEMD_253;

View File

@@ -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;

View File

@@ -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);