/* SPDX-License-Identifier: LGPL-2.1-or-later */ /* Copied and adapted from systemd source code. */ #ifndef _SD_SOCKET_H #define _SD_SOCKET_H 1 #include #include #include /* The following functionality is provided: - Support for logging with log levels on stderr - File descriptor passing for socket-based activation - Daemon startup and status notification - Detection of systemd boots See sd-daemon(3) for more information. */ /* The first passed file descriptor is fd 3 */ #define SD_LISTEN_FDS_START 3 /* Helper call for identifying a passed file descriptor. Returns 1 if the file descriptor is a socket of type (SOCK_DGRAM, SOCK_STREAM, ...), 0 otherwise. If type is 0 a socket type check will not be done and the call only verifies if the file descriptor refers to a socket. If listening is > 0 it is verified that the socket is in listening mode. (i.e. listen() has been called) If listening is == 0 it is verified that the socket is not in listening mode. If listening is < 0 no listening mode check is done. Returns a negative errno style error code on failure. See sd_is_socket(3) for more information. */ int sd_is_socket(int fd, int type, int listening); /* Informs systemd about changed daemon state. This takes a number of newline separated environment-style variable assignments in a string. The following variables are known: MAINPID=... The main PID of a daemon, in case systemd did not fork off the process itself. Example: "MAINPID=4711" READY=1 Tells systemd that daemon startup or daemon reload is finished (only relevant for services of Type=notify). The passed argument is a boolean "1" or "0". Since there is little value in signaling non-readiness the only value daemons should send is "READY=1". RELOADING=1 Tell systemd that the daemon began reloading its configuration. When the configuration has been reloaded completely, READY=1 should be sent to inform systemd about this. STOPPING=1 Tells systemd that the daemon is about to go down. STATUS=... Passes a single-line status string back to systemd that describes the daemon state. This is free-form and can be used for various purposes: general state feedback, fsck-like programs could pass completion percentages and failing programs could pass a human readable error message. Example: "STATUS=Completed 66% of file system check..." NOTIFYACCESS=... Reset the access to the service status notification socket. Example: "NOTIFYACCESS=main" ERRNO=... If a daemon fails, the errno-style error code, formatted as string. Example: "ERRNO=2" for ENOENT. BUSERROR=... If a daemon fails, the D-Bus error-style error code. Example: "BUSERROR=org.freedesktop.DBus.Error.TimedOut" WATCHDOG=1 Tells systemd to update the watchdog timestamp. Services using this feature should do this in regular intervals. A watchdog framework can use the timestamps to detect failed services. Also see sd_watchdog_enabled() below. WATCHDOG_USEC=... Reset watchdog_usec value during runtime. To reset watchdog_usec value, start the service again. Example: "WATCHDOG_USEC=20000000" FDSTORE=1 Store the file descriptors passed along with the message in the per-service file descriptor store, and pass them to the main process again on next invocation. This variable is only supported with sd_pid_notify_with_fds(). FDSTOREREMOVE=1 Remove one or more file descriptors from the file descriptor store, identified by the name specified in FDNAME=, see below. FDNAME= A name to assign to new file descriptors stored in the file descriptor store, or the name of the file descriptors to remove in case of FDSTOREREMOVE=1. Daemons can choose to send additional variables. However, it is recommended to prefix variable names not listed above with X_. Returns a negative errno-style error code on failure. Returns > 0 if systemd could be notified, 0 if it couldn't possibly because systemd is not running. Example: When a daemon finished starting up, it could issue this call to notify systemd about it: sd_notify(0, "READY=1"); See sd_notifyf() for more complete examples. See sd_notify(3) for more information. */ /* This is actually a simplified version that you can find right there : https://www.freedesktop.org/software/systemd/man/devel/sd_notify.html#Notes */ int sd_notify_ready(void); int sd_notify_stopping(void); #endif