]> git.ipfire.org Git - thirdparty/systemd.git/blame - man/sd_listen_fds.xml
man: don't advertise sd-daemon as embeddable anymore
[thirdparty/systemd.git] / man / sd_listen_fds.xml
CommitLineData
f9378423
LP
1<?xml version='1.0'?> <!--*-nxml-*-->
2<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
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
f9378423
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.
f9378423 19
5430f7f2 20 You should have received a copy of the GNU Lesser General Public License
f9378423
LP
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22-->
23
24<refentry id="sd_listen_fds">
25
26 <refentryinfo>
27 <title>sd_listen_fds</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_listen_fds</refentrytitle>
42 <manvolnum>3</manvolnum>
43 </refmeta>
44
45 <refnamediv>
46 <refname>sd_listen_fds</refname>
976c46f8 47 <refname>SD_LISTEN_FDS_START</refname>
34511ca7 48 <refpurpose>Check for file descriptors passed by the system manager</refpurpose>
f9378423
LP
49 </refnamediv>
50
51 <refsynopsisdiv>
52 <funcsynopsis>
a822cbfa 53 <funcsynopsisinfo>#include &lt;systemd/sd-daemon.h&gt;</funcsynopsisinfo>
f9378423
LP
54
55 <funcsynopsisinfo>#define SD_LISTEN_FDS_START 3</funcsynopsisinfo>
56
57 <funcprototype>
58 <funcdef>int <function>sd_listen_fds</function></funcdef>
59 <paramdef>int <parameter>unset_environment</parameter></paramdef>
60 </funcprototype>
61 </funcsynopsis>
62 </refsynopsisdiv>
63
64 <refsect1>
65 <title>Description</title>
66
67 <para><function>sd_listen_fds()</function> shall be
68 called by a daemon to check for file descriptors
69 passed by the init system as part of the socket-based
70 activation logic.</para>
71
72 <para>If the <parameter>unset_environment</parameter>
79640424 73 parameter is non-zero,
f9378423
LP
74 <function>sd_listen_fds()</function> will unset the
75 <varname>$LISTEN_FDS</varname>/<varname>$LISTEN_PID</varname>
494a6682 76 environment variables before returning (regardless of
f9378423
LP
77 whether the function call itself succeeded or
78 not). Further calls to
79 <function>sd_listen_fds()</function> will then fail,
80 but the variables are no longer inherited by child
81 processes.</para>
82
83 <para>If a daemon receives more than one file
84 descriptor, they will be passed in the same order as
85 configured in the systemd socket definition
79640424 86 file. Nonetheless, it is recommended to verify the
f9378423 87 correct socket types before using them. To simplify
79640424 88 this checking, the functions
f9378423
LP
89 <citerefentry><refentrytitle>sd_is_fifo</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
90 <citerefentry><refentrytitle>sd_is_socket</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
91 <citerefentry><refentrytitle>sd_is_socket_inet</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
92 <citerefentry><refentrytitle>sd_is_socket_unix</refentrytitle><manvolnum>3</manvolnum></citerefentry>
79640424 93 are provided. In order to maximize flexibility, it is
436c44a5 94 recommended to make these checks as loose as possible
79640424 95 without allowing incorrect setups. i.e. often, the
f9378423
LP
96 actual port number a socket is bound to matters little
97 for the service to work, hence it should not be
98 verified. On the other hand, whether a socket is a
99 datagram or stream socket matters a lot for the most
af62c704 100 common program logics and should be checked.</para>
f9378423
LP
101
102 <para>This function call will set the FD_CLOEXEC flag
103 for all passed file descriptors to avoid further
104 inheritance to children of the calling process.</para>
105 </refsect1>
106
107 <refsect1>
108 <title>Return Value</title>
109
110 <para>On failure, this call returns a negative
111 errno-style error code. If
112 <varname>$LISTEN_FDS</varname>/<varname>$LISTEN_PID</varname>
ad678a06
CM
113 was not set or was not correctly set for this daemon and
114 hence no file descriptors were received, 0 is
79640424 115 returned. Otherwise, the number of file descriptors
af62c704 116 passed is returned. The application may find them
f9378423
LP
117 starting with file descriptor SD_LISTEN_FDS_START,
118 i.e. file descriptor 3.</para>
119 </refsect1>
120
121 <refsect1>
122 <title>Notes</title>
123
26e3ff59
LP
124 <para>These APIs are implemented as a shared library,
125 which can be compiled and linked to with the
126 <constant>libsystemd</constant> <citerefentry><refentrytitle>pkg-config</refentrytitle><manvolnum>1</manvolnum></citerefentry>
127 file.</para>
f9378423
LP
128
129 <para>Internally, this function checks whether the
130 <varname>$LISTEN_PID</varname> environment variable
131 equals the daemon PID. If not, it returns
79640424 132 immediately. Otherwise, it parses the number passed in
f9378423
LP
133 the <varname>$LISTEN_FDS</varname> environment
134 variable, then sets the FD_CLOEXEC flag for the parsed
135 number of file descriptors starting from
79640424 136 SD_LISTEN_FDS_START. Finally, it returns the parsed
f9378423 137 number.</para>
f9378423
LP
138 </refsect1>
139
7874bcd6
LP
140 <refsect1>
141 <title>Environment</title>
142
ccc9a4f9 143 <variablelist class='environment-variables'>
7874bcd6
LP
144 <varlistentry>
145 <term><varname>$LISTEN_PID</varname></term>
146 <term><varname>$LISTEN_FDS</varname></term>
147
148 <listitem><para>Set by the init system
149 for supervised processes that use
150 socket-based activation. This
151 environment variable specifies the
152 data
153 <function>sd_listen_fds()</function>
154 parses. See above for
155 details.</para></listitem>
156 </varlistentry>
157 </variablelist>
158 </refsect1>
159
f9378423
LP
160 <refsect1>
161 <title>See Also</title>
162
163 <para>
160cd5c9 164 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
cb07866b 165 <citerefentry><refentrytitle>sd-daemon</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
f9378423
LP
166 <citerefentry><refentrytitle>sd_is_fifo</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
167 <citerefentry><refentrytitle>sd_is_socket</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
168 <citerefentry><refentrytitle>sd_is_socket_inet</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
169 <citerefentry><refentrytitle>sd_is_socket_unix</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
170 <citerefentry><refentrytitle>daemon</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
f9378423
LP
171 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
172 <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry>
173 </para>
174 </refsect1>
175
176</refentry>