]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/sd_pid_get_session.xml
NEWS: add entries for v226
[thirdparty/systemd.git] / man / sd_pid_get_session.xml
CommitLineData
0b3b020a
LP
1<?xml version='1.0'?> <!--*-nxml-*-->
2<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
12b42c76 3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
0b3b020a
LP
4
5<!--
6 This file is part of systemd.
7
8 Copyright 2010 Lennart Poettering
9
10 systemd is free software; you can redistribute it and/or modify it
5430f7f2
LP
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
0b3b020a
LP
13 (at your option) any later version.
14
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5430f7f2 18 Lesser General Public License for more details.
0b3b020a 19
5430f7f2 20 You should have received a copy of the GNU Lesser General Public License
0b3b020a
LP
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22-->
23
56ba3c78 24<refentry id="sd_pid_get_session" conditional='HAVE_PAM'>
0b3b020a 25
798d3a52
ZJS
26 <refentryinfo>
27 <title>sd_pid_get_session</title>
28 <productname>systemd</productname>
29
30 <authorgroup>
31 <author>
32 <contrib>Developer</contrib>
33 <firstname>Lennart</firstname>
34 <surname>Poettering</surname>
35 <email>lennart@poettering.net</email>
36 </author>
37 </authorgroup>
38 </refentryinfo>
39
40 <refmeta>
41 <refentrytitle>sd_pid_get_session</refentrytitle>
42 <manvolnum>3</manvolnum>
43 </refmeta>
44
45 <refnamediv>
46 <refname>sd_pid_get_session</refname>
47 <refname>sd_pid_get_unit</refname>
48 <refname>sd_pid_get_user_unit</refname>
49 <refname>sd_pid_get_owner_uid</refname>
50 <refname>sd_pid_get_machine_name</refname>
51 <refname>sd_pid_get_slice</refname>
dddbc695 52 <refname>sd_pid_get_user_slice</refname>
798d3a52
ZJS
53 <refname>sd_peer_get_session</refname>
54 <refname>sd_peer_get_unit</refname>
55 <refname>sd_peer_get_user_unit</refname>
56 <refname>sd_peer_get_owner_uid</refname>
57 <refname>sd_peer_get_machine_name</refname>
58 <refname>sd_peer_get_slice</refname>
dddbc695
LP
59 <refname>sd_peer_get_user_slice</refname>
60 <refpurpose>Determine session, unit, owner of a session,
61 container/VM or slice of a specific PID or socket
62 peer</refpurpose>
798d3a52
ZJS
63 </refnamediv>
64
65 <refsynopsisdiv>
66 <funcsynopsis>
67 <funcsynopsisinfo>#include &lt;systemd/sd-login.h&gt;</funcsynopsisinfo>
68
69 <funcprototype>
70 <funcdef>int <function>sd_pid_get_session</function></funcdef>
71 <paramdef>pid_t <parameter>pid</parameter></paramdef>
72 <paramdef>char **<parameter>session</parameter></paramdef>
73 </funcprototype>
74
75 <funcprototype>
76 <funcdef>int <function>sd_pid_get_unit</function></funcdef>
77 <paramdef>pid_t <parameter>pid</parameter></paramdef>
78 <paramdef>char **<parameter>unit</parameter></paramdef>
79 </funcprototype>
80
81 <funcprototype>
82 <funcdef>int <function>sd_pid_get_user_unit</function></funcdef>
83 <paramdef>pid_t <parameter>pid</parameter></paramdef>
84 <paramdef>char **<parameter>unit</parameter></paramdef>
85 </funcprototype>
86
87 <funcprototype>
88 <funcdef>int <function>sd_pid_get_owner_uid</function></funcdef>
89 <paramdef>pid_t <parameter>pid</parameter></paramdef>
90 <paramdef>uid_t *<parameter>uid</parameter></paramdef>
91 </funcprototype>
92
93 <funcprototype>
94 <funcdef>int <function>sd_pid_get_machine_name</function></funcdef>
95 <paramdef>pid_t <parameter>pid</parameter></paramdef>
96 <paramdef>char **<parameter>name</parameter></paramdef>
97 </funcprototype>
98
99 <funcprototype>
100 <funcdef>int <function>sd_pid_get_slice</function></funcdef>
101 <paramdef>pid_t <parameter>pid</parameter></paramdef>
102 <paramdef>char **<parameter>slice</parameter></paramdef>
103 </funcprototype>
104
dddbc695
LP
105 <funcprototype>
106 <funcdef>int <function>sd_pid_get_user_slice</function></funcdef>
107 <paramdef>pid_t <parameter>pid</parameter></paramdef>
108 <paramdef>char **<parameter>slice</parameter></paramdef>
109 </funcprototype>
110
798d3a52
ZJS
111 <funcprototype>
112 <funcdef>int <function>sd_peer_get_session</function></funcdef>
113 <paramdef>int <parameter>fd</parameter></paramdef>
114 <paramdef>char **<parameter>session</parameter></paramdef>
115 </funcprototype>
116
117 <funcprototype>
118 <funcdef>int <function>sd_peer_get_unit</function></funcdef>
119 <paramdef>int <parameter>fd</parameter></paramdef>
120 <paramdef>char **<parameter>unit</parameter></paramdef>
121 </funcprototype>
122
123 <funcprototype>
124 <funcdef>int <function>sd_peer_get_user_unit</function></funcdef>
125 <paramdef>int <parameter>fd</parameter></paramdef>
126 <paramdef>char **<parameter>unit</parameter></paramdef>
127 </funcprototype>
128
129 <funcprototype>
130 <funcdef>int <function>sd_peer_get_owner_uid</function></funcdef>
131 <paramdef>int <parameter>fd</parameter></paramdef>
132 <paramdef>uid_t *<parameter>uid</parameter></paramdef>
133 </funcprototype>
134
135 <funcprototype>
136 <funcdef>int <function>sd_peer_get_machine_name</function></funcdef>
137 <paramdef>int <parameter>fd</parameter></paramdef>
138 <paramdef>char **<parameter>name</parameter></paramdef>
139 </funcprototype>
140
141 <funcprototype>
142 <funcdef>int <function>sd_peer_get_slice</function></funcdef>
143 <paramdef>int <parameter>fd</parameter></paramdef>
144 <paramdef>char **<parameter>slice</parameter></paramdef>
145 </funcprototype>
dddbc695
LP
146
147 <funcprototype>
148 <funcdef>int <function>sd_peer_get_user_slice</function></funcdef>
149 <paramdef>int <parameter>fd</parameter></paramdef>
150 <paramdef>char **<parameter>slice</parameter></paramdef>
151 </funcprototype>
798d3a52
ZJS
152 </funcsynopsis>
153 </refsynopsisdiv>
154
155 <refsect1>
156 <title>Description</title>
157
158 <para><function>sd_pid_get_session()</function> may be used to
159 determine the login session identifier of a process identified by
160 the specified process identifier. The session identifier is a
161 short string, suitable for usage in file system paths. Note that
162 not all processes are part of a login session (e.g. system service
163 processes, user processes that are shared between multiple
164 sessions of the same user, or kernel threads). For processes not
882f407f
LP
165 being part of a login session this function will fail with
166 -ENXIO. The returned string needs to be freed with the libc
167 <citerefentry
168 project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
798d3a52
ZJS
169 call after use.</para>
170
171 <para><function>sd_pid_get_unit()</function> may be used to
dddbc695
LP
172 determine the systemd system unit (i.e. system service or scope
173 unit) identifier of a process identified by the specified PID. The
174 unit name is a short string, suitable for usage in file system
175 paths. Note that not all processes are part of a system
176 unit/service (e.g. user processes, or kernel threads). For
177 processes not being part of a systemd system unit this function
178 will fail with -ENXIO (More specifically: this call will not work
179 for kernel threads.) The returned string needs to be freed with
180 the libc <citerefentry
882f407f 181 project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
798d3a52
ZJS
182 call after use.</para>
183
184 <para><function>sd_pid_get_user_unit()</function> may be used to
dddbc695
LP
185 determine the systemd user unit (i.e. user service or scope unit)
186 identifier of a process identified by the specified PID. This is
187 similar to <function>sd_pid_get_unit()</function> but applies to
188 user units instead of system units.</para>
798d3a52
ZJS
189
190 <para><function>sd_pid_get_owner_uid()</function> may be used to
dddbc695
LP
191 determine the Unix UID (user identifier) of the owner of the
192 session of a process identified the specified PID. Note that this
193 function will succeed for user processes which are shared between
194 multiple login sessions of the same user, where
798d3a52
ZJS
195 <function>sd_pid_get_session()</function> will fail. For processes
196 not being part of a login session and not being a shared process
882f407f 197 of a user this function will fail with -ENXIO.</para>
798d3a52
ZJS
198
199 <para><function>sd_pid_get_machine_name()</function> may be used
200 to determine the name of the VM or container is a member of. The
201 machine name is a short string, suitable for usage in file system
202 paths. The returned string needs to be freed with the libc
882f407f
LP
203 <citerefentry
204 project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
205 call after use. For processes not part of a VM or containers this
206 function fails with -ENXIO.</para>
798d3a52
ZJS
207
208 <para><function>sd_pid_get_slice()</function> may be used to
209 determine the slice unit the process is a member of. See
210 <citerefentry><refentrytitle>systemd.slice</refentrytitle><manvolnum>5</manvolnum></citerefentry>
211 for details about slices. The returned string needs to be freed
212 with the libc
213 <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
214 call after use.</para>
215
dddbc695
LP
216 <para>Similar, <function>sd_pid_get_user_slice()</function>
217 returns the user slice (as managed by the user's systemd instance)
218 of a process.</para>
219
798d3a52
ZJS
220 <para>If the <varname>pid</varname> parameter of any of these
221 functions is passed as 0, the operation is executed for the
222 calling process.</para>
223
224 <para>The <function>sd_peer_get_session()</function>,
225 <function>sd_peer_get_unit()</function>,
226 <function>sd_peer_get_user_unit()</function>,
227 <function>sd_peer_get_owner_uid()</function>,
dddbc695
LP
228 <function>sd_peer_get_machine_name()</function>,
229 <function>sd_peer_get_slice()</function> and
230 <function>sd_peer_get_user_slice()</function> calls operate
231 similar to their PID counterparts, but operate on a connected
232 AF_UNIX socket and retrieve information about the connected peer
233 process. Note that these fields are retrieved via
234 <filename>/proc</filename>, and hence are not suitable for
235 authorization purposes, as they are subject to races.</para>
798d3a52
ZJS
236 </refsect1>
237
238 <refsect1>
239 <title>Return Value</title>
240
241 <para>On success, these calls return 0 or a positive integer. On
242 failure, these calls return a negative errno-style error
243 code.</para>
244 </refsect1>
245
882f407f
LP
246 <refsect1>
247 <title>Errors</title>
248
249 <para>Returned errors may indicate the following problems:</para>
250
251 <variablelist>
252
253 <varlistentry>
254 <term><constant>-ENXIO</constant></term>
255
256 <listitem><para>Given field is not specified for the described
257 process or peer.</para>
258 </listitem>
259 </varlistentry>
260
261 <varlistentry>
262 <term><constant>-ESRCH</constant></term>
263
264 <listitem><para>The specified PID does not refer to a running
265 process.</para>
266 </listitem>
267 </varlistentry>
268
269 <varlistentry>
270 <term><constant>-ENOMEM</constant></term>
271
272 <listitem><para>Memory allocation failed.</para></listitem>
273 </varlistentry>
274 </variablelist>
275 </refsect1>
276
798d3a52
ZJS
277 <refsect1>
278 <title>Notes</title>
279
280 <para>The <function>sd_pid_get_session()</function>,
281 <function>sd_pid_get_unit()</function>,
282 <function>sd_pid_get_user_unit()</function>,
283 <function>sd_pid_get_owner_uid()</function>,
284 <function>sd_pid_get_machine_name()</function>,
285 <function>sd_pid_get_slice()</function>,
dddbc695 286 <function>sd_pid_get_user_slice()</function>,
798d3a52
ZJS
287 <function>sd_peer_get_session()</function>,
288 <function>sd_peer_get_unit()</function>,
289 <function>sd_peer_get_user_unit()</function>,
290 <function>sd_peer_get_owner_uid()</function>,
dddbc695
LP
291 <function>sd_peer_get_machine_name()</function>,
292 <function>sd_peer_get_slice()</function> and
293 <function>sd_peer_get_user_slice()</function> interfaces are
294 available as a shared library, which can be compiled and linked to
295 with the <constant>libsystemd</constant> <citerefentry
296 project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
798d3a52
ZJS
297 file.</para>
298
299 <para>Note that the login session identifier as
300 returned by <function>sd_pid_get_session()</function>
301 is completely unrelated to the process session
302 identifier as returned by
303 <citerefentry><refentrytitle>getsid</refentrytitle><manvolnum>2</manvolnum></citerefentry>.</para>
304 </refsect1>
305
306 <refsect1>
307 <title>See Also</title>
308
309 <para>
310 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
311 <citerefentry><refentrytitle>sd-login</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
312 <citerefentry><refentrytitle>sd_session_is_active</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
313 <citerefentry><refentrytitle>getsid</refentrytitle><manvolnum>2</manvolnum></citerefentry>,
314 <citerefentry><refentrytitle>systemd.slice</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
315 <citerefentry><refentrytitle>systemd-machined.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
316 </para>
317 </refsect1>
0b3b020a
LP
318
319</refentry>