1 <?xml version='
1.0'
?> <!--*-nxml-*-->
2 <!DOCTYPE refentry PUBLIC
"-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
6 SPDX-License-Identifier: LGPL-2.1+
9 <refentry id=
"sd_watchdog_enabled"
10 xmlns:
xi=
"http://www.w3.org/2001/XInclude">
13 <title>sd_watchdog_enabled
</title>
14 <productname>systemd
</productname>
18 <refentrytitle>sd_watchdog_enabled
</refentrytitle>
19 <manvolnum>3</manvolnum>
23 <refname>sd_watchdog_enabled
</refname>
24 <refpurpose>Check whether the service manager expects watchdog keep-alive notifications from a service
</refpurpose>
29 <funcsynopsisinfo>#include
<systemd/sd-daemon.h
></funcsynopsisinfo>
32 <funcdef>int
<function>sd_watchdog_enabled
</function></funcdef>
33 <paramdef>int
<parameter>unset_environment
</parameter></paramdef>
34 <paramdef>uint64_t *
<parameter>usec
</parameter></paramdef>
40 <title>Description
</title>
41 <para><function>sd_watchdog_enabled()
</function> may be called by
42 a service to detect whether the service manager expects regular
43 keep-alive watchdog notification events from it, and the timeout
44 after which the manager will act on the service if it did not get
45 such a notification.
</para>
47 <para>If the
<varname>$WATCHDOG_USEC
</varname> environment
48 variable is set, and the
<varname>$WATCHDOG_PID
</varname> variable
49 is unset or set to the PID of the current process, the service
50 manager expects notifications from this process. The manager will
51 usually terminate a service when it does not get a notification
52 message within the specified time after startup and after each
53 previous message. It is recommended that a daemon sends a
54 keep-alive notification message to the service manager every half
55 of the time returned here. Notification messages may be sent with
56 <citerefentry><refentrytitle>sd_notify
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
57 with a message string of
<literal>WATCHDOG=
1</literal>.
</para>
59 <para>If the
<parameter>unset_environment
</parameter> parameter is
60 non-zero,
<function>sd_watchdog_enabled()
</function> will unset
61 the
<varname>$WATCHDOG_USEC
</varname> and
62 <varname>$WATCHDOG_PID
</varname> environment variables before
63 returning (regardless of whether the function call itself
64 succeeded or not). Those variables are no longer inherited by
65 child processes. Further calls to
66 <function>sd_watchdog_enabled()
</function> will also return with
69 <para>If the
<parameter>usec
</parameter> parameter is non-NULL,
70 <function>sd_watchdog_enabled()
</function> will write the timeout
71 in µs for the watchdog logic to it.
</para>
73 <para>To enable service supervision with the watchdog logic, use
74 <varname>WatchdogSec=
</varname> in service files. See
75 <citerefentry><refentrytitle>systemd.service
</refentrytitle><manvolnum>5</manvolnum></citerefentry>
79 <citerefentry><refentrytitle>sd_event_set_watchdog
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
80 to enable automatic watchdog support in
81 <citerefentry><refentrytitle>sd-event
</refentrytitle><manvolnum>3</manvolnum></citerefentry>-based event loops.
</para>
85 <title>Return Value
</title>
87 <para>On failure, this call returns a negative errno-style error
88 code. If the service manager expects watchdog keep-alive
89 notification messages to be sent,
> 0 is returned, otherwise
0
90 is returned. Only if the return value is
> 0, the
91 <parameter>usec
</parameter> parameter is valid after the
98 <xi:include href=
"libsystemd-pkgconfig.xml" xpointer=
"pkgconfig-text"/>
100 <para>Internally, this function parses the
101 <varname>$WATCHDOG_PID
</varname> and
102 <varname>$WATCHDOG_USEC
</varname> environment variable. The call
103 will ignore these variables if
<varname>$WATCHDOG_PID
</varname>
104 does not contain the PID of the current process, under the
105 assumption that in that case, the variables were set for a
106 different process further up the process tree.
</para>
110 <title>Environment
</title>
112 <variablelist class='environment-variables'
>
114 <term><varname>$WATCHDOG_PID
</varname></term>
116 <listitem><para>Set by the system manager for supervised
117 process for which watchdog support is enabled, and contains
118 the PID of that process. See above for
119 details.
</para></listitem>
123 <term><varname>$WATCHDOG_USEC
</varname></term>
125 <listitem><para>Set by the system manager for supervised
126 process for which watchdog support is enabled, and contains
127 the watchdog timeout in µs. See above for
128 details.
</para></listitem>
134 <title>See Also
</title>
136 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
137 <citerefentry><refentrytitle>sd-daemon
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
138 <citerefentry><refentrytitle>daemon
</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
139 <citerefentry><refentrytitle>systemd.service
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
140 <citerefentry><refentrytitle>sd_notify
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
141 <citerefentry><refentrytitle>sd_event_set_watchdog
</refentrytitle><manvolnum>3</manvolnum></citerefentry>