1SD_PID_GET_OWNER_UID(3)      sd_pid_get_owner_uid      SD_PID_GET_OWNER_UID(3)
2
3
4

NAME

6       sd_pid_get_owner_uid, sd_pid_get_session, sd_pid_get_user_unit,
7       sd_pid_get_unit, sd_pid_get_machine_name, sd_pid_get_slice,
8       sd_pid_get_user_slice, sd_pid_get_cgroup, sd_pidfd_get_owner_uid,
9       sd_pidfd_get_session, sd_pidfd_get_user_unit, sd_pidfd_get_unit,
10       sd_pidfd_get_machine_name, sd_pidfd_get_slice, sd_pidfd_get_user_slice,
11       sd_pidfd_get_cgroup, sd_peer_get_owner_uid, sd_peer_get_session,
12       sd_peer_get_user_unit, sd_peer_get_unit, sd_peer_get_machine_name,
13       sd_peer_get_slice, sd_peer_get_user_slice, sd_peer_get_cgroup -
14       Determine the owner uid of the user unit or session, or the session,
15       user unit, system unit, container/VM or slice that a specific PID or
16       socket peer belongs to
17

SYNOPSIS

19       #include <systemd/sd-login.h>
20
21       int sd_pid_get_owner_uid(pid_t pid, uid_t *uid);
22
23       int sd_pid_get_session(pid_t pid, char **session);
24
25       int sd_pid_get_user_unit(pid_t pid, char **unit);
26
27       int sd_pid_get_unit(pid_t pid, char **unit);
28
29       int sd_pid_get_machine_name(pid_t pid, char **name);
30
31       int sd_pid_get_slice(pid_t pid, char **slice);
32
33       int sd_pid_get_user_slice(pid_t pid, char **slice);
34
35       int sd_pid_get_cgroup(pid_t pid, char **cgroup);
36
37       int sd_pidfd_get_owner_uid(int pidfd, uid_t *uid);
38
39       int sd_pidfd_get_session(int pidfd, char **session);
40
41       int sd_pidfd_get_user_unit(int pidfd, char **unit);
42
43       int sd_pidfd_get_unit(int pidfd, char **unit);
44
45       int sd_pidfd_get_machine_name(int pidfd, char **name);
46
47       int sd_pidfd_get_slice(int pidfd, char **slice);
48
49       int sd_pidfd_get_user_slice(int pidfd, char **slice);
50
51       int sd_pidfd_get_cgroup(int pidfd, char **cgroup);
52
53       int sd_peer_get_owner_uid(int fd, uid_t *uid);
54
55       int sd_peer_get_session(int fd, char **session);
56
57       int sd_peer_get_user_unit(int fd, char **unit);
58
59       int sd_peer_get_unit(int fd, char **unit);
60
61       int sd_peer_get_machine_name(int fd, char **name);
62
63       int sd_peer_get_slice(int fd, char **slice);
64
65       int sd_peer_get_user_slice(int fd, char **slice);
66
67       int sd_peer_get_cgroup(int fd, char **cgroup);
68

DESCRIPTION

