| 1 |
'\" t |
| 2 |
.TH "SD_IS_FIFO" "3" "" "systemd 261~rc3" "sd_is_fifo" |
| 3 |
.\" ----------------------------------------------------------------- |
| 4 |
.\" * Define some portability stuff |
| 5 |
.\" ----------------------------------------------------------------- |
| 6 |
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 7 |
.\" http://bugs.debian.org/507673 |
| 8 |
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html |
| 9 |
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 10 |
.ie \n(.g .ds Aq \(aq |
| 11 |
.el .ds Aq ' |
| 12 |
.\" ----------------------------------------------------------------- |
| 13 |
.\" * set default formatting |
| 14 |
.\" ----------------------------------------------------------------- |
| 15 |
.\" disable hyphenation |
| 16 |
.nh |
| 17 |
.\" disable justification (adjust text to left margin only) |
| 18 |
.ad l |
| 19 |
.\" ----------------------------------------------------------------- |
| 20 |
.\" * MAIN CONTENT STARTS HERE * |
| 21 |
.\" ----------------------------------------------------------------- |
| 22 |
.SH "NAME" |
| 23 |
sd_is_fifo, sd_is_socket, sd_is_socket_inet, sd_is_socket_unix, sd_is_socket_sockaddr, sd_is_mq, sd_is_special \- Check the type of a file descriptor |
| 24 |
.SH "SYNOPSIS" |
| 25 |
.sp |
| 26 |
.ft B |
| 27 |
.nf |
| 28 |
#include <systemd/sd\-daemon\&.h> |
| 29 |
.fi |
| 30 |
.ft |
| 31 |
.HP \w'int\ sd_is_fifo('u |
| 32 |
.BI "int sd_is_fifo(int\ " "fd" ", const\ char\ *" "path" ");" |
| 33 |
.HP \w'int\ sd_is_socket('u |
| 34 |
.BI "int sd_is_socket(int\ " "fd" ", int\ " "family" ", int\ " "type" ", int\ " "listening" ");" |
| 35 |
.HP \w'int\ sd_is_socket_inet('u |
| 36 |
.BI "int sd_is_socket_inet(int\ " "fd" ", int\ " "family" ", int\ " "type" ", int\ " "listening" ", uint16_t\ " "port" ");" |
| 37 |
.HP \w'int\ sd_is_socket_sockaddr('u |
| 38 |
.BI "int sd_is_socket_sockaddr(int\ " "fd" ", int\ " "type" ", const\ struct\ sockaddr\ *" "addr" ", unsigned\ " "addr_len" ", int\ " "listening" ");" |
| 39 |
.HP \w'int\ sd_is_socket_unix('u |
| 40 |
.BI "int sd_is_socket_unix(int\ " "fd" ", int\ " "type" ", int\ " "listening" ", const\ char\ *" "path" ", size_t\ " "length" ");" |
| 41 |
.HP \w'int\ sd_is_mq('u |
| 42 |
.BI "int sd_is_mq(int\ " "fd" ", const\ char\ *" "path" ");" |
| 43 |
.HP \w'int\ sd_is_special('u |
| 44 |
.BI "int sd_is_special(int\ " "fd" ", const\ char\ *" "path" ");" |
| 45 |
.SH "DESCRIPTION" |
| 46 |
.PP |
| 47 |
\fBsd_is_fifo()\fR |
| 48 |
may be called to check whether the specified file descriptor refers to a FIFO or pipe\&. If the |
| 49 |
\fIpath\fR |
| 50 |
parameter is not |
| 51 |
\fBNULL\fR, it is checked whether the FIFO is bound to the specified file system path\&. |
| 52 |
.PP |
| 53 |
\fBsd_is_socket()\fR |
| 54 |
may be called to check whether the specified file descriptor refers to a socket\&. If the |
| 55 |
\fIfamily\fR |
| 56 |
parameter is not |
| 57 |
\fBAF_UNSPEC\fR, it is checked whether the socket is of the specified family (\fBAF_UNIX\fR, |
| 58 |
\fBAF_INET\fR, \&...)\&. If the |
| 59 |
\fItype\fR |
| 60 |
parameter is not 0, it is checked whether the socket is of the specified type (\fBSOCK_STREAM\fR, |
| 61 |
\fBSOCK_DGRAM\fR, \&...)\&. If the |
| 62 |
\fIlistening\fR |
| 63 |
parameter is positive, it is checked whether the socket is in accepting mode, i\&.e\&. |
| 64 |
\fBlisten()\fR |
| 65 |
has been called for it\&. If |
| 66 |
\fIlistening\fR |
| 67 |
is 0, it is checked whether the socket is not in this mode\&. If the parameter is negative, no such check is made\&. The |
| 68 |
\fIlistening\fR |
| 69 |
parameter should only be used for stream sockets and should be set to a negative value otherwise\&. |
| 70 |
.PP |
| 71 |
\fBsd_is_socket_inet()\fR |
| 72 |
is similar to |
| 73 |
\fBsd_is_socket()\fR, but optionally checks the IPv4 or IPv6 port number the socket is bound to, unless |
| 74 |
\fIport\fR |
| 75 |
is zero\&. For this call |
| 76 |
\fIfamily\fR |
| 77 |
must be passed as either |
| 78 |
\fBAF_UNSPEC\fR, |
| 79 |
\fBAF_INET\fR, or |
| 80 |
\fBAF_INET6\fR\&. |
| 81 |
.PP |
| 82 |
\fBsd_is_socket_sockaddr()\fR |
| 83 |
is similar to |
| 84 |
\fBsd_is_socket_inet()\fR, but checks if the socket is bound to the address specified by |
| 85 |
\fIaddr\fR\&. The |
| 86 |
\fIfamily\fR |
| 87 |
specified by |
| 88 |
\fIaddr\fR |
| 89 |
must be either |
| 90 |
\fBAF_INET\fR |
| 91 |
or |
| 92 |
\fBAF_INET6\fR |
| 93 |
and |
| 94 |
\fIaddr_len\fR |
| 95 |
must be large enough for that family\&. If |
| 96 |
\fIaddr\fR |
| 97 |
specifies a non\-zero port, it is also checked if the socket is bound to this port\&. In addition, for IPv6, if |
| 98 |
\fIaddr\fR |
| 99 |
specifies non\-zero |
| 100 |
\fIsin6_flowinfo\fR |
| 101 |
or |
| 102 |
\fIsin6_scope_id\fR, it is checked if the socket has the same values\&. |
| 103 |
.PP |
| 104 |
\fBsd_is_socket_unix()\fR |
| 105 |
is similar to |
| 106 |
\fBsd_is_socket()\fR |
| 107 |
but optionally checks the |
| 108 |
\fBAF_UNIX\fR |
| 109 |
path the socket is bound to, unless the |
| 110 |
\fIpath\fR |
| 111 |
parameter is |
| 112 |
\fBNULL\fR\&. For normal file system |
| 113 |
\fBAF_UNIX\fR |
| 114 |
sockets, set the |
| 115 |
\fIlength\fR |
| 116 |
parameter to 0\&. For Linux abstract namespace sockets, set the |
| 117 |
\fIlength\fR |
| 118 |
to the size of the address, including the initial 0 byte, and set the |
| 119 |
\fIpath\fR |
| 120 |
to the initial 0 byte of the socket address\&. |
| 121 |
.PP |
| 122 |
\fBsd_is_mq()\fR |
| 123 |
may be called to check whether the specified file descriptor refers to a POSIX message queue\&. If the |
| 124 |
\fIpath\fR |
| 125 |
parameter is not |
| 126 |
\fBNULL\fR, it is checked whether the message queue is bound to the specified name\&. |
| 127 |
.PP |
| 128 |
\fBsd_is_special()\fR |
| 129 |
may be called to check whether the specified file descriptor refers to a special file\&. If the |
| 130 |
\fIpath\fR |
| 131 |
parameter is not |
| 132 |
\fBNULL\fR, it is checked whether the file descriptor is bound to the specified filename\&. Special files in this context are character device nodes and files in |
| 133 |
/proc/ |
| 134 |
or |
| 135 |
/sys/\&. |
| 136 |
.SH "RETURN VALUE" |
| 137 |
.PP |
| 138 |
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\&. |
| 139 |
.SH "NOTES" |
| 140 |
.PP |
| 141 |
Functions described here are available as a shared library, which can be compiled against and linked to with the |
| 142 |
\fBlibsystemd\fR\ \&\fBpkg-config\fR(1) |
| 143 |
file\&. |
| 144 |
.PP |
| 145 |
Internally, these functions use a combination of |
| 146 |
\fBfstat\fR(2) |
| 147 |
and |
| 148 |
\fBgetsockname\fR(2) |
| 149 |
to check the file descriptor type and where it is bound to\&. |
| 150 |
.SH "HISTORY" |
| 151 |
.PP |
| 152 |
\fBsd_is_special()\fR |
| 153 |
was added in version 209\&. |
| 154 |
.PP |
| 155 |
\fBsd_is_socket_sockaddr()\fR |
| 156 |
was added in version 233\&. |
| 157 |
.SH "SEE ALSO" |
| 158 |
.PP |
| 159 |
\fBsystemd\fR(1), \fBsd-daemon\fR(3), \fBsd_listen_fds\fR(3), \fBsystemd.service\fR(5), \fBsystemd.socket\fR(5), \fBip\fR(7), \fBipv6\fR(7), \fBunix\fR(7), \fBfifo\fR(7), \fBmq_overview\fR(7), \fBsocket\fR(7)\&. |