systemd/man/sd_is_fifo.3
2015-02-17 11:22:16 +01:00

133 lines
4.8 KiB
Groff

'\" t
.TH "SD_IS_FIFO" "3" "" "systemd 219" "sd_is_fifo"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
sd_is_fifo, sd_is_socket, sd_is_socket_inet, sd_is_socket_unix, sd_is_mq, sd_is_special \- Check the type of a file descriptor
.SH "SYNOPSIS"
.sp
.ft B
.nf
#include <systemd/sd\-daemon\&.h>
.fi
.ft
.HP \w'int\ sd_is_fifo('u
.BI "int sd_is_fifo(int\ " "fd" ", const\ char\ *" "path" ");"
.HP \w'int\ sd_is_socket('u
.BI "int sd_is_socket(int\ " "fd" ", int\ " "family" ", int\ " "type" ", int\ " "listening" ");"
.HP \w'int\ sd_is_socket_inet('u
.BI "int sd_is_socket_inet(int\ " "fd" ", int\ " "family" ", int\ " "type" ", int\ " "listening" ", uint16_t\ " "port" ");"
.HP \w'int\ sd_is_socket_unix('u
.BI "int sd_is_socket_unix(int\ " "fd" ", int\ " "type" ", int\ " "listening" ", const\ char\ *" "path" ", size_t\ " "length" ");"
.HP \w'int\ sd_is_mq('u
.BI "int sd_is_mq(int\ " "fd" ", const\ char\ *" "path" ");"
.HP \w'int\ sd_is_special('u
.BI "int sd_is_special(int\ " "fd" ", const\ char\ *" "path" ");"
.SH "DESCRIPTION"
.PP
\fBsd_is_fifo()\fR
may be called to check whether the specified file descriptor refers to a FIFO or pipe\&. If the
\fIpath\fR
parameter is not
\fBNULL\fR, it is checked whether the FIFO is bound to the specified file system path\&.
.PP
\fBsd_is_socket()\fR
may be called to check whether the specified file descriptor refers to a socket\&. If the
\fIfamily\fR
parameter is not
\fBAF_UNSPEC\fR, it is checked whether the socket is of the specified family (AF_UNIX,
\fBAF_INET\fR, \&.\&.\&.)\&. If the
\fItype\fR
parameter is not 0, it is checked whether the socket is of the specified type (\fBSOCK_STREAM\fR,
\fBSOCK_DGRAM\fR, \&.\&.\&.)\&. If the
\fIlistening\fR
parameter is positive, it is checked whether the socket is in accepting mode, i\&.e\&.
\fBlisten()\fR
has been called for it\&. If
\fIlistening\fR
is 0, it is checked whether the socket is not in this mode\&. If the parameter is negative, no such check is made\&. The
\fIlistening\fR
parameter should only be used for stream sockets and should be set to a negative value otherwise\&.
.PP
\fBsd_is_socket_inet()\fR
is similar to
\fBsd_is_socket()\fR, but optionally checks the IPv4 or IPv6 port number the socket is bound to, unless
\fIport\fR
is zero\&. For this call
\fIfamily\fR
must be passed as either
\fBAF_UNSPEC\fR,
\fBAF_INET\fR, or
\fBAF_INET6\fR\&.
.PP
\fBsd_is_socket_unix()\fR
is similar to
\fBsd_is_socket()\fR
but optionally checks the
\fBAF_UNIX\fR
path the socket is bound to, unless the
\fIpath\fR
parameter is
\fBNULL\fR\&. For normal file system
\fBAF_UNIX\fR
sockets, set the
\fIlength\fR
parameter to 0\&. For Linux abstract namespace sockets, set the
\fIlength\fR
to the size of the address, including the initial 0 byte, and set the
\fIpath\fR
to the initial 0 byte of the socket address\&.
.PP
\fBsd_is_mq()\fR
may be called to check whether the specified file descriptor refers to a POSIX message queue\&. If the
\fIpath\fR
parameter is not
\fBNULL\fR, it is checked whether the message queue is bound to the specified name\&.
.PP
\fBsd_is_special()\fR
may be called to check whether the specified file descriptor refers to a special file\&. If the
\fIpath\fR
parameter is not
\fBNULL\fR, it is checked whether the file descriptor is bound to the specified file name\&. Special files in this context are character device nodes and files in
/proc
or
/sys\&.
.SH "RETURN VALUE"
.PP
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\&.
.SH "NOTES"
.PP
These APIs are implemented as a shared library, which can be compiled and linked to with the
\fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
file\&.
.PP
Internally, these function use a combination of
fstat()
and
getsockname()
to check the file descriptor type and where it is bound to\&.
.SH "SEE ALSO"
.PP
\fBsystemd\fR(1),
\fBsd-daemon\fR(3),
\fBsd_listen_fds\fR(3),
\fBsystemd.service\fR(5),
\fBsystemd.socket\fR(5)