]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/sd_watchdog_enabled.xml
Merge pull request #8822 from fbuihuu/rfc-tmpfiles-safe-upstream
[thirdparty/systemd.git] / man / sd_watchdog_enabled.xml
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">
4
5 <!--
6 SPDX-License-Identifier: LGPL-2.1+
7 -->
8
9 <refentry id="sd_watchdog_enabled"
10 xmlns:xi="http://www.w3.org/2001/XInclude">
11
12 <refentryinfo>
13 <title>sd_watchdog_enabled</title>
14 <productname>systemd</productname>
15 </refentryinfo>
16
17 <refmeta>
18 <refentrytitle>sd_watchdog_enabled</refentrytitle>
19 <manvolnum>3</manvolnum>
20 </refmeta>
21
22 <refnamediv>
23 <refname>sd_watchdog_enabled</refname>
24 <refpurpose>Check whether the service manager expects watchdog keep-alive notifications from a service</refpurpose>
25 </refnamediv>
26
27 <refsynopsisdiv>
28 <funcsynopsis>
29 <funcsynopsisinfo>#include &lt;systemd/sd-daemon.h&gt;</funcsynopsisinfo>
30
31 <funcprototype>
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>
35 </funcprototype>
36 </funcsynopsis>
37 </refsynopsisdiv>
38
39 <refsect1>
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>
46
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>
58
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
67 zero.</para>
68
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>
72
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>
76 for details.</para>
77
78 <para>Use
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>
82 </refsect1>
83
84 <refsect1>
85 <title>Return Value</title>
86
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, &gt; 0 is returned, otherwise 0
90 is returned. Only if the return value is &gt; 0, the
91 <parameter>usec</parameter> parameter is valid after the
92 call.</para>
93 </refsect1>
94
95 <refsect1>
96 <title>Notes</title>
97
98 <xi:include href="libsystemd-pkgconfig.xml" xpointer="pkgconfig-text"/>
99
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>
107 </refsect1>
108
109 <refsect1>
110 <title>Environment</title>
111
112 <variablelist class='environment-variables'>
113 <varlistentry>
114 <term><varname>$WATCHDOG_PID</varname></term>
115
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>
120 </varlistentry>
121
122 <varlistentry>
123 <term><varname>$WATCHDOG_USEC</varname></term>
124
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>
129 </varlistentry>
130 </variablelist>
131 </refsect1>
132
133 <refsect1>
134 <title>See Also</title>
135 <para>
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>
142 </para>
143 </refsect1>
144
145 </refentry>