1 <?xml version='
1.0'
?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC
"-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4 <!-- SPDX-License-Identifier: LGPL-2.1+ -->
6 <refentry id=
"sd_watchdog_enabled"
7 xmlns:
xi=
"http://www.w3.org/2001/XInclude">
10 <title>sd_watchdog_enabled
</title>
11 <productname>systemd
</productname>
15 <refentrytitle>sd_watchdog_enabled
</refentrytitle>
16 <manvolnum>3</manvolnum>
20 <refname>sd_watchdog_enabled
</refname>
21 <refpurpose>Check whether the service manager expects watchdog keep-alive notifications from a service
</refpurpose>
26 <funcsynopsisinfo>#include
<systemd/sd-daemon.h
></funcsynopsisinfo>
29 <funcdef>int
<function>sd_watchdog_enabled
</function></funcdef>
30 <paramdef>int
<parameter>unset_environment
</parameter></paramdef>
31 <paramdef>uint64_t *
<parameter>usec
</parameter></paramdef>
37 <title>Description
</title>
38 <para><function>sd_watchdog_enabled()
</function> may be called by
39 a service to detect whether the service manager expects regular
40 keep-alive watchdog notification events from it, and the timeout
41 after which the manager will act on the service if it did not get
42 such a notification.
</para>
44 <para>If the
<varname>$WATCHDOG_USEC
</varname> environment
45 variable is set, and the
<varname>$WATCHDOG_PID
</varname> variable
46 is unset or set to the PID of the current process, the service
47 manager expects notifications from this process. The manager will
48 usually terminate a service when it does not get a notification
49 message within the specified time after startup and after each
50 previous message. It is recommended that a daemon sends a
51 keep-alive notification message to the service manager every half
52 of the time returned here. Notification messages may be sent with
53 <citerefentry><refentrytitle>sd_notify
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
54 with a message string of
<literal>WATCHDOG=
1</literal>.
</para>
56 <para>If the
<parameter>unset_environment
</parameter> parameter is
57 non-zero,
<function>sd_watchdog_enabled()
</function> will unset
58 the
<varname>$WATCHDOG_USEC
</varname> and
59 <varname>$WATCHDOG_PID
</varname> environment variables before
60 returning (regardless of whether the function call itself
61 succeeded or not). Those variables are no longer inherited by
62 child processes. Further calls to
63 <function>sd_watchdog_enabled()
</function> will also return with
66 <para>If the
<parameter>usec
</parameter> parameter is non-NULL,
67 <function>sd_watchdog_enabled()
</function> will write the timeout
68 in µs for the watchdog logic to it.
</para>
70 <para>To enable service supervision with the watchdog logic, use
71 <varname>WatchdogSec=
</varname> in service files. See
72 <citerefentry><refentrytitle>systemd.service
</refentrytitle><manvolnum>5</manvolnum></citerefentry>
76 <citerefentry><refentrytitle>sd_event_set_watchdog
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
77 to enable automatic watchdog support in
78 <citerefentry><refentrytitle>sd-event
</refentrytitle><manvolnum>3</manvolnum></citerefentry>-based event loops.
</para>
82 <title>Return Value
</title>
84 <para>On failure, this call returns a negative errno-style error
85 code. If the service manager expects watchdog keep-alive
86 notification messages to be sent,
> 0 is returned, otherwise
0
87 is returned. Only if the return value is
> 0, the
88 <parameter>usec
</parameter> parameter is valid after the
95 <xi:include href=
"libsystemd-pkgconfig.xml" xpointer=
"pkgconfig-text"/>
97 <para>Internally, this function parses the
98 <varname>$WATCHDOG_PID
</varname> and
99 <varname>$WATCHDOG_USEC
</varname> environment variable. The call
100 will ignore these variables if
<varname>$WATCHDOG_PID
</varname>
101 does not contain the PID of the current process, under the
102 assumption that in that case, the variables were set for a
103 different process further up the process tree.
</para>
107 <title>Environment
</title>
109 <variablelist class='environment-variables'
>
111 <term><varname>$WATCHDOG_PID
</varname></term>
113 <listitem><para>Set by the system manager for supervised
114 process for which watchdog support is enabled, and contains
115 the PID of that process. See above for
116 details.
</para></listitem>
120 <term><varname>$WATCHDOG_USEC
</varname></term>
122 <listitem><para>Set by the system manager for supervised
123 process for which watchdog support is enabled, and contains
124 the watchdog timeout in µs. See above for
125 details.
</para></listitem>
131 <title>See Also
</title>
133 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
134 <citerefentry><refentrytitle>sd-daemon
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
135 <citerefentry><refentrytitle>daemon
</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
136 <citerefentry><refentrytitle>systemd.service
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
137 <citerefentry><refentrytitle>sd_notify
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
138 <citerefentry><refentrytitle>sd_event_set_watchdog
</refentrytitle><manvolnum>3</manvolnum></citerefentry>