1SD_WATCHDOG_ENABLED(3) sd_watchdog_enabled SD_WATCHDOG_ENABLED(3)
2
3
4
6 sd_watchdog_enabled - Check whether the service manager expects
7 watchdog keep-alive notifications from a service
8
10 #include <systemd/sd-daemon.h>
11
12 int sd_watchdog_enabled(int unset_environment, uint64_t *usec);
13
15 sd_watchdog_enabled() may be called by a service to detect whether the
16 service manager expects regular keep-alive watchdog notification events
17 from it, and the timeout after which the manager will act on the
18 service if it did not get such a notification.
19
20 If the $WATCHDOG_USEC environment variable is set, and the
21 $WATCHDOG_PID variable is unset or set to the PID of the current
22 process, the service manager expects notifications from this process.
23 The manager will usually terminate a service when it does not get a
24 notification message within the specified time after startup and after
25 each previous message. It is recommended that a daemon sends a
26 keep-alive notification message to the service manager every half of
27 the time returned here. Notification messages may be sent with
28 sd_notify(3) with a message string of "WATCHDOG=1".
29
30 If the unset_environment parameter is non-zero, sd_watchdog_enabled()
31 will unset the $WATCHDOG_USEC and $WATCHDOG_PID environment variables
32 before returning (regardless of whether the function call itself
33 succeeded or not). Those variables are no longer inherited by child
34 processes. Further calls to sd_watchdog_enabled() will also return with
35 zero.
36
37 If the usec parameter is non-NULL, sd_watchdog_enabled() will write the
38 timeout in µs for the watchdog logic to it.
39
40 To enable service supervision with the watchdog logic, use WatchdogSec=
41 in service files. See systemd.service(5) for details.
42
43 Use sd_event_set_watchdog(3) to enable automatic watchdog support in
44 sd-event(3)-based event loops.
45
47 On failure, this call returns a negative errno-style error code. If the
48 service manager expects watchdog keep-alive notification messages to be
49 sent, > 0 is returned, otherwise 0 is returned. Only if the return
50 value is > 0, the usec parameter is valid after the call.
51
53 These APIs are implemented as a shared library, which can be compiled
54 and linked to with the libsystemd pkg-config(1) file.
55
56 Internally, this function parses the $WATCHDOG_PID and $WATCHDOG_USEC
57 environment variable. The call will ignore these variables if
58 $WATCHDOG_PID does not contain the PID of the current process, under
59 the assumption that in that case, the variables were set for a
60 different process further up the process tree.
61
63 $WATCHDOG_PID
64 Set by the system manager for supervised process for which watchdog
65 support is enabled, and contains the PID of that process. See above
66 for details.
67
68 $WATCHDOG_USEC
69 Set by the system manager for supervised process for which watchdog
70 support is enabled, and contains the watchdog timeout in µs. See
71 above for details.
72
74 systemd(1), sd-daemon(3), daemon(7), systemd.service(5), sd_notify(3),
75 sd_event_set_watchdog(3)
76
77
78
79systemd 250 SD_WATCHDOG_ENABLED(3)