Debian Codegraph @

upstream/debian-unstable/man3/sd_pid_get_owner_uid.3

raw
1 '\" t
2 .TH "SD_PID_GET_OWNER_UID" "3" "" "systemd 261~rc3" "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 .PP
124 If the
125 \fIpid\fR
126 parameter of any of these functions is passed as 0, the operation is executed for the calling process\&.
127 .PP
128 The
129 \fBsd_pidfd_get_owner_uid()\fR,
130 \fBsd_pidfd_get_session()\fR,
131 \fBsd_pidfd_get_user_unit()\fR,
132 \fBsd_pidfd_get_unit()\fR,
133 \fBsd_pidfd_get_machine_name()\fR,
134 \fBsd_pidfd_get_slice()\fR,
135 \fBsd_pidfd_get_user_slice()\fR
136 and
137 \fBsd_pidfd_get_cgroup()\fR
138 calls operate similarly to their PID counterparts, but accept a
139 \fBPIDFD\fR
140 instead of a
141 \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
142 \fBPIDFD\fR\&. A suitable file descriptor may be acquired via
143 \fBpidfd_open\fR(2)\&.
144 .PP
145 The
146 \fBsd_peer_get_owner_uid()\fR,
147 \fBsd_peer_get_session()\fR,
148 \fBsd_peer_get_user_unit()\fR,
149 \fBsd_peer_get_unit()\fR,
150 \fBsd_peer_get_machine_name()\fR,
151 \fBsd_peer_get_slice()\fR,
152 \fBsd_peer_get_user_slice()\fR
153 and
154 \fBsd_peer_get_cgroup()\fR
155 calls operate similarly to their PID counterparts, but accept a connected
156 \fBAF_UNIX\fR
157 socket and retrieve information about the connected peer process\&. Note that these fields are retrieved via
158 /proc/, and hence are not suitable for authorization purposes, as they are subject to races\&.
159 .SH "RETURN VALUE"
160 .PP
161 On success, these calls return 0 or a positive integer\&. On failure, these calls return a negative errno\-style error code\&.
162 .SS "Errors"
163 .PP
164 Returned errors may indicate the following problems:
165 .PP
166 \fB\-ESRCH\fR
167 .RS 4
168 The specified PID does not refer to a running process\&.
169 .RE
170 .PP
171 \fB\-EBADF\fR
172 .RS 4
173 The specified file descriptor is invalid\&.
174 .RE
175 .PP
176 \fB\-ENODATA\fR
177 .RS 4
178 The given field is not specified for the described process or peer\&.
179 .RE
180 .PP
181 \fB\-EINVAL\fR
182 .RS 4
183 An input parameter was invalid (out of range, or
184 \fBNULL\fR, where that is not accepted)\&.
185 .RE
186 .PP
187 \fB\-ENOMEM\fR
188 .RS 4
189 Memory allocation failed\&.
190 .RE
191 .SH "NOTES"
192 .PP
193 Functions described here are available as a shared library, which can be compiled against and linked to with the
194 \fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
195 file\&.
196 .PP
197 Note that the login session identifier as returned by
198 \fBsd_pid_get_session()\fR
199 is completely unrelated to the process session identifier as returned by
200 \fBgetsid\fR(2)\&.
201 .SH "HISTORY"
202 .PP
203 \fBsd_peer_get_cgroup()\fR,
204 \fBsd_peer_get_machine_name()\fR,
205 \fBsd_peer_get_owner_uid()\fR,
206 \fBsd_peer_get_session()\fR,
207 \fBsd_peer_get_slice()\fR,
208 \fBsd_peer_get_unit()\fR,
209 \fBsd_peer_get_user_slice()\fR,
210 \fBsd_peer_get_user_unit()\fR,
211 \fBsd_pid_get_cgroup()\fR,
212 \fBsd_pid_get_machine_name()\fR,
213 \fBsd_pid_get_owner_uid()\fR,
214 \fBsd_pid_get_session()\fR,
215 \fBsd_pid_get_slice()\fR,
216 \fBsd_pid_get_unit()\fR,
217 \fBsd_pid_get_user_slice()\fR, and
218 \fBsd_pid_get_user_unit()\fR
219 were added in version 236\&.
220 .PP
221 \fBsd_pidfd_get_owner_uid()\fR,
222 \fBsd_pidfd_get_session()\fR,
223 \fBsd_pidfd_get_user_unit()\fR,
224 \fBsd_pidfd_get_unit()\fR,
225 \fBsd_pidfd_get_machine_name()\fR,
226 \fBsd_pidfd_get_slice()\fR,
227 \fBsd_pidfd_get_user_slice()\fR, and
228 \fBsd_pidfd_get_cgroup()\fR
229 were added in version 253\&.
230 .SH "SEE ALSO"
231 .PP
232 \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)