]>
Commit | Line | Data |
---|---|---|
514094f9 | 1 | <?xml version='1.0'?> |
3a54a157 ZJS |
2 | <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
3 | "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> | |
1eb54dc6 LP |
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 <systemd/sd-event.h></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 specifie 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 NULL no reference to the | |
99 | event source object is returned. In this case the event source is considered "floating", and will be destroyed | |
100 | implicitly when the event loop itself is destroyed.</para> | |
101 | ||
102 | <para><function>sd_event_source_get_inotify_mask()</function> retrieves the configured inotify watch mask of an | |
103 | event source created previously with <function>sd_event_add_inotify()</function>. It takes the event source object | |
104 | as the <parameter>source</parameter> parameter and a pointer to a <type>uint32_t</type> variable to return the mask | |
105 | in.</para> | |
106 | </refsect1> | |
107 | ||
108 | <refsect1> | |
109 | <title>Return Value</title> | |
110 | ||
111 | <para>On success, these functions return 0 or a positive integer. On failure, they return a negative errno-style | |
112 | error code.</para> | |
113 | </refsect1> | |
114 | ||
115 | <refsect1> | |
116 | <title>Errors</title> | |
117 | ||
118 | <para>Returned errors may indicate the following problems:</para> | |
119 | ||
120 | <variablelist> | |
121 | <varlistentry> | |
122 | <term><constant>-ENOMEM</constant></term> | |
123 | ||
124 | <listitem><para>Not enough memory to allocate an object.</para></listitem> | |
125 | </varlistentry> | |
126 | ||
127 | <varlistentry> | |
128 | <term><constant>-EINVAL</constant></term> | |
129 | ||
130 | <listitem><para>An invalid argument has been passed. This includes specifying a mask with | |
131 | <constant>IN_MASK_ADD</constant> set.</para></listitem> | |
132 | </varlistentry> | |
133 | ||
134 | <varlistentry> | |
135 | <term><constant>-ESTALE</constant></term> | |
136 | ||
137 | <listitem><para>The event loop is already terminated.</para></listitem> | |
138 | ||
139 | </varlistentry> | |
140 | ||
141 | <varlistentry> | |
142 | <term><constant>-ECHILD</constant></term> | |
143 | ||
144 | <listitem><para>The event loop has been created in a different process.</para></listitem> | |
145 | ||
146 | </varlistentry> | |
147 | ||
148 | <varlistentry> | |
149 | <term><constant>-EDOM</constant></term> | |
150 | ||
151 | <listitem><para>The passed event source is not an inotify process event source.</para></listitem> | |
152 | </varlistentry> | |
153 | ||
154 | </variablelist> | |
155 | </refsect1> | |
156 | ||
0e37c169 ZJS |
157 | <refsect1> |
158 | <title>Examples</title> | |
159 | ||
160 | <example> | |
161 | <title>A simple program that uses inotify to monitor one or two directories</title> | |
162 | ||
163 | <programlisting><xi:include href="inotify-watch-tmp.c" parse="text" /></programlisting> | |
164 | </example> | |
165 | </refsect1> | |
166 | ||
1eb54dc6 LP |
167 | <xi:include href="libsystemd-pkgconfig.xml" /> |
168 | ||
169 | <refsect1> | |
170 | <title>See Also</title> | |
171 | ||
172 | <para> | |
173 | <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, | |
174 | <citerefentry><refentrytitle>sd-event</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
175 | <citerefentry><refentrytitle>sd_event_new</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
176 | <citerefentry><refentrytitle>sd_event_now</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
177 | <citerefentry><refentrytitle>sd_event_add_io</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
178 | <citerefentry><refentrytitle>sd_event_add_time</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
179 | <citerefentry><refentrytitle>sd_event_add_signal</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
180 | <citerefentry><refentrytitle>sd_event_add_defer</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
181 | <citerefentry><refentrytitle>sd_event_add_child</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
182 | <citerefentry><refentrytitle>sd_event_source_set_enabled</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
183 | <citerefentry><refentrytitle>sd_event_source_set_priority</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
184 | <citerefentry><refentrytitle>sd_event_source_set_userdata</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
185 | <citerefentry><refentrytitle>sd_event_source_set_description</refentrytitle><manvolnum>3</manvolnum></citerefentry>, | |
186 | <citerefentry project='man-pages'><refentrytitle>waitid</refentrytitle><manvolnum>2</manvolnum></citerefentry> | |
187 | </para> | |
188 | </refsect1> | |
189 | ||
190 | </refentry> |