systemd/man/sd_is_socket_unix.html
2014-04-27 12:02:08 +02:00

103 lines
11 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>sd_is_fifo</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><style>
a.headerlink {
color: #c60f0f;
font-size: 0.8em;
padding: 0 4px 0 4px;
text-decoration: none;
visibility: hidden;
}
a.headerlink:hover {
background-color: #c60f0f;
color: white;
}
h1:hover > a.headerlink, h2:hover > a.headerlink, h3:hover > a.headerlink, dt:hover > a.headerlink {
visibility: visible;
}
</style><a href="index.html">Index </a>·
<a href="systemd.directives.html">Directives </a>·
<a href="../python-systemd/index.html">Python </a>·
<a href="../libudev/index.html">libudev </a>·
<a href="../libudev/index.html">gudev </a><span style="float:right">systemd 208</span><hr><div class="refentry"><a name="sd_is_fifo"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>sd_is_fifo, sd_is_socket, sd_is_socket_inet, sd_is_socket_unix, sd_is_mq — Check the type of a file descriptor</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><pre class="funcsynopsisinfo">#include &lt;systemd/sd-daemon.h&gt;</pre><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_is_fifo</b>(</code></td><td>int <var class="pdparam">fd</var>, </td></tr><tr><td> </td><td>const char *<var class="pdparam">path</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_is_socket</b>(</code></td><td>int <var class="pdparam">fd</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">family</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">type</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">listening</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_is_socket_inet</b>(</code></td><td>int <var class="pdparam">fd</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">family</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">type</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">listening</var>, </td></tr><tr><td> </td><td>uint16_t <var class="pdparam">port</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_is_socket_unix</b>(</code></td><td>int <var class="pdparam">fd</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">type</var>, </td></tr><tr><td> </td><td>int <var class="pdparam">listening</var>, </td></tr><tr><td> </td><td>const char* <var class="pdparam">path</var>, </td></tr><tr><td> </td><td>size_t <var class="pdparam">length</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">int <b class="fsfunc">sd_is_mq</b>(</code></td><td>int <var class="pdparam">fd</var>, </td></tr><tr><td> </td><td>const char *<var class="pdparam">path</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer"> </div></div></div><div class="refsect1"><a name="idm274698824000"></a><h2 id="Description">Description<a class="headerlink" title="Permalink to this headline" href="#Description"></a></h2><p><code class="function">sd_is_fifo()</code> may be called
to check whether the specified file descriptor refers
to a FIFO or pipe. If the <em class="parameter"><code>path</code></em>
parameter is not <code class="constant">NULL</code>, it is
checked whether the FIFO is bound to the specified
file system path.</p><p><code class="function">sd_is_socket()</code> may be
called to check whether the specified file descriptor
refers to a socket. If the
<em class="parameter"><code>family</code></em> parameter is not
<code class="constant">AF_UNSPEC</code>, it is checked whether
the socket is of the specified family (AF_UNIX,
<code class="constant">AF_INET</code>, ...). If the
<em class="parameter"><code>type</code></em> parameter is not 0, it is
checked whether the socket is of the specified type
(<code class="constant">SOCK_STREAM</code>,
<code class="constant">SOCK_DGRAM</code>, ...). If the
<em class="parameter"><code>listening</code></em> parameter is positive,
it is checked whether the socket is in accepting mode,
i.e. <code class="function">listen()</code> has been called for
it. If <em class="parameter"><code>listening</code></em> is 0, it is
checked whether the socket is not in this mode. If the
parameter is negative, no such check is made. The
<em class="parameter"><code>listening</code></em> parameter should only
be used for stream sockets and should be set to a
negative value otherwise.</p><p><code class="function">sd_is_socket_inet()</code> is
similar to <code class="function">sd_is_socket()</code>, but
optionally checks the IPv4 or IPv6 port number the
socket is bound to, unless <em class="parameter"><code>port</code></em>
is zero. For this call <em class="parameter"><code>family</code></em>
must be passed as either <code class="constant">AF_UNSPEC</code>, <code class="constant">AF_INET</code>, or
<code class="constant">AF_INET6</code>.</p><p><code class="function">sd_is_socket_unix()</code> is
similar to <code class="function">sd_is_socket()</code> but
optionally checks the <code class="constant">AF_UNIX</code> path the socket is bound
to, unless the <em class="parameter"><code>path</code></em> parameter
is <code class="constant">NULL</code>. For normal file system <code class="constant">AF_UNIX</code> sockets,
set the <em class="parameter"><code>length</code></em> parameter to 0. For
Linux abstract namespace sockets, set the
<em class="parameter"><code>length</code></em> to the size of the
address, including the initial 0 byte, and set the
<em class="parameter"><code>path</code></em> to the initial 0 byte of
the socket address.</p><p><code class="function">sd_is_mq()</code> may be called to
check whether the specified file descriptor refers to
a POSIX message queue. If the
<em class="parameter"><code>path</code></em> parameter is not
<code class="constant">NULL</code>, it is checked whether the
message queue is bound to the specified name.</p></div><div class="refsect1"><a name="idm274698792912"></a><h2 id="Return Value">Return Value<a class="headerlink" title="Permalink to this headline" href="#Return%20Value"></a></h2><p>On failure, these calls return a negative
errno-style error code. If the file descriptor is of
the specified type and bound to the specified address,
a positive return value is returned, otherwise
zero.</p></div><div class="refsect1"><a name="idm274698791440"></a><h2 id="Notes">Notes<a class="headerlink" title="Permalink to this headline" href="#Notes"></a></h2><p>These functions are provided by the reference
implementation of APIs for new-style daemons and
distributed with the systemd package. The algorithms
they implement are simple, and they can easily be
reimplemented in daemons if it is important to support
this interface without using the reference
implementation.</p><p>Internally, these function use a combination of
<code class="filename">fstat()</code> and
<code class="filename">getsockname()</code> to check the file
descriptor type and where it is bound to.</p><p>For details about the algorithms, check the
liberally licensed reference implementation sources:
<a class="ulink" href="http://cgit.freedesktop.org/systemd/systemd/plain/src/libsystemd-daemon/sd-daemon.c" target="_top">http://cgit.freedesktop.org/systemd/systemd/plain/src/libsystemd-daemon/sd-daemon.c</a>
and <a class="ulink" href="http://cgit.freedesktop.org/systemd/systemd/plain/src/systemd/sd-daemon.h" target="_top">http://cgit.freedesktop.org/systemd/systemd/plain/src/systemd/sd-daemon.h</a></p><p><code class="function">sd_is_fifo()</code> and the
related functions are implemented in the reference
implementation's <code class="filename">sd-daemon.c</code> and
<code class="filename">sd-daemon.h</code> files. These
interfaces are available as shared library, which can
be compiled and linked to with the
<code class="constant">libsystemd-daemon</code> <a href="pkg-config.html"><span class="citerefentry"><span class="refentrytitle">pkg-config</span>(1)</span></a>
file. Alternatively, applications consuming these APIs
may copy the implementation into their source
tree. For more details about the reference
implementation see
<a href="sd-daemon.html"><span class="citerefentry"><span class="refentrytitle">sd-daemon</span>(3)</span></a>.</p><p>These functions continue to work as described,
even if -DDISABLE_SYSTEMD is set during
compilation.</p></div><div class="refsect1"><a name="idm274698781152"></a><h2 id="See Also">See Also<a class="headerlink" title="Permalink to this headline" href="#See%20Also"></a></h2><p>
<a href="systemd.html"><span class="citerefentry"><span class="refentrytitle">systemd</span>(1)</span></a>,
<a href="sd-daemon.html"><span class="citerefentry"><span class="refentrytitle">sd-daemon</span>(3)</span></a>,
<a href="sd_listen_fds.html"><span class="citerefentry"><span class="refentrytitle">sd_listen_fds</span>(3)</span></a>,
<a href="systemd.service.html"><span class="citerefentry"><span class="refentrytitle">systemd.service</span>(5)</span></a>,
<a href="systemd.socket.html"><span class="citerefentry"><span class="refentrytitle">systemd.socket</span>(5)</span></a>
</p></div></div></body></html>