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