chiark / gitweb /
be2d7fa3a9c8d4bdc9af1dabeba32ba9101a76ff
[elogind.git] / man / sd_is_fifo.xml
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   SPDX-License-Identifier: LGPL-2.1+
7
8   Copyright 2010 Lennart Poettering
9 -->
10
11 <refentry id="sd_is_fifo"
12   xmlns:xi="http://www.w3.org/2001/XInclude">
13
14   <refentryinfo>
15     <title>sd_is_fifo</title>
16     <productname>systemd</productname>
17
18     <authorgroup>
19       <author>
20         <contrib>Developer</contrib>
21         <firstname>Lennart</firstname>
22         <surname>Poettering</surname>
23         <email>lennart@poettering.net</email>
24       </author>
25     </authorgroup>
26   </refentryinfo>
27
28   <refmeta>
29     <refentrytitle>sd_is_fifo</refentrytitle>
30     <manvolnum>3</manvolnum>
31   </refmeta>
32
33   <refnamediv>
34     <refname>sd_is_fifo</refname>
35     <refname>sd_is_socket</refname>
36     <refname>sd_is_socket_inet</refname>
37     <refname>sd_is_socket_unix</refname>
38     <refname>sd_is_socket_sockaddr</refname>
39     <refname>sd_is_mq</refname>
40     <refname>sd_is_special</refname>
41     <refpurpose>Check the type of a file descriptor</refpurpose>
42   </refnamediv>
43
44   <refsynopsisdiv>
45     <funcsynopsis>
46       <funcsynopsisinfo>#include &lt;systemd/sd-daemon.h&gt;</funcsynopsisinfo>
47
48       <funcprototype>
49         <funcdef>int <function>sd_is_fifo</function></funcdef>
50         <paramdef>int <parameter>fd</parameter></paramdef>
51         <paramdef>const char *<parameter>path</parameter></paramdef>
52       </funcprototype>
53
54       <funcprototype>
55         <funcdef>int <function>sd_is_socket</function></funcdef>
56         <paramdef>int <parameter>fd</parameter></paramdef>
57         <paramdef>int <parameter>family</parameter></paramdef>
58         <paramdef>int <parameter>type</parameter></paramdef>
59         <paramdef>int <parameter>listening</parameter></paramdef>
60       </funcprototype>
61
62       <funcprototype>
63         <funcdef>int <function>sd_is_socket_inet</function></funcdef>
64         <paramdef>int <parameter>fd</parameter></paramdef>
65         <paramdef>int <parameter>family</parameter></paramdef>
66         <paramdef>int <parameter>type</parameter></paramdef>
67         <paramdef>int <parameter>listening</parameter></paramdef>
68         <paramdef>uint16_t <parameter>port</parameter></paramdef>
69       </funcprototype>
70
71       <funcprototype>
72         <funcdef>int <function>sd_is_socket_sockaddr</function></funcdef>
73         <paramdef>int <parameter>fd</parameter></paramdef>
74         <paramdef>int <parameter>type</parameter></paramdef>
75         <paramdef>const struct sockaddr *<parameter>addr</parameter></paramdef>
76         <paramdef>unsigned <parameter>addr_len</parameter></paramdef>
77         <paramdef>int <parameter>listening</parameter></paramdef>
78       </funcprototype>
79
80       <funcprototype>
81         <funcdef>int <function>sd_is_socket_unix</function></funcdef>
82         <paramdef>int <parameter>fd</parameter></paramdef>
83         <paramdef>int <parameter>type</parameter></paramdef>
84         <paramdef>int <parameter>listening</parameter></paramdef>
85         <paramdef>const char *<parameter>path</parameter></paramdef>
86         <paramdef>size_t <parameter>length</parameter></paramdef>
87       </funcprototype>
88
89       <funcprototype>
90         <funcdef>int <function>sd_is_mq</function></funcdef>
91         <paramdef>int <parameter>fd</parameter></paramdef>
92         <paramdef>const char *<parameter>path</parameter></paramdef>
93       </funcprototype>
94
95       <funcprototype>
96         <funcdef>int <function>sd_is_special</function></funcdef>
97         <paramdef>int <parameter>fd</parameter></paramdef>
98         <paramdef>const char *<parameter>path</parameter></paramdef>
99       </funcprototype>
100
101     </funcsynopsis>
102   </refsynopsisdiv>
103
104   <refsect1>
105     <title>Description</title>
106
107     <para><function>sd_is_fifo()</function> may be called to check
108     whether the specified file descriptor refers to a FIFO or pipe. If
109     the <parameter>path</parameter> parameter is not
110     <constant>NULL</constant>, it is checked whether the FIFO is bound
111     to the specified file system path.</para>
112
113     <para><function>sd_is_socket()</function> may be called to check
114     whether the specified file descriptor refers to a socket. If the
115     <parameter>family</parameter> parameter is not
116     <constant>AF_UNSPEC</constant>, it is checked whether the socket
117     is of the specified family (<constant>AF_UNIX</constant>,
118     <constant>AF_INET</constant>, …). If the <parameter>type</parameter>
119     parameter is not 0, it is checked whether the socket is of the
120     specified type (<constant>SOCK_STREAM</constant>,
121     <constant>SOCK_DGRAM</constant>, …). If the
122     <parameter>listening</parameter> parameter is positive, it is
123     checked whether the socket is in accepting mode, i.e.
124     <function>listen()</function> has been called for it. If
125     <parameter>listening</parameter> is 0, it is checked whether the
126     socket is not in this mode. If the parameter is negative, no such
127     check is made. The <parameter>listening</parameter> parameter
128     should only be used for stream sockets and should be set to a
129     negative value otherwise.</para>
130
131     <para><function>sd_is_socket_inet()</function> is similar to
132     <function>sd_is_socket()</function>, but optionally checks the
133     IPv4 or IPv6 port number the socket is bound to, unless
134     <parameter>port</parameter> is zero. For this call
135     <parameter>family</parameter> must be passed as either
136     <constant>AF_UNSPEC</constant>, <constant>AF_INET</constant>, or
137     <constant>AF_INET6</constant>.</para>
138
139     <para><function>sd_is_socket_sockaddr()</function> is similar to
140     <function>sd_is_socket_inet()</function>, but checks if the socket is bound to the
141     address specified by <parameter>addr</parameter>. The
142     <structfield>family</structfield> specified by <parameter>addr</parameter> must be
143     either <constant>AF_INET</constant> or <constant>AF_INET6</constant> and
144     <parameter>addr_len</parameter> must be large enough for that family. If
145     <parameter>addr</parameter> specifies a non-zero port, it is also checked if the
146     socket is bound to this port. In addition, for IPv6, if <parameter>addr</parameter>
147     specifies non-zero <structfield>sin6_flowinfo</structfield> or
148     <structfield>sin6_scope_id</structfield>, it is checked if the socket has the same
149     values.</para>
150
151     <para><function>sd_is_socket_unix()</function> is similar to
152     <function>sd_is_socket()</function> but optionally checks the
153     <constant>AF_UNIX</constant> path the socket is bound to, unless
154     the <parameter>path</parameter> parameter is
155     <constant>NULL</constant>. For normal file system
156     <constant>AF_UNIX</constant> sockets, set the
157     <parameter>length</parameter> parameter to 0. For Linux abstract
158     namespace sockets, set the <parameter>length</parameter> to the
159     size of the address, including the initial 0 byte, and set the
160     <parameter>path</parameter> to the initial 0 byte of the socket
161     address.</para>
162
163     <para><function>sd_is_mq()</function> may be called to check
164     whether the specified file descriptor refers to a POSIX message
165     queue. If the <parameter>path</parameter> parameter is not
166     <constant>NULL</constant>, it is checked whether the message queue
167     is bound to the specified name.</para>
168
169     <para><function>sd_is_special()</function> may be called to check
170     whether the specified file descriptor refers to a special file. If
171     the <parameter>path</parameter> parameter is not
172     <constant>NULL</constant>, it is checked whether the file
173     descriptor is bound to the specified filename. Special files in
174     this context are character device nodes and files in
175     <filename>/proc</filename> or <filename>/sys</filename>.</para>
176   </refsect1>
177
178   <refsect1>
179     <title>Return Value</title>
180
181     <para>On failure, these calls return a negative errno-style error
182     code. If the file descriptor is of the specified type and bound to
183     the specified address, a positive return value is returned,
184     otherwise zero.</para>
185   </refsect1>
186
187   <refsect1>
188     <title>Notes</title>
189
190     <xi:include href="libelogind-pkgconfig.xml" xpointer="pkgconfig-text"/>
191
192     <para>Internally, these function use a combination of
193     <filename>fstat()</filename> and
194     <filename>getsockname()</filename> to check the file descriptor
195     type and where it is bound to.</para>
196   </refsect1>
197
198   <refsect1>
199     <title>See Also</title>
200     <para>
201       <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
202       <citerefentry><refentrytitle>sd-daemon</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
203       <citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
204       <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
205       <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
206       <citerefentry project='man-pages'><refentrytitle>ip</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
207       <citerefentry project='man-pages'><refentrytitle>ipv6</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
208       <citerefentry project='man-pages'><refentrytitle>unix</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
209       <citerefentry project='man-pages'><refentrytitle>fifo</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
210       <citerefentry project='man-pages'><refentrytitle>mq_overview</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
211       <citerefentry project='man-pages'><refentrytitle>socket</refentrytitle><manvolnum>7</manvolnum></citerefentry>.
212     </para>
213   </refsect1>
214
215 </refentry>