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 This file is part of systemd.
10 Copyright 2013 Lennart Poettering
13 <refentry id=
"sd_watchdog_enabled"
14 xmlns:
xi=
"http://www.w3.org/2001/XInclude">
17 <title>sd_watchdog_enabled
</title>
18 <productname>systemd
</productname>
22 <contrib>Developer
</contrib>
23 <firstname>Lennart
</firstname>
24 <surname>Poettering
</surname>
25 <email>lennart@poettering.net
</email>
31 <refentrytitle>sd_watchdog_enabled
</refentrytitle>
32 <manvolnum>3</manvolnum>
36 <refname>sd_watchdog_enabled
</refname>
37 <refpurpose>Check whether the service manager expects watchdog keep-alive notifications from a service
</refpurpose>
42 <funcsynopsisinfo>#include
<systemd/sd-daemon.h
></funcsynopsisinfo>
45 <funcdef>int
<function>sd_watchdog_enabled
</function></funcdef>
46 <paramdef>int
<parameter>unset_environment
</parameter></paramdef>
47 <paramdef>uint64_t *
<parameter>usec
</parameter></paramdef>
53 <title>Description
</title>
54 <para><function>sd_watchdog_enabled()
</function> may be called by
55 a service to detect whether the service manager expects regular
56 keep-alive watchdog notification events from it, and the timeout
57 after which the manager will act on the service if it did not get
58 such a notification.
</para>
60 <para>If the
<varname>$WATCHDOG_USEC
</varname> environment
61 variable is set, and the
<varname>$WATCHDOG_PID
</varname> variable
62 is unset or set to the PID of the current process, the service
63 manager expects notifications from this process. The manager will
64 usually terminate a service when it does not get a notification
65 message within the specified time after startup and after each
66 previous message. It is recommended that a daemon sends a
67 keep-alive notification message to the service manager every half
68 of the time returned here. Notification messages may be sent with
69 <citerefentry><refentrytitle>sd_notify
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
70 with a message string of
<literal>WATCHDOG=
1</literal>.
</para>
72 <para>If the
<parameter>unset_environment
</parameter> parameter is
73 non-zero,
<function>sd_watchdog_enabled()
</function> will unset
74 the
<varname>$WATCHDOG_USEC
</varname> and
75 <varname>$WATCHDOG_PID
</varname> environment variables before
76 returning (regardless of whether the function call itself
77 succeeded or not). Those variables are no longer inherited by
78 child processes. Further calls to
79 <function>sd_watchdog_enabled()
</function> will also return with
82 <para>If the
<parameter>usec
</parameter> parameter is non-NULL,
83 <function>sd_watchdog_enabled()
</function> will write the timeout
84 in µs for the watchdog logic to it.
</para>
86 <para>To enable service supervision with the watchdog logic, use
87 <varname>WatchdogSec=
</varname> in service files. See
88 <citerefentry><refentrytitle>systemd.service
</refentrytitle><manvolnum>5</manvolnum></citerefentry>
92 <citerefentry><refentrytitle>sd_event_set_watchdog
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
93 to enable automatic watchdog support in
94 <citerefentry><refentrytitle>sd-event
</refentrytitle><manvolnum>3</manvolnum></citerefentry>-based event loops.
</para>
98 <title>Return Value
</title>
100 <para>On failure, this call returns a negative errno-style error
101 code. If the service manager expects watchdog keep-alive
102 notification messages to be sent,
> 0 is returned, otherwise
0
103 is returned. Only if the return value is
> 0, the
104 <parameter>usec
</parameter> parameter is valid after the
111 <xi:include href=
"libsystemd-pkgconfig.xml" xpointer=
"pkgconfig-text"/>
113 <para>Internally, this function parses the
114 <varname>$WATCHDOG_PID
</varname> and
115 <varname>$WATCHDOG_USEC
</varname> environment variable. The call
116 will ignore these variables if
<varname>$WATCHDOG_PID
</varname>
117 does not contain the PID of the current process, under the
118 assumption that in that case, the variables were set for a
119 different process further up the process tree.
</para>
123 <title>Environment
</title>
125 <variablelist class='environment-variables'
>
127 <term><varname>$WATCHDOG_PID
</varname></term>
129 <listitem><para>Set by the system manager for supervised
130 process for which watchdog support is enabled, and contains
131 the PID of that process. See above for
132 details.
</para></listitem>
136 <term><varname>$WATCHDOG_USEC
</varname></term>
138 <listitem><para>Set by the system manager for supervised
139 process for which watchdog support is enabled, and contains
140 the watchdog timeout in µs. See above for
141 details.
</para></listitem>
147 <title>See Also
</title>
149 <citerefentry><refentrytitle>systemd
</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
150 <citerefentry><refentrytitle>sd-daemon
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
151 <citerefentry><refentrytitle>daemon
</refentrytitle><manvolnum>7</manvolnum></citerefentry>,
152 <citerefentry><refentrytitle>systemd.service
</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
153 <citerefentry><refentrytitle>sd_notify
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
154 <citerefentry><refentrytitle>sd_event_set_watchdog
</refentrytitle><manvolnum>3</manvolnum></citerefentry>