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+
8 Copyright 2013 Lennart Poettering
11 <refentry id="sd_watchdog_enabled"
12 xmlns:xi="http://www.w3.org/2001/XInclude">
15 <title>sd_watchdog_enabled</title>
16 <productname>elogind</productname>
20 <contrib>Developer</contrib>
21 <firstname>Lennart</firstname>
22 <surname>Poettering</surname>
23 <email>lennart@poettering.net</email>
29 <refentrytitle>sd_watchdog_enabled</refentrytitle>
30 <manvolnum>3</manvolnum>
34 <refname>sd_watchdog_enabled</refname>
35 <refpurpose>Check whether the service manager expects watchdog keep-alive notifications from a service</refpurpose>
40 <funcsynopsisinfo>#include <elogind/sd-daemon.h></funcsynopsisinfo>
43 <funcdef>int <function>sd_watchdog_enabled</function></funcdef>
44 <paramdef>int <parameter>unset_environment</parameter></paramdef>
45 <paramdef>uint64_t *<parameter>usec</parameter></paramdef>
51 <title>Description</title>
52 <para><function>sd_watchdog_enabled()</function> may be called by
53 a service to detect whether the service manager expects regular
54 keep-alive watchdog notification events from it, and the timeout
55 after which the manager will act on the service if it did not get
56 such a notification.</para>
58 <para>If the <varname>$WATCHDOG_USEC</varname> environment
59 variable is set, and the <varname>$WATCHDOG_PID</varname> variable
60 is unset or set to the PID of the current process, the service
61 manager expects notifications from this process. The manager will
62 usually terminate a service when it does not get a notification
63 message within the specified time after startup and after each
64 previous message. It is recommended that a daemon sends a
65 keep-alive notification message to the service manager every half
66 of the time returned here. Notification messages may be sent with
67 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>
68 with a message string of <literal>WATCHDOG=1</literal>.</para>
70 <para>If the <parameter>unset_environment</parameter> parameter is
71 non-zero, <function>sd_watchdog_enabled()</function> will unset
72 the <varname>$WATCHDOG_USEC</varname> and
73 <varname>$WATCHDOG_PID</varname> environment variables before
74 returning (regardless of whether the function call itself
75 succeeded or not). Those variables are no longer inherited by
76 child processes. Further calls to
77 <function>sd_watchdog_enabled()</function> will also return with
80 <para>If the <parameter>usec</parameter> parameter is non-NULL,
81 <function>sd_watchdog_enabled()</function> will write the timeout
82 in µs for the watchdog logic to it.</para>
84 <para>To enable service supervision with the watchdog logic, use
85 <varname>WatchdogSec=</varname> in service files. See
86 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
90 <citerefentry><refentrytitle>sd_event_set_watchdog</refentrytitle><manvolnum>3</manvolnum></citerefentry>
91 to enable automatic watchdog support in
92 <citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry>-based event loops.</para>
96 <title>Return Value</title>
98 <para>On failure, this call returns a negative errno-style error
99 code. If the service manager expects watchdog keep-alive
100 notification messages to be sent, > 0 is returned, otherwise 0
101 is returned. Only if the return value is > 0, the
102 <parameter>usec</parameter> parameter is valid after the
109 <xi:include href="libelogind-pkgconfig.xml" xpointer="pkgconfig-text"/>
111 <para>Internally, this function parses the
112 <varname>$WATCHDOG_PID</varname> and
113 <varname>$WATCHDOG_USEC</varname> environment variable. The call
114 will ignore these variables if <varname>$WATCHDOG_PID</varname>
115 does not contain the PID of the current process, under the
116 assumption that in that case, the variables were set for a
117 different process further up the process tree.</para>
121 <title>Environment</title>
123 <variablelist class='environment-variables'>
125 <term><varname>$WATCHDOG_PID</varname></term>
127 <listitem><para>Set by the system manager for supervised
128 process for which watchdog support is enabled, and contains
129 the PID of that process. See above for
130 details.</para></listitem>
134 <term><varname>$WATCHDOG_USEC</varname></term>
136 <listitem><para>Set by the system manager for supervised
137 process for which watchdog support is enabled, and contains
138 the watchdog timeout in µs. See above for
139 details.</para></listitem>
145 <title>See Also</title>
147 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
148 <citerefentry><refentrytitle>sd-daemon</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
149 <citerefentry><refentrytitle>daemon</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
150 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
151 <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
152 <citerefentry><refentrytitle>sd_event_set_watchdog</refentrytitle><manvolnum>3</manvolnum></citerefentry>