'\" t .\" Title: sd_is_fifo .\" Author: Lennart Poettering .\" Generator: DocBook XSL Stylesheets v1.76.1 .\" Date: 10/07/2013 .\" Manual: sd_is_fifo .\" Source: systemd .\" Language: English .\" .TH "SD_IS_FIFO" "3" "10/07/2013" "systemd" "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 \- Check the type of a file descriptor .SH "SYNOPSIS" .sp .ft B .nf #include .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" ");" .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 NULL, 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\&. It the \fIfamily\fR parameter is not AF_UNSPEC it is checked whether the socket is of the specified family (AF_UNIX, AF_INET, \&.\&.\&.)\&. If the \fItype\fR parameter is not 0 it is checked whether the socket is of the specified type (SOCK_STREAM, SOCK_DGRAM, \&.\&.\&.)\&. 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 AF_UNSPEC, AF_INET or AF_INET6\&. .PP \fBsd_is_socket_unix()\fR is similar to \fBsd_is_socket()\fR, but optionally checks the AF_UNIX path the socket is bound to, unless the \fIpath\fR parameter is NULL\&. For normal file system AF_UNIX 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 \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 NULL, it is checked whether the message queue is bound to the specified name\&. .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 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 can easily be reimplemented in daemons if it is important to support this interface without using the reference implementation\&. .PP Internally, these function use a combination of fstat() and getsockname() to check the file descriptor type and where it is bound to\&. .PP For details about the algorithms check the liberally licensed reference implementation sources: \m[blue]\fB\%http://cgit.freedesktop.org/systemd/systemd/plain/src/sd-daemon.c\fR\m[] resp\&. \m[blue]\fB\%http://cgit.freedesktop.org/systemd/systemd/plain/src/systemd/sd-daemon.h\fR\m[] .PP \fBsd_is_fifo()\fR and the related functions are implemented in the reference implementation\*(Aqs sd\-daemon\&.c and sd\-daemon\&.h files\&. These interfaces are available as shared library, which can be compiled and linked to with the libsystemd\-daemon \fBpkg-config\fR(1) file\&. Alternatively, applications consuming these APIs may copy the implementation into their source tree\&. For more details about the reference implementation see \fBsd_daemon\fR(7)\&. .PP These functions continue to work as described, even if \-DDISABLE_SYSTEMD is set during compilation\&. .SH "SEE ALSO" .PP \fBsystemd\fR(1), \fBsd-daemon\fR(7), \fBsd_listen_fds\fR(3), \fBsystemd.service\fR(5), \fBsystemd.socket\fR(5) .SH "AUTHOR" .PP \fBLennart Poettering\fR <\&lennart@poettering\&.net\&> .RS 4 Developer .RE