sd-daemon.h revision 952d1536f4d7b64cfe938a569402434decffe4cd
d657c51f14601d0235434ffb78cf6ac0f27cc83cLennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
220a21d38f675eb835f5758e3d23e896573aa5eaLennart Poettering
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek#ifndef foosddaemonhfoo
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek#define foosddaemonhfoo
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering/***
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering This file is part of systemd.
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek Copyright 2013 Lennart Poettering
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek systemd is free software; you can redistribute it and/or modify it
4bdc60cb6fab336d455abbbd269e5bfccf760c91Lennart Poettering under the terms of the GNU Lesser General Public License as published by
4bdc60cb6fab336d455abbbd269e5bfccf760c91Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering (at your option) any later version.
4bdc60cb6fab336d455abbbd269e5bfccf760c91Lennart Poettering
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek systemd is distributed in the hope that it will be useful, but
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek Lesser General Public License for more details.
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek You should have received a copy of the GNU Lesser General Public License
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek along with systemd; If not, see <http://www.gnu.org/licenses/>.
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek***/
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek
4ffd29fda1a2621d8f1711ccaad723d327fef93aLennart Poettering#include <sys/types.h>
4ffd29fda1a2621d8f1711ccaad723d327fef93aLennart Poettering#include <inttypes.h>
4ffd29fda1a2621d8f1711ccaad723d327fef93aLennart Poettering
4ffd29fda1a2621d8f1711ccaad723d327fef93aLennart Poettering#include "_sd-common.h"
4ffd29fda1a2621d8f1711ccaad723d327fef93aLennart Poettering
4ffd29fda1a2621d8f1711ccaad723d327fef93aLennart Poettering_SD_BEGIN_DECLARATIONS;
4ffd29fda1a2621d8f1711ccaad723d327fef93aLennart Poettering
4ffd29fda1a2621d8f1711ccaad723d327fef93aLennart Poettering/*
4ffd29fda1a2621d8f1711ccaad723d327fef93aLennart Poettering The following functionality is provided:
4ffd29fda1a2621d8f1711ccaad723d327fef93aLennart Poettering
4ffd29fda1a2621d8f1711ccaad723d327fef93aLennart Poettering - Support for logging with log levels on stderr
4ffd29fda1a2621d8f1711ccaad723d327fef93aLennart Poettering - File descriptor passing for socket-based activation
4ffd29fda1a2621d8f1711ccaad723d327fef93aLennart Poettering - Daemon startup and status notification
4ffd29fda1a2621d8f1711ccaad723d327fef93aLennart Poettering - Detection of systemd boots
4ffd29fda1a2621d8f1711ccaad723d327fef93aLennart Poettering
4ffd29fda1a2621d8f1711ccaad723d327fef93aLennart Poettering See sd-daemon(3) for more information.
4ffd29fda1a2621d8f1711ccaad723d327fef93aLennart Poettering*/
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek/*
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek Log levels for usage on stderr:
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek fprintf(stderr, SD_NOTICE "Hello World!\n");
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek This is similar to printk() usage in the kernel.
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek*/
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek#define SD_EMERG "<0>" /* system is unusable */
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering#define SD_ALERT "<1>" /* action must be taken immediately */
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering#define SD_CRIT "<2>" /* critical conditions */
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering#define SD_ERR "<3>" /* error conditions */
090771492f155cebe7075171530e96c1cd515d71Lennart Poettering#define SD_WARNING "<4>" /* warning conditions */
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek#define SD_NOTICE "<5>" /* normal but significant condition */
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek#define SD_INFO "<6>" /* informational */
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek#define SD_DEBUG "<7>" /* debug-level messages */
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek
ba8df74bb643c0f7c343fef78bba3661b0f9c31cKay Sievers/* The first passed file descriptor is fd 3 */
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering#define SD_LISTEN_FDS_START 3
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek/*
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek Returns how many file descriptors have been passed, or a negative
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek errno code on failure. Optionally, removes the $LISTEN_FDS and
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek $LISTEN_PID file descriptors from the environment (recommended, but
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek problematic in threaded environments). If r is the return value of
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek this function you'll find the file descriptors passed as fds
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek SD_LISTEN_FDS_START to SD_LISTEN_FDS_START+r-1. Returns a negative
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek errno style error code on failure. This function call ensures that
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering the FD_CLOEXEC flag is set for the passed file descriptors, to make
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek sure they are not passed on to child processes. If FD_CLOEXEC shall
4bdc60cb6fab336d455abbbd269e5bfccf760c91Lennart Poettering not be set, the caller needs to unset it after this call for all file
f6d1de8547b1e957773f8b6764420579c8378aafRonny Chevalier descriptors that are used.
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering See sd_listen_fds(3) for more information.
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering*/
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poetteringint sd_listen_fds(int unset_environment);
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek
c4ac990007cd0069bb7e76ec15dd731320f382fdLennart Poettering/*
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek Helper call for identifying a passed file descriptor. Returns 1 if
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek the file descriptor is a FIFO in the file system stored under the
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek specified path, 0 otherwise. If path is NULL a path name check will
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek not be done and the call only verifies if the file descriptor
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek refers to a FIFO. Returns a negative errno style error code on
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek failure.
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek
ba8df74bb643c0f7c343fef78bba3661b0f9c31cKay Sievers See sd_is_fifo(3) for more information.
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering*/
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poetteringint sd_is_fifo(int fd, const char *path);
b62a309a47dd11e11729616767421397b6ca7053Zbigniew Jędrzejewski-Szmek
e6c253e363dee77ef7e5c5f44c4ca55cded3fd47Michal Schmidt/*
e6c253e363dee77ef7e5c5f44c4ca55cded3fd47Michal Schmidt Helper call for identifying a passed file descriptor. Returns 1 if
e6c253e363dee77ef7e5c5f44c4ca55cded3fd47Michal Schmidt the file descriptor is a special character device on the file
e6c253e363dee77ef7e5c5f44c4ca55cded3fd47Michal Schmidt system stored under the specified path, 0 otherwise.
ba8df74bb643c0f7c343fef78bba3661b0f9c31cKay Sievers If path is NULL a path name check will not be done and the call
ba8df74bb643c0f7c343fef78bba3661b0f9c31cKay Sievers only verifies if the file descriptor refers to a special character.
e6c253e363dee77ef7e5c5f44c4ca55cded3fd47Michal Schmidt Returns a negative errno style error code on failure.
e6c253e363dee77ef7e5c5f44c4ca55cded3fd47Michal Schmidt
e6c253e363dee77ef7e5c5f44c4ca55cded3fd47Michal Schmidt See sd_is_special(3) for more information.
e6c253e363dee77ef7e5c5f44c4ca55cded3fd47Michal Schmidt*/
e6c253e363dee77ef7e5c5f44c4ca55cded3fd47Michal Schmidtint sd_is_special(int fd, const char *path);
e6c253e363dee77ef7e5c5f44c4ca55cded3fd47Michal Schmidt
4bdc60cb6fab336d455abbbd269e5bfccf760c91Lennart Poettering/*
4bdc60cb6fab336d455abbbd269e5bfccf760c91Lennart Poettering Helper call for identifying a passed file descriptor. Returns 1 if
4bdc60cb6fab336d455abbbd269e5bfccf760c91Lennart Poettering the file descriptor is a socket of the specified family (AF_INET,
4bdc60cb6fab336d455abbbd269e5bfccf760c91Lennart Poettering ...) and type (SOCK_DGRAM, SOCK_STREAM, ...), 0 otherwise. If
4bdc60cb6fab336d455abbbd269e5bfccf760c91Lennart Poettering family is 0 a socket family check will not be done. If type is 0 a
4bdc60cb6fab336d455abbbd269e5bfccf760c91Lennart Poettering socket type check will not be done and the call only verifies if
4bdc60cb6fab336d455abbbd269e5bfccf760c91Lennart Poettering the file descriptor refers to a socket. If listening is > 0 it is
4bdc60cb6fab336d455abbbd269e5bfccf760c91Lennart Poettering verified that the socket is in listening mode. (i.e. listen() has
4bdc60cb6fab336d455abbbd269e5bfccf760c91Lennart Poettering been called) If listening is == 0 it is verified that the socket is
4bdc60cb6fab336d455abbbd269e5bfccf760c91Lennart Poettering not in listening mode. If listening is < 0 no listening mode check
4bdc60cb6fab336d455abbbd269e5bfccf760c91Lennart Poettering is done. Returns a negative errno style error code on failure.
4bdc60cb6fab336d455abbbd269e5bfccf760c91Lennart Poettering
4bdc60cb6fab336d455abbbd269e5bfccf760c91Lennart Poettering See sd_is_socket(3) for more information.
4bdc60cb6fab336d455abbbd269e5bfccf760c91Lennart Poettering*/
4bdc60cb6fab336d455abbbd269e5bfccf760c91Lennart Poetteringint sd_is_socket(int fd, int family, int type, int listening);
4bdc60cb6fab336d455abbbd269e5bfccf760c91Lennart Poettering
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering/*
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering Helper call for identifying a passed file descriptor. Returns 1 if
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering the file descriptor is an Internet socket, of the specified family
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering (either AF_INET or AF_INET6) and the specified type (SOCK_DGRAM,
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering SOCK_STREAM, ...), 0 otherwise. If version is 0 a protocol version
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering check is not done. If type is 0 a socket type check will not be
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering done. If port is 0 a socket port check will not be done. The
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering listening flag is used the same way as in sd_is_socket(). Returns a
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering negative errno style error code on failure.
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering See sd_is_socket_inet(3) for more information.
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering*/
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poetteringint sd_is_socket_inet(int fd, int family, int type, int listening, uint16_t port);
d4474c41ca3854db1b7a7b30765bb59fc570e1c4Tom Gundersen
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering/*
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering Helper call for identifying a passed file descriptor. Returns 1 if
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering the file descriptor is an AF_UNIX socket of the specified type
f6d1de8547b1e957773f8b6764420579c8378aafRonny Chevalier (SOCK_DGRAM, SOCK_STREAM, ...) and path, 0 otherwise. If type is 0
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering a socket type check will not be done. If path is NULL a socket path
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering check will not be done. For normal AF_UNIX sockets set length to
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering 0. For abstract namespace sockets set length to the length of the
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering socket name (including the initial 0 byte), and pass the full
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering socket path in path (including the initial 0 byte). The listening
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering flag is used the same way as in sd_is_socket(). Returns a negative
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering errno style error code on failure.
78b6b7ceb2c76a3e29aeaa4b00c257be0706bffcLennart Poettering
3769415e6573da64fb80e31f4bb3f850cd99031eTimofey Titovets See sd_is_socket_unix(3) for more information.
3769415e6573da64fb80e31f4bb3f850cd99031eTimofey Titovets*/
3769415e6573da64fb80e31f4bb3f850cd99031eTimofey Titovetsint sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t length);
3769415e6573da64fb80e31f4bb3f850cd99031eTimofey Titovets
3769415e6573da64fb80e31f4bb3f850cd99031eTimofey Titovets/*
3769415e6573da64fb80e31f4bb3f850cd99031eTimofey Titovets Helper call for identifying a passed file descriptor. Returns 1 if
fae9332b140ffa3c1b04c80ac4cd3f2796e8cf3cLennart Poettering the file descriptor is a POSIX Message Queue of the specified name,
fae9332b140ffa3c1b04c80ac4cd3f2796e8cf3cLennart Poettering 0 otherwise. If path is NULL a message queue name check is not
fae9332b140ffa3c1b04c80ac4cd3f2796e8cf3cLennart Poettering done. Returns a negative errno style error code on failure.
fae9332b140ffa3c1b04c80ac4cd3f2796e8cf3cLennart Poettering
ba8df74bb643c0f7c343fef78bba3661b0f9c31cKay Sievers See sd_is_mq(3) for more information.
fae9332b140ffa3c1b04c80ac4cd3f2796e8cf3cLennart Poettering*/
fae9332b140ffa3c1b04c80ac4cd3f2796e8cf3cLennart Poetteringint sd_is_mq(int fd, const char *path);
cfa1571b7f5a45927f76e54790974183a273d17aLennart Poettering
cfa1571b7f5a45927f76e54790974183a273d17aLennart Poettering/*
cfa1571b7f5a45927f76e54790974183a273d17aLennart Poettering Informs systemd about changed daemon state. This takes a number of
cfa1571b7f5a45927f76e54790974183a273d17aLennart Poettering newline separated environment-style variable assignments in a
cfa1571b7f5a45927f76e54790974183a273d17aLennart Poettering string. The following variables are known:
cfa1571b7f5a45927f76e54790974183a273d17aLennart Poettering
cfa1571b7f5a45927f76e54790974183a273d17aLennart Poettering READY=1 Tells systemd that daemon startup is finished (only
cfa1571b7f5a45927f76e54790974183a273d17aLennart Poettering relevant for services of Type=notify). The passed
7e63dd1015c9ac6fc2042e45b0a87a3f9f8b9336Lennart Poettering argument is a boolean "1" or "0". Since there is
7e63dd1015c9ac6fc2042e45b0a87a3f9f8b9336Lennart Poettering little value in signaling non-readiness the only
ba8df74bb643c0f7c343fef78bba3661b0f9c31cKay Sievers value daemons should send is "READY=1".
7e63dd1015c9ac6fc2042e45b0a87a3f9f8b9336Lennart Poettering
7e63dd1015c9ac6fc2042e45b0a87a3f9f8b9336Lennart Poettering STATUS=... Passes a single-line status string back to systemd
d4474c41ca3854db1b7a7b30765bb59fc570e1c4Tom Gundersen that describes the daemon state. This is free-from
d4474c41ca3854db1b7a7b30765bb59fc570e1c4Tom Gundersen and can be used for various purposes: general state
d4474c41ca3854db1b7a7b30765bb59fc570e1c4Tom Gundersen feedback, fsck-like programs could pass completion
d4474c41ca3854db1b7a7b30765bb59fc570e1c4Tom Gundersen percentages and failing programs could pass a human
d4474c41ca3854db1b7a7b30765bb59fc570e1c4Tom Gundersen readable error message. Example: "STATUS=Completed
d4474c41ca3854db1b7a7b30765bb59fc570e1c4Tom Gundersen 66% of file system check..."
3b187c5cee0a9584d7c31e10f9fe008b94cf6d58Lennart Poettering
3b187c5cee0a9584d7c31e10f9fe008b94cf6d58Lennart Poettering ERRNO=... If a daemon fails, the errno-style error code,
3b187c5cee0a9584d7c31e10f9fe008b94cf6d58Lennart Poettering formatted as string. Example: "ERRNO=2" for ENOENT.
3b187c5cee0a9584d7c31e10f9fe008b94cf6d58Lennart Poettering
3b187c5cee0a9584d7c31e10f9fe008b94cf6d58Lennart Poettering BUSERROR=... If a daemon fails, the D-Bus error-style error
3b187c5cee0a9584d7c31e10f9fe008b94cf6d58Lennart Poettering code. Example: "BUSERROR=org.freedesktop.DBus.Error.TimedOut"
3b187c5cee0a9584d7c31e10f9fe008b94cf6d58Lennart Poettering
3b187c5cee0a9584d7c31e10f9fe008b94cf6d58Lennart Poettering MAINPID=... The main pid of a daemon, in case systemd did not
4b08dd87eebb4b634bdd5708ac1ba68dcee205b3Lennart Poettering fork off the process itself. Example: "MAINPID=4711"
4b08dd87eebb4b634bdd5708ac1ba68dcee205b3Lennart Poettering
4b08dd87eebb4b634bdd5708ac1ba68dcee205b3Lennart Poettering WATCHDOG=1 Tells systemd to update the watchdog timestamp.
4b08dd87eebb4b634bdd5708ac1ba68dcee205b3Lennart Poettering Services using this feature should do this in
4b08dd87eebb4b634bdd5708ac1ba68dcee205b3Lennart Poettering regular intervals. A watchdog framework can use the
4b08dd87eebb4b634bdd5708ac1ba68dcee205b3Lennart Poettering timestamps to detect failed services. Also see
4b08dd87eebb4b634bdd5708ac1ba68dcee205b3Lennart Poettering sd_watchdog_enabled() below.
4b08dd87eebb4b634bdd5708ac1ba68dcee205b3Lennart Poettering
4b08dd87eebb4b634bdd5708ac1ba68dcee205b3Lennart Poettering Daemons can choose to send additional variables. However, it is
4b08dd87eebb4b634bdd5708ac1ba68dcee205b3Lennart Poettering recommended to prefix variable names not listed above with X_.
4b08dd87eebb4b634bdd5708ac1ba68dcee205b3Lennart Poettering
4b08dd87eebb4b634bdd5708ac1ba68dcee205b3Lennart Poettering Returns a negative errno-style error code on failure. Returns > 0
4b08dd87eebb4b634bdd5708ac1ba68dcee205b3Lennart Poettering if systemd could be notified, 0 if it couldn't possibly because
4b08dd87eebb4b634bdd5708ac1ba68dcee205b3Lennart Poettering systemd is not running.
4b08dd87eebb4b634bdd5708ac1ba68dcee205b3Lennart Poettering
4b08dd87eebb4b634bdd5708ac1ba68dcee205b3Lennart Poettering Example: When a daemon finished starting up, it could issue this
4b08dd87eebb4b634bdd5708ac1ba68dcee205b3Lennart Poettering call to notify systemd about it:
4b08dd87eebb4b634bdd5708ac1ba68dcee205b3Lennart Poettering
4b08dd87eebb4b634bdd5708ac1ba68dcee205b3Lennart Poettering sd_notify(0, "READY=1");
4b08dd87eebb4b634bdd5708ac1ba68dcee205b3Lennart Poettering
4b08dd87eebb4b634bdd5708ac1ba68dcee205b3Lennart Poettering See sd_notifyf() for more complete examples.
4b08dd87eebb4b634bdd5708ac1ba68dcee205b3Lennart Poettering
4b08dd87eebb4b634bdd5708ac1ba68dcee205b3Lennart Poettering See sd_notify(3) for more information.
4b08dd87eebb4b634bdd5708ac1ba68dcee205b3Lennart Poettering*/
4b08dd87eebb4b634bdd5708ac1ba68dcee205b3Lennart Poetteringint sd_notify(int unset_environment, const char *state);
b72ddf0f4f552dd53d6404b6ddbc9f17d02b8e12Kay Sievers
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering/*
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering Similar to sd_notify() but takes a format string.
b72ddf0f4f552dd53d6404b6ddbc9f17d02b8e12Kay Sievers
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering Example 1: A daemon could send the following after initialization:
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering
b72ddf0f4f552dd53d6404b6ddbc9f17d02b8e12Kay Sievers sd_notifyf(0, "READY=1\n"
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering "STATUS=Processing requests...\n"
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering "MAINPID=%lu",
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering (unsigned long) getpid());
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering Example 2: A daemon could send the following shortly before
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering exiting, on failure:
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering sd_notifyf(0, "STATUS=Failed to start up: %s\n"
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering "ERRNO=%i",
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering strerror(errno),
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering errno);
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering See sd_notifyf(3) for more information.
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering*/
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poetteringint sd_notifyf(int unset_environment, const char *format, ...) _sd_printf_(2,3);
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering/*
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering Returns > 0 if the system was booted with systemd. Returns < 0 on
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering error. Returns 0 if the system was not booted with systemd. Note
5f02e26ca7c039837dbaea63f3d3664fe45c26b9Thomas Hindoe Paaboel Andersen that all of the functions above handle non-systemd boots just
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering fine. You should NOT protect them with a call to this function. Also
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering note that this function checks whether the system, not the user
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering session is controlled by systemd. However the functions above work
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering for both user and system services.
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering See sd_booted(3) for more information.
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering*/
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poetteringint sd_booted(void);
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering/*
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering Returns > 0 if the service manager expects watchdog keep-alive
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering events to be sent regularly via sd_notify(0, "WATCHDOG=1"). Returns
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering 0 if it does not expect this. If the usec argument is non-NULL
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering returns the watchdog timeout in µs after which the service manager
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering will act on a process that has not sent a watchdog keep alive
daa05349dfefb12638c96e034c11be613bdc39b7Ansgar Burchardt message. This function is useful to implement services that
daa05349dfefb12638c96e034c11be613bdc39b7Ansgar Burchardt recognize automatically if they are being run under supervision of
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering systemd with WatchdogSec= set. It is recommended for clients to
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering generate keep-alive pings via sd_notify(0, "WATCHDOG=1") every half
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering of the returned time.
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering
5f02e26ca7c039837dbaea63f3d3664fe45c26b9Thomas Hindoe Paaboel Andersen See sd_watchdog_enabled(3) for more information.
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering*/
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poetteringint sd_watchdog_enabled(int unset_environment, uint64_t *usec);
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering
a1a4a25e7f6b515d0c8c25257714299853f261aaDaniel Mack_SD_END_DECLARATIONS;
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering#endif
b2ca0d63277b10c9382d5bcfcdf320dbb712511bLennart Poettering