]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/sd_pid_get_owner_uid.xml
mkosi: Fix particle profile
[thirdparty/systemd.git] / man / sd_pid_get_owner_uid.xml
CommitLineData
514094f9 1<?xml version='1.0'?>
3a54a157 2<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
eea10b26 3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
db9ecf05 4<!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
0b3b020a 5
7d6b2723
ZJS
6<refentry id="sd_pid_get_owner_uid" conditional='HAVE_PAM'
7 xmlns:xi="http://www.w3.org/2001/XInclude">
0b3b020a 8
798d3a52 9 <refentryinfo>
1c97e2eb 10 <title>sd_pid_get_owner_uid</title>
798d3a52 11 <productname>systemd</productname>
798d3a52
ZJS
12 </refentryinfo>
13
14 <refmeta>
1c97e2eb 15 <refentrytitle>sd_pid_get_owner_uid</refentrytitle>
798d3a52
ZJS
16 <manvolnum>3</manvolnum>
17 </refmeta>
18
19 <refnamediv>
1c97e2eb 20 <refname>sd_pid_get_owner_uid</refname>
798d3a52 21 <refname>sd_pid_get_session</refname>
798d3a52 22 <refname>sd_pid_get_user_unit</refname>
1c97e2eb 23 <refname>sd_pid_get_unit</refname>
798d3a52
ZJS
24 <refname>sd_pid_get_machine_name</refname>
25 <refname>sd_pid_get_slice</refname>
dddbc695 26 <refname>sd_pid_get_user_slice</refname>
f5aaf575 27 <refname>sd_pid_get_cgroup</refname>
da20baae
LB
28 <refname>sd_pidfd_get_owner_uid</refname>
29 <refname>sd_pidfd_get_session</refname>
30 <refname>sd_pidfd_get_user_unit</refname>
31 <refname>sd_pidfd_get_unit</refname>
32 <refname>sd_pidfd_get_machine_name</refname>
33 <refname>sd_pidfd_get_slice</refname>
34 <refname>sd_pidfd_get_user_slice</refname>
35 <refname>sd_pidfd_get_cgroup</refname>
1c97e2eb 36 <refname>sd_peer_get_owner_uid</refname>
798d3a52 37 <refname>sd_peer_get_session</refname>
798d3a52 38 <refname>sd_peer_get_user_unit</refname>
1c97e2eb 39 <refname>sd_peer_get_unit</refname>
798d3a52
ZJS
40 <refname>sd_peer_get_machine_name</refname>
41 <refname>sd_peer_get_slice</refname>
dddbc695 42 <refname>sd_peer_get_user_slice</refname>
f5aaf575 43 <refname>sd_peer_get_cgroup</refname>
1c97e2eb
AJ
44 <refpurpose>Determine the owner uid of the user unit or session,
45 or the session, user unit, system unit, container/VM or slice that
e9dd6984 46 a specific PID or socket peer belongs to</refpurpose>
798d3a52
ZJS
47 </refnamediv>
48
49 <refsynopsisdiv>
50 <funcsynopsis>
51 <funcsynopsisinfo>#include &lt;systemd/sd-login.h&gt;</funcsynopsisinfo>
52
53 <funcprototype>
1c97e2eb 54 <funcdef>int <function>sd_pid_get_owner_uid</function></funcdef>
798d3a52 55 <paramdef>pid_t <parameter>pid</parameter></paramdef>
1c97e2eb 56 <paramdef>uid_t *<parameter>uid</parameter></paramdef>
798d3a52
ZJS
57 </funcprototype>
58
59 <funcprototype>
1c97e2eb 60 <funcdef>int <function>sd_pid_get_session</function></funcdef>
798d3a52 61 <paramdef>pid_t <parameter>pid</parameter></paramdef>
1c97e2eb 62 <paramdef>char **<parameter>session</parameter></paramdef>
798d3a52
ZJS
63 </funcprototype>
64
65 <funcprototype>
66 <funcdef>int <function>sd_pid_get_user_unit</function></funcdef>
67 <paramdef>pid_t <parameter>pid</parameter></paramdef>
68 <paramdef>char **<parameter>unit</parameter></paramdef>
69 </funcprototype>
70
71 <funcprototype>
1c97e2eb 72 <funcdef>int <function>sd_pid_get_unit</function></funcdef>
798d3a52 73 <paramdef>pid_t <parameter>pid</parameter></paramdef>
1c97e2eb 74 <paramdef>char **<parameter>unit</parameter></paramdef>
798d3a52
ZJS
75 </funcprototype>
76
77 <funcprototype>
78 <funcdef>int <function>sd_pid_get_machine_name</function></funcdef>
79 <paramdef>pid_t <parameter>pid</parameter></paramdef>
80 <paramdef>char **<parameter>name</parameter></paramdef>
81 </funcprototype>
82
83 <funcprototype>
84 <funcdef>int <function>sd_pid_get_slice</function></funcdef>
85 <paramdef>pid_t <parameter>pid</parameter></paramdef>
86 <paramdef>char **<parameter>slice</parameter></paramdef>
87 </funcprototype>
88
dddbc695
LP
89 <funcprototype>
90 <funcdef>int <function>sd_pid_get_user_slice</function></funcdef>
91 <paramdef>pid_t <parameter>pid</parameter></paramdef>
92 <paramdef>char **<parameter>slice</parameter></paramdef>
93 </funcprototype>
94
f5aaf575
LP
95 <funcprototype>
96 <funcdef>int <function>sd_pid_get_cgroup</function></funcdef>
97 <paramdef>pid_t <parameter>pid</parameter></paramdef>
98 <paramdef>char **<parameter>cgroup</parameter></paramdef>
99 </funcprototype>
100
da20baae
LB
101 <funcprototype>
102 <funcdef>int <function>sd_pidfd_get_owner_uid</function></funcdef>
103 <paramdef>int <parameter>pidfd</parameter></paramdef>
104 <paramdef>uid_t *<parameter>uid</parameter></paramdef>
105 </funcprototype>
106
107 <funcprototype>
108 <funcdef>int <function>sd_pidfd_get_session</function></funcdef>
109 <paramdef>int <parameter>pidfd</parameter></paramdef>
110 <paramdef>char **<parameter>session</parameter></paramdef>
111 </funcprototype>
112
113 <funcprototype>
114 <funcdef>int <function>sd_pidfd_get_user_unit</function></funcdef>
115 <paramdef>int <parameter>pidfd</parameter></paramdef>
116 <paramdef>char **<parameter>unit</parameter></paramdef>
117 </funcprototype>
118
119 <funcprototype>
120 <funcdef>int <function>sd_pidfd_get_unit</function></funcdef>
121 <paramdef>int <parameter>pidfd</parameter></paramdef>
122 <paramdef>char **<parameter>unit</parameter></paramdef>
123 </funcprototype>
124
125 <funcprototype>
126 <funcdef>int <function>sd_pidfd_get_machine_name</function></funcdef>
127 <paramdef>int <parameter>pidfd</parameter></paramdef>
128 <paramdef>char **<parameter>name</parameter></paramdef>
129 </funcprototype>
130
131 <funcprototype>
132 <funcdef>int <function>sd_pidfd_get_slice</function></funcdef>
133 <paramdef>int <parameter>pidfd</parameter></paramdef>
134 <paramdef>char **<parameter>slice</parameter></paramdef>
135 </funcprototype>
136
137 <funcprototype>
138 <funcdef>int <function>sd_pidfd_get_user_slice</function></funcdef>
139 <paramdef>int <parameter>pidfd</parameter></paramdef>
140 <paramdef>char **<parameter>slice</parameter></paramdef>
141 </funcprototype>
142
143 <funcprototype>
144 <funcdef>int <function>sd_pidfd_get_cgroup</function></funcdef>
145 <paramdef>int <parameter>pidfd</parameter></paramdef>
146 <paramdef>char **<parameter>cgroup</parameter></paramdef>
147 </funcprototype>
148
798d3a52 149 <funcprototype>
1c97e2eb 150 <funcdef>int <function>sd_peer_get_owner_uid</function></funcdef>
798d3a52 151 <paramdef>int <parameter>fd</parameter></paramdef>
1c97e2eb 152 <paramdef>uid_t *<parameter>uid</parameter></paramdef>
798d3a52
ZJS
153 </funcprototype>
154
155 <funcprototype>
1c97e2eb 156 <funcdef>int <function>sd_peer_get_session</function></funcdef>
798d3a52 157 <paramdef>int <parameter>fd</parameter></paramdef>
1c97e2eb 158 <paramdef>char **<parameter>session</parameter></paramdef>
798d3a52
ZJS
159 </funcprototype>
160
161 <funcprototype>
162 <funcdef>int <function>sd_peer_get_user_unit</function></funcdef>
163 <paramdef>int <parameter>fd</parameter></paramdef>
164 <paramdef>char **<parameter>unit</parameter></paramdef>
165 </funcprototype>
166
167 <funcprototype>
1c97e2eb 168 <funcdef>int <function>sd_peer_get_unit</function></funcdef>
798d3a52 169 <paramdef>int <parameter>fd</parameter></paramdef>
1c97e2eb 170 <paramdef>char **<parameter>unit</parameter></paramdef>
798d3a52
ZJS
171 </funcprototype>
172
173 <funcprototype>
174 <funcdef>int <function>sd_peer_get_machine_name</function></funcdef>
175 <paramdef>int <parameter>fd</parameter></paramdef>
176 <paramdef>char **<parameter>name</parameter></paramdef>
177 </funcprototype>
178
179 <funcprototype>
180 <funcdef>int <function>sd_peer_get_slice</function></funcdef>
181 <paramdef>int <parameter>fd</parameter></paramdef>
182 <paramdef>char **<parameter>slice</parameter></paramdef>
183 </funcprototype>
dddbc695
LP
184
185 <funcprototype>
186 <funcdef>int <function>sd_peer_get_user_slice</function></funcdef>
187 <paramdef>int <parameter>fd</parameter></paramdef>
188 <paramdef>char **<parameter>slice</parameter></paramdef>
189 </funcprototype>
f5aaf575
LP
190
191 <funcprototype>
192 <funcdef>int <function>sd_peer_get_cgroup</function></funcdef>
193 <paramdef>int <parameter>fd</parameter></paramdef>
194 <paramdef>char **<parameter>cgroup</parameter></paramdef>
195 </funcprototype>
798d3a52
ZJS
196 </funcsynopsis>
197 </refsynopsisdiv>
198
199 <refsect1>
200 <title>Description</title>
201
1c97e2eb
AJ
202 <para><function>sd_pid_get_owner_uid()</function> may be used to
203 determine the Unix UID (user identifier) which owns the login
204 session or systemd user unit of a process identified by the
205 specified PID. For processes which are not part of a login session
206 and not managed by a user manager, this function will fail with
207 <constant>-ENODATA</constant>.</para>
208
798d3a52
ZJS
209 <para><function>sd_pid_get_session()</function> may be used to
210 determine the login session identifier of a process identified by
211 the specified process identifier. The session identifier is a
1c97e2eb
AJ
212 short string, suitable for usage in file system paths. Please
213 note the login session may be limited to a stub process or two.
214 User processes may instead be started from their systemd user
215 manager, e.g. GUI applications started using DBus activation, as
216 well as service processes which are shared between multiple logins
217 of the same user. For processes which are not part of a login
218 session, this function will fail with <constant>-ENODATA</constant>.
219 The returned string needs to be freed with the libc <citerefentry
220 project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
221 call after use.</para>
222
223 <para><function>sd_pid_get_user_unit()</function> may be used to
224 determine the systemd user unit (i.e. user service or scope unit)
225 identifier of a process identified by the specified PID. The
226 unit name is a short string, suitable for usage in file system
227 paths. For processes which are not managed by a user manager, this
228 function will fail with <constant>-ENODATA</constant>. The
229 returned string needs to be freed with the libc <citerefentry
882f407f 230 project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
798d3a52
ZJS
231 call after use.</para>
232
233 <para><function>sd_pid_get_unit()</function> may be used to
dddbc695
LP
234 determine the systemd system unit (i.e. system service or scope
235 unit) identifier of a process identified by the specified PID. The
236 unit name is a short string, suitable for usage in file system
1c97e2eb
AJ
237 paths. Note that not all processes are part of a system
238 unit/service. For processes not being part of a systemd system
239 unit, this function will fail with <constant>-ENODATA</constant>.
240 (More specifically, this call will not work for kernel threads.)
241 The returned string needs to be freed with the libc <citerefentry
882f407f 242 project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
798d3a52
ZJS
243 call after use.</para>
244
798d3a52
ZJS
245 <para><function>sd_pid_get_machine_name()</function> may be used
246 to determine the name of the VM or container is a member of. The
247 machine name is a short string, suitable for usage in file system
248 paths. The returned string needs to be freed with the libc
882f407f
LP
249 <citerefentry
250 project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
1c97e2eb 251 call after use. For processes not part of a VM or container, this
ce737f46 252 function fails with <constant>-ENODATA</constant>.</para>
798d3a52
ZJS
253
254 <para><function>sd_pid_get_slice()</function> may be used to
255 determine the slice unit the process is a member of. See
256 <citerefentry><refentrytitle>systemd.slice</refentrytitle><manvolnum>5</manvolnum></citerefentry>
257 for details about slices. The returned string needs to be freed
258 with the libc
259 <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
260 call after use.</para>
261
a8eaaee7 262 <para>Similarly, <function>sd_pid_get_user_slice()</function>
dddbc695
LP
263 returns the user slice (as managed by the user's systemd instance)
264 of a process.</para>
265
f5aaf575
LP
266 <para><function>sd_pid_get_cgroup()</function> returns the control
267 group path of the specified process, relative to the root of the
268 hierarchy. Returns the path without trailing slash, except for
269 processes located in the root control group, where "/" is
b938cb90 270 returned. To find the actual control group path in the file system,
f5aaf575
LP
271 the returned path needs to be prefixed with
272 <filename>/sys/fs/cgroup/</filename> (if the unified control group
273 setup is used), or
274 <filename>/sys/fs/cgroup/<replaceable>HIERARCHY</replaceable>/</filename>
275 (if the legacy multi-hierarchy control group setup is used).</para>
276
798d3a52
ZJS
277 <para>If the <varname>pid</varname> parameter of any of these
278 functions is passed as 0, the operation is executed for the
279 calling process.</para>
280
da20baae
LB
281 <para>The <function>sd_pidfd_get_owner_uid()</function>,
282 <function>sd_pidfd_get_session()</function>,
283 <function>sd_pidfd_get_user_unit()</function>,
284 <function>sd_pidfd_get_unit()</function>,
285 <function>sd_pidfd_get_machine_name()</function>,
286 <function>sd_pidfd_get_slice()</function>,
287 <function>sd_pidfd_get_user_slice()</function> and
288 <function>sd_pidfd_get_cgroup()</function> calls operate similarly to their PID counterparts, but accept a
289 <constant>PIDFD</constant> instead of a <constant>PID</constant>, which means they are not subject to recycle
290 race conditions as the process is pinned by the file descriptor during the whole duration of the invocation.
291 Note that these require a kernel that supports <constant>PIDFD</constant>. A suitable file descriptor may be
292 acquired via
293 <citerefentry project='man-pages'><refentrytitle>pidfd_open</refentrytitle><manvolnum>2</manvolnum></citerefentry>.</para>
294
1c97e2eb
AJ
295 <para>The <function>sd_peer_get_owner_uid()</function>,
296 <function>sd_peer_get_session()</function>,
798d3a52 297 <function>sd_peer_get_user_unit()</function>,
1c97e2eb 298 <function>sd_peer_get_unit()</function>,
dddbc695 299 <function>sd_peer_get_machine_name()</function>,
f5aaf575
LP
300 <function>sd_peer_get_slice()</function>,
301 <function>sd_peer_get_user_slice()</function> and
15102ced
ZJS
302 <function>sd_peer_get_cgroup()</function> calls operate similarly to their PID counterparts, but accept a
303 connected <constant>AF_UNIX</constant> socket and retrieve information about the connected peer process.
304 Note that these fields are retrieved via <filename>/proc/</filename>, and hence are not suitable for
305 authorization purposes, as they are subject to races.</para>
798d3a52
ZJS
306 </refsect1>
307
308 <refsect1>
309 <title>Return Value</title>
310
b1de39de
ZJS
311 <para>On success, these calls return 0 or a positive integer. On failure, these calls return a negative
312 errno-style error code.</para>
798d3a52 313
b1de39de
ZJS
314 <refsect2>
315 <title>Errors</title>
882f407f 316
b1de39de 317 <para>Returned errors may indicate the following problems:</para>
882f407f 318
b1de39de 319 <variablelist>
882f407f 320
b1de39de
ZJS
321 <varlistentry>
322 <term><constant>-ESRCH</constant></term>
707b66c6 323
b1de39de
ZJS
324 <listitem><para>The specified PID does not refer to a running process.</para>
325 </listitem>
326 </varlistentry>
707b66c6 327
b1de39de
ZJS
328 <varlistentry>
329 <term><constant>-EBADF</constant></term>
707b66c6 330
b1de39de
ZJS
331 <listitem><para>The specified socket file descriptor was invalid.</para></listitem>
332 </varlistentry>
707b66c6 333
b1de39de
ZJS
334 <varlistentry>
335 <term><constant>-ENODATA</constant></term>
882f407f 336
b1de39de
ZJS
337 <listitem><para>The given field is not specified for the described process or peer.</para>
338 </listitem>
339 </varlistentry>
882f407f 340
b1de39de
ZJS
341 <varlistentry>
342 <term><constant>-EINVAL</constant></term>
882f407f 343
b1de39de
ZJS
344 <listitem><para>An input parameter was invalid (out of range, or <constant>NULL</constant>, where
345 that is not accepted).</para></listitem>
346 </varlistentry>
882f407f 347
b1de39de
ZJS
348 <varlistentry>
349 <term><constant>-ENOMEM</constant></term>
882f407f 350
b1de39de
ZJS
351 <listitem><para>Memory allocation failed.</para></listitem>
352 </varlistentry>
353 </variablelist>
354 </refsect2>
882f407f
LP
355 </refsect1>
356
798d3a52
ZJS
357 <refsect1>
358 <title>Notes</title>
359
7d6b2723 360 <xi:include href="libsystemd-pkgconfig.xml" xpointer="pkgconfig-text"/>
798d3a52
ZJS
361
362 <para>Note that the login session identifier as
363 returned by <function>sd_pid_get_session()</function>
364 is completely unrelated to the process session
365 identifier as returned by
366 <citerefentry><refentrytitle>getsid</refentrytitle><manvolnum>2</manvolnum></citerefentry>.</para>
367 </refsect1>
368
69106f47
AK
369 <refsect1>
370 <title>History</title>
8074a036
AK
371 <para><function>sd_peer_get_cgroup()</function>,
372 <function>sd_peer_get_machine_name()</function>,
373 <function>sd_peer_get_owner_uid()</function>,
374 <function>sd_peer_get_session()</function>,
375 <function>sd_peer_get_slice()</function>,
376 <function>sd_peer_get_unit()</function>,
377 <function>sd_peer_get_user_slice()</function>,
378 <function>sd_peer_get_user_unit()</function>,
379 <function>sd_pid_get_cgroup()</function>,
380 <function>sd_pid_get_machine_name()</function>,
381 <function>sd_pid_get_owner_uid()</function>,
00f95506 382 <function>sd_pid_get_session()</function>,
8074a036 383 <function>sd_pid_get_slice()</function>,
00f95506 384 <function>sd_pid_get_unit()</function>,
8074a036
AK
385 <function>sd_pid_get_user_slice()</function>, and
386 <function>sd_pid_get_user_unit()</function> were added in version 236.</para>
00f95506
AK
387 <para><function>sd_pidfd_get_owner_uid()</function>,
388 <function>sd_pidfd_get_session()</function>,
389 <function>sd_pidfd_get_user_unit()</function>,
390 <function>sd_pidfd_get_unit()</function>,
391 <function>sd_pidfd_get_machine_name()</function>,
392 <function>sd_pidfd_get_slice()</function>,
393 <function>sd_pidfd_get_user_slice()</function>, and
394 <function>sd_pidfd_get_cgroup()</function> were added in version 253.</para>
69106f47
AK
395 </refsect1>
396
798d3a52
ZJS
397 <refsect1>
398 <title>See Also</title>
399
13a69c12
DT
400 <para><simplelist type="inline">
401 <member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member>
402 <member><citerefentry><refentrytitle>sd-login</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
403 <member><citerefentry><refentrytitle>sd_session_is_active</refentrytitle><manvolnum>3</manvolnum></citerefentry></member>
404 <member><citerefentry><refentrytitle>getsid</refentrytitle><manvolnum>2</manvolnum></citerefentry></member>
405 <member><citerefentry><refentrytitle>systemd.slice</refentrytitle><manvolnum>5</manvolnum></citerefentry></member>
406 <member><citerefentry><refentrytitle>systemd-machined.service</refentrytitle><manvolnum>8</manvolnum></citerefentry></member>
407 </simplelist></para>
798d3a52 408 </refsect1>
0b3b020a
LP
409
410</refentry>