SD_IS_FIFO(3)
πΈ NAME πΈ
hey bestie!! welcome to the sd_is_fifo(3) manual page β it's giving βfile descriptor vibe checkβ energy. the whole squad is here: sd_is_fifo, sd_is_socket, sd_is_socket_inet, sd_is_socket_unix, sd_is_socket_sockaddr, sd_is_mq, and sd_is_special. what do they do? Check the type of a file descriptor, periodt. π
β¨ SYNOPSIS β¨
okay so first things first, include this header and then you got the function signatures. no cap, this is the exact code block:
#include <systemd/sd-daemon.h>
int sd_is_fifo(int fd, const char *path);
int sd_is_socket(int fd, int family, int type, int listening);
int sd_is_socket_inet(int fd, int family, int type, int listening,
uint16_t port);
int sd_is_socket_sockaddr(int fd, int type, const struct sockaddr *addr,
unsigned addr_len, int listening);
int sd_is_socket_unix(int fd, int type, int listening, const char *path,
size_t length);
int sd_is_mq(int fd, const char *path);
int sd_is_special(int fd, const char *path);
slay, now we know what we're working with π«Ά
π DESCRIPTION π
π§ sd_is_fifo() β the FIFO/pipe vibe check
call sd_is_fifo() when you need to know if fd refers to a FIFO or pipe. if path is not NULL, it also checks whether the FIFO is bound to that file system path. iconic.
π¦ sd_is_socket() β socket detective era
sd_is_socket() checks whether fd refers to a socket. if family is not AF_UNSPEC, it checks whether the socket is of that family (AF_UNIX, AF_INET, ...). if type is not 0, it checks whether the socket is of that type (SOCK_STREAM, SOCK_DGRAM, ...). if listening is positive, it checks whether the socket is in accepting mode β i.e. listen() has been called for it. if listening is 0, it checks that the socket is not in this mode. if listening is negative, no such check happens.
caveat bestie: listening should only be used for stream sockets, and should be set to a negative value otherwise. don't do a chaos. π
π sd_is_socket_inet() β now with port energy
sd_is_socket_inet() is similar to sd_is_socket(), but it optionally checks the IPv4 or IPv6 port number the socket is bound to β unless port is zero. for this call, family must be passed as either AF_UNSPEC, AF_INET, or AF_INET6. lowkey specific, highkey useful. π
π sd_is_socket_sockaddr() β address-specific queen
sd_is_socket_sockaddr() is similar to sd_is_socket_inet(), but it checks if the socket is bound to the address specified by addr. the family specified by addr must be either AF_INET or AF_INET6, and addr_len must be large enough for that family. if addr specifies a non-zero port, it also checks if the socket is bound to this port. plus, for IPv6, if addr specifies non-zero sin6_flowinfo or sin6_scope_id, it checks if the socket has the same values. the way this one gets specific?? obsessed. π
π sd_is_socket_unix() β abstract namespace iykyk
sd_is_socket_unix() is similar to sd_is_socket(), but it optionally checks the AF_UNIX path the socket is bound to β unless path is NULL. for normal file system AF_UNIX sockets, set length to 0. for Linux abstract namespace sockets, set length to the size of the address, including the initial 0 byte, and set path to the initial 0 byte of the socket address. iykyk. π¦
π sd_is_mq() β message queue moment
call sd_is_mq() to check whether fd refers to a POSIX message queue. if path is not NULL, it checks whether the message queue is bound to that specified name. cute. π
π sd_is_special() β special file check
sd_is_special() checks whether fd refers to a special file. if path is not NULL, it checks whether the file descriptor is bound to the specified filename. in this context, βspecial filesβ are character device nodes and files in /proc/ or /sys/. not me being obsessed with the /proc/ girlies. π
π₯ RETURN VALUE π₯
if something goes wrong, these calls return a negative errno-style error code. if the file descriptor is of the specified type and bound to the specified address, you get a positive return value. otherwise? zero. that's the whole scale, bestie: negative = oops, positive = yes, zero = nope. π
π§ NOTES π§
these functions are available as a shared library, which can be compiled against and linked to with the libsystemd pkg-config(1) file.
internally, these functions use a combination of fstat(2) and getsockname(2) to check the file descriptor type and where it is bound to. the way they're doing fstat + getsockname?? iconic teamwork. π«Ά
π°οΈ HISTORY π°οΈ
sd_is_special()was added in version 209.sd_is_socket_sockaddr()was added in version 233.
π SEE ALSO π
go read these next, bestie:
systemd(1)sd-daemon(3)sd_listen_fds(3)systemd.service(5)systemd.socket(5)ip(7)ipv6(7)unix(7)fifo(7)mq_overview(7)socket(7)
and that's the tea β β footer says systemd 261.3, page SD_IS_FIFO(3). luv u, bye! πβ¨
π¦ where this page comes from
- ubuntu stonking: libsystemd-dev 261.3-0ubuntu3 Β· LGPL-2.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms