1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
'\" t
.TH "SD_WATCHDOG_ENABLED" "3" "" "systemd 255" "sd_watchdog_enabled"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
sd_watchdog_enabled \- Check whether the service manager expects watchdog keep\-alive notifications from a service
.SH "SYNOPSIS"
.sp
.ft B
.nf
#include <systemd/sd\-daemon\&.h>
.fi
.ft
.HP \w'int\ sd_watchdog_enabled('u
.BI "int sd_watchdog_enabled(int\ " "unset_environment" ", uint64_t\ *" "usec" ");"
.SH "DESCRIPTION"
.PP
\fBsd_watchdog_enabled()\fR
may be called by a service to detect whether the service manager expects regular keep\-alive watchdog notification events from it, and the timeout after which the manager will act on the service if it did not get such a notification\&.
.PP
If the
\fI$WATCHDOG_USEC\fR
environment variable is set, and the
\fI$WATCHDOG_PID\fR
variable is unset or set to the PID of the current process, the service manager expects notifications from this process\&. The manager will usually terminate a service when it does not get a notification message within the specified time after startup and after each previous message\&. It is recommended that a daemon sends a keep\-alive notification message to the service manager every half of the time returned here\&. Notification messages may be sent with
\fBsd_notify\fR(3)
with a message string of
"WATCHDOG=1"\&.
.PP
If the
\fIunset_environment\fR
parameter is non\-zero,
\fBsd_watchdog_enabled()\fR
will unset the
\fI$WATCHDOG_USEC\fR
and
\fI$WATCHDOG_PID\fR
environment variables before returning (regardless of whether the function call itself succeeded or not)\&. Those variables are no longer inherited by child processes\&. Further calls to
\fBsd_watchdog_enabled()\fR
will also return with zero\&.
.PP
If the
\fIusec\fR
parameter is non\-\fBNULL\fR,
\fBsd_watchdog_enabled()\fR
will write the timeout in μs for the watchdog logic to it\&.
.PP
To enable service supervision with the watchdog logic, use
\fIWatchdogSec=\fR
in service files\&. See
\fBsystemd.service\fR(5)
for details\&.
.PP
Use
\fBsd_event_set_watchdog\fR(3)
to enable automatic watchdog support in
\fBsd-event\fR(3)\-based event loops\&.
.SH "RETURN VALUE"
.PP
On failure, this call returns a negative errno\-style error code\&. If the service manager expects watchdog keep\-alive notification messages to be sent, > 0 is returned, otherwise 0 is returned\&. Only if the return value is > 0, the
\fIusec\fR
parameter is valid after the call\&.
.SH "NOTES"
.PP
Functions described here are available as a shared library, which can be compiled against and linked to with the
\fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
file\&.
.PP
The code described here uses
\fBgetenv\fR(3), which is declared to be not multi\-thread\-safe\&. This means that the code calling the functions described here must not call
\fBsetenv\fR(3)
from a parallel thread\&. It is recommended to only do calls to
\fBsetenv()\fR
from an early phase of the program when no other threads have been started\&.
.PP
Internally, this function parses the
\fI$WATCHDOG_PID\fR
and
\fI$WATCHDOG_USEC\fR
environment variable\&. The call will ignore these variables if
\fI$WATCHDOG_PID\fR
does not contain the PID of the current process, under the assumption that in that case, the variables were set for a different process further up the process tree\&.
.SH "ENVIRONMENT"
.PP
\fI$WATCHDOG_PID\fR
.RS 4
Set by the system manager for supervised process for which watchdog support is enabled, and contains the PID of that process\&. See above for details\&.
.sp
Added in version 209\&.
.RE
.PP
\fI$WATCHDOG_USEC\fR
.RS 4
Set by the system manager for supervised process for which watchdog support is enabled, and contains the watchdog timeout in μs\&. See above for details\&.
.sp
Added in version 209\&.
.RE
.SH "HISTORY"
.PP
\fBsd_watchdog_enabled()\fR
was added in version 209\&.
.SH "SEE ALSO"
.PP
\fBsystemd\fR(1),
\fBsd-daemon\fR(3),
\fBdaemon\fR(7),
\fBsystemd.service\fR(5),
\fBsd_notify\fR(3),
\fBsd_event_set_watchdog\fR(3)
|