1 <?xml version='1.0'?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4 <!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
6 <refentry id="sd_is_fifo"
7 xmlns:xi="http://www.w3.org/2001/XInclude">
10 <title>sd_is_fifo</title>
11 <productname>systemd</productname>
15 <refentrytitle>sd_is_fifo</refentrytitle>
16 <manvolnum>3</manvolnum>
20 <refname>sd_is_fifo</refname>
21 <refname>sd_is_socket</refname>
22 <refname>sd_is_socket_inet</refname>
23 <refname>sd_is_socket_unix</refname>
24 <refname>sd_is_socket_sockaddr</refname>
25 <refname>sd_is_mq</refname>
26 <refname>sd_is_special</refname>
27 <refpurpose>Check the type of a file descriptor</refpurpose>
32 <funcsynopsisinfo>#include <systemd/sd-daemon.h></funcsynopsisinfo>
35 <funcdef>int <function>sd_is_fifo</function></funcdef>
36 <paramdef>int <parameter>fd</parameter></paramdef>
37 <paramdef>const char *<parameter>path</parameter></paramdef>
41 <funcdef>int <function>sd_is_socket</function></funcdef>
42 <paramdef>int <parameter>fd</parameter></paramdef>
43 <paramdef>int <parameter>family</parameter></paramdef>
44 <paramdef>int <parameter>type</parameter></paramdef>
45 <paramdef>int <parameter>listening</parameter></paramdef>
49 <funcdef>int <function>sd_is_socket_inet</function></funcdef>
50 <paramdef>int <parameter>fd</parameter></paramdef>
51 <paramdef>int <parameter>family</parameter></paramdef>
52 <paramdef>int <parameter>type</parameter></paramdef>
53 <paramdef>int <parameter>listening</parameter></paramdef>
54 <paramdef>uint16_t <parameter>port</parameter></paramdef>
58 <funcdef>int <function>sd_is_socket_sockaddr</function></funcdef>
59 <paramdef>int <parameter>fd</parameter></paramdef>
60 <paramdef>int <parameter>type</parameter></paramdef>
61 <paramdef>const struct sockaddr *<parameter>addr</parameter></paramdef>
62 <paramdef>unsigned <parameter>addr_len</parameter></paramdef>
63 <paramdef>int <parameter>listening</parameter></paramdef>
67 <funcdef>int <function>sd_is_socket_unix</function></funcdef>
68 <paramdef>int <parameter>fd</parameter></paramdef>
69 <paramdef>int <parameter>type</parameter></paramdef>
70 <paramdef>int <parameter>listening</parameter></paramdef>
71 <paramdef>const char *<parameter>path</parameter></paramdef>
72 <paramdef>size_t <parameter>length</parameter></paramdef>
76 <funcdef>int <function>sd_is_mq</function></funcdef>
77 <paramdef>int <parameter>fd</parameter></paramdef>
78 <paramdef>const char *<parameter>path</parameter></paramdef>
82 <funcdef>int <function>sd_is_special</function></funcdef>
83 <paramdef>int <parameter>fd</parameter></paramdef>
84 <paramdef>const char *<parameter>path</parameter></paramdef>
91 <title>Description</title>
93 <para><function>sd_is_fifo()</function> may be called to check
94 whether the specified file descriptor refers to a FIFO or pipe. If
95 the <parameter>path</parameter> parameter is not
96 <constant>NULL</constant>, it is checked whether the FIFO is bound
97 to the specified file system path.</para>
99 <para><function>sd_is_socket()</function> may be called to check
100 whether the specified file descriptor refers to a socket. If the
101 <parameter>family</parameter> parameter is not
102 <constant>AF_UNSPEC</constant>, it is checked whether the socket
103 is of the specified family (<constant>AF_UNIX</constant>,
104 <constant>AF_INET</constant>, …). If the <parameter>type</parameter>
105 parameter is not 0, it is checked whether the socket is of the
106 specified type (<constant>SOCK_STREAM</constant>,
107 <constant>SOCK_DGRAM</constant>, …). If the
108 <parameter>listening</parameter> parameter is positive, it is
109 checked whether the socket is in accepting mode, i.e.
110 <function>listen()</function> has been called for it. If
111 <parameter>listening</parameter> is 0, it is checked whether the
112 socket is not in this mode. If the parameter is negative, no such
113 check is made. The <parameter>listening</parameter> parameter
114 should only be used for stream sockets and should be set to a
115 negative value otherwise.</para>
117 <para><function>sd_is_socket_inet()</function> is similar to
118 <function>sd_is_socket()</function>, but optionally checks the
119 IPv4 or IPv6 port number the socket is bound to, unless
120 <parameter>port</parameter> is zero. For this call
121 <parameter>family</parameter> must be passed as either
122 <constant>AF_UNSPEC</constant>, <constant>AF_INET</constant>, or
123 <constant>AF_INET6</constant>.</para>
125 <para><function>sd_is_socket_sockaddr()</function> is similar to
126 <function>sd_is_socket_inet()</function>, but checks if the socket is bound to the
127 address specified by <parameter>addr</parameter>. The
128 <structfield>family</structfield> specified by <parameter>addr</parameter> must be
129 either <constant>AF_INET</constant> or <constant>AF_INET6</constant> and
130 <parameter>addr_len</parameter> must be large enough for that family. If
131 <parameter>addr</parameter> specifies a non-zero port, it is also checked if the
132 socket is bound to this port. In addition, for IPv6, if <parameter>addr</parameter>
133 specifies non-zero <structfield>sin6_flowinfo</structfield> or
134 <structfield>sin6_scope_id</structfield>, it is checked if the socket has the same
137 <para><function>sd_is_socket_unix()</function> is similar to
138 <function>sd_is_socket()</function> but optionally checks the
139 <constant>AF_UNIX</constant> path the socket is bound to, unless
140 the <parameter>path</parameter> parameter is
141 <constant>NULL</constant>. For normal file system
142 <constant>AF_UNIX</constant> sockets, set the
143 <parameter>length</parameter> parameter to 0. For Linux abstract
144 namespace sockets, set the <parameter>length</parameter> to the
145 size of the address, including the initial 0 byte, and set the
146 <parameter>path</parameter> to the initial 0 byte of the socket
149 <para><function>sd_is_mq()</function> may be called to check
150 whether the specified file descriptor refers to a POSIX message
151 queue. If the <parameter>path</parameter> parameter is not
152 <constant>NULL</constant>, it is checked whether the message queue
153 is bound to the specified name.</para>
155 <para><function>sd_is_special()</function> may be called to check
156 whether the specified file descriptor refers to a special file. If
157 the <parameter>path</parameter> parameter is not
158 <constant>NULL</constant>, it is checked whether the file
159 descriptor is bound to the specified filename. Special files in
160 this context are character device nodes and files in
161 <filename>/proc/</filename> or <filename>/sys/</filename>.</para>
165 <title>Return Value</title>
167 <para>On failure, these calls return a negative errno-style error
168 code. If the file descriptor is of the specified type and bound to
169 the specified address, a positive return value is returned,
170 otherwise zero.</para>
176 <xi:include href="libsystemd-pkgconfig.xml" xpointer="pkgconfig-text"/>
178 <para>Internally, these functions use a combination of
179 <citerefentry project='man-pages'><refentrytitle>fstat</refentrytitle><manvolnum>2</manvolnum></citerefentry>
181 <citerefentry project='man-pages'><refentrytitle>getsockname</refentrytitle><manvolnum>2</manvolnum></citerefentry>
182 to check the file descriptor type and where it is bound to.</para>
186 <title>History</title>
187 <para><function>sd_is_special()</function> was added in version 209.</para>
188 <para><function>sd_is_socket_sockaddr()</function> was added in version 233.</para>
192 <title>See Also</title>
194 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
195 <citerefentry><refentrytitle>sd-daemon</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
196 <citerefentry><refentrytitle>sd_listen_fds</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
197 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
198 <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
199 <citerefentry project='man-pages'><refentrytitle>ip</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
200 <citerefentry project='man-pages'><refentrytitle>ipv6</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
201 <citerefentry project='man-pages'><refentrytitle>unix</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
202 <citerefentry project='man-pages'><refentrytitle>fifo</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
203 <citerefentry project='man-pages'><refentrytitle>mq_overview</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
204 <citerefentry project='man-pages'><refentrytitle>socket</refentrytitle><manvolnum>7</manvolnum></citerefentry>.