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>elogind</productname>
18 <contrib>Developer</contrib>
19 <firstname>Lennart</firstname>
20 <surname>Poettering</surname>
21 <email>lennart@poettering.net</email>
27 <refentrytitle>sd_watchdog_enabled</refentrytitle>
28 <manvolnum>3</manvolnum>
32 <refname>sd_watchdog_enabled</refname>
33 <refpurpose>Check whether the service manager expects watchdog keep-alive notifications from a service</refpurpose>
38 <funcsynopsisinfo>#include <elogind/sd-daemon.h></funcsynopsisinfo>
41 <funcdef>int <function>sd_watchdog_enabled</function></funcdef>
42 <paramdef>int <parameter>unset_environment</parameter></paramdef>
43 <paramdef>uint64_t *<parameter>usec</parameter></paramdef>
49 <title>Description</title>
50 <para><function>sd_watchdog_enabled()</function> may be called by
51 a service to detect whether the service manager expects regular
52 keep-alive watchdog notification events from it, and the timeout
53 after which the manager will act on the service if it did not get
54 such a notification.</para>
56 <para>If the <varname>$WATCHDOG_USEC</varname> environment
57 variable is set, and the <varname>$WATCHDOG_PID</varname> variable
58 is unset or set to the PID of the current process, the service
59 manager expects notifications from this process. The manager will
60 usually terminate a service when it does not get a notification
61 message within the specified time after startup and after each
62 previous message. It is recommended that a daemon sends a
63 keep-alive notification message to the service manager every half
64 of the time returned here. Notification messages may be sent with
65 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>
66 with a message string of <literal>WATCHDOG=1</literal>.</para>
68 <para>If the <parameter>unset_environment</parameter> parameter is
69 non-zero, <function>sd_watchdog_enabled()</function> will unset
70 the <varname>$WATCHDOG_USEC</varname> and
71 <varname>$WATCHDOG_PID</varname> environment variables before
72 returning (regardless of whether the function call itself
73 succeeded or not). Those variables are no longer inherited by
74 child processes. Further calls to
75 <function>sd_watchdog_enabled()</function> will also return with
78 <para>If the <parameter>usec</parameter> parameter is non-NULL,
79 <function>sd_watchdog_enabled()</function> will write the timeout
80 in µs for the watchdog logic to it.</para>
82 <para>To enable service supervision with the watchdog logic, use
83 <varname>WatchdogSec=</varname> in service files. See
84 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
88 <citerefentry><refentrytitle>sd_event_set_watchdog</refentrytitle><manvolnum>3</manvolnum></citerefentry>
89 to enable automatic watchdog support in
90 <citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry>-based event loops.</para>
94 <title>Return Value</title>
96 <para>On failure, this call returns a negative errno-style error
97 code. If the service manager expects watchdog keep-alive
98 notification messages to be sent, > 0 is returned, otherwise 0
99 is returned. Only if the return value is > 0, the
100 <parameter>usec</parameter> parameter is valid after the
107 <xi:include href="libelogind-pkgconfig.xml" xpointer="pkgconfig-text"/>
109 <para>Internally, this function parses the
110 <varname>$WATCHDOG_PID</varname> and
111 <varname>$WATCHDOG_USEC</varname> environment variable. The call
112 will ignore these variables if <varname>$WATCHDOG_PID</varname>
113 does not contain the PID of the current process, under the
114 assumption that in that case, the variables were set for a
115 different process further up the process tree.</para>
119 <title>Environment</title>
121 <variablelist class='environment-variables'>
123 <term><varname>$WATCHDOG_PID</varname></term>
125 <listitem><para>Set by the system manager for supervised
126 process for which watchdog support is enabled, and contains
127 the PID of that process. See above for
128 details.</para></listitem>
132 <term><varname>$WATCHDOG_USEC</varname></term>
134 <listitem><para>Set by the system manager for supervised
135 process for which watchdog support is enabled, and contains
136 the watchdog timeout in µs. See above for
137 details.</para></listitem>
143 <title>See Also</title>
145 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
146 <citerefentry><refentrytitle>sd-daemon</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
147 <citerefentry><refentrytitle>daemon</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
148 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
149 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
150 <citerefentry><refentrytitle>sd_event_set_watchdog</refentrytitle><manvolnum>3</manvolnum></citerefentry>