chiark / gitweb /
85a2b6bd1a8462891825e549c1aa4c39817c1486
[elogind.git] / man / sd_event_set_watchdog.xml
1 <?xml version='1.0'?> <!--*- Mode: nxml; nxml-child-indent: 2; indent-tabs-mode: nil -*-->
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   This file is part of elogind.
7   SPDX-License-Identifier: LGPL-2.1+
8
9
10   Copyright 2015 Lennart Poettering
11 -->
12
13 <refentry id="sd_event_set_watchdog" xmlns:xi="http://www.w3.org/2001/XInclude">
14
15   <refentryinfo>
16     <title>sd_event_set_watchdog</title>
17     <productname>elogind</productname>
18
19     <authorgroup>
20       <author>
21         <contrib>Developer</contrib>
22         <firstname>Lennart</firstname>
23         <surname>Poettering</surname>
24         <email>lennart@poettering.net</email>
25       </author>
26     </authorgroup>
27   </refentryinfo>
28
29   <refmeta>
30     <refentrytitle>sd_event_set_watchdog</refentrytitle>
31     <manvolnum>3</manvolnum>
32   </refmeta>
33
34   <refnamediv>
35     <refname>sd_event_set_watchdog</refname>
36     <refname>sd_event_get_watchdog</refname>
37
38     <refpurpose>Enable event loop watchdog support</refpurpose>
39   </refnamediv>
40
41   <refsynopsisdiv>
42     <funcsynopsis>
43       <funcsynopsisinfo>#include &lt;elogind/sd-event.h&gt;</funcsynopsisinfo>
44
45       <funcprototype>
46         <funcdef>int <function>sd_event_set_watchdog</function></funcdef>
47         <paramdef>sd_event *<parameter>event</parameter></paramdef>
48         <paramdef>int b</paramdef>
49       </funcprototype>
50
51       <funcprototype>
52         <funcdef>int <function>sd_event_get_watchdog</function></funcdef>
53         <paramdef>sd_event *<parameter>event</parameter></paramdef>
54       </funcprototype>
55
56     </funcsynopsis>
57   </refsynopsisdiv>
58
59   <refsect1>
60     <title>Description</title>
61
62     <para><function>sd_event_set_watchdog()</function> may be used to
63     enable or disable automatic watchdog notification support in the
64     event loop object specified in the <parameter>event</parameter>
65     parameter. Specifically, depending on the <parameter>b</parameter>
66     boolean argument this will make sure the event loop wakes up in
67     regular intervals and sends watchdog notification messages to the
68     service manager, if this was requested by the service
69     manager. Watchdog support is determined with
70     <citerefentry><refentrytitle>sd_watchdog_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
71     and watchdog messages are sent with
72     <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>. See
73     the <varname>WatchdogSec=</varname> setting in
74     <citerefentry><refentrytitle>elogind.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
75     for details on how to enable watchdog support for a service and
76     the protocol used. The wake-up interval is chosen as half the
77     watchdog timeout declared by the service manager via the
78     <varname>$WATCHDOG_USEC</varname> environment variable. If the
79     service manager did not request watchdog notifications, or if the
80     process was not invoked by the service manager this call with a
81     true <parameter>b</parameter> parameter executes no
82     operation. Passing a false <parameter>b</parameter> parameter will
83     disable the automatic sending of watchdog notification messages if
84     it was enabled before. Newly allocated event loop objects have
85     this feature disabled.</para>
86
87     <para>The first watchdog notification message is sent immediately
88     when <function>set_event_set_watchdog()</function> is invoked with
89     a true <parameter>b</parameter> parameter.</para>
90
91     <para>The watchdog logic is designed to allow the service manager
92     to automatically detect services that ceased processing of
93     incoming events, and thus appear "hung". Watchdog notifications
94     are sent out only at the beginning of each event loop
95     iteration. If an event source dispatch function blocks for an
96     excessively long time and does not return execution to the event
97     loop quickly, this might hence cause the notification message to
98     be delayed, and possibly result in abnormal program termination,
99     as configured in the service unit file.</para>
100
101     <para><function>sd_event_get_watchdog()</function> may be used to
102     determine whether watchdog support was previously requested by a
103     call to <function>sd_event_set_watchdog()</function> with a true
104     <parameter>b</parameter> parameter and successfully
105     enabled.</para>
106   </refsect1>
107
108   <refsect1>
109     <title>Return Value</title>
110
111     <para>On success, <function>sd_event_set_watchdog()</function> and
112     <function>sd_event_get_watchdog()</function> return a non-zero
113     positive integer if the service manager requested watchdog support
114     and watchdog support was successfully enabled. They return zero if
115     the service manager did not request watchdog support, or if
116     watchdog support was explicitly disabled with a false
117     <parameter>b</parameter> parameter. On failure, they return a
118     negative errno-style error
119     code.</para>
120   </refsect1>
121
122   <refsect1>
123     <title>Errors</title>
124
125     <para>Returned errors may indicate the following problems:</para>
126
127     <variablelist>
128
129       <varlistentry>
130         <term><constant>-ECHILD</constant></term>
131
132         <listitem><para>The event loop has been created in a different process.</para></listitem>
133       </varlistentry>
134
135       <varlistentry>
136         <term><constant>-EINVAL</constant></term>
137
138         <listitem><para>The passed event loop object was invalid.</para></listitem>
139       </varlistentry>
140
141     </variablelist>
142   </refsect1>
143
144   <xi:include href="libelogind-pkgconfig.xml" />
145
146   <refsect1>
147     <title>See Also</title>
148
149     <para>
150       <!-- 0 /// elogind is in section 8
151       <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
152       --><!-- else -->
153       <citerefentry><refentrytitle>elogind</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
154       <!-- // 0 -->
155       <citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
156       <citerefentry><refentrytitle>sd_event_new</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
157       <citerefentry><refentrytitle>sd_event_add_io</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
158       <citerefentry><refentrytitle>sd_event_add_time</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
159       <citerefentry><refentrytitle>sd_event_add_signal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
160       <citerefentry><refentrytitle>sd_event_add_child</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
161       <citerefentry><refentrytitle>sd_event_add_defer</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
162       <citerefentry><refentrytitle>sd_event_add_post</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
163       <citerefentry><refentrytitle>sd_event_add_exit</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
164       <citerefentry><refentrytitle>sd_watchdog_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
165       <citerefentry><refentrytitle>sd_notify</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
166       <citerefentry><refentrytitle>elogind.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
167     </para>
168   </refsect1>
169
170 </refentry>