70       sd_pid_get_owner_uid() may be used to determine the Unix UID (user
71       identifier) which owns the login session or systemd user unit of a
72       process identified by the specified PID. For processes which are not
73       part of a login session and not managed by a user manager, this
74       function will fail with -ENODATA.
75
76       sd_pid_get_session() may be used to determine the login session
77       identifier of a process identified by the specified process identifier.
78       The session identifier is a short string, suitable for usage in file
79       system paths. Please note the login session may be limited to a stub
80       process or two. User processes may instead be started from their
81       systemd user manager, e.g. GUI applications started using DBus
82       activation, as well as service processes which are shared between
83       multiple logins of the same user. For processes which are not part of a
84       login session, this function will fail with -ENODATA. The returned
85       string needs to be freed with the libc free(3) call after use.
86
87       sd_pid_get_user_unit() may be used to determine the systemd user unit
88       (i.e. user service or scope unit) identifier of a process identified by
89       the specified PID. The unit name is a short string, suitable for usage
90       in file system paths. For processes which are not managed by a user
91       manager, this function will fail with -ENODATA. The returned string
92       needs to be freed with the libc free(3) call after use.
93
94       sd_pid_get_unit() may be used to determine the systemd system unit
95       (i.e. system service or scope unit) identifier of a process identified
96       by the specified PID. The unit name is a short string, suitable for
97       usage in file system paths. Note that not all processes are part of a
98       system unit/service. For processes not being part of a systemd system
99       unit, this function will fail with -ENODATA. (More specifically, this
100       call will not work for kernel threads.) The returned string needs to be
101       freed with the libc free(3) call after use.
102
103       sd_pid_get_machine_name() may be used to determine the name of the VM
104       or container is a member of. The machine name is a short string,
105       suitable for usage in file system paths. The returned string needs to
106       be freed with the libc free(3) call after use. For processes not part
107       of a VM or container, this function fails with -ENODATA.
108
109       sd_pid_get_slice() may be used to determine the slice unit the process
110       is a member of. See systemd.slice(5) for details about slices. The
111       returned string needs to be freed with the libc free(3) call after use.
112
113       Similarly, sd_pid_get_user_slice() returns the user slice (as managed
114       by the user's systemd instance) of a process.
115
116       sd_pid_get_cgroup() returns the control group path of the specified
117       process, relative to the root of the hierarchy. Returns the path
118       without trailing slash, except for processes located in the root
119       control group, where "/" is returned. To find the actual control group
120       path in the file system, the returned path needs to be prefixed with
121       /sys/fs/cgroup/ (if the unified control group setup is used), or
122       /sys/fs/cgroup/HIERARCHY/ (if the legacy multi-hierarchy control group
123       setup is used).
124
125       If the pid parameter of any of these functions is passed as 0, the
126       operation is executed for the calling process.
127
128       The sd_pidfd_get_owner_uid(), sd_pidfd_get_session(),
129       sd_pidfd_get_user_unit(), sd_pidfd_get_unit(),
130       sd_pidfd_get_machine_name(), sd_pidfd_get_slice(),
131       sd_pidfd_get_user_slice() and sd_pidfd_get_cgroup() calls operate
132       similarly to their PID counterparts, but accept a PIDFD instead of a
133       PID, which means they are not subject to recycle race conditions as the
134       process is pinned by the file descriptor during the whole duration of
135       the invocation. Note that these require a kernel that supports PIDFD. A
136       suitable file descriptor may be acquired via pidfd_open(2).
137
138       The sd_peer_get_owner_uid(), sd_peer_get_session(),
139       sd_peer_get_user_unit(), sd_peer_get_unit(),
140       sd_peer_get_machine_name(), sd_peer_get_slice(),
141       sd_peer_get_user_slice() and sd_peer_get_cgroup() calls operate
142       similarly to their PID counterparts, but accept a connected AF_UNIX
143       socket and retrieve information about the connected peer process. Note
144       that these fields are retrieved via /proc/, and hence are not suitable
145       for authorization purposes, as they are subject to races.
146

RETURN VALUE

148       On success, these calls return 0 or a positive integer. On failure,
149       these calls return a negative errno-style error code.
150
151   Errors
152       Returned errors may indicate the following problems:
153
154       -ESRCH
155           The specified PID does not refer to a running process.
156
157       -EBADF
158           The specified socket file descriptor was invalid.
159
160       -ENODATA
161           The given field is not specified for the described process or peer.
162
163       -EINVAL
164           An input parameter was invalid (out of range, or NULL, where that
165           is not accepted).
166
167       -ENOMEM
168           Memory allocation failed.
169

NOTES

171       Functions described here are available as a shared library, which can
172       be compiled against and linked to with the libsystemd pkg-config(1)
173       file.
174
175       Note that the login session identifier as returned by
176       sd_pid_get_session() is completely unrelated to the process session
177       identifier as returned by getsid(2).
178

SEE ALSO

180       systemd(1), sd-login(3), sd_session_is_active(3), getsid(2),
181       systemd.slice(5), systemd-machined.service(8)
182
183
184
185systemd 254                                            SD_PID_GET_OWNER_UID(3)
Impressum