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+
9 <refentry id=
"sd_event_source_set_enabled" xmlns:
xi=
"http://www.w3.org/2001/XInclude">
12 <title>sd_event_source_set_enabled
</title>
13 <productname>systemd
</productname>
17 <refentrytitle>sd_event_source_set_enabled
</refentrytitle>
18 <manvolnum>3</manvolnum>
22 <refname>sd_event_source_set_enabled
</refname>
23 <refname>sd_event_source_get_enabled
</refname>
24 <refname>SD_EVENT_ON
</refname>
25 <refname>SD_EVENT_OFF
</refname>
26 <refname>SD_EVENT_ONESHOT
</refname>
28 <refpurpose>Enable or disable event sources
</refpurpose>
33 <funcsynopsisinfo>#include
<systemd/sd-event.h
></funcsynopsisinfo>
35 <funcsynopsisinfo><token>enum
</token> {
36 <constant>SD_EVENT_OFF
</constant> =
0,
37 <constant>SD_EVENT_ON
</constant> =
1,
38 <constant>SD_EVENT_ONESHOT
</constant> = -
1,
42 <funcdef>int
<function>sd_event_source_set_enabled
</function></funcdef>
43 <paramdef>sd_event_source *
<parameter>source
</parameter></paramdef>
44 <paramdef>int
<parameter>enabled
</parameter></paramdef>
48 <funcdef>int
<function>sd_event_source_get_enabled
</function></funcdef>
49 <paramdef>sd_event_source *
<parameter>source
</parameter></paramdef>
50 <paramdef>int *
<parameter>enabled
</parameter></paramdef>
57 <title>Description
</title>
59 <para><function>sd_event_source_set_enabled()
</function> may be
60 used to enable or disable the event source object specified as
61 <parameter>source
</parameter>. The
<parameter>enabled
</parameter>
62 parameter takes one of
<constant>SD_EVENT_ON
</constant> (to
63 enable),
<constant>SD_EVENT_OFF
</constant> (to disable) or
64 <constant>SD_EVENT_ONESHOT
</constant>. If invoked with
65 <constant>SD_EVENT_ONESHOT
</constant> the event source will be
66 enabled but automatically reset to
67 <constant>SD_EVENT_OFF
</constant> after the event source was
68 dispatched once.
</para>
70 <para>Event sources that are disabled will not result in event
71 loop wakeups and will not be dispatched, until they are enabled
74 <para><function>sd_event_source_get_enabled()
</function> may be
75 used to query whether the event source object
76 <parameter>source
</parameter> is currently enabled or not. It
77 returns the enablement state in
78 <parameter>enabled
</parameter>.
</para>
80 <para>Event source objects are enabled when they are first created
82 <citerefentry><refentrytitle>sd_event_add_io
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
83 <citerefentry><refentrytitle>sd_event_add_time
</refentrytitle><manvolnum>3</manvolnum></citerefentry>. However,
84 depending on the event source type they are enabled continuously
85 (
<constant>SD_EVENT_ON
</constant>) or only for a single invocation
86 of the event source handler
87 (
<constant>SD_EVENT_ONESHOT
</constant>). For details see the
88 respective manual pages.
</para>
90 <para>As event source objects stay active and may be dispatched as
91 long as there is at least one reference to them, in many cases it
92 is a good idea to combine a call to
93 <citerefentry><refentrytitle>sd_event_source_unref
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
95 <function>sd_event_source_set_enabled()
</function> with
96 <constant>SD_EVENT_OFF
</constant>, to ensure the event source is
97 not dispatched again until all other remaining references are dropped.
</para>
101 <title>Return Value
</title>
103 <para>On success,
<function>sd_event_source_set_enabled()
</function> and
104 <function>sd_event_source_get_enabled()
</function> return a
105 non-negative integer. On failure, they return a negative
106 errno-style error code.
</para>
110 <title>Errors
</title>
112 <para>Returned errors may indicate the following problems:
</para>
116 <term><constant>-EINVAL
</constant></term>
118 <listitem><para><parameter>source
</parameter> is not a valid
119 pointer to an
<structname>sd_event_source
</structname>
120 object.
</para></listitem>
124 <term><constant>-ENOMEM
</constant></term>
126 <listitem><para>Not enough memory.
</para></listitem>
130 <term><constant>-ECHILD
</constant></term>
132 <listitem><para>The event loop has been created in a different process.
</para></listitem>
139 <xi:include href=
"libsystemd-pkgconfig.xml" />
142 <title>See Also
</title>
145 <citerefentry><refentrytitle>sd-event
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
146 <citerefentry><refentrytitle>sd_event_add_io
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
147 <citerefentry><refentrytitle>sd_event_add_time
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
148 <citerefentry><refentrytitle>sd_event_add_child
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
149 <citerefentry><refentrytitle>sd_event_add_signal
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
150 <citerefentry><refentrytitle>sd_event_add_defer
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
151 <citerefentry><refentrytitle>sd_event_source_unref
</refentrytitle><manvolnum>3</manvolnum></citerefentry>