]> git.ipfire.org Git - thirdparty/systemd.git/blob - man/sd_event_add_inotify.xml
Merge pull request #17444 from BtbN/fix_ib_dhcp4
[thirdparty/systemd.git] / man / sd_event_add_inotify.xml
1 <?xml version='1.0'?>
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
4 <!-- SPDX-License-Identifier: LGPL-2.1+ -->
5
6 <refentry id="sd_event_add_inotify" xmlns:xi="http://www.w3.org/2001/XInclude">
7
8 <refentryinfo>
9 <title>sd_event_add_inotify</title>
10 <productname>systemd</productname>
11 </refentryinfo>
12
13 <refmeta>
14 <refentrytitle>sd_event_add_inotify</refentrytitle>
15 <manvolnum>3</manvolnum>
16 </refmeta>
17
18 <refnamediv>
19 <refname>sd_event_add_inotify</refname>
20 <refname>sd_event_source_get_inotify_mask</refname>
21 <refname>sd_event_inotify_handler_t</refname>
22
23 <refpurpose>Add an "inotify" file system inode event source to an event loop</refpurpose>
24 </refnamediv>
25
26 <refsynopsisdiv>
27 <funcsynopsis>
28 <funcsynopsisinfo>#include &lt;systemd/sd-event.h&gt;</funcsynopsisinfo>
29
30 <funcsynopsisinfo><token>typedef</token> struct sd_event_source sd_event_source;</funcsynopsisinfo>
31
32 <funcprototype>
33 <funcdef>typedef int (*<function>sd_event_inotify_handler_t</function>)</funcdef>
34 <paramdef>sd_event_source *<parameter>s</parameter></paramdef>
35 <paramdef>const struct inotify_event *<parameter>event</parameter></paramdef>
36 <paramdef>void *<parameter>userdata</parameter></paramdef>
37 </funcprototype>
38
39 <funcprototype>
40 <funcdef>int <function>sd_event_add_inotify</function></funcdef>
41 <paramdef>sd_event *<parameter>event</parameter></paramdef>
42 <paramdef>sd_event_source **<parameter>source</parameter></paramdef>
43 <paramdef>const char *<parameter>path</parameter></paramdef>
44 <paramdef>uint32_t <parameter>mask</parameter></paramdef>
45 <paramdef>sd_event_inotify_handler_t <parameter>handler</parameter></paramdef>
46 <paramdef>void *<parameter>userdata</parameter></paramdef>
47 </funcprototype>
48
49 <funcprototype>
50 <funcdef>int <function>sd_event_source_get_inotify_mask</function></funcdef>
51 <paramdef>sd_event_source *<parameter>source</parameter></paramdef>
52 <paramdef>uint32_t *<parameter>mask</parameter></paramdef>
53 </funcprototype>
54
55 </funcsynopsis>
56 </refsynopsisdiv>
57
58 <refsect1>
59 <title>Description</title>
60
61 <para><function>sd_event_add_inotify()</function> adds a new <citerefentry
62 project='man-pages'><refentrytitle>inotify</refentrytitle><manvolnum>7</manvolnum></citerefentry> file system inode
63 event source to an event loop. The event loop object is specified in the <parameter>event</parameter> parameter,
64 the event source object is returned in the <parameter>source</parameter> parameter. The <parameter>path</parameter>
65 parameter specifies the path of the file system inode to watch. The <parameter>handler</parameter> must reference a
66 function to call when the inode changes. The handler function will be passed the <parameter>userdata</parameter>
67 pointer, which may be chosen freely by the caller. The handler also receives a pointer to a <structname>struct
68 inotify_event</structname> structure containing information about the inode event. The <parameter>mask</parameter>
69 parameter specifies which types of inode events to watch specifically. It must contain an OR-ed combination of
70 <constant>IN_ACCESS</constant>, <constant>IN_ATTRIB</constant>, <constant>IN_CLOSE_WRITE</constant>, … flags. See
71 <citerefentry project='man-pages'><refentrytitle>inotify</refentrytitle><manvolnum>7</manvolnum></citerefentry> for
72 further information.</para>
73
74 <para>If multiple event sources are installed for the same inode the backing inotify watch descriptor is
75 automatically shared. The mask parameter may contain any flag defined by the inotify API, with the exception of
76 <constant>IN_MASK_ADD</constant>.</para>
77
78 <para>The handler is enabled continuously (<constant>SD_EVENT_ON</constant>), but this may be changed with
79 <citerefentry><refentrytitle>sd_event_source_set_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>. Alternatively,
80 the <constant>IN_ONESHOT</constant> mask flag may be used to request <constant>SD_EVENT_ONESHOT</constant> mode.
81 If the handler function returns a negative error code, it will be disabled after the invocation, even if the
82 <constant>SD_EVENT_ON</constant> mode was requested before.
83 </para>
84
85 <para>As a special limitation the priority of inotify event sources may only be altered (see
86 <citerefentry><refentrytitle>sd_event_source_set_priority</refentrytitle><manvolnum>3</manvolnum></citerefentry>)
87 in the time between creation of the event source object with <function>sd_event_add_inotify()</function> and the
88 beginning of the next event loop iteration. Attempts of changing the priority any later will be refused. Consider
89 freeing and allocating a new inotify event source to change the priority at that point.</para>
90
91 <para>To destroy an event source object use
92 <citerefentry><refentrytitle>sd_event_source_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>, but note
93 that the event source is only removed from the event loop when all references to the event source are dropped. To
94 make sure an event source does not fire anymore, even when there's still a reference to it kept, consider disabling
95 it with
96 <citerefentry><refentrytitle>sd_event_source_set_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para>
97
98 <para>If the second parameter of <function>sd_event_add_inotify()</function> is passed as
99 <constant>NULL</constant> no reference to the event source object is returned. In this case the event
100 source is considered "floating", and will be destroyed implicitly when the event loop itself is
101 destroyed.</para>
102
103 <para>If the <parameter>handler</parameter> parameter to <function>sd_event_add_inotify()</function> is
104 <constant>NULL</constant>, and the event source fires, this will be considered a request to exit the
105 event loop. In this case, the <parameter>userdata</parameter> parameter, cast to an integer, is passed as
106 the exit code parameter to
107 <citerefentry><refentrytitle>sd_event_exit</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para>
108
109 <para><function>sd_event_source_get_inotify_mask()</function> retrieves the configured inotify watch mask of an
110 event source created previously with <function>sd_event_add_inotify()</function>. It takes the event source object
111 as the <parameter>source</parameter> parameter and a pointer to a <type>uint32_t</type> variable to return the mask
112 in.</para>
113 </refsect1>
114
115 <refsect1>
116 <title>Return Value</title>
117
118 <para>On success, these functions return 0 or a positive integer. On failure, they return a negative errno-style
119 error code.</para>
120
121 <refsect2>
122 <title>Errors</title>
123
124 <para>Returned errors may indicate the following problems:</para>
125
126 <variablelist>
127 <varlistentry>
128 <term><constant>-ENOMEM</constant></term>
129
130 <listitem><para>Not enough memory to allocate an object.</para></listitem>
131 </varlistentry>
132
133 <varlistentry>
134 <term><constant>-EINVAL</constant></term>
135
136 <listitem><para>An invalid argument has been passed. This includes specifying a mask with
137 <constant>IN_MASK_ADD</constant> set.</para></listitem>
138 </varlistentry>
139
140 <varlistentry>
141 <term><constant>-ESTALE</constant></term>
142
143 <listitem><para>The event loop is already terminated.</para></listitem>
144
145 </varlistentry>
146
147 <varlistentry>
148 <term><constant>-ECHILD</constant></term>
149
150 <listitem><para>The event loop has been created in a different process.</para></listitem>
151
152 </varlistentry>
153
154 <varlistentry>
155 <term><constant>-EDOM</constant></term>
156
157 <listitem><para>The passed event source is not an inotify process event source.</para></listitem>
158 </varlistentry>
159
160 </variablelist>
161 </refsect2>
162 </refsect1>
163
164 <refsect1>
165 <title>Examples</title>
166
167 <example>
168 <title>A simple program that uses inotify to monitor one or two directories</title>
169
170 <programlisting><xi:include href="inotify-watch-tmp.c" parse="text" /></programlisting>
171 </example>
172 </refsect1>
173
174 <xi:include href="libsystemd-pkgconfig.xml" />
175
176 <refsect1>
177 <title>See Also</title>
178
179 <para>
180 <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>,
181 <citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
182 <citerefentry><refentrytitle>sd_event_new</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
183 <citerefentry><refentrytitle>sd_event_now</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
184 <citerefentry><refentrytitle>sd_event_add_io</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
185 <citerefentry><refentrytitle>sd_event_add_time</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
186 <citerefentry><refentrytitle>sd_event_add_signal</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
187 <citerefentry><refentrytitle>sd_event_add_defer</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
188 <citerefentry><refentrytitle>sd_event_add_child</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
189 <citerefentry><refentrytitle>sd_event_source_set_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
190 <citerefentry><refentrytitle>sd_event_source_set_priority</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
191 <citerefentry><refentrytitle>sd_event_source_set_userdata</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
192 <citerefentry><refentrytitle>sd_event_source_set_description</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
193 <citerefentry><refentrytitle>sd_event_source_set_floating</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
194 <citerefentry project='man-pages'><refentrytitle>waitid</refentrytitle><manvolnum>2</manvolnum></citerefentry>
195 </para>
196 </refsect1>
197
198 </refentry>