707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering<?xml version='1.0'?> <!--*- Mode: nxml; nxml-child-indent: 2; indent-tabs-mode: nil -*-->
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
12b42c76672a66c2d4ea7212c14f8f1b5a62b78dTom Gundersen "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering<!--
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering This file is part of systemd.
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering Copyright 2010 Lennart Poettering
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering systemd is free software; you can redistribute it and/or modify it
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering under the terms of the GNU Lesser General Public License as published by
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering (at your option) any later version.
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering systemd is distributed in the hope that it will be useful, but
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering Lesser General Public License for more details.
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering
5430f7f2bc7330f3088b894166bf3524a067e3d8Lennart Poettering You should have received a copy of the GNU Lesser General Public License
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering-->
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering
56ba3c78ae35065064c4289a0c8e22a81256af20Zbigniew Jędrzejewski-Szmek<refentry id="sd_pid_get_session" conditional='HAVE_PAM'>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refentryinfo>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <title>sd_pid_get_session</title>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <productname>systemd</productname>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <authorgroup>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <author>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <contrib>Developer</contrib>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <firstname>Lennart</firstname>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <surname>Poettering</surname>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <email>lennart@poettering.net</email>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </author>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </authorgroup>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </refentryinfo>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refmeta>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refentrytitle>sd_pid_get_session</refentrytitle>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <manvolnum>3</manvolnum>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </refmeta>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refnamediv>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refname>sd_pid_get_session</refname>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refname>sd_pid_get_unit</refname>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refname>sd_pid_get_user_unit</refname>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refname>sd_pid_get_owner_uid</refname>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refname>sd_pid_get_machine_name</refname>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refname>sd_pid_get_slice</refname>
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering <refname>sd_pid_get_user_slice</refname>
f5aaf575626022313b07d505699fa1af25d248acLennart Poettering <refname>sd_pid_get_cgroup</refname>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refname>sd_peer_get_session</refname>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refname>sd_peer_get_unit</refname>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refname>sd_peer_get_user_unit</refname>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refname>sd_peer_get_owner_uid</refname>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refname>sd_peer_get_machine_name</refname>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refname>sd_peer_get_slice</refname>
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering <refname>sd_peer_get_user_slice</refname>
f5aaf575626022313b07d505699fa1af25d248acLennart Poettering <refname>sd_peer_get_cgroup</refname>
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering <refpurpose>Determine session, unit, owner of a session,
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering container/VM or slice of a specific PID or socket
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering peer</refpurpose>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </refnamediv>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refsynopsisdiv>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcsynopsis>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcsynopsisinfo>#include &lt;systemd/sd-login.h&gt;</funcsynopsisinfo>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcdef>int <function>sd_pid_get_session</function></funcdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <paramdef>pid_t <parameter>pid</parameter></paramdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <paramdef>char **<parameter>session</parameter></paramdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcdef>int <function>sd_pid_get_unit</function></funcdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <paramdef>pid_t <parameter>pid</parameter></paramdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <paramdef>char **<parameter>unit</parameter></paramdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcdef>int <function>sd_pid_get_user_unit</function></funcdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <paramdef>pid_t <parameter>pid</parameter></paramdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <paramdef>char **<parameter>unit</parameter></paramdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcdef>int <function>sd_pid_get_owner_uid</function></funcdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <paramdef>pid_t <parameter>pid</parameter></paramdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <paramdef>uid_t *<parameter>uid</parameter></paramdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcdef>int <function>sd_pid_get_machine_name</function></funcdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <paramdef>pid_t <parameter>pid</parameter></paramdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <paramdef>char **<parameter>name</parameter></paramdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcdef>int <function>sd_pid_get_slice</function></funcdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <paramdef>pid_t <parameter>pid</parameter></paramdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <paramdef>char **<parameter>slice</parameter></paramdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering <funcprototype>
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering <funcdef>int <function>sd_pid_get_user_slice</function></funcdef>
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering <paramdef>pid_t <parameter>pid</parameter></paramdef>
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering <paramdef>char **<parameter>slice</parameter></paramdef>
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering </funcprototype>
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering
f5aaf575626022313b07d505699fa1af25d248acLennart Poettering <funcprototype>
f5aaf575626022313b07d505699fa1af25d248acLennart Poettering <funcdef>int <function>sd_pid_get_cgroup</function></funcdef>
f5aaf575626022313b07d505699fa1af25d248acLennart Poettering <paramdef>pid_t <parameter>pid</parameter></paramdef>
f5aaf575626022313b07d505699fa1af25d248acLennart Poettering <paramdef>char **<parameter>cgroup</parameter></paramdef>
f5aaf575626022313b07d505699fa1af25d248acLennart Poettering </funcprototype>
f5aaf575626022313b07d505699fa1af25d248acLennart Poettering
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcdef>int <function>sd_peer_get_session</function></funcdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <paramdef>int <parameter>fd</parameter></paramdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <paramdef>char **<parameter>session</parameter></paramdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcdef>int <function>sd_peer_get_unit</function></funcdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <paramdef>int <parameter>fd</parameter></paramdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <paramdef>char **<parameter>unit</parameter></paramdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcdef>int <function>sd_peer_get_user_unit</function></funcdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <paramdef>int <parameter>fd</parameter></paramdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <paramdef>char **<parameter>unit</parameter></paramdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcdef>int <function>sd_peer_get_owner_uid</function></funcdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <paramdef>int <parameter>fd</parameter></paramdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <paramdef>uid_t *<parameter>uid</parameter></paramdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcdef>int <function>sd_peer_get_machine_name</function></funcdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <paramdef>int <parameter>fd</parameter></paramdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <paramdef>char **<parameter>name</parameter></paramdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <funcdef>int <function>sd_peer_get_slice</function></funcdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <paramdef>int <parameter>fd</parameter></paramdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <paramdef>char **<parameter>slice</parameter></paramdef>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </funcprototype>
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering <funcprototype>
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering <funcdef>int <function>sd_peer_get_user_slice</function></funcdef>
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering <paramdef>int <parameter>fd</parameter></paramdef>
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering <paramdef>char **<parameter>slice</parameter></paramdef>
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering </funcprototype>
f5aaf575626022313b07d505699fa1af25d248acLennart Poettering
f5aaf575626022313b07d505699fa1af25d248acLennart Poettering <funcprototype>
f5aaf575626022313b07d505699fa1af25d248acLennart Poettering <funcdef>int <function>sd_peer_get_cgroup</function></funcdef>
f5aaf575626022313b07d505699fa1af25d248acLennart Poettering <paramdef>int <parameter>fd</parameter></paramdef>
f5aaf575626022313b07d505699fa1af25d248acLennart Poettering <paramdef>char **<parameter>cgroup</parameter></paramdef>
f5aaf575626022313b07d505699fa1af25d248acLennart Poettering </funcprototype>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </funcsynopsis>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </refsynopsisdiv>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refsect1>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <title>Description</title>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <para><function>sd_pid_get_session()</function> may be used to
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek determine the login session identifier of a process identified by
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek the specified process identifier. The session identifier is a
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek short string, suitable for usage in file system paths. Note that
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek not all processes are part of a login session (e.g. system service
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek processes, user processes that are shared between multiple
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek sessions of the same user, or kernel threads). For processes not
b938cb902c3b5bca807a94b277672c64d6767886Jan Engelhardt being part of a login session, this function will fail with
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering -ENODATA. The returned string needs to be freed with the libc
882f407f3133f3603b69be162940002a9a37ba48Lennart Poettering <citerefentry
882f407f3133f3603b69be162940002a9a37ba48Lennart Poettering project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek call after use.</para>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <para><function>sd_pid_get_unit()</function> may be used to
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering determine the systemd system unit (i.e. system service or scope
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering unit) identifier of a process identified by the specified PID. The
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering unit name is a short string, suitable for usage in file system
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering paths. Note that not all processes are part of a system
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering unit/service (e.g. user processes, or kernel threads). For
b938cb902c3b5bca807a94b277672c64d6767886Jan Engelhardt processes not being part of a systemd system unit, this function
b938cb902c3b5bca807a94b277672c64d6767886Jan Engelhardt will fail with -ENODATA. (More specifically, this call will not
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering work for kernel threads.) The returned string needs to be freed
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering with the libc <citerefentry
882f407f3133f3603b69be162940002a9a37ba48Lennart Poettering project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek call after use.</para>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <para><function>sd_pid_get_user_unit()</function> may be used to
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering determine the systemd user unit (i.e. user service or scope unit)
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering identifier of a process identified by the specified PID. This is
b938cb902c3b5bca807a94b277672c64d6767886Jan Engelhardt similar to <function>sd_pid_get_unit()</function>, but applies to
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering user units instead of system units.</para>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <para><function>sd_pid_get_owner_uid()</function> may be used to
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering determine the Unix UID (user identifier) of the owner of the
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering session of a process identified the specified PID. Note that this
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering function will succeed for user processes which are shared between
a8eaaee72a2f06e0fb64fb71de3b71ecba31dafbJan Engelhardt multiple login sessions of the same user, whereas
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <function>sd_pid_get_session()</function> will fail. For processes
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek not being part of a login session and not being a shared process
b938cb902c3b5bca807a94b277672c64d6767886Jan Engelhardt of a user, this function will fail with -ENODATA.</para>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <para><function>sd_pid_get_machine_name()</function> may be used
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek to determine the name of the VM or container is a member of. The
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek machine name is a short string, suitable for usage in file system
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek paths. The returned string needs to be freed with the libc
882f407f3133f3603b69be162940002a9a37ba48Lennart Poettering <citerefentry
882f407f3133f3603b69be162940002a9a37ba48Lennart Poettering project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
b938cb902c3b5bca807a94b277672c64d6767886Jan Engelhardt call after use. For processes not part of a VM or containers, this
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering function fails with -ENODATA.</para>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <para><function>sd_pid_get_slice()</function> may be used to
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek determine the slice unit the process is a member of. See
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <citerefentry><refentrytitle>systemd.slice</refentrytitle><manvolnum>5</manvolnum></citerefentry>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek for details about slices. The returned string needs to be freed
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek with the libc
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <citerefentry project='man-pages'><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek call after use.</para>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
a8eaaee72a2f06e0fb64fb71de3b71ecba31dafbJan Engelhardt <para>Similarly, <function>sd_pid_get_user_slice()</function>
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering returns the user slice (as managed by the user's systemd instance)
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering of a process.</para>
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering
f5aaf575626022313b07d505699fa1af25d248acLennart Poettering <para><function>sd_pid_get_cgroup()</function> returns the control
f5aaf575626022313b07d505699fa1af25d248acLennart Poettering group path of the specified process, relative to the root of the
f5aaf575626022313b07d505699fa1af25d248acLennart Poettering hierarchy. Returns the path without trailing slash, except for
f5aaf575626022313b07d505699fa1af25d248acLennart Poettering processes located in the root control group, where "/" is
b938cb902c3b5bca807a94b277672c64d6767886Jan Engelhardt returned. To find the actual control group path in the file system,
f5aaf575626022313b07d505699fa1af25d248acLennart Poettering the returned path needs to be prefixed with
f5aaf575626022313b07d505699fa1af25d248acLennart Poettering <filename>/sys/fs/cgroup/</filename> (if the unified control group
f5aaf575626022313b07d505699fa1af25d248acLennart Poettering setup is used), or
f5aaf575626022313b07d505699fa1af25d248acLennart Poettering <filename>/sys/fs/cgroup/<replaceable>HIERARCHY</replaceable>/</filename>
f5aaf575626022313b07d505699fa1af25d248acLennart Poettering (if the legacy multi-hierarchy control group setup is used).</para>
f5aaf575626022313b07d505699fa1af25d248acLennart Poettering
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <para>If the <varname>pid</varname> parameter of any of these
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek functions is passed as 0, the operation is executed for the
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek calling process.</para>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <para>The <function>sd_peer_get_session()</function>,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <function>sd_peer_get_unit()</function>,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <function>sd_peer_get_user_unit()</function>,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <function>sd_peer_get_owner_uid()</function>,
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering <function>sd_peer_get_machine_name()</function>,
f5aaf575626022313b07d505699fa1af25d248acLennart Poettering <function>sd_peer_get_slice()</function>,
f5aaf575626022313b07d505699fa1af25d248acLennart Poettering <function>sd_peer_get_user_slice()</function> and
f5aaf575626022313b07d505699fa1af25d248acLennart Poettering <function>sd_peer_get_cgroup()</function> calls operate similar to
f5aaf575626022313b07d505699fa1af25d248acLennart Poettering their PID counterparts, but operate on a connected AF_UNIX socket
f5aaf575626022313b07d505699fa1af25d248acLennart Poettering and retrieve information about the connected peer process. Note
f5aaf575626022313b07d505699fa1af25d248acLennart Poettering that these fields are retrieved via <filename>/proc</filename>,
f5aaf575626022313b07d505699fa1af25d248acLennart Poettering and hence are not suitable for authorization purposes, as they are
f5aaf575626022313b07d505699fa1af25d248acLennart Poettering subject to races.</para>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </refsect1>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refsect1>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <title>Return Value</title>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <para>On success, these calls return 0 or a positive integer. On
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek failure, these calls return a negative errno-style error
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek code.</para>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </refsect1>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
882f407f3133f3603b69be162940002a9a37ba48Lennart Poettering <refsect1>
882f407f3133f3603b69be162940002a9a37ba48Lennart Poettering <title>Errors</title>
882f407f3133f3603b69be162940002a9a37ba48Lennart Poettering
882f407f3133f3603b69be162940002a9a37ba48Lennart Poettering <para>Returned errors may indicate the following problems:</para>
882f407f3133f3603b69be162940002a9a37ba48Lennart Poettering
882f407f3133f3603b69be162940002a9a37ba48Lennart Poettering <variablelist>
882f407f3133f3603b69be162940002a9a37ba48Lennart Poettering
882f407f3133f3603b69be162940002a9a37ba48Lennart Poettering <varlistentry>
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering <term><constant>-ESRCH</constant></term>
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering <listitem><para>The specified PID does not refer to a running
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering process.</para>
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering </listitem>
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering </varlistentry>
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering <varlistentry>
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering <term><constant>-BADF</constant></term>
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering <listitem><para>The specified socket file descriptor was
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering invalid.</para></listitem>
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering </varlistentry>
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering <varlistentry>
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering <term><constant>-ENODATA</constant></term>
882f407f3133f3603b69be162940002a9a37ba48Lennart Poettering
a8eaaee72a2f06e0fb64fb71de3b71ecba31dafbJan Engelhardt <listitem><para>The given field is not specified for the described
882f407f3133f3603b69be162940002a9a37ba48Lennart Poettering process or peer.</para>
882f407f3133f3603b69be162940002a9a37ba48Lennart Poettering </listitem>
882f407f3133f3603b69be162940002a9a37ba48Lennart Poettering </varlistentry>
882f407f3133f3603b69be162940002a9a37ba48Lennart Poettering
882f407f3133f3603b69be162940002a9a37ba48Lennart Poettering <varlistentry>
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering <term><constant>-EINVAL</constant></term>
882f407f3133f3603b69be162940002a9a37ba48Lennart Poettering
707b66c66381c899d7ef640e158ffdd5bcff4debLennart Poettering <listitem><para>An input parameter was invalid (out of range,
7ca4155737730ece73ae4b4ac80571005cb99b69Jan Engelhardt or NULL, where that is not accepted).</para></listitem>
882f407f3133f3603b69be162940002a9a37ba48Lennart Poettering </varlistentry>
882f407f3133f3603b69be162940002a9a37ba48Lennart Poettering
882f407f3133f3603b69be162940002a9a37ba48Lennart Poettering <varlistentry>
882f407f3133f3603b69be162940002a9a37ba48Lennart Poettering <term><constant>-ENOMEM</constant></term>
882f407f3133f3603b69be162940002a9a37ba48Lennart Poettering
882f407f3133f3603b69be162940002a9a37ba48Lennart Poettering <listitem><para>Memory allocation failed.</para></listitem>
882f407f3133f3603b69be162940002a9a37ba48Lennart Poettering </varlistentry>
882f407f3133f3603b69be162940002a9a37ba48Lennart Poettering </variablelist>
882f407f3133f3603b69be162940002a9a37ba48Lennart Poettering </refsect1>
882f407f3133f3603b69be162940002a9a37ba48Lennart Poettering
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refsect1>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <title>Notes</title>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <para>The <function>sd_pid_get_session()</function>,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <function>sd_pid_get_unit()</function>,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <function>sd_pid_get_user_unit()</function>,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <function>sd_pid_get_owner_uid()</function>,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <function>sd_pid_get_machine_name()</function>,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <function>sd_pid_get_slice()</function>,
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering <function>sd_pid_get_user_slice()</function>,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <function>sd_peer_get_session()</function>,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <function>sd_peer_get_unit()</function>,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <function>sd_peer_get_user_unit()</function>,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <function>sd_peer_get_owner_uid()</function>,
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering <function>sd_peer_get_machine_name()</function>,
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering <function>sd_peer_get_slice()</function> and
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering <function>sd_peer_get_user_slice()</function> interfaces are
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering available as a shared library, which can be compiled and linked to
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering with the <constant>libsystemd</constant> <citerefentry
dddbc69577820e6ecce17d3ac836ad865fcbcde2Lennart Poettering project='die-net'><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek file.</para>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <para>Note that the login session identifier as
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek returned by <function>sd_pid_get_session()</function>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek is completely unrelated to the process session
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek identifier as returned by
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <citerefentry><refentrytitle>getsid</refentrytitle><manvolnum>2</manvolnum></citerefentry>.</para>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </refsect1>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <refsect1>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <title>See Also</title>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <para>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <citerefentry><refentrytitle>sd-login</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <citerefentry><refentrytitle>sd_session_is_active</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <citerefentry><refentrytitle>getsid</refentrytitle><manvolnum>2</manvolnum></citerefentry>,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <citerefentry><refentrytitle>systemd.slice</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek <citerefentry><refentrytitle>systemd-machined.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </para>
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek </refsect1>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering</refentry>