| 1 |
<?xml version='1.0'?> |
| 2 |
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
| 3 |
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"> |
| 4 |
<!-- SPDX-License-Identifier: LGPL-2.1-or-later --> |
| 5 |
|
| 6 |
<refentry id="sd_pidfd_get_inode_id" |
| 7 |
xmlns:xi="http://www.w3.org/2001/XInclude"> |
| 8 |
|
| 9 |
<refentryinfo> |
| 10 |
<title>sd_pidfd_get_inode_id</title> |
| 11 |
<productname>systemd</productname> |
| 12 |
</refentryinfo> |
| 13 |
|
| 14 |
<refmeta> |
| 15 |
<refentrytitle>sd_pidfd_get_inode_id</refentrytitle> |
| 16 |
<manvolnum>3</manvolnum> |
| 17 |
</refmeta> |
| 18 |
|
| 19 |
<refnamediv> |
| 20 |
<refname>sd_pidfd_get_inode_id</refname> |
| 21 |
<refpurpose>Acquire the 64-bit inode ID of a PID file descriptor (PIDFD)</refpurpose> |
| 22 |
</refnamediv> |
| 23 |
|
| 24 |
<refsynopsisdiv> |
| 25 |
<funcsynopsis> |
| 26 |
<funcsynopsisinfo>#include <systemd/sd-daemon.h></funcsynopsisinfo> |
| 27 |
|
| 28 |
<funcprototype> |
| 29 |
<funcdef>int <function>sd_pidfd_get_inode_id</function></funcdef> |
| 30 |
<paramdef>int <parameter>pidfd</parameter></paramdef> |
| 31 |
<paramdef>uint64_t *<parameter>ret</parameter></paramdef> |
| 32 |
</funcprototype> |
| 33 |
</funcsynopsis> |
| 34 |
</refsynopsisdiv> |
| 35 |
|
| 36 |
<refsect1> |
| 37 |
<title>Description</title> |
| 38 |
|
| 39 |
<para><function>sd_pidfd_get_inode_id()</function> may be invoked to acquire the 64-bit inode ID of |
| 40 |
a PID file descriptor (PIDFD), which can be used to reliably identify a process for the current boot.</para> |
| 41 |
|
| 42 |
<para>As a typical example, the service manager sets <varname>$MAINPIDFDID</varname> and <varname>$MANAGERPIDFDID</varname> |
| 43 |
environment variables to the inode IDs of the service main process and the service manager itself, respectively, |
| 44 |
if such functionality is supported by the kernel.</para> |
| 45 |
|
| 46 |
<para>On 64-bit architectures, the inode ID can be directly obtained via a call to |
| 47 |
<citerefentry project='man-pages'><refentrytitle>fstat</refentrytitle><manvolnum>2</manvolnum></citerefentry> |
| 48 |
on a given pidfd. However, on 32-bit architectures <structname>struct stat</structname>'s .st_ino |
| 49 |
field is also 32-bit, which similar to PIDs is subject to reuse. Therefore, a second mechanism leveraging |
| 50 |
<citerefentry project='man-pages'><refentrytitle>name_to_handle_at</refentrytitle><manvolnum>2</manvolnum></citerefentry> |
| 51 |
has been added to kernel in v6.14. This helper is added to simplify downstream handling of pidfd/pidfs internals. |
| 52 |
</para> |
| 53 |
</refsect1> |
| 54 |
|
| 55 |
<refsect1> |
| 56 |
<title>Return Value</title> |
| 57 |
|
| 58 |
<para>On success, the function returns 0 or a positive integer. On failure, a negative errno-style |
| 59 |
error code is returned.</para> |
| 60 |
|
| 61 |
<refsect2> |
| 62 |
<title>Errors</title> |
| 63 |
|
| 64 |
<para>Returned errors may indicate the following problems:</para> |
| 65 |
|
| 66 |
<variablelist> |
| 67 |
|
| 68 |
<varlistentry> |
| 69 |
<term><constant>-EOPNOTSUPP</constant></term> |
| 70 |
|
| 71 |
<listitem><para>The stable PIDFD inode ID is not supported by the running kernel, or the system |
| 72 |
is 32-bit and <function>name_to_handle_at()</function> is unavailable.</para></listitem> |
| 73 |
</varlistentry> |
| 74 |
|
| 75 |
<varlistentry> |
| 76 |
<term><constant>-EBADF</constant></term> |
| 77 |
|
| 78 |
<listitem><para>The specified file descriptor is invalid, or is not a PIDFD.</para></listitem> |
| 79 |
</varlistentry> |
| 80 |
|
| 81 |
</variablelist> |
| 82 |
</refsect2> |
| 83 |
</refsect1> |
| 84 |
|
| 85 |
<refsect1> |
| 86 |
<title>Notes</title> |
| 87 |
|
| 88 |
<xi:include href="libsystemd-pkgconfig.xml" xpointer="pkgconfig-text"/> |
| 89 |
</refsect1> |
| 90 |
|
| 91 |
<refsect1> |
| 92 |
<title>History</title> |
| 93 |
<para><function>sd_pidfd_get_inode_id()</function> was added in version 258.</para> |
| 94 |
</refsect1> |
| 95 |
|
| 96 |
<refsect1> |
| 97 |
<title>See Also</title> |
| 98 |
|
| 99 |
<para><simplelist type="inline"> |
| 100 |
<member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 101 |
<member><citerefentry><refentrytitle>sd-daemon</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 102 |
<member><citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 103 |
<member><citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry></member> |
| 104 |
</simplelist></para> |
| 105 |
</refsect1> |
| 106 |
|
| 107 |
</refentry> |