sd_pid_get_session.xml revision 0b3b020a178cf3b957fed627de13c895773995ec
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering This file is part of systemd.
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering Copyright 2010 Lennart Poettering
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering systemd is free software; you can redistribute it and/or modify it
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering under the terms of the GNU General Public License as published by
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering the Free Software Foundation; either version 2 of the License, or
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering (at your option) any later version.
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
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering General Public License for more details.
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering You should have received a copy of the GNU General Public License
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering <refentryinfo>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering </authorgroup>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering </refentryinfo>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering <refentrytitle>sd_pid_get_session</refentrytitle>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering <refpurpose>Determine session or owner of a session of a specific PID</refpurpose>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering <refsynopsisdiv>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering <funcsynopsis>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering <funcsynopsisinfo>#include <systemd/sd-login.h></funcsynopsisinfo>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering <funcprototype>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering <funcdef>int <function>sd_pid_get_session</function></funcdef>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering <paramdef>pid_t <parameter>pid</parameter></paramdef>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering <paramdef>char** <parameter>session</parameter></paramdef>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering </funcprototype>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering <funcprototype>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering <funcdef>int <function>sd_pid_get_owner_uid</function></funcdef>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering <paramdef>pid_t <parameter>pid</parameter></paramdef>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering <paramdef>uid_t* <parameter>uid</parameter></paramdef>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering </funcprototype>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering </funcsynopsis>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering </refsynopsisdiv>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering <para><function>sd_pid_get_session()</function> may be
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering used to determine the login session identifier of a
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering process identified by the specified process identifier. The session
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering identifier is a short string (up to 64 characters),
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering consisting only of the characters a-zA-Z0-9 as well as
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering '-' and '_'. It is suitable for usage in file system
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering paths. Note that not all processes are part of a login
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering session (e.g. system service processes and user
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering processes that are shared between multiple sessions of
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering the same user). For processes not being part of a
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering login session this function will fail. The returned
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering string needs to be freed with the libc
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering <citerefentry><refentrytitle>free</refentrytitle><manvolnum>3</manvolnum></citerefentry>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering call after use.</para>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering <para><function>sd_pid_get_owner_uid()</function> may
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering be used to determine the Unix user identifier of the
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering owner of the session of a process identified the
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering specified PID. Note that this function will succeed
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering for user processes which are shared between multiple
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering login sessions of the same user, where
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering <function>sd_pid_get_session()</function> will
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering fail. For processes not being part of a login session
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering and not being a shared process of a user this function
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering will fail.</para>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering <para>On success these calls return 0 or a positive
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering integer. On failure, these calls return a negative
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering errno-style error code.</para>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering <para>The <function>sd_pid_get_session()</function>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering and <function>sd_pid_get_owner_uid()</function>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering interfaces are available as shared library, which can
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering be compiled and linked to with the
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering <citerefentry><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering <para>Note that the login session identifier as
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering returned by <function>sd_pid_get_session()</function>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering is completely unrelated to the process session
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering identifier as returned by
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering <citerefentry><refentrytitle>getsid</refentrytitle><manvolnum>2</manvolnum></citerefentry>.</para>
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering <citerefentry><refentrytitle>sd-login</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering <citerefentry><refentrytitle>sd_session_is_active</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
0b3b020a178cf3b957fed627de13c895773995ecLennart Poettering <citerefentry><refentrytitle>getsid</refentrytitle><manvolnum>2</manvolnum></citerefentry>