1SD_IS_FIFO(3)                     sd_is_fifo                     SD_IS_FIFO(3)
2
3
4

NAME

6       sd_is_fifo, sd_is_socket, sd_is_socket_inet, sd_is_socket_unix - Check
7       the type of a file descriptor
8

SYNOPSIS

10       #include "sd-daemon.h"
11
12       int sd_is_fifo(int fd, const char *path);
13
14       int sd_is_socket(int fd, int family, int type, int listening);
15
16       int sd_is_socket_inet(int fd, int family, int type, int listening,
17                             uint16_t port);
18
19       int sd_is_socket_unix(int fd, int type, int listening,
20                             const char* path, size_t length);
21

DESCRIPTION

23       sd_is_fifo() may be called to check whether the specified file
24       descriptor refers to a FIFO or pipe. If the path parameter is not NULL,
25       it is checked whether the FIFO is bound to the specified file system
26       path.
27
28       sd_is_socket() may be called to check whether the specified file
29       descriptor refers to a socket. It the family parameter is not AF_UNSPEC
30       it is checked whether the socket is of the specified family (AF_UNIX,
31       AF_INET, ...). If the type parameter is not 0 it is checked whether the
32       socket is of the specified type (SOCK_STREAM, SOCK_DGRAM, ...). If the
33       listening parameter is positive it is checked whether the socket is in
34       accepting mode, i.e.  listen() has been called for it. If listening is
35       0, it is checked whether the socket is not in this mode. If the
36       parameter is negative, no such check is made. The listening parameter
37       should only be used for stream sockets and should be set to a negative
38       value otherwise.
39
40       sd_is_socket_inet() is similar to sd_is_socket(), but optionally checks
41       the IPv4 or IPv6 port number the socket is bound to, unless port is
42       zero. For this call family must be passed as either AF_UNSPEC, AF_INET
43       or AF_INET6.
44
45       sd_is_socket_unix() is similar to sd_is_socket(), but optionally checks
46       the AF_UNIX path the socket is bound to, unless the path parameter is
47       NULL. For normal file system AF_UNIX sockets set the length parameter
48       to 0. For Linux abstract namespace sockets set the length to the size
49       of the address, including the initial 0 byte and set path to the
50       initial 0 byte of the socket address.
51

RETURN VALUE

53       On failure, these calls return a negative errno-style error code. If
54       the file descriptor is of the specified type and bound to the specified
55       address a positive return value is returned, otherwise zero.
56

NOTES

58       These functions are provided by the reference implementation of APIs
59       for new-style daemons and distributed with the systemd package. The
60       algorithms they implement are simple, and can easily be reimplemented
61       in daemons if it is important to support this interface without using
62       the reference implementation.
63
64       Internally, these function use a combination of fstat() and
65       getsockname() to check the file descriptor type and where it is bound
66       to.
67
68       For details about the algorithm check the liberally licensed reference
69       implementation sources:
70       http://cgit.freedesktop.org/systemd/tree/src/sd-daemon.c resp.
71       http://cgit.freedesktop.org/systemd/tree/src/sd-daemon.h
72
73       sd_is_fifo() and the related functions are implemented in the reference
74       implementation´s drop-in sd-daemon.c and sd-daemon.h files. It is
75       recommended that applications consuming these APIs copy the
76       implementation into their source tree. For more details about the
77       reference implementation see sd_daemon(7)
78
79       These functions continue to work as described, even if
80       -DDISABLE_SYSTEMD is set during compilation.
81

SEE ALSO

83       systemd(1), sd-daemon(7), sd_listen_fds(3), systemd.service(5),
84       systemd.socket(5)
85

AUTHOR

87       Lennart Poettering <lennart@poettering.net>
88           Developer
89
90
91
92systemd                           09/14/2010                     SD_IS_FIFO(3)
Impressum