1SD_IS_FIFO(3) sd_is_fifo SD_IS_FIFO(3)
2
3
4
6 sd_is_fifo, sd_is_socket, sd_is_socket_inet, sd_is_socket_unix,
7 sd_is_mq, sd_is_special - Check the type of a file descriptor
8
10 #include <systemd/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
22 int sd_is_mq(int fd, const char *path);
23
24 int sd_is_special(int fd, const char *path);
25
27 sd_is_fifo() may be called to check whether the specified file
28 descriptor refers to a FIFO or pipe. If the path parameter is not NULL,
29 it is checked whether the FIFO is bound to the specified file system
30 path.
31
32 sd_is_socket() may be called to check whether the specified file
33 descriptor refers to a socket. If the family parameter is not
34 AF_UNSPEC, it is checked whether the socket is of the specified family
35 (AF_UNIX, AF_INET, ...). If the type parameter is not 0, it is checked
36 whether the socket is of the specified type (SOCK_STREAM, SOCK_DGRAM,
37 ...). If the listening parameter is positive, it is checked whether the
38 socket is in accepting mode, i.e. listen() has been called for it. If
39 listening is 0, it is checked whether the socket is not in this mode.
40 If the parameter is negative, no such check is made. The listening
41 parameter should only be used for stream sockets and should be set to a
42 negative value otherwise.
43
44 sd_is_socket_inet() is similar to sd_is_socket(), but optionally checks
45 the IPv4 or IPv6 port number the socket is bound to, unless port is
46 zero. For this call family must be passed as either AF_UNSPEC, AF_INET,
47 or AF_INET6.
48
49 sd_is_socket_unix() is similar to sd_is_socket() but optionally checks
50 the AF_UNIX path the socket is bound to, unless the path parameter is
51 NULL. For normal file system AF_UNIX sockets, set the length parameter
52 to 0. For Linux abstract namespace sockets, set the length to the size
53 of the address, including the initial 0 byte, and set the path to the
54 initial 0 byte of the socket address.
55
56 sd_is_mq() may be called to check whether the specified file descriptor
57 refers to a POSIX message queue. If the path parameter is not NULL, it
58 is checked whether the message queue is bound to the specified name.
59
60 sd_is_special() may be called to check whether the specified file
61 descriptor refers to a special file. If the path parameter is not NULL,
62 it is checked whether the file descriptor is bound to the specified
63 file name. Special files in this context are character device nodes and
64 files in /proc or /sys.
65
67 On failure, these calls return a negative errno-style error code. If
68 the file descriptor is of the specified type and bound to the specified
69 address, a positive return value is returned, otherwise zero.
70
72 These APIs are implemented as a shared library, which can be compiled
73 and linked to with the libsystemd pkg-config(1) file.
74
75 Internally, these function use a combination of fstat() and
76 getsockname() to check the file descriptor type and where it is bound
77 to.
78
80 systemd(1), sd-daemon(3), sd_listen_fds(3), systemd.service(5),
81 systemd.socket(5)
82
83
84
85systemd 219 SD_IS_FIFO(3)