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:


and that's the tea β˜• β€” footer says systemd 261.3, page SD_IS_FIFO(3). luv u, bye! πŸ’–βœ¨

πŸ“¦ where this page comes from