| 1 |
<?xml version='1.0'?> <!--*-nxml-*--> |
| 2 |
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
| 3 |
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"> |
| 4 |
<!-- SPDX-License-Identifier: LGPL-2.1-or-later --> |
| 5 |
|
| 6 |
<refentry id="sd_watchdog_enabled" |
| 7 |
xmlns:xi="http://www.w3.org/2001/XInclude"> |
| 8 |
|
| 9 |
<refentryinfo> |
| 10 |
<title>sd_watchdog_enabled</title> |
| 11 |
<productname>systemd</productname> |
| 12 |
</refentryinfo> |
| 13 |
|
| 14 |
<refmeta> |
| 15 |
<refentrytitle>sd_watchdog_enabled</refentrytitle> |
| 16 |
<manvolnum>3</manvolnum> |
| 17 |
</refmeta> |
| 18 |
|
| 19 |
<refnamediv> |
| 20 |
<refname>sd_watchdog_enabled</refname> |
| 21 |
<refpurpose>Check whether the service manager expects watchdog keep-alive notifications from a service</refpurpose> |
| 22 |
</refnamediv> |
| 23 |
|
| 24 |
<refsynopsisdiv> |
| 25 |
<funcsynopsis> |
| 26 |
<funcsynopsisinfo>#include <systemd/sd-daemon.h></funcsynopsisinfo> |
| 27 |
|
| 28 |
<funcprototype> |
| 29 |
<funcdef>int <function>sd_watchdog_enabled</function></funcdef> |
| 30 |
<paramdef>int <parameter>unset_environment</parameter></paramdef> |
| 31 |
<paramdef>uint64_t *<parameter>usec</parameter></paramdef> |
| 32 |
</funcprototype> |
| 33 |
</funcsynopsis> |
| 34 |
</refsynopsisdiv> |
| 35 |
|
| 36 |
<refsect1> |
| 37 |
<title>Description</title> |
| 38 |
<para><function>sd_watchdog_enabled()</function> may be called by |
| 39 |
a service to detect whether the service manager expects regular |
| 40 |
keep-alive watchdog notification events from it, and the timeout |
| 41 |
after which the manager will act on the service if it did not get |
| 42 |
such a notification.</para> |
| 43 |
|
| 44 |
<para>If the <varname>$WATCHDOG_USEC</varname> environment |
| 45 |
variable is set, and the <varname>$WATCHDOG_PID</varname> variable |
| 46 |
is unset or set to the PID of the current process, the service |
| 47 |
manager expects notifications from this process. The manager will |
| 48 |
usually terminate a service when it does not get a notification |
| 49 |
message within the specified time after startup and after each |
| 50 |
previous message. It is recommended that a daemon sends a |
| 51 |
keep-alive notification message to the service manager every half |
| 52 |
of the time returned here. Notification messages may be sent with |
| 53 |
<citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry> |
| 54 |
with a message string of <literal>WATCHDOG=1</literal>.</para> |
| 55 |
|
| 56 |
<para>If the <parameter>unset_environment</parameter> parameter is |
| 57 |
non-zero, <function>sd_watchdog_enabled()</function> will unset |
| 58 |
the <varname>$WATCHDOG_USEC</varname> and |
| 59 |
<varname>$WATCHDOG_PID</varname> environment variables before |
| 60 |
returning (regardless of whether the function call itself |
| 61 |
succeeded or not). Those variables are no longer inherited by |
| 62 |
child processes. Further calls to |
| 63 |
<function>sd_watchdog_enabled()</function> will also return with |
| 64 |
zero.</para> |
| 65 |
|
| 66 |
<para>If the <parameter>usec</parameter> parameter is non-<constant>NULL</constant>, |
| 67 |
<function>sd_watchdog_enabled()</function> will write the timeout |
| 68 |
in μs for the watchdog logic to it.</para> |
| 69 |
|
| 70 |
<para>To enable service supervision with the watchdog logic, use |
| 71 |
<varname>WatchdogSec=</varname> in service files. See |
| 72 |
<citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry> |
| 73 |
for details.</para> |
| 74 |
|
| 75 |
<para>Use |
| 76 |
<citerefentry><refentrytitle>sd_event_set_watchdog</refentrytitle><manvolnum>3</manvolnum></citerefentry> |
| 77 |
to enable automatic watchdog support in |
| 78 |
<citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry>-based event loops.</para> |
| 79 |
</refsect1> |
| 80 |
|
| 81 |
<refsect1> |
| 82 |
<title>Return Value</title> |
| 83 |
|
| 84 |
<para>On failure, this call returns a negative errno-style error |
| 85 |
code. If the service manager expects watchdog keep-alive |
| 86 |
notification messages to be sent, > 0 is returned, otherwise 0 |
| 87 |
is returned. Only if the return value is > 0, the |
| 88 |
<parameter>usec</parameter> parameter is valid after the |
| 89 |
call.</para> |
| 90 |
</refsect1> |
| 91 |
|
| 92 |
<refsect1> |
| 93 |
<title>Notes</title> |
| 94 |
|
| 95 |
<xi:include href="libsystemd-pkgconfig.xml" xpointer="pkgconfig-text"/> |
| 96 |
<xi:include href="threads-aware.xml" xpointer="getenv"/> |
| 97 |
|
| 98 |
<para>Internally, this function parses the |
| 99 |
<varname>$WATCHDOG_PID</varname> and |
| 100 |
<varname>$WATCHDOG_USEC</varname> environment variable. The call |
| 101 |
will ignore these variables if <varname>$WATCHDOG_PID</varname> |
| 102 |
does not contain the PID of the current process, under the |
| 103 |
assumption that in that case, the variables were set for a |
| 104 |
different process further up the process tree.</para> |
| 105 |
</refsect1> |
| 106 |
|
| 107 |
<refsect1> |
| 108 |
<title>Environment</title> |
| 109 |
|
| 110 |
<variablelist class='environment-variables'> |
| 111 |
<varlistentry> |
| 112 |
<term><varname>$WATCHDOG_PID</varname></term> |
| 113 |
|
| 114 |
<listitem><para>Set by the system manager for supervised |
| 115 |
process for which watchdog support is enabled, and contains |
| 116 |
the PID of that process. See above for |
| 117 |
details.</para> |
| 118 |
|
| 119 |
<xi:include href="version-info.xml" xpointer="v209"/></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> |
| 129 |
|
| 130 |
<xi:include href="version-info.xml" xpointer="v209"/></listitem> |
| 131 |
</varlistentry> |
| 132 |
</variablelist> |
| 133 |
</refsect1> |
| 134 |
|
| 135 |
<refsect1> |
| 136 |
<title>History</title> |
| 137 |
<para><function>sd_watchdog_enabled()</function> was added in version 209.</para> |
| 138 |
</refsect1> |
| 139 |
|
| 140 |
<refsect1> |
| 141 |
<title>See Also</title> |
| 142 |
<para><simplelist type="inline"> |
| 143 |
<member><citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry></member> |
| 144 |
<member><citerefentry><refentrytitle>sd-daemon</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 145 |
<member><citerefentry><refentrytitle>daemon</refentrytitle><manvolnum>7</manvolnum></citerefentry></member> |
| 146 |
<member><citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry></member> |
| 147 |
<member><citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 148 |
<member><citerefentry><refentrytitle>sd_event_set_watchdog</refentrytitle><manvolnum>3</manvolnum></citerefentry></member> |
| 149 |
</simplelist></para> |
| 150 |
</refsect1> |
| 151 |
|
| 152 |
</refentry> |