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 (one of
<constant>SD_EVENT_ON
</constant>,
78 <constant>SD_EVENT_OFF
</constant>,
<constant>SD_EVENT_ONESHOT
</constant>)
79 in
<parameter>enabled
</parameter>, if it is not
<constant>NULL
</constant>.
80 It also returns true if the event source is not disabled.
</para>
82 <para>Event source objects are enabled when they are first created
84 <citerefentry><refentrytitle>sd_event_add_io
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
85 <citerefentry><refentrytitle>sd_event_add_time
</refentrytitle><manvolnum>3</manvolnum></citerefentry>. However,
86 depending on the event source type they are enabled continuously
87 (
<constant>SD_EVENT_ON
</constant>) or only for a single invocation
88 of the event source handler
89 (
<constant>SD_EVENT_ONESHOT
</constant>). For details see the
90 respective manual pages.
</para>
92 <para>As event source objects stay active and may be dispatched as
93 long as there is at least one reference to them, in many cases it
94 is a good idea to combine a call to
95 <citerefentry><refentrytitle>sd_event_source_unref
</refentrytitle><manvolnum>3</manvolnum></citerefentry>
97 <function>sd_event_source_set_enabled()
</function> with
98 <constant>SD_EVENT_OFF
</constant>, to ensure the event source is
99 not dispatched again until all other remaining references are dropped.
</para>
103 <title>Return Value
</title>
105 <para>On success,
<function>sd_event_source_set_enabled()
</function> returns a non-negative
106 integer.
<function>sd_event_source_get_enabled()
</function> returns zero if the source is
107 disabled (
<constant>SD_EVENT_OFF
</constant>) and a positive integer otherwise. On failure, they
108 return a negative errno-style error code.
</para>
112 <title>Errors
</title>
114 <para>Returned errors may indicate the following problems:
</para>
118 <term><constant>-EINVAL
</constant></term>
120 <listitem><para><parameter>source
</parameter> is not a valid
121 pointer to an
<structname>sd_event_source
</structname>
122 object.
</para></listitem>
126 <term><constant>-ENOMEM
</constant></term>
128 <listitem><para>Not enough memory.
</para></listitem>
132 <term><constant>-ECHILD
</constant></term>
134 <listitem><para>The event loop has been created in a different process.
</para></listitem>
141 <xi:include href=
"libsystemd-pkgconfig.xml" />
144 <title>See Also
</title>
147 <citerefentry><refentrytitle>sd-event
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
148 <citerefentry><refentrytitle>sd_event_add_io
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
149 <citerefentry><refentrytitle>sd_event_add_time
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
150 <citerefentry><refentrytitle>sd_event_add_signal
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
151 <citerefentry><refentrytitle>sd_event_add_child
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
152 <citerefentry><refentrytitle>sd_event_add_inotify
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
153 <citerefentry><refentrytitle>sd_event_add_defer
</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
154 <citerefentry><refentrytitle>sd_event_source_unref
</refentrytitle><manvolnum>3</manvolnum></citerefentry>