sd-login: add sd_pidfd_* APIs

Same as the sd_pid_* counterparts, but take a pid file descriptor instead of
a pid, so that the callers can be sure that the returned values are really
about the process they asked for, and not about a recycled PID.
This commit is contained in:
Luca Boccassi
2023-01-20 12:18:05 +00:00
parent f840c7d58d
commit da20baaecc
6 changed files with 332 additions and 1 deletions
+9 -1
View File
@@ -815,7 +815,15 @@ manpages = [
'sd_pid_get_slice',
'sd_pid_get_unit',
'sd_pid_get_user_slice',
'sd_pid_get_user_unit'],
'sd_pid_get_user_unit',
'sd_pidfd_get_cgroup',
'sd_pidfd_get_machine_name',
'sd_pidfd_get_owner_uid',
'sd_pidfd_get_session',
'sd_pidfd_get_slice',
'sd_pidfd_get_unit',
'sd_pidfd_get_user_slice',
'sd_pidfd_get_user_unit'],
'HAVE_PAM'],
['sd_seat_get_active',
'3',
+70
View File
@@ -25,6 +25,14 @@
<refname>sd_pid_get_slice</refname>
<refname>sd_pid_get_user_slice</refname>
<refname>sd_pid_get_cgroup</refname>
<refname>sd_pidfd_get_owner_uid</refname>
<refname>sd_pidfd_get_session</refname>
<refname>sd_pidfd_get_user_unit</refname>
<refname>sd_pidfd_get_unit</refname>
<refname>sd_pidfd_get_machine_name</refname>
<refname>sd_pidfd_get_slice</refname>
<refname>sd_pidfd_get_user_slice</refname>
<refname>sd_pidfd_get_cgroup</refname>
<refname>sd_peer_get_owner_uid</refname>
<refname>sd_peer_get_session</refname>
<refname>sd_peer_get_user_unit</refname>
@@ -90,6 +98,54 @@
<paramdef>char **<parameter>cgroup</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>sd_pidfd_get_owner_uid</function></funcdef>
<paramdef>int <parameter>pidfd</parameter></paramdef>
<paramdef>uid_t *<parameter>uid</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>sd_pidfd_get_session</function></funcdef>
<paramdef>int <parameter>pidfd</parameter></paramdef>
<paramdef>char **<parameter>session</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>sd_pidfd_get_user_unit</function></funcdef>
<paramdef>int <parameter>pidfd</parameter></paramdef>
<paramdef>char **<parameter>unit</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>sd_pidfd_get_unit</function></funcdef>
<paramdef>int <parameter>pidfd</parameter></paramdef>
<paramdef>char **<parameter>unit</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>sd_pidfd_get_machine_name</function></funcdef>
<paramdef>int <parameter>pidfd</parameter></paramdef>
<paramdef>char **<parameter>name</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>sd_pidfd_get_slice</function></funcdef>
<paramdef>int <parameter>pidfd</parameter></paramdef>
<paramdef>char **<parameter>slice</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>sd_pidfd_get_user_slice</function></funcdef>
<paramdef>int <parameter>pidfd</parameter></paramdef>
<paramdef>char **<parameter>slice</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>sd_pidfd_get_cgroup</function></funcdef>
<paramdef>int <parameter>pidfd</parameter></paramdef>
<paramdef>char **<parameter>cgroup</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>sd_peer_get_owner_uid</function></funcdef>
<paramdef>int <parameter>fd</parameter></paramdef>
@@ -222,6 +278,20 @@
functions is passed as 0, the operation is executed for the
calling process.</para>
<para>The <function>sd_pidfd_get_owner_uid()</function>,
<function>sd_pidfd_get_session()</function>,
<function>sd_pidfd_get_user_unit()</function>,
<function>sd_pidfd_get_unit()</function>,
<function>sd_pidfd_get_machine_name()</function>,
<function>sd_pidfd_get_slice()</function>,
<function>sd_pidfd_get_user_slice()</function> and
<function>sd_pidfd_get_cgroup()</function> calls operate similarly to their PID counterparts, but accept a
<constant>PIDFD</constant> instead of a <constant>PID</constant>, which means they are not subject to recycle
race conditions as the process is pinned by the file descriptor during the whole duration of the invocation.
Note that these require a kernel that supports <constant>PIDFD</constant>. A suitable file descriptor may be
acquired via
<citerefentry project='man-pages'><refentrytitle>pidfd_open</refentrytitle><manvolnum>2</manvolnum></citerefentry>.</para>
<para>The <function>sd_peer_get_owner_uid()</function>,
<function>sd_peer_get_session()</function>,
<function>sd_peer_get_user_unit()</function>,