Debian Codegraph @

upstream/debian-trixie/man3/sd_pid_get_owner_uid.3

raw
1 '\" t
2 .TH "SD_PID_GET_OWNER_UID" "3" "" "systemd 257.13" "sd_pid_get_owner_uid"
3 .\" -----------------------------------------------------------------
4 .\" * Define some portability stuff
5 .\" -----------------------------------------------------------------
6 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 .\" http://bugs.debian.org/507673
8 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
9 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 .ie \n(.g .ds Aq \(aq
11 .el .ds Aq '
12 .\" -----------------------------------------------------------------
13 .\" * set default formatting
14 .\" -----------------------------------------------------------------
15 .\" disable hyphenation
16 .nh
17 .\" disable justification (adjust text to left margin only)
18 .ad l
19 .\" -----------------------------------------------------------------
20 .\" * MAIN CONTENT STARTS HERE *
21 .\" -----------------------------------------------------------------
22 .SH "NAME"
23 sd_pid_get_owner_uid, sd_pid_get_session, sd_pid_get_user_unit, sd_pid_get_unit, sd_pid_get_machine_name, sd_pid_get_slice, sd_pid_get_user_slice, sd_pid_get_cgroup, sd_pidfd_get_owner_uid, sd_pidfd_get_session, sd_pidfd_get_user_unit, sd_pidfd_get_unit, sd_pidfd_get_machine_name, sd_pidfd_get_slice, sd_pidfd_get_user_slice, sd_pidfd_get_cgroup, sd_peer_get_owner_uid, sd_peer_get_session, sd_peer_get_user_unit, sd_peer_get_unit, sd_peer_get_machine_name, sd_peer_get_slice, sd_peer_get_user_slice, sd_peer_get_cgroup \- Determine the owner uid of the user unit or session, or the session, user unit, system unit, container/VM or slice that a specific PID or socket peer belongs to
24 .SH "SYNOPSIS"
25 .sp
26 .ft B
27 .nf
28 #include <systemd/sd\-login\&.h>
29 .fi
30 .ft
31 .HP \w'int\ sd_pid_get_owner_uid('u
32 .BI "int sd_pid_get_owner_uid(pid_t\ " "pid" ", uid_t\ *" "uid" ");"
33 .HP \w'int\ sd_pid_get_session('u
34 .BI "int sd_pid_get_session(pid_t\ " "pid" ", char\ **" "session" ");"
35 .HP \w'int\ sd_pid_get_user_unit('u
36 .BI "int sd_pid_get_user_unit(pid_t\ " "pid" ", char\ **" "unit" ");"
37 .HP \w'int\ sd_pid_get_unit('u
38 .BI "int sd_pid_get_unit(pid_t\ " "pid" ", char\ **" "unit" ");"
39 .HP \w'int\ sd_pid_get_machine_name('u
40 .BI "int sd_pid_get_machine_name(pid_t\ " "pid" ", char\ **" "name" ");"
41 .HP \w'int\ sd_pid_get_slice('u
42 .BI "int sd_pid_get_slice(pid_t\ " "pid" ", char\ **" "slice" ");"
43 .HP \w'int\ sd_pid_get_user_slice('u
44 .BI "int sd_pid_get_user_slice(pid_t\ " "pid" ", char\ **" "slice" ");"
45 .HP \w'int\ sd_pid_get_cgroup('u
46 .BI "int sd_pid_get_cgroup(pid_t\ " "pid" ", char\ **" "cgroup" ");"
47 .HP \w'int\ sd_pidfd_get_owner_uid('u
48 .BI "int sd_pidfd_get_owner_uid(int\ " "pidfd" ", uid_t\ *" "uid" ");"
49 .HP \w'int\ sd_pidfd_get_session('u
50 .BI "int sd_pidfd_get_session(int\ " "pidfd" ", char\ **" "session" ");"
51 .HP \w'int\ sd_pidfd_get_user_unit('u
52 .BI "int sd_pidfd_get_user_unit(int\ " "pidfd" ", char\ **" "unit" ");"
53 .HP \w'int\ sd_pidfd_get_unit('u
54 .BI "int sd_pidfd_get_unit(int\ " "pidfd" ", char\ **" "unit" ");"
55 .HP \w'int\ sd_pidfd_get_machine_name('u
56 .BI "int sd_pidfd_get_machine_name(int\ " "pidfd" ", char\ **" "name" ");"
57 .HP \w'int\ sd_pidfd_get_slice('u
58 .BI "int sd_pidfd_get_slice(int\ " "pidfd" ", char\ **" "slice" ");"
59 .HP \w'int\ sd_pidfd_get_user_slice('u
60 .BI "int sd_pidfd_get_user_slice(int\ " "pidfd" ", char\ **" "slice" ");"
61 .HP \w'int\ sd_pidfd_get_cgroup('u
62 .BI "int sd_pidfd_get_cgroup(int\ " "pidfd" ", char\ **" "cgroup" ");"
63 .HP \w'int\ sd_peer_get_owner_uid('u
64 .BI "int sd_peer_get_owner_uid(int\ " "fd" ", uid_t\ *" "uid" ");"
65 .HP \w'int\ sd_peer_get_session('u
66 .BI "int sd_peer_get_session(int\ " "fd" ", char\ **" "session" ");"
67 .HP \w'int\ sd_peer_get_user_unit('u
68 .BI "int sd_peer_get_user_unit(int\ " "fd" ", char\ **" "unit" ");"
69 .HP \w'int\ sd_peer_get_unit('u
70 .BI "int sd_peer_get_unit(int\ " "fd" ", char\ **" "unit" ");"
71 .HP \w'int\ sd_peer_get_machine_name('u
72 .BI "int sd_peer_get_machine_name(int\ " "fd" ", char\ **" "name" ");"
73 .HP \w'int\ sd_peer_get_slice('u
74 .BI "int sd_peer_get_slice(int\ " "fd" ", char\ **" "slice" ");"
75 .HP \w'int\ sd_peer_get_user_slice('u
76 .BI "int sd_peer_get_user_slice(int\ " "fd" ", char\ **" "slice" ");"
77 .HP \w'int\ sd_peer_get_cgroup('u
78 .BI "int sd_peer_get_cgroup(int\ " "fd" ", char\ **" "cgroup" ");"
79 .SH "DESCRIPTION"
80 .PP
81 \fBsd_pid_get_owner_uid()\fR
82 may be used to determine the Unix UID (user identifier) which owns the login session or systemd user unit of a process identified by the specified PID\&. For processes which are not part of a login session and not managed by a user manager, this function will fail with
83 \fB\-ENODATA\fR\&.
84 .PP
85 \fBsd_pid_get_session()\fR
86 may be used to determine the login session identifier of a process identified by the specified process identifier\&. The session identifier is a short string, suitable for usage in file system paths\&. Please note the login session may be limited to a stub process or two\&. User processes may instead be started from their systemd user manager, e\&.g\&. GUI applications started using DBus activation, as well as service processes which are shared between multiple logins of the same user\&. For processes which are not part of a login session, this function will fail with
87 \fB\-ENODATA\fR\&. The returned string needs to be freed with the libc
88 \fBfree\fR(3)
89 call after use\&.
90 .PP
91 \fBsd_pid_get_user_unit()\fR
92 may be used to determine the systemd user unit (i\&.e\&. user service or scope unit) identifier of a process identified by the specified PID\&. The unit name is a short string, suitable for usage in file system paths\&. For processes which are not managed by a user manager, this function will fail with
93 \fB\-ENODATA\fR\&. The returned string needs to be freed with the libc
94 \fBfree\fR(3)
95 call after use\&.
96 .PP
97 \fBsd_pid_get_unit()\fR
98 may be used to determine the systemd system unit (i\&.e\&. system service or scope unit) identifier of a process identified by the specified PID\&. The unit name is a short string, suitable for usage in file system paths\&. Note that not all processes are part of a system unit/service\&. For processes not being part of a systemd system unit, this function will fail with
99 \fB\-ENODATA\fR\&. (More specifically, this call will not work for kernel threads\&.) The returned string needs to be freed with the libc
100 \fBfree\fR(3)
101 call after use\&.
102 .PP
103 \fBsd_pid_get_machine_name()\fR
104 may be used to determine the name of the VM or container is a member of\&. The machine name is a short string, suitable for usage in file system paths\&. The returned string needs to be freed with the libc
105 \fBfree\fR(3)
106 call after use\&. For processes not part of a VM or container, this function fails with
107 \fB\-ENODATA\fR\&.
108 .PP
109 \fBsd_pid_get_slice()\fR
110 may be used to determine the slice unit the process is a member of\&. See
111 \fBsystemd.slice\fR(5)
112 for details about slices\&. The returned string needs to be freed with the libc
113 \fBfree\fR(3)
114 call after use\&.
115 .PP
116 Similarly,
117 \fBsd_pid_get_user_slice()\fR
118 returns the user slice (as managed by the user\*(Aqs systemd instance) of a process\&.
119 .PP
120 \fBsd_pid_get_cgroup()\fR
121 returns the control group path of the specified process, relative to the root of the hierarchy\&. Returns the path without trailing slash, except for processes located in the root control group, where "/" is returned\&. To find the actual control group path in the file system, the returned path needs to be prefixed with
122 /sys/fs/cgroup/
123 (if the unified control group setup is used), or
124 /sys/fs/cgroup/\fIHIERARCHY\fR/
125 (if the legacy multi\-hierarchy control group setup is used)\&.
126 .PP
127 If the
128 \fIpid\fR
129 parameter of any of these functions is passed as 0, the operation is executed for the calling process\&.
130 .PP
131 The
132 \fBsd_pidfd_get_owner_uid()\fR,
133 \fBsd_pidfd_get_session()\fR,
134 \fBsd_pidfd_get_user_unit()\fR,
135 \fBsd_pidfd_get_unit()\fR,
136 \fBsd_pidfd_get_machine_name()\fR,
137 \fBsd_pidfd_get_slice()\fR,
138 \fBsd_pidfd_get_user_slice()\fR
139 and
140 \fBsd_pidfd_get_cgroup()\fR
141 calls operate similarly to their PID counterparts, but accept a
142 \fBPIDFD\fR
143 instead of a
144 \fBPID\fR, 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
145 \fBPIDFD\fR\&. A suitable file descriptor may be acquired via
146 \fBpidfd_open\fR(2)\&.
147 .PP
148 The
149 \fBsd_peer_get_owner_uid()\fR,
150 \fBsd_peer_get_session()\fR,
151 \fBsd_peer_get_user_unit()\fR,
152 \fBsd_peer_get_unit()\fR,
153 \fBsd_peer_get_machine_name()\fR,
154 \fBsd_peer_get_slice()\fR,
155 \fBsd_peer_get_user_slice()\fR
156 and
157 \fBsd_peer_get_cgroup()\fR
158 calls operate similarly to their PID counterparts, but accept a connected
159 \fBAF_UNIX\fR
160 socket and retrieve information about the connected peer process\&. Note that these fields are retrieved via
161 /proc/, and hence are not suitable for authorization purposes, as they are subject to races\&.
162 .SH "RETURN VALUE"
163 .PP
164 On success, these calls return 0 or a positive integer\&. On failure, these calls return a negative errno\-style error code\&.
165 .SS "Errors"
166 .PP
167 Returned errors may indicate the following problems:
168 .PP
169 \fB\-ESRCH\fR
170 .RS 4
171 The specified PID does not refer to a running process\&.
172 .RE
173 .PP
174 \fB\-EBADF\fR
175 .RS 4
176 The specified socket file descriptor was invalid\&.
177 .RE
178 .PP
179 \fB\-ENODATA\fR
180 .RS 4
181 The given field is not specified for the described process or peer\&.
182 .RE
183 .PP
184 \fB\-EINVAL\fR
185 .RS 4
186 An input parameter was invalid (out of range, or
187 \fBNULL\fR, where that is not accepted)\&.
188 .RE
189 .PP
190 \fB\-ENOMEM\fR
191 .RS 4
192 Memory allocation failed\&.
193 .RE
194 .SH "NOTES"
195 .PP
196 Functions described here are available as a shared library, which can be compiled against and linked to with the
197 \fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
198 file\&.
199 .PP
200 Note that the login session identifier as returned by
201 \fBsd_pid_get_session()\fR
202 is completely unrelated to the process session identifier as returned by
203 \fBgetsid\fR(2)\&.
204 .SH "HISTORY"
205 .PP
206 \fBsd_peer_get_cgroup()\fR,
207 \fBsd_peer_get_machine_name()\fR,
208 \fBsd_peer_get_owner_uid()\fR,
209 \fBsd_peer_get_session()\fR,
210 \fBsd_peer_get_slice()\fR,
211 \fBsd_peer_get_unit()\fR,
212 \fBsd_peer_get_user_slice()\fR,
213 \fBsd_peer_get_user_unit()\fR,
214 \fBsd_pid_get_cgroup()\fR,
215 \fBsd_pid_get_machine_name()\fR,
216 \fBsd_pid_get_owner_uid()\fR,
217 \fBsd_pid_get_session()\fR,
218 \fBsd_pid_get_slice()\fR,
219 \fBsd_pid_get_unit()\fR,
220 \fBsd_pid_get_user_slice()\fR, and
221 \fBsd_pid_get_user_unit()\fR
222 were added in version 236\&.
223 .PP
224 \fBsd_pidfd_get_owner_uid()\fR,
225 \fBsd_pidfd_get_session()\fR,
226 \fBsd_pidfd_get_user_unit()\fR,
227 \fBsd_pidfd_get_unit()\fR,
228 \fBsd_pidfd_get_machine_name()\fR,
229 \fBsd_pidfd_get_slice()\fR,
230 \fBsd_pidfd_get_user_slice()\fR, and
231 \fBsd_pidfd_get_cgroup()\fR
232 were added in version 253\&.
233 .SH "SEE ALSO"
234 .PP
235 \fBsystemd\fR(1), \fBsd-login\fR(3), \fBsd_session_is_active\fR(3), \fBgetsid\fR(2), \fBsystemd.slice\fR(5), \fBsystemd-machined.service\fR(8)