17812
|
1 |
diff --git a/configure.in b/configure.in
|
|
2 |
index e4b684e..5836bb7 100644
|
|
3 |
--- a/configure.in
|
|
4 |
+++ b/configure.in
|
|
5 |
@@ -42,6 +42,12 @@ if test -z "$ENV_CFLAGS"; then
|
14665
|
6 |
CFLAGS=""
|
|
7 |
fi
|
11099
|
8 |
|
|
9 |
+dnl If the user set no CFLAGS, then don't assume the autotools defaults of
|
|
10 |
+dnl "-g -O2". We set default CFLAGS later based on the --disable-debug flag.
|
|
11 |
+if test -z "$ENV_CFLAGS"; then
|
|
12 |
+ CFLAGS=""
|
|
13 |
+fi
|
|
14 |
+
|
|
15 |
dnl for the spec file
|
|
16 |
RELDATE=`date +'%a %b %e %Y'`
|
|
17 |
AC_SUBST(RELDATE)
|
17812
|
18 |
@@ -279,6 +285,43 @@ if test x$kqueue = xtrue; then
|
11099
|
19 |
backends="${backends}, kqueue"
|
|
20 |
fi
|
|
21 |
|
|
22 |
+case "$os" in
|
|
23 |
+ solaris*)
|
|
24 |
+ AM_CONDITIONAL(ON_SOLARIS, true)
|
|
25 |
+ AC_COMPILE_IFELSE([
|
|
26 |
+ #include <port.h>
|
|
27 |
+ #ifndef PORT_SOURCE_FILE
|
|
28 |
+ #error "Please upgrade to Nevada 72 or above to suppoert FEN"
|
|
29 |
+ #endif
|
|
30 |
+ int main() { return 0; }
|
|
31 |
+ ],[have_fen=1],)
|
|
32 |
+ if test x$have_fen = x1 ; then
|
|
33 |
+ AC_ARG_ENABLE(fen,
|
|
34 |
+ AC_HELP_STRING([--disable-fen], [Disable the FEN backend]),
|
|
35 |
+ [fen="${enableval}"], [fen=true])
|
|
36 |
+
|
|
37 |
+ if test x$fen = xyes; then
|
|
38 |
+ fen=true
|
|
39 |
+ elif test x$fen = xno; then
|
|
40 |
+ fen=false
|
|
41 |
+ elif test x$fen != xtrue; then
|
|
42 |
+ AC_MSG_ERROR(bad value ${enableval} for --disable-fen)
|
|
43 |
+ fi
|
|
44 |
+ fi
|
|
45 |
+ break;
|
|
46 |
+ ;;
|
|
47 |
+ *)
|
|
48 |
+ fen=false
|
|
49 |
+ break;
|
|
50 |
+ ;;
|
|
51 |
+esac
|
|
52 |
+
|
|
53 |
+AM_CONDITIONAL(ENABLE_FEN, test x$fen = xtrue)
|
|
54 |
+if test x$fen = xtrue; then
|
|
55 |
+ AC_DEFINE(ENABLE_FEN,1,[Use Solaris FEN as backend])
|
|
56 |
+ backends="${backends}, FEN"
|
|
57 |
+fi
|
|
58 |
+
|
|
59 |
dnl pthread support for reentrance of the client library.
|
|
60 |
AC_ARG_WITH(threads,
|
|
61 |
[ --with-threads add multithread support(on)])
|
17812
|
62 |
@@ -387,6 +430,14 @@ if test x$dbus_have_struct_cmsgcred = xyes; then
|
11099
|
63 |
AC_DEFINE(HAVE_CMSGCRED,1,[Have cmsgcred structure])
|
|
64 |
fi
|
|
65 |
|
|
66 |
+dnl Check for getpeerucred support - Solaris
|
|
67 |
+
|
|
68 |
+AC_CHECK_HEADER(ucred.h,
|
|
69 |
+ AC_CHECK_LIB(c, getpeerucred,[
|
|
70 |
+ AC_DEFINE([HAVE_GETPEERUCRED],[],[Define if has getpeerucred])
|
|
71 |
+ AC_DEFINE([HAVE_UCRED_H],[],[Define if <ucred.h> exists])]))
|
|
72 |
+
|
|
73 |
+
|
|
74 |
#### Abstract sockets
|
|
75 |
|
|
76 |
AC_MSG_CHECKING(abstract socket namespace)
|
17812
|
77 |
@@ -531,6 +582,16 @@ AC_SUBST(PYTHON_VERSION)
|
11099
|
78 |
AC_SUBST(PYTHON_INCLUDES)
|
|
79 |
AC_SUBST(PYTHON_SITE_PACKAGES)
|
|
80 |
|
|
81 |
+dnl Check for -lsocket -lnsl
|
|
82 |
+
|
|
83 |
+AC_CHECK_FUNC(gethostent, , AC_CHECK_LIB(nsl, gethostent))
|
|
84 |
+AC_CHECK_FUNC(setsockopt, , AC_CHECK_LIB(socket, setsockopt))
|
|
85 |
+
|
|
86 |
+dnl Check for <sys/mnttab.h>
|
|
87 |
+
|
|
88 |
+AC_CHECK_HEADER(sys/mnttab.h,
|
|
89 |
+ AC_DEFINE([HAVE_SYS_MNTTAB_H], [], [Define if <sys/mnttab.h> is there]))
|
|
90 |
+
|
|
91 |
dnl After all config-related tweaking of CFLAGS, set it to its "build" value
|
|
92 |
|
|
93 |
AC_MSG_CHECKING(for more compiler warnings)
|
17812
|
94 |
diff --git a/libgamin/Makefile.am b/libgamin/Makefile.am
|
|
95 |
index 35aa740..4f725a2 100644
|
|
96 |
--- a/libgamin/Makefile.am
|
|
97 |
+++ b/libgamin/Makefile.am
|
|
98 |
@@ -39,13 +39,24 @@ CLEANFILES=gam_error.c gam_event.c
|
|
99 |
|
|
100 |
libgamin_1_la_LIBADD =
|
|
101 |
|
|
102 |
+if ON_SOLARIS
|
|
103 |
+libgamin_1_la_LDFLAGS = -Wl,-M$(srcdir)/gamin_sym.version \
|
|
104 |
+ -version-info @GAMIN_VERSION_INFO@ @THREAD_LIBS@
|
|
105 |
+else
|
|
106 |
libgamin_1_la_LDFLAGS = -Wl,--version-script=$(srcdir)/gamin_sym.version \
|
|
107 |
-version-info @GAMIN_VERSION_INFO@ @THREAD_LIBS@
|
|
108 |
+endif
|
|
109 |
|
|
110 |
libfam_la_SOURCES = $(libgamin_1_la_SOURCES)
|
|
111 |
libfam_la_LIBADD = $(libgamin_1_la_LIBADD)
|
|
112 |
-libfam_la_LDFLAGS = -Wl,--version-script=$(srcdir)/gamin_sym.version \
|
|
113 |
+
|
|
114 |
+if ON_SOLARIS
|
|
115 |
+libfam_la_LDFLAGS = -Wl,-M$(srcdir)/gamin_sym.version \
|
|
116 |
-version-info @FAM_VERSION_INFO@ @THREAD_LIBS@
|
|
117 |
+else
|
|
118 |
+libfam_la_LDFLAGS = -Wl,--version-script=$(srcdir)/gamin_sym.version \
|
|
119 |
+ -version-info @FAM_VERSION_INFO@ @THREAD_LIBS@
|
|
120 |
+endif
|
12172
|
121 |
|
17812
|
122 |
#
|
|
123 |
# Compile a program locally to check
|
|
124 |
diff --git a/libgamin/gam_api.c b/libgamin/gam_api.c
|
|
125 |
index 4e87e63..3630213 100644
|
|
126 |
--- a/libgamin/gam_api.c
|
|
127 |
+++ b/libgamin/gam_api.c
|
|
128 |
@@ -14,6 +14,12 @@
|
|
129 |
#include <sys/socket.h>
|
|
130 |
#include <sys/un.h>
|
|
131 |
#include <sys/uio.h>
|
|
132 |
+#if defined(sun)
|
|
133 |
+#include <string.h>
|
14665
|
134 |
+#endif
|
17812
|
135 |
+#if defined(HAVE_UCRED_H)
|
|
136 |
+#include <ucred.h>
|
|
137 |
+#endif defined(HAVE_UCRED_H)
|
|
138 |
#include "fam.h"
|
|
139 |
#include "gam_protocol.h"
|
|
140 |
#include "gam_data.h"
|
|
141 |
@@ -660,6 +666,10 @@ gamin_check_cred(GAMDataPtr conn, int fd)
|
|
142 |
} cmsg;
|
|
143 |
#endif
|
|
144 |
|
|
145 |
+#if defined(HAVE_GETPEERUCRED)
|
|
146 |
+ ucred_t *creds;
|
|
147 |
+#endif
|
|
148 |
+
|
|
149 |
s_uid = getuid();
|
14662
|
150 |
|
17812
|
151 |
#if defined(LOCAL_CREDS) && defined(HAVE_CMSGCRED)
|
|
152 |
@@ -726,11 +736,25 @@ retry:
|
|
153 |
fd, cr_len, (int) sizeof(cr));
|
|
154 |
goto failed;
|
|
155 |
}
|
|
156 |
+#elif defined(HAVE_GETPEERUCRED)
|
|
157 |
+ if ((creds = (ucred_t *)malloc(ucred_size()))==(ucred_t *)NULL){
|
|
158 |
+ GAM_DEBUG(DEBUG_INFO,"Malloc failed for ucreds");
|
|
159 |
+ goto failed;
|
|
160 |
+ }
|
|
161 |
+
|
|
162 |
+ if (getpeerucred(fd, &creds)!=0){
|
|
163 |
+ GAM_DEBUG(DEBUG_INFO,"getpeerucred call failed");
|
|
164 |
+ goto failed;
|
|
165 |
+ }
|
|
166 |
+ c_uid = ucred_getruid(creds);
|
|
167 |
+ c_gid = ucred_getrgid(creds);
|
|
168 |
+ c_pid = ucred_getpid(creds);
|
|
169 |
+ ucred_free(creds);
|
|
170 |
#elif defined(HAVE_CMSGCRED)
|
|
171 |
c_pid = cmsg.cred.cmcred_pid;
|
|
172 |
c_uid = cmsg.cred.cmcred_euid;
|
|
173 |
c_gid = cmsg.cred.cmcred_groups[0];
|
|
174 |
-#else /* !SO_PEERCRED && !HAVE_CMSGCRED */
|
|
175 |
+#else /* !SO_PEERCRED && !HAVE_CMSGCRED && !HAVE_GETPEERUCRED */
|
|
176 |
GAM_DEBUG(DEBUG_INFO,
|
|
177 |
"Socket credentials not supported on this OS\n");
|
|
178 |
goto failed;
|
|
179 |
diff --git a/libgamin/gamin_sym.version b/libgamin/gamin_sym.version
|
|
180 |
index dba5f20..5c6d661 100644
|
|
181 |
--- a/libgamin/gamin_sym.version
|
|
182 |
+++ b/libgamin/gamin_sym.version
|
|
183 |
@@ -2,8 +2,6 @@
|
|
184 |
global:
|
|
185 |
FAMCancelMonitor;
|
|
186 |
FAMClose;
|
|
187 |
- FAMDebugLevel;
|
|
188 |
- FAMDebug;
|
|
189 |
FamErrlist;
|
|
190 |
FAMErrno;
|
|
191 |
FAMMonitorCollection;
|
|
192 |
diff --git a/server/Makefile.am b/server/Makefile.am
|
|
193 |
index 37aed8b..7964d17 100644
|
|
194 |
--- a/server/Makefile.am
|
|
195 |
+++ b/server/Makefile.am
|
|
196 |
@@ -10,7 +10,7 @@ INCLUDES = \
|
|
197 |
-DG_DISABLE_DEPRECATED
|
11099
|
198 |
|
17812
|
199 |
if GAMIN_DEBUG
|
|
200 |
-INCLUDES += -DGAM_DEBUG_ENABLED
|
|
201 |
+INCLUDES += -DGAM_DEBUG_ENABLED -g
|
|
202 |
endif
|
|
203 |
|
|
204 |
|
|
205 |
@@ -68,6 +68,18 @@ if ENABLE_KQUEUE
|
|
206 |
gam_server_SOURCES += gam_kqueue.c gam_kqueue.h
|
|
207 |
endif
|
|
208 |
|
|
209 |
+if ENABLE_FEN
|
|
210 |
+gam_server_SOURCES += gam_fen.c gam_fen.h \
|
|
211 |
+ fen-dump.c \
|
|
212 |
+ fen-dump.h \
|
|
213 |
+ fen-kernel.c \
|
|
214 |
+ fen-kernel.h \
|
|
215 |
+ fen-helper.c \
|
|
216 |
+ fen-helper.h \
|
|
217 |
+ fen-node.c \
|
|
218 |
+ fen-node.h
|
|
219 |
+endif
|
|
220 |
+
|
|
221 |
if ENABLE_HURD_MACH_NOTIFY
|
|
222 |
gam_server_SOURCES += gam_hurd_mach_notify.c gam_hurd_mach_notify.h
|
|
223 |
|
|
224 |
diff --git a/server/fen-dump.c b/server/fen-dump.c
|
|
225 |
new file mode 100644
|
|
226 |
index 0000000..98d20eb
|
|
227 |
--- /dev/null
|
|
228 |
+++ b/server/fen-dump.c
|
|
229 |
@@ -0,0 +1,77 @@
|
11099
|
230 |
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
231 |
+/* vim:set expandtab ts=4 shiftwidth=4: */
|
11952
|
232 |
+/*
|
17812
|
233 |
+ * Copyright (c) 2008, 2010 Oracle and/or its affiliates, Inc. All rights
|
|
234 |
+ * reserved.
|
11877
|
235 |
+ *
|
|
236 |
+ * This library is free software; you can redistribute it and/or
|
|
237 |
+ * modify it under the terms of the GNU Lesser General Public
|
|
238 |
+ * License as published by the Free Software Foundation; either
|
|
239 |
+ * version 2 of the License, or (at your option) any later version.
|
|
240 |
+ *
|
|
241 |
+ * This library is distributed in the hope that it will be useful,
|
|
242 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
243 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
244 |
+ * Lesser General Public License for more details.
|
|
245 |
+ *
|
|
246 |
+ * You should have received a copy of the GNU Lesser General
|
|
247 |
+ * Public License along with this library; if not, write to the
|
|
248 |
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
249 |
+ * Boston, MA 02111-1307, USA.
|
|
250 |
+ *
|
|
251 |
+ * Authors: Lin Ma <[email protected]>
|
|
252 |
+ */
|
11099
|
253 |
+
|
11824
|
254 |
+#include "config.h"
|
|
255 |
+#include <glib.h>
|
|
256 |
+#include <glib/gprintf.h>
|
|
257 |
+#include "fen-node.h"
|
|
258 |
+#include "fen-dump.h"
|
|
259 |
+
|
|
260 |
+G_LOCK_EXTERN (fen_lock);
|
11099
|
261 |
+
|
11824
|
262 |
+/*-------------------- node ------------------*/
|
|
263 |
+static void
|
|
264 |
+dump_node (node_t* node, gpointer data)
|
|
265 |
+{
|
17812
|
266 |
+ g_printf ("n:0x%p ds:0x%p s:0x%p %s\n", node, node->dir_subs, node->subs, NODE_NAME(node));
|
11824
|
267 |
+}
|
|
268 |
+
|
17812
|
269 |
+static void
|
|
270 |
+dump_tree (node_t* node)
|
11824
|
271 |
+{
|
|
272 |
+ if (G_TRYLOCK (fen_lock)) {
|
17812
|
273 |
+ node_traverse(NULL, dump_node, NULL);
|
11824
|
274 |
+ G_UNLOCK (fen_lock);
|
|
275 |
+ }
|
|
276 |
+}
|
11099
|
277 |
+
|
11824
|
278 |
+/* ------------------ fdata port hash --------------------*/
|
|
279 |
+void
|
|
280 |
+dump_hash_cb (gpointer key,
|
|
281 |
+ gpointer value,
|
|
282 |
+ gpointer user_data)
|
|
283 |
+{
|
17812
|
284 |
+ g_printf ("k:0x%p v:0x%p >\n", key, value);
|
11824
|
285 |
+}
|
|
286 |
+
|
|
287 |
+gboolean
|
|
288 |
+dump_hash (GHashTable* hash, gpointer user_data)
|
|
289 |
+{
|
|
290 |
+ if (G_TRYLOCK (fen_lock)) {
|
|
291 |
+ if (g_hash_table_size (hash) > 0) {
|
|
292 |
+ g_hash_table_foreach (hash, dump_hash_cb, user_data);
|
|
293 |
+ }
|
|
294 |
+ G_UNLOCK (fen_lock);
|
|
295 |
+ }
|
|
296 |
+ return TRUE;
|
|
297 |
+}
|
11099
|
298 |
+
|
11824
|
299 |
+/* ------------------ event --------------------*/
|
|
300 |
+void
|
17812
|
301 |
+dump_event (node_event_t* ev, gpointer user_data)
|
11824
|
302 |
+{
|
17812
|
303 |
+ node_t* node = ev->user_data;
|
|
304 |
+ g_printf ("ne:0x%p e:%p n:0x%p ds:0x%p s:0x%p s\n", ev, ev->e, node, node->dir_subs, node->subs, NODE_NAME(node));
|
11824
|
305 |
+}
|
11099
|
306 |
+
|
17812
|
307 |
diff --git a/server/fen-dump.h b/server/fen-dump.h
|
|
308 |
new file mode 100644
|
|
309 |
index 0000000..ffac822
|
|
310 |
--- /dev/null
|
|
311 |
+++ b/server/fen-dump.h
|
11952
|
312 |
@@ -0,0 +1,29 @@
|
11824
|
313 |
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
314 |
+/* vim:set expandtab ts=4 shiftwidth=4: */
|
11877
|
315 |
+/*
|
17812
|
316 |
+ * Copyright (c) 2008, 2010 Oracle and/or its affiliates, Inc. All rights
|
|
317 |
+ * reserved.
|
11877
|
318 |
+ *
|
|
319 |
+ * This library is free software; you can redistribute it and/or
|
|
320 |
+ * modify it under the terms of the GNU Lesser General Public
|
|
321 |
+ * License as published by the Free Software Foundation; either
|
|
322 |
+ * version 2 of the License, or (at your option) any later version.
|
|
323 |
+ *
|
|
324 |
+ * This library is distributed in the hope that it will be useful,
|
|
325 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
326 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
327 |
+ * Lesser General Public License for more details.
|
|
328 |
+ *
|
|
329 |
+ * You should have received a copy of the GNU Lesser General
|
|
330 |
+ * Public License along with this library; if not, write to the
|
|
331 |
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
332 |
+ * Boston, MA 02111-1307, USA.
|
|
333 |
+ *
|
|
334 |
+ * Authors: Lin Ma <[email protected]>
|
|
335 |
+ */
|
|
336 |
+
|
11824
|
337 |
+#ifndef _FEN_DUMP_H_
|
|
338 |
+#define _FEN_DUMP_H_
|
|
339 |
+
|
11099
|
340 |
+
|
11824
|
341 |
+#endif /* _FEN_DUMP_H_ */
|
17812
|
342 |
diff --git a/server/fen-helper.c b/server/fen-helper.c
|
|
343 |
new file mode 100644
|
|
344 |
index 0000000..e68e7c3
|
|
345 |
--- /dev/null
|
|
346 |
+++ b/server/fen-helper.c
|
|
347 |
@@ -0,0 +1,197 @@
|
11824
|
348 |
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
349 |
+/* vim:set expandtab ts=4 shiftwidth=4: */
|
11877
|
350 |
+/*
|
17812
|
351 |
+ * Copyright (c) 2008, 2010 Oracle and/or its affiliates, Inc. All rights
|
|
352 |
+ * reserved.
|
11877
|
353 |
+ *
|
|
354 |
+ * This library is free software; you can redistribute it and/or
|
|
355 |
+ * modify it under the terms of the GNU Lesser General Public
|
|
356 |
+ * License as published by the Free Software Foundation; either
|
|
357 |
+ * version 2 of the License, or (at your option) any later version.
|
11824
|
358 |
+ *
|
11877
|
359 |
+ * This library is distributed in the hope that it will be useful,
|
|
360 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
361 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
362 |
+ * Lesser General Public License for more details.
|
11824
|
363 |
+ *
|
11877
|
364 |
+ * You should have received a copy of the GNU Lesser General
|
|
365 |
+ * Public License along with this library; if not, write to the
|
|
366 |
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
367 |
+ * Boston, MA 02111-1307, USA.
|
|
368 |
+ *
|
|
369 |
+ * Authors: Lin Ma <[email protected]>
|
11824
|
370 |
+ */
|
11877
|
371 |
+
|
11824
|
372 |
+#include "config.h"
|
|
373 |
+#include <glib.h>
|
17812
|
374 |
+#include "fen-helper.h"
|
|
375 |
+#include "fen-kernel.h"
|
|
376 |
+#ifdef GIO_COMPILATION
|
|
377 |
+#include "gfilemonitor.h"
|
|
378 |
+#else
|
|
379 |
+#include "gam_event.h"
|
|
380 |
+#include "gam_server.h"
|
|
381 |
+#include "gam_protocol.h"
|
|
382 |
+#endif
|
12172
|
383 |
+
|
|
384 |
+#ifdef GIO_COMPILATION
|
17812
|
385 |
+#define FH_W if (fh_debug_enabled) g_debug
|
|
386 |
+static gboolean fh_debug_enabled = FALSE;
|
12172
|
387 |
+#else
|
|
388 |
+#include "gam_error.h"
|
17812
|
389 |
+#define FH_W(...) GAM_DEBUG(DEBUG_INFO, __VA_ARGS__)
|
12172
|
390 |
+#endif
|
11824
|
391 |
+
|
17812
|
392 |
+G_LOCK_EXTERN (fen_lock);
|
11824
|
393 |
+
|
17812
|
394 |
+/* misc */
|
|
395 |
+static void
|
|
396 |
+scan_children_init(node_t *f, gpointer sub)
|
11824
|
397 |
+{
|
17812
|
398 |
+ gboolean emit;
|
|
399 |
+ gint event;
|
11824
|
400 |
+
|
17812
|
401 |
+ FH_W ("%s %s [0x%p]\n", __func__, NODE_NAME(f), f);
|
|
402 |
+
|
|
403 |
+#ifdef GIO_COMPILATION
|
|
404 |
+ emit = FALSE;
|
|
405 |
+ event = G_FILE_MONITOR_EVENT_CREATED;
|
|
406 |
+#else
|
|
407 |
+ emit = TRUE;
|
|
408 |
+ event = GAMIN_EVENT_EXISTS;
|
|
409 |
+#endif
|
11824
|
410 |
+
|
17812
|
411 |
+ if (!NODE_HAS_FLAG(f, NODE_FLAG_SNAPSHOT_UPDATED)) {
|
|
412 |
+ /* TODO snapshot should also compare to the sub created timestamp. */
|
|
413 |
+ /* GIO initially doesn't emit created/existed events. */
|
|
414 |
+ node_create_children_snapshot(f, event, emit);
|
|
415 |
+ } else {
|
|
416 |
+ GHashTableIter iter;
|
|
417 |
+ gpointer value;
|
11824
|
418 |
+
|
17812
|
419 |
+ g_hash_table_iter_init (&iter, f->children);
|
|
420 |
+ while (g_hash_table_iter_next (&iter, NULL, &value)) {
|
|
421 |
+ node_t *child = (node_t *)value;
|
11824
|
422 |
+
|
17812
|
423 |
+#ifdef GIO_COMPILATION
|
|
424 |
+ /* GIO initially doesn't emit created/existed events. */
|
|
425 |
+ /* g_file_monitor_emit_event(G_FILE_MONITOR(sub), child->gfile, NULL, event); */
|
|
426 |
+#else
|
|
427 |
+ gam_server_emit_one_event(NODE_NAME(child), gam_subscription_is_dir(sub), event, sub, 1);
|
|
428 |
+#endif
|
|
429 |
+ }
|
11824
|
430 |
+ }
|
|
431 |
+}
|
|
432 |
+
|
|
433 |
+/**
|
17812
|
434 |
+ * fen_add
|
|
435 |
+ *
|
|
436 |
+ * Won't hold a ref, we have a timout callback to clean unused node_t.
|
|
437 |
+ * If there is no value for a key, add it and return it; else return the old
|
|
438 |
+ * one.
|
11824
|
439 |
+ */
|
|
440 |
+void
|
17812
|
441 |
+fen_add (const gchar *filename, gpointer sub, gboolean is_mondir)
|
11824
|
442 |
+{
|
17812
|
443 |
+ node_t* f;
|
|
444 |
+
|
|
445 |
+ g_assert (filename);
|
|
446 |
+ g_assert (sub);
|
|
447 |
+
|
|
448 |
+ G_LOCK (fen_lock);
|
|
449 |
+ f = node_find(NULL, filename, TRUE);
|
|
450 |
+ FH_W ("%s 0x%p sub[0x%p] %s\n", __func__, f, sub, filename);
|
|
451 |
+ g_assert (f);
|
|
452 |
+
|
|
453 |
+ /* Update timestamp, the events in global queue will compare itself to this
|
|
454 |
+ * timestamp to decide if be emitted. TODO, timestamp should be per sub.
|
|
455 |
+ */
|
|
456 |
+ if (!NODE_IS_ACTIVE(f)) {
|
|
457 |
+ g_get_current_time(&f->atv);
|
|
458 |
+ }
|
|
459 |
+
|
|
460 |
+ if (is_mondir) {
|
|
461 |
+ f->dir_subs = g_list_prepend(f->dir_subs, sub);
|
|
462 |
+ } else {
|
|
463 |
+ f->subs = g_list_prepend(f->subs, sub);
|
|
464 |
+ }
|
|
465 |
+
|
|
466 |
+ if (NODE_HAS_STATE(f, NODE_STATE_ASSOCIATED) ||
|
|
467 |
+ (node_lstat(f) == 0 && port_add(f) == 0)) {
|
|
468 |
+#ifndef GIO_COMPILATION
|
|
469 |
+ gam_server_emit_one_event (NODE_NAME(f),
|
|
470 |
+ gam_subscription_is_dir (sub), GAMIN_EVENT_EXISTS, sub, 1);
|
|
471 |
+#endif
|
|
472 |
+ if (is_mondir) {
|
|
473 |
+ scan_children_init (f, sub);
|
|
474 |
+ }
|
|
475 |
+ } else {
|
|
476 |
+#ifndef GIO_COMPILATION
|
|
477 |
+ gam_server_emit_one_event (NODE_NAME(f),
|
|
478 |
+ gam_subscription_is_dir (sub), GAMIN_EVENT_DELETED, sub, 1);
|
|
479 |
+#endif
|
|
480 |
+ node_adjust_deleted (f);
|
|
481 |
+ }
|
|
482 |
+#ifndef GIO_COMPILATION
|
|
483 |
+ gam_server_emit_one_event (NODE_NAME(f),
|
|
484 |
+ gam_subscription_is_dir (sub), GAMIN_EVENT_ENDEXISTS, sub, 1);
|
|
485 |
+#endif
|
|
486 |
+ G_UNLOCK (fen_lock);
|
11824
|
487 |
+}
|
17812
|
488 |
+
|
|
489 |
+void
|
|
490 |
+fen_remove (const gchar *filename, gpointer sub, gboolean is_mondir)
|
|
491 |
+{
|
|
492 |
+ node_t* f;
|
|
493 |
+
|
|
494 |
+ g_assert (filename);
|
|
495 |
+ g_assert (sub);
|
|
496 |
+
|
|
497 |
+ G_LOCK (fen_lock);
|
|
498 |
+ f = node_find(NULL, filename, FALSE);
|
|
499 |
+ FH_W ("%s 0x%p sub[0x%p] %s\n", __func__, f, sub, filename);
|
|
500 |
+
|
|
501 |
+ if (f) {
|
|
502 |
+ if (is_mondir) {
|
|
503 |
+ f->dir_subs = g_list_remove(f->dir_subs, sub);
|
|
504 |
+ } else {
|
|
505 |
+ f->subs = g_list_remove(f->subs, sub);
|
|
506 |
+ }
|
|
507 |
+
|
|
508 |
+ if (!NODE_IS_ACTIVE(f)) {
|
|
509 |
+ node_try_delete (f);
|
|
510 |
+ }
|
|
511 |
+ }
|
|
512 |
+ G_UNLOCK (fen_lock);
|
|
513 |
+}
|
|
514 |
+
|
|
515 |
+/**
|
|
516 |
+ * fen_init:
|
|
517 |
+ *
|
|
518 |
+ * FEN subsystem initializing.
|
|
519 |
+ */
|
|
520 |
+gboolean
|
|
521 |
+fen_init ()
|
|
522 |
+{
|
|
523 |
+ static gboolean initialized = FALSE;
|
|
524 |
+ static gboolean result = FALSE;
|
|
525 |
+
|
|
526 |
+ G_LOCK (fen_lock);
|
|
527 |
+ if (initialized) {
|
|
528 |
+ G_UNLOCK (fen_lock);
|
|
529 |
+ return result;
|
|
530 |
+ }
|
|
531 |
+
|
|
532 |
+ result = node_class_init();
|
|
533 |
+
|
|
534 |
+ if (!result) {
|
|
535 |
+ G_UNLOCK (fen_lock);
|
|
536 |
+ return result;
|
|
537 |
+ }
|
|
538 |
+
|
|
539 |
+ initialized = TRUE;
|
|
540 |
+
|
|
541 |
+ G_UNLOCK (fen_lock);
|
|
542 |
+ return result;
|
|
543 |
+}
|
|
544 |
+
|
|
545 |
diff --git a/server/fen-helper.h b/server/fen-helper.h
|
|
546 |
new file mode 100644
|
|
547 |
index 0000000..25df38f
|
|
548 |
--- /dev/null
|
|
549 |
+++ b/server/fen-helper.h
|
|
550 |
@@ -0,0 +1,33 @@
|
11824
|
551 |
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
552 |
+/* vim:set expandtab ts=4 shiftwidth=4: */
|
11877
|
553 |
+/*
|
17812
|
554 |
+ * Copyright (c) 2008, 2010 Oracle and/or its affiliates, Inc. All rights
|
|
555 |
+ * reserved.
|
11877
|
556 |
+ *
|
|
557 |
+ * This library is free software; you can redistribute it and/or
|
|
558 |
+ * modify it under the terms of the GNU Lesser General Public
|
|
559 |
+ * License as published by the Free Software Foundation; either
|
|
560 |
+ * version 2 of the License, or (at your option) any later version.
|
|
561 |
+ *
|
|
562 |
+ * This library is distributed in the hope that it will be useful,
|
|
563 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
564 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
565 |
+ * Lesser General Public License for more details.
|
|
566 |
+ *
|
|
567 |
+ * You should have received a copy of the GNU Lesser General
|
|
568 |
+ * Public License along with this library; if not, write to the
|
|
569 |
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
570 |
+ * Boston, MA 02111-1307, USA.
|
|
571 |
+ *
|
|
572 |
+ * Authors: Lin Ma <[email protected]>
|
|
573 |
+ */
|
11099
|
574 |
+
|
17812
|
575 |
+#ifndef _FEN_HELPER_H_
|
|
576 |
+#define _FEN_HELPER_H_
|
11824
|
577 |
+
|
17812
|
578 |
+void fen_add (const gchar *filename, gpointer sub, gboolean is_mondir);
|
|
579 |
+void fen_remove (const gchar *filename, gpointer sub, gboolean is_mondir);
|
11877
|
580 |
+
|
17812
|
581 |
+gboolean fen_init ();
|
11099
|
582 |
+
|
17812
|
583 |
+#endif /* _FEN_HELPER_H_ */
|
|
584 |
diff --git a/server/fen-kernel.c b/server/fen-kernel.c
|
|
585 |
new file mode 100644
|
18141
|
586 |
index 0000000..8b9c58b
|
17812
|
587 |
--- /dev/null
|
|
588 |
+++ b/server/fen-kernel.c
|
18141
|
589 |
@@ -0,0 +1,557 @@
|
11099
|
590 |
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
591 |
+/* vim:set expandtab ts=4 shiftwidth=4: */
|
11877
|
592 |
+/*
|
17812
|
593 |
+ * Copyright (c) 2008, 2010 Oracle and/or its affiliates, Inc. All rights
|
|
594 |
+ * reserved.
|
11877
|
595 |
+ *
|
|
596 |
+ * This library is free software; you can redistribute it and/or
|
|
597 |
+ * modify it under the terms of the GNU Lesser General Public
|
|
598 |
+ * License as published by the Free Software Foundation; either
|
|
599 |
+ * version 2 of the License, or (at your option) any later version.
|
|
600 |
+ *
|
|
601 |
+ * This library is distributed in the hope that it will be useful,
|
|
602 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
603 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
604 |
+ * Lesser General Public License for more details.
|
|
605 |
+ *
|
|
606 |
+ * You should have received a copy of the GNU Lesser General
|
|
607 |
+ * Public License along with this library; if not, write to the
|
|
608 |
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
609 |
+ * Boston, MA 02111-1307, USA.
|
|
610 |
+ *
|
|
611 |
+ * Authors: Lin Ma <[email protected]>
|
|
612 |
+ */
|
11099
|
613 |
+
|
11824
|
614 |
+#include "config.h"
|
11099
|
615 |
+#include <rctl.h>
|
|
616 |
+#include <strings.h>
|
|
617 |
+#include <stdio.h>
|
|
618 |
+#include <stdlib.h>
|
|
619 |
+#include <unistd.h>
|
|
620 |
+#include <glib.h>
|
|
621 |
+#include "fen-kernel.h"
|
11824
|
622 |
+#include "fen-dump.h"
|
|
623 |
+
|
12172
|
624 |
+#ifdef GIO_COMPILATION
|
17812
|
625 |
+#define FK_W if (fk_debug_enabled) g_debug
|
11824
|
626 |
+static gboolean fk_debug_enabled = FALSE;
|
11882
|
627 |
+#else
|
12172
|
628 |
+#include "gam_error.h"
|
|
629 |
+#define FK_W(...) GAM_DEBUG(DEBUG_INFO, __VA_ARGS__)
|
11882
|
630 |
+#endif
|
11099
|
631 |
+
|
11824
|
632 |
+G_GNUC_INTERNAL G_LOCK_DEFINE (fen_lock);
|
11099
|
633 |
+
|
11824
|
634 |
+static ulong max_port_events = 512;
|
17812
|
635 |
+static GList *pn_visible_list; /* the queue of ports which don't have the max objs */
|
11824
|
636 |
+static GQueue *g_eventq = NULL;
|
17812
|
637 |
+static timespec_t zero_wait;
|
|
638 |
+static void (*user_process_events_cb) (gpointer, node_event_t*);
|
|
639 |
+static port_event_t *pevents = NULL;
|
|
640 |
+static gint PE_ALLOC = 2048;
|
|
641 |
+static GHashTable *renamed_hash = NULL; /* <parent node, ev> */
|
|
642 |
+
|
|
643 |
+typedef struct _PSource {
|
|
644 |
+ GSource source; /* Inherit from GSource, must be the first. */
|
|
645 |
+ GPollFD gfd;
|
|
646 |
+ gboolean pending;
|
|
647 |
+ uint_t event_growing_factor;
|
|
648 |
+ uint_t pending_events;
|
|
649 |
+} PSource;
|
|
650 |
+
|
|
651 |
+#define PGPFD(s) (&((PSource *)(s))->gfd)
|
|
652 |
+#define SLEEP_BASE_TIME 10 /* in milliseconds */
|
|
653 |
+#define EXPECT_INC_EVENTS(pn) (1 << (pn->event_growing_factor))
|
|
654 |
+
|
|
655 |
+#define RENAME_EVENTS_INTERVAL 500 /* in milliseconds */
|
|
656 |
+#define PROCESS_PORT_EVENTS_TIME 1000 /* in milliseconds */
|
|
657 |
+guint process_port_event_id = 0;
|
|
658 |
+
|
|
659 |
+static gchar* _event_strings(int event);
|
|
660 |
+static const gchar* _event_string (int event);
|
|
661 |
+static GSource *psource_new();
|
|
662 |
+
|
|
663 |
+static gboolean port_prepare(GSource *source, gint *timeout_);
|
|
664 |
+static gboolean port_check(GSource *source);
|
|
665 |
+static gboolean port_dispatch(GSource *source, GSourceFunc callback, gpointer user_data);
|
|
666 |
+static GSourceFuncs fen_source_func = {
|
|
667 |
+ port_prepare,
|
|
668 |
+ port_check,
|
|
669 |
+ port_dispatch,
|
|
670 |
+ NULL
|
|
671 |
+};
|
|
672 |
+
|
|
673 |
+static gboolean
|
|
674 |
+port_prepare(GSource *source, gint *timeout_)
|
|
675 |
+{
|
|
676 |
+ return FALSE;
|
|
677 |
+}
|
|
678 |
+
|
|
679 |
+static gboolean
|
|
680 |
+port_check(GSource *source)
|
|
681 |
+{
|
|
682 |
+ PSource *pn = (PSource *)source;
|
|
683 |
+ uint_t nget;
|
|
684 |
+
|
|
685 |
+ if (pn->pending) {
|
|
686 |
+ pn->pending = FALSE;
|
|
687 |
+ g_source_add_poll(source, PGPFD(source));
|
|
688 |
+ g_source_unref(source);
|
|
689 |
+ return FALSE;
|
|
690 |
+ }
|
|
691 |
+
|
|
692 |
+ if (!(PGPFD(pn)->revents & G_IO_IN))
|
|
693 |
+ return FALSE;
|
|
694 |
+
|
|
695 |
+ if (port_getn(PGPFD(source)->fd, NULL, 0, &nget, 0) == 0) {
|
|
696 |
+ if (nget - pn->pending_events > EXPECT_INC_EVENTS(pn)) {
|
|
697 |
+ /* Sleep for a while. */
|
|
698 |
+ pn->pending_events = nget;
|
|
699 |
+ pn->event_growing_factor ++;
|
|
700 |
+
|
|
701 |
+ pn->pending = TRUE;
|
|
702 |
+ g_source_ref(source);
|
|
703 |
+ g_source_remove_poll(source, PGPFD(source));
|
|
704 |
+ g_timeout_add(SLEEP_BASE_TIME,
|
|
705 |
+ (GSourceFunc)port_check,
|
|
706 |
+ (gpointer)pn);
|
|
707 |
+ return FALSE;
|
|
708 |
+ }
|
|
709 |
+ }
|
|
710 |
+
|
|
711 |
+ pn->pending_events = 0;
|
|
712 |
+ pn->event_growing_factor = 0;
|
|
713 |
+
|
|
714 |
+ return TRUE;
|
|
715 |
+}
|
|
716 |
+
|
|
717 |
+static gboolean
|
|
718 |
+port_dispatch(GSource *source, GSourceFunc callback, gpointer user_data)
|
|
719 |
+{
|
|
720 |
+ node_t *f;
|
|
721 |
+ uint_t nget = 0;
|
|
722 |
+ uint_t total = 0;
|
|
723 |
+
|
|
724 |
+ FK_W ("%s 0x%p fd %d\n", __func__, source, PGPFD(source)->fd);
|
11824
|
725 |
+
|
17812
|
726 |
+ G_LOCK (fen_lock);
|
|
727 |
+ do {
|
|
728 |
+ nget = 1;
|
|
729 |
+ if (port_getn(PGPFD(source)->fd, pevents, PE_ALLOC, &nget, &zero_wait) == 0) {
|
|
730 |
+ int i;
|
|
731 |
+ for (i = 0; i < nget; i++) {
|
|
732 |
+ f = (node_t *)pevents[i].portev_user;
|
|
733 |
+
|
|
734 |
+ if (pevents[i].portev_source == PORT_SOURCE_FILE) {
|
|
735 |
+
|
|
736 |
+ NODE_CLE_STATE(f, NODE_STATE_ASSOCIATED);
|
|
737 |
+ NODE_SET_STATE(f, NODE_STATE_HAS_EVENTS);
|
|
738 |
+
|
|
739 |
+ if (HAS_NO_EXCEPTION_EVENTS(pevents[i].portev_events)) {
|
|
740 |
+ /* If the events do not show it's deleted, update
|
|
741 |
+ * file timestamp to avoid missing events next time.
|
|
742 |
+ */
|
|
743 |
+ if (node_lstat(f) != 0 /* || port_add(f) != 0 */) {
|
|
744 |
+ /* Included deleted event. */
|
|
745 |
+ pevents[i].portev_events |= FILE_DELETE;
|
|
746 |
+ }
|
|
747 |
+ }
|
|
748 |
+
|
|
749 |
+ /* Queue it and waiting for processing. */
|
|
750 |
+ g_queue_push_tail(g_eventq,
|
|
751 |
+ node_event_new(pevents[i].portev_events, (gpointer)f));
|
|
752 |
+
|
|
753 |
+ } else {
|
|
754 |
+ FK_W ("[kernel] unknown portev_source %d\n", pevents[i].portev_source);
|
|
755 |
+ }
|
|
756 |
+ }
|
|
757 |
+
|
|
758 |
+ total += nget;
|
|
759 |
+
|
|
760 |
+ } else {
|
|
761 |
+ FK_W ("[kernel] port_getn %s\n", g_strerror (errno));
|
|
762 |
+ break;
|
|
763 |
+ }
|
|
764 |
+ } while (nget == PE_ALLOC);
|
|
765 |
+
|
|
766 |
+ G_UNLOCK (fen_lock);
|
|
767 |
+
|
|
768 |
+ if (total > 0 && callback) {
|
|
769 |
+ FK_W ("[kernel] get total %ld events\n", total);
|
|
770 |
+ return callback (user_data);
|
|
771 |
+ }
|
|
772 |
+ return TRUE;
|
|
773 |
+}
|
|
774 |
+
|
|
775 |
+static gboolean
|
|
776 |
+process_renamed_hash_cb(gpointer key, gpointer value, gpointer user_data)
|
11824
|
777 |
+{
|
17812
|
778 |
+ node_event_t *ev = value;
|
|
779 |
+
|
|
780 |
+#if 0
|
|
781 |
+ node_add_event(ev->user_data, ev);
|
|
782 |
+#else
|
|
783 |
+ user_process_events_cb(ev->user_data, ev);
|
|
784 |
+#endif
|
|
785 |
+ /* Always delete self from hash. */
|
|
786 |
+ return TRUE;
|
|
787 |
+}
|
|
788 |
+
|
|
789 |
+static gboolean
|
|
790 |
+port_events_process_cb(gpointer user_data)
|
|
791 |
+{
|
|
792 |
+ node_event_t *ev;
|
|
793 |
+
|
|
794 |
+ G_LOCK (fen_lock);
|
|
795 |
+
|
|
796 |
+ /* Processing g_eventq */
|
|
797 |
+ while ((ev = (node_event_t*)g_queue_pop_head (g_eventq)) != NULL) {
|
|
798 |
+
|
|
799 |
+ /* FK_W ("[%s] 0x%p %s\n", __func__, ev, _event_string (ev->e)); */
|
|
800 |
+
|
|
801 |
+ {
|
|
802 |
+ gchar *log = _event_strings(ev->e);
|
|
803 |
+ FK_W ("%s %s %s\n", __func__, NODE_NAME(ev->user_data), log);
|
|
804 |
+ g_free(log);
|
|
805 |
+ }
|
|
806 |
+
|
|
807 |
+#ifdef GIO_COMPILATION
|
|
808 |
+ /* Use the parent node as a hash, because only the dir_subs in the
|
|
809 |
+ * parent node should receive MOVE event.
|
|
810 |
+ */
|
|
811 |
+ if (NODE_PARENT(ev->user_data)) {
|
|
812 |
+ if (ev->e == FILE_RENAME_TO) {
|
|
813 |
+ g_hash_table_insert(renamed_hash, NODE_PARENT(ev->user_data), ev);
|
|
814 |
+ g_time_val_add(&ev->rename_tv, RENAME_EVENTS_INTERVAL);
|
|
815 |
+ continue;
|
|
816 |
+ }
|
|
817 |
+ if (ev->e == FILE_RENAME_FROM) {
|
|
818 |
+ node_event_t *pair_ev;
|
11099
|
819 |
+
|
17812
|
820 |
+ pair_ev = g_hash_table_lookup(renamed_hash, NODE_PARENT(ev->user_data));
|
|
821 |
+ if (pair_ev && node_timeval_lt(&ev->ctv, &pair_ev->rename_tv)) {
|
|
822 |
+ g_hash_table_remove(renamed_hash, NODE_PARENT(ev->user_data));
|
|
823 |
+ pair_ev->pair_data = ev->user_data;
|
|
824 |
+ /* Free ev, exchange pair_ev and ev. */
|
|
825 |
+ node_event_delete(ev);
|
|
826 |
+ ev = pair_ev;
|
|
827 |
+ }
|
|
828 |
+ }
|
|
829 |
+ }
|
|
830 |
+#endif
|
|
831 |
+
|
|
832 |
+#if 0
|
|
833 |
+ node_add_event(ev->user_data, ev);
|
|
834 |
+#else
|
|
835 |
+ user_process_events_cb(ev->user_data, ev);
|
|
836 |
+#endif
|
|
837 |
+ }
|
|
838 |
+
|
|
839 |
+ /* Processing the events in renamed_hash. TODO we should delay it and wait
|
|
840 |
+ * for more possible pair.
|
|
841 |
+ */
|
|
842 |
+ g_hash_table_foreach_remove(renamed_hash, process_renamed_hash_cb, NULL);
|
|
843 |
+
|
|
844 |
+ G_UNLOCK (fen_lock);
|
|
845 |
+
|
|
846 |
+ process_port_event_id = 0;
|
|
847 |
+ return FALSE;
|
|
848 |
+}
|
|
849 |
+
|
|
850 |
+static gboolean
|
|
851 |
+port_events_read_cb(gpointer user_data)
|
|
852 |
+{
|
|
853 |
+
|
|
854 |
+ if (process_port_event_id == 0) {
|
|
855 |
+ process_port_event_id = g_timeout_add(PROCESS_PORT_EVENTS_TIME,
|
|
856 |
+ port_events_process_cb,
|
|
857 |
+ NULL);
|
|
858 |
+ }
|
|
859 |
+
|
|
860 |
+ return TRUE;
|
|
861 |
+}
|
11099
|
862 |
+
|
17812
|
863 |
+/*
|
|
864 |
+ * malloc PSource and port_create, start thread at pnode_ref.
|
|
865 |
+ * if psource_new succeeded, the PSource will never
|
|
866 |
+ * be freed. So PSource can be freed only in psource_new.
|
|
867 |
+ * Note pnode_monitor_remove_all can also free PSource, but currently no one
|
|
868 |
+ * invork it.
|
|
869 |
+ */
|
|
870 |
+static GSource*
|
|
871 |
+psource_new()
|
|
872 |
+{
|
|
873 |
+ GSource *source = NULL;
|
|
874 |
+ int fd;
|
|
875 |
+
|
|
876 |
+ if ((fd = port_create()) >= 0) {
|
|
877 |
+ source = g_source_new(&fen_source_func, sizeof(PSource));
|
|
878 |
+ PGPFD(source)->fd = fd;
|
|
879 |
+ PGPFD(source)->events = G_IO_IN | G_IO_HUP | G_IO_ERR;
|
|
880 |
+ g_source_set_callback(source, port_events_read_cb, NULL, NULL);
|
|
881 |
+ g_source_attach(source, NULL);
|
|
882 |
+ g_source_unref(source);
|
|
883 |
+ g_source_add_poll(source, PGPFD(source));
|
|
884 |
+
|
|
885 |
+ FK_W ("%s 0x%p fd %d\n", __func__, source, PGPFD(source)->fd);
|
|
886 |
+ } else {
|
|
887 |
+ FK_W ("PORT_CREATE %s\n", g_strerror(errno));
|
|
888 |
+ g_return_val_if_reached(NULL);
|
|
889 |
+ }
|
|
890 |
+
|
|
891 |
+ return source;
|
|
892 |
+}
|
|
893 |
+
|
|
894 |
+/**
|
|
895 |
+ * port_add:
|
|
896 |
+ * @f:
|
|
897 |
+ *
|
|
898 |
+ * Unsafe, need lock fen_lock.
|
|
899 |
+ * port_add will associate a GSource to @f->source
|
|
900 |
+ */
|
|
901 |
+gint
|
|
902 |
+port_add(node_t *f)
|
|
903 |
+{
|
|
904 |
+ GSource *source = f->source;
|
|
905 |
+
|
|
906 |
+ FK_W ("%s [0x%p] %s\n", __func__, f, NODE_NAME(f));
|
|
907 |
+
|
|
908 |
+ g_assert(f);
|
|
909 |
+ g_assert(NODE_HAS_FLAG(f, NODE_FLAG_STAT_UPDATED));
|
|
910 |
+
|
|
911 |
+ /* if (!NODE_HAS_FLAG(f, NODE_FLAG_STAT_DONE)) { */
|
|
912 |
+ /* if (NODE_STAT(f) != 0) { */
|
|
913 |
+ /* return errno; */
|
|
914 |
+ /* } */
|
|
915 |
+ /* } */
|
11824
|
916 |
+
|
17812
|
917 |
+ /* Try re-use f->pn. f->pn may be used by other request, e.g. f is deleted
|
|
918 |
+ * for a long time. So if pn is full, we try to open a new one.
|
|
919 |
+ */
|
|
920 |
+ if (!source) {
|
|
921 |
+start_over:
|
|
922 |
+ /* Try the next visible source. */
|
|
923 |
+ if (pn_visible_list) {
|
|
924 |
+ source = (GSource *)pn_visible_list->data;
|
|
925 |
+ } else {
|
|
926 |
+ if ((source = psource_new()) != NULL) {
|
|
927 |
+ g_assert (g_list_find (pn_visible_list, source) == NULL);
|
|
928 |
+ pn_visible_list = g_list_prepend (pn_visible_list, source);
|
|
929 |
+ }
|
|
930 |
+ }
|
|
931 |
+ }
|
11099
|
932 |
+
|
17812
|
933 |
+ if (port_associate(PGPFD(source)->fd, PORT_SOURCE_FILE, (uintptr_t)FILE_OBJECT(f),
|
|
934 |
+ CONCERNED_EVENTS,
|
|
935 |
+ (void *)f) == 0) {
|
|
936 |
+ f->source = source;
|
|
937 |
+ NODE_SET_STATE(f, NODE_STATE_ASSOCIATED);
|
|
938 |
+ NODE_CLE_FLAG(f, NODE_FLAG_STAT_UPDATED);
|
|
939 |
+ FK_W ("PORT_ASSOCIATE 0x%p OK\n", f);
|
|
940 |
+ return 0;
|
|
941 |
+ } else if (errno == EAGAIN) {
|
|
942 |
+ /* Full, remove it. */
|
|
943 |
+ pn_visible_list = g_list_remove (pn_visible_list, source);
|
|
944 |
+ /* Re-add to port */
|
|
945 |
+ goto start_over;
|
|
946 |
+
|
|
947 |
+ } else if (errno == ENOENT) {
|
|
948 |
+ /* File is not exist */
|
18141
|
949 |
+ } else if (errno == ENOTSUP) {
|
|
950 |
+ /* FS is not supported. Currently we think it no longer make sense to
|
|
951 |
+ * monitor it, so clean the stat info and return 0 to ignore this
|
|
952 |
+ * node. If there are requirement, we can consider to add polling
|
|
953 |
+ * method.
|
|
954 |
+ */
|
|
955 |
+ NODE_CLE_FLAG(f, NODE_FLAG_STAT_UPDATED);
|
|
956 |
+ return 0;
|
17812
|
957 |
+ } else {
|
|
958 |
+ FK_W ("PORT_ASSOCIATE 0x%p %s\n", f, g_strerror (errno));
|
|
959 |
+ }
|
|
960 |
+
|
|
961 |
+ /* No matter if associated successfully, stat info is out-of-date, so clean it. */
|
|
962 |
+ NODE_CLE_FLAG(f, NODE_FLAG_STAT_UPDATED);
|
|
963 |
+ return errno;
|
|
964 |
+}
|
|
965 |
+
|
|
966 |
+/**
|
|
967 |
+ * port_remove
|
|
968 |
+ *
|
|
969 |
+ * < private >
|
|
970 |
+ * Unsafe, need lock fen_lock.
|
|
971 |
+ */
|
|
972 |
+void
|
|
973 |
+port_remove (node_t *f)
|
11099
|
974 |
+{
|
17812
|
975 |
+ /* g_assert(f->source); */
|
|
976 |
+
|
|
977 |
+ if (NODE_HAS_STATE(f, NODE_STATE_ASSOCIATED)) {
|
|
978 |
+ /* Mark unregisted. */
|
|
979 |
+ if (port_dissociate(PGPFD(f->source)->fd, PORT_SOURCE_FILE, (uintptr_t)FILE_OBJECT(f)) == 0) {
|
|
980 |
+ /*
|
|
981 |
+ * Note, we can run foode_delete if dissociating is failed,
|
|
982 |
+ * because there may be some pending events (mostly like
|
|
983 |
+ * FILE_DELETE) in the port_get. If we delete the foode
|
|
984 |
+ * the fnode may be deleted, then port_get will run on an invalid
|
|
985 |
+ * address.
|
|
986 |
+ */
|
|
987 |
+ NODE_CLE_STATE(f, NODE_STATE_ASSOCIATED);
|
|
988 |
+ FK_W ("PORT_DISSOCIATE 0x%p OK\n", f);
|
|
989 |
+ } else if (errno == ENOENT) {
|
|
990 |
+ /* The file has been removed from port, after port_get or before
|
|
991 |
+ * port_get but DELETED event has been generated.
|
|
992 |
+ * Ignored. */
|
|
993 |
+ } else {
|
|
994 |
+ FK_W ("PORT_DISSOCIATE 0x%p %s\n", f, g_strerror (errno));
|
|
995 |
+ g_return_if_reached();
|
|
996 |
+ }
|
11824
|
997 |
+ }
|
17812
|
998 |
+}
|
|
999 |
+
|
|
1000 |
+/**
|
|
1001 |
+ * Get Solaris resouce values.
|
|
1002 |
+ *
|
|
1003 |
+ */
|
|
1004 |
+
|
|
1005 |
+extern gboolean
|
|
1006 |
+port_class_init (void (*user_process_events_callback) (gpointer, node_event_t*))
|
|
1007 |
+{
|
|
1008 |
+ rctlblk_t *rblk;
|
|
1009 |
+
|
|
1010 |
+ if ((rblk = malloc (rctlblk_size ())) == NULL) {
|
|
1011 |
+ FK_W ("[kernel] rblk malloc %s\n", g_strerror (errno));
|
|
1012 |
+ return FALSE;
|
|
1013 |
+ }
|
|
1014 |
+ if (getrctl ("process.max-port-events", NULL, rblk, RCTL_FIRST) == -1) {
|
|
1015 |
+ FK_W ("[kernel] getrctl %s\n", g_strerror (errno));
|
|
1016 |
+ free (rblk);
|
|
1017 |
+ return FALSE;
|
|
1018 |
+ } else {
|
|
1019 |
+ max_port_events = rctlblk_get_value(rblk);
|
|
1020 |
+ FK_W ("max_port_events = %u\n", max_port_events);
|
|
1021 |
+ free (rblk);
|
|
1022 |
+ }
|
|
1023 |
+ renamed_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal,
|
|
1024 |
+ NULL, NULL);
|
|
1025 |
+ if (renamed_hash == NULL) {
|
|
1026 |
+ FK_W ("[kernel] FEN global renamed queue initializing faild\n");
|
|
1027 |
+ return FALSE;
|
|
1028 |
+ }
|
|
1029 |
+ if ((g_eventq = g_queue_new ()) == NULL) {
|
|
1030 |
+ FK_W ("[kernel] FEN global event queue initializing faild\n");
|
|
1031 |
+ return FALSE;
|
|
1032 |
+ }
|
|
1033 |
+ if (user_process_events_callback == NULL) {
|
|
1034 |
+ FK_W ("[kernel] FEN global no user_process_events_callback\n");
|
|
1035 |
+ return FALSE;
|
|
1036 |
+ }
|
|
1037 |
+ user_process_events_cb = user_process_events_callback;
|
|
1038 |
+ memset (&zero_wait, 0, sizeof (timespec_t));
|
|
1039 |
+
|
|
1040 |
+ pevents = g_malloc(PE_ALLOC * sizeof(port_event_t));
|
|
1041 |
+ if (pevents == NULL) {
|
|
1042 |
+ FK_W ("[kernel] FEN global alloc pevents failed\n");
|
|
1043 |
+ return FALSE;
|
|
1044 |
+ }
|
|
1045 |
+
|
|
1046 |
+ return TRUE;
|
11824
|
1047 |
+}
|
11099
|
1048 |
+
|
12172
|
1049 |
+static gchar*
|
11824
|
1050 |
+printevent (const char *pname, int event, const char *tag)
|
11099
|
1051 |
+{
|
12172
|
1052 |
+ static gchar *event_string = NULL;
|
|
1053 |
+ GString *str;
|
|
1054 |
+
|
|
1055 |
+ if (event_string) {
|
|
1056 |
+ g_free(event_string);
|
|
1057 |
+ }
|
|
1058 |
+
|
11824
|
1059 |
+ str = g_string_new ("");
|
|
1060 |
+ g_string_printf (str, "[%s] [%-20s]", tag, pname);
|
|
1061 |
+ if (event & FILE_ACCESS) {
|
|
1062 |
+ str = g_string_append (str, " ACCESS");
|
|
1063 |
+ }
|
|
1064 |
+ if (event & FILE_MODIFIED) {
|
|
1065 |
+ str = g_string_append (str, " MODIFIED");
|
|
1066 |
+ }
|
|
1067 |
+ if (event & FILE_ATTRIB) {
|
|
1068 |
+ str = g_string_append (str, " ATTRIB");
|
|
1069 |
+ }
|
|
1070 |
+ if (event & FILE_DELETE) {
|
|
1071 |
+ str = g_string_append (str, " DELETE");
|
|
1072 |
+ }
|
|
1073 |
+ if (event & FILE_RENAME_TO) {
|
|
1074 |
+ str = g_string_append (str, " RENAME_TO");
|
|
1075 |
+ }
|
|
1076 |
+ if (event & FILE_RENAME_FROM) {
|
|
1077 |
+ str = g_string_append (str, " RENAME_FROM");
|
|
1078 |
+ }
|
|
1079 |
+ if (event & UNMOUNTED) {
|
|
1080 |
+ str = g_string_append (str, " UNMOUNTED");
|
|
1081 |
+ }
|
|
1082 |
+ if (event & MOUNTEDOVER) {
|
|
1083 |
+ str = g_string_append (str, " MOUNTEDOVER");
|
|
1084 |
+ }
|
12172
|
1085 |
+ event_string = str->str;
|
|
1086 |
+ g_string_free (str, FALSE);
|
|
1087 |
+ return event_string;
|
11099
|
1088 |
+}
|
|
1089 |
+
|
17812
|
1090 |
+static gchar *
|
|
1091 |
+_event_strings(int event)
|
11099
|
1092 |
+{
|
17812
|
1093 |
+ GString *str = g_string_sized_new(80);
|
|
1094 |
+
|
|
1095 |
+ if (event & FILE_DELETE)
|
|
1096 |
+ g_string_append(str, " FILE_DELETE");
|
|
1097 |
+
|
|
1098 |
+ if (event & FILE_RENAME_FROM)
|
|
1099 |
+ g_string_append(str, " FILE_RENAME_FROM");
|
|
1100 |
+
|
|
1101 |
+ if (event & FILE_MODIFIED)
|
|
1102 |
+ g_string_append(str, " FILE_MODIFIED");
|
|
1103 |
+
|
|
1104 |
+ if (event & FILE_RENAME_TO)
|
|
1105 |
+ g_string_append(str, " FILE_RENAME_TO");
|
11099
|
1106 |
+
|
17812
|
1107 |
+ if (event & MOUNTEDOVER)
|
|
1108 |
+ g_string_append(str, " MOUNTEDOVER");
|
|
1109 |
+
|
|
1110 |
+ if (event & FILE_ATTRIB)
|
|
1111 |
+ g_string_append(str, " FILE_ATTRIB");
|
11099
|
1112 |
+
|
17812
|
1113 |
+ if (event & UNMOUNTED)
|
|
1114 |
+ g_string_append(str, " UNMOUNTED");
|
|
1115 |
+
|
|
1116 |
+ if (event & FILE_ACCESS)
|
|
1117 |
+ g_string_append(str, " FILE_ACCESS");
|
|
1118 |
+
|
|
1119 |
+ return g_string_free(str, FALSE);
|
11099
|
1120 |
+}
|
|
1121 |
+
|
17812
|
1122 |
+static const gchar *
|
11824
|
1123 |
+_event_string (int event)
|
11099
|
1124 |
+{
|
11824
|
1125 |
+ switch (event) {
|
|
1126 |
+ case FILE_DELETE:
|
|
1127 |
+ return "FILE_DELETE";
|
|
1128 |
+ case FILE_RENAME_FROM:
|
|
1129 |
+ return "FILE_RENAME_FROM";
|
|
1130 |
+ case FILE_MODIFIED:
|
|
1131 |
+ return "FILE_MODIFIED";
|
|
1132 |
+ case FILE_RENAME_TO:
|
|
1133 |
+ return "FILE_RENAME_TO";
|
|
1134 |
+ case MOUNTEDOVER:
|
|
1135 |
+ return "MOUNTEDOVER";
|
|
1136 |
+ case FILE_ATTRIB:
|
|
1137 |
+ return "FILE_ATTRIB";
|
|
1138 |
+ case UNMOUNTED:
|
|
1139 |
+ return "UNMOUNTED";
|
|
1140 |
+ case FILE_ACCESS:
|
|
1141 |
+ return "FILE_ACCESS";
|
|
1142 |
+ default:
|
|
1143 |
+ return "EVENT_UNKNOWN";
|
|
1144 |
+ }
|
11099
|
1145 |
+}
|
|
1146 |
+
|
17812
|
1147 |
diff --git a/server/fen-kernel.h b/server/fen-kernel.h
|
|
1148 |
new file mode 100644
|
|
1149 |
index 0000000..6d2c49b
|
|
1150 |
--- /dev/null
|
|
1151 |
+++ b/server/fen-kernel.h
|
|
1152 |
@@ -0,0 +1,43 @@
|
|
1153 |
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
1154 |
+/* vim:set expandtab ts=4 shiftwidth=4: */
|
|
1155 |
+/*
|
|
1156 |
+ * Copyright (c) 2008, 2010 Oracle and/or its affiliates, Inc. All rights
|
|
1157 |
+ * reserved.
|
|
1158 |
+ *
|
|
1159 |
+ * This library is free software; you can redistribute it and/or
|
|
1160 |
+ * modify it under the terms of the GNU Lesser General Public
|
|
1161 |
+ * License as published by the Free Software Foundation; either
|
|
1162 |
+ * version 2 of the License, or (at your option) any later version.
|
|
1163 |
+ *
|
|
1164 |
+ * This library is distributed in the hope that it will be useful,
|
|
1165 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
1166 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
1167 |
+ * Lesser General Public License for more details.
|
|
1168 |
+ *
|
|
1169 |
+ * You should have received a copy of the GNU Lesser General
|
|
1170 |
+ * Public License along with this library; if not, write to the
|
|
1171 |
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
1172 |
+ * Boston, MA 02111-1307, USA.
|
11099
|
1173 |
+ *
|
17812
|
1174 |
+ * Authors: Lin Ma <[email protected]>
|
|
1175 |
+ */
|
|
1176 |
+
|
|
1177 |
+#include <sys/types.h>
|
|
1178 |
+#include <errno.h>
|
|
1179 |
+
|
|
1180 |
+#include "fen-node.h"
|
|
1181 |
+
|
|
1182 |
+#ifndef _FEN_KERNEL_H_
|
|
1183 |
+#define _FEN_KERNEL_H_
|
|
1184 |
+
|
|
1185 |
+#define CONCERNED_EVENTS (FILE_MODIFIED | FILE_ATTRIB | FILE_NOFOLLOW)
|
|
1186 |
+#define EXCEPTION_EVENTS (FILE_DELETE | FILE_RENAME_FROM)
|
|
1187 |
+#define HAS_EXCEPTION_EVENTS(e) ((e & EXCEPTION_EVENTS) != 0)
|
|
1188 |
+#define HAS_NO_EXCEPTION_EVENTS(e) ((e & EXCEPTION_EVENTS) == 0)
|
|
1189 |
+
|
|
1190 |
+gint port_add (node_t* f);
|
|
1191 |
+void port_remove (node_t *f);
|
|
1192 |
+
|
|
1193 |
+gboolean port_class_init ();
|
|
1194 |
+
|
|
1195 |
+#endif /* _FEN_KERNEL_H_ */
|
|
1196 |
diff --git a/server/fen-node.c b/server/fen-node.c
|
|
1197 |
new file mode 100644
|
18141
|
1198 |
index 0000000..d4d7ddb
|
17812
|
1199 |
--- /dev/null
|
|
1200 |
+++ b/server/fen-node.c
|
18141
|
1201 |
@@ -0,0 +1,642 @@
|
17812
|
1202 |
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
1203 |
+/* vim:set expandtab ts=4 shiftwidth=4: */
|
|
1204 |
+/*
|
|
1205 |
+ * Copyright (c) 2008, 2010 Oracle and/or its affiliates, Inc. All rights
|
|
1206 |
+ * reserved.
|
|
1207 |
+ *
|
|
1208 |
+ * This library is free software; you can redistribute it and/or
|
|
1209 |
+ * modify it under the terms of the GNU Lesser General Public
|
|
1210 |
+ * License as published by the Free Software Foundation; either
|
|
1211 |
+ * version 2 of the License, or (at your option) any later version.
|
|
1212 |
+ *
|
|
1213 |
+ * This library is distributed in the hope that it will be useful,
|
|
1214 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
1215 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
1216 |
+ * Lesser General Public License for more details.
|
|
1217 |
+ *
|
|
1218 |
+ * You should have received a copy of the GNU Lesser General
|
|
1219 |
+ * Public License along with this library; if not, write to the
|
|
1220 |
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
1221 |
+ * Boston, MA 02111-1307, USA.
|
|
1222 |
+ *
|
|
1223 |
+ * Authors: Lin Ma <[email protected]>
|
11099
|
1224 |
+ */
|
|
1225 |
+
|
17812
|
1226 |
+#include "config.h"
|
|
1227 |
+#include <sys/stat.h>
|
|
1228 |
+#include <errno.h>
|
|
1229 |
+#include <strings.h>
|
|
1230 |
+#include <glib.h>
|
|
1231 |
+#include "fen-kernel.h"
|
|
1232 |
+#include "fen-node.h"
|
|
1233 |
+#include "fen-dump.h"
|
|
1234 |
+
|
|
1235 |
+#ifdef GIO_COMPILATION
|
|
1236 |
+#include "gfilemonitor.h"
|
|
1237 |
+#else
|
|
1238 |
+#include "gam_event.h"
|
|
1239 |
+#include "gam_server.h"
|
|
1240 |
+#include "gam_protocol.h"
|
|
1241 |
+#endif
|
|
1242 |
+
|
|
1243 |
+#ifdef GIO_COMPILATION
|
|
1244 |
+#define FN_W if (fn_debug_enabled) g_debug
|
|
1245 |
+static gboolean fn_debug_enabled = FALSE;
|
|
1246 |
+#else
|
|
1247 |
+#include "gam_error.h"
|
|
1248 |
+#define FN_W(...) GAM_DEBUG(DEBUG_INFO, __VA_ARGS__)
|
|
1249 |
+#endif
|
|
1250 |
+
|
|
1251 |
+G_LOCK_EXTERN (fen_lock);
|
|
1252 |
+
|
|
1253 |
+/* Must continue monitoring if:
|
|
1254 |
+ * 1) I'm subscribed,
|
|
1255 |
+ * 2) The subscribed children (one of the children has subs) are missing,
|
|
1256 |
+ * 3) my parent is subscribed (monitoring directory).
|
|
1257 |
+ */
|
|
1258 |
+#define NODE_NEED_MONITOR(f) \
|
|
1259 |
+ (NODE_IS_ACTIVE(f) || node_children_num(f) > 0 || NODE_IS_REQUIRED_BY_PARENT(f))
|
|
1260 |
+
|
|
1261 |
+static int concern_events[] = {
|
|
1262 |
+ FILE_DELETE,
|
|
1263 |
+ FILE_RENAME_FROM,
|
|
1264 |
+ UNMOUNTED,
|
|
1265 |
+ MOUNTEDOVER,
|
|
1266 |
+#ifdef GIO_COMPILATION
|
|
1267 |
+ FILE_MODIFIED,
|
|
1268 |
+ FILE_ATTRIB,
|
|
1269 |
+#else
|
|
1270 |
+ FILE_MODIFIED | FILE_ATTRIB,
|
|
1271 |
+#endif
|
|
1272 |
+ FILE_RENAME_TO,
|
|
1273 |
+};
|
|
1274 |
+
|
|
1275 |
+node_t *ROOT = NULL;
|
|
1276 |
+
|
|
1277 |
+static void node_emit_one_event(node_t *f, GList *subs, node_t *other, int event);
|
|
1278 |
+static void node_emit_events(node_t *f, const node_event_t *ne);
|
|
1279 |
+static int node_event_translate(int event, gboolean pair);
|
|
1280 |
+static void node_add_event (node_t *f, node_event_t *ev);
|
|
1281 |
+static node_t* node_new (node_t* parent, const gchar* basename);
|
|
1282 |
+static void node_delete (node_t* parent);
|
|
1283 |
+static node_t* node_get_child (node_t *f, const gchar *basename);
|
|
1284 |
+static void children_add (node_t *p, node_t *f);
|
|
1285 |
+static void children_remove (node_t *p, node_t *f);
|
|
1286 |
+static gboolean children_remove_cb (gpointer key, gpointer value, gpointer user_data);
|
|
1287 |
+static guint node_children_num (node_t *f);
|
|
1288 |
+
|
|
1289 |
+gboolean
|
|
1290 |
+node_timeval_lt(const GTimeVal *val1, const GTimeVal *val2)
|
|
1291 |
+{
|
|
1292 |
+ if (val1->tv_sec < val2->tv_sec)
|
|
1293 |
+ return TRUE;
|
|
1294 |
+
|
|
1295 |
+ if (val1->tv_sec > val2->tv_sec)
|
|
1296 |
+ return FALSE;
|
|
1297 |
+
|
|
1298 |
+ /* val1->tv_sec == val2->tv_sec */
|
|
1299 |
+ if (val1->tv_usec < val2->tv_usec)
|
|
1300 |
+ return TRUE;
|
|
1301 |
+
|
|
1302 |
+ return FALSE;
|
|
1303 |
+}
|
|
1304 |
+
|
|
1305 |
+void
|
|
1306 |
+node_traverse (node_t* node, void(*traverse_cb)(node_t*, gpointer), gpointer user_data)
|
|
1307 |
+{
|
|
1308 |
+ GHashTableIter iter;
|
|
1309 |
+ gpointer value;
|
|
1310 |
+
|
|
1311 |
+ g_assert(traverse_cb);
|
|
1312 |
+ if (node == NULL) {
|
|
1313 |
+ node = ROOT;
|
|
1314 |
+ }
|
|
1315 |
+
|
|
1316 |
+ if (node) {
|
|
1317 |
+ traverse_cb(node, user_data);
|
|
1318 |
+ }
|
|
1319 |
+
|
|
1320 |
+ g_hash_table_iter_init (&iter, node->children);
|
|
1321 |
+ while (g_hash_table_iter_next (&iter, NULL, &value)) {
|
|
1322 |
+ node_traverse((node_t *)value, traverse_cb, user_data);
|
|
1323 |
+ }
|
|
1324 |
+}
|
|
1325 |
+
|
|
1326 |
+node_t*
|
|
1327 |
+node_find(node_t* node, const gchar* filename, gboolean create_on_missing)
|
|
1328 |
+{
|
|
1329 |
+ gchar* str;
|
|
1330 |
+ gchar* token;
|
|
1331 |
+ gchar* lasts;
|
|
1332 |
+ node_t* parent;
|
|
1333 |
+ node_t* child;
|
|
1334 |
+
|
|
1335 |
+ g_assert (filename && filename[0] == '/');
|
|
1336 |
+
|
|
1337 |
+ if (node == NULL) {
|
|
1338 |
+ node = ROOT;
|
|
1339 |
+ }
|
|
1340 |
+
|
|
1341 |
+ FN_W ("%s %s\n", __func__, filename);
|
|
1342 |
+
|
|
1343 |
+ parent = child = node;
|
|
1344 |
+ str = g_strdup (filename);
|
|
1345 |
+
|
|
1346 |
+ for (token = strtok_r (str, G_DIR_SEPARATOR_S, &lasts);
|
|
1347 |
+ token != NULL && child != NULL;
|
|
1348 |
+ token = strtok_r (NULL, G_DIR_SEPARATOR_S, &lasts)) {
|
|
1349 |
+ FN_W ("%s %s + %s\n", __func__, NODE_NAME(parent), token);
|
|
1350 |
+ child = node_get_child(parent, token);
|
|
1351 |
+ if (child) {
|
|
1352 |
+ parent = child;
|
|
1353 |
+ } else if (create_on_missing) {
|
|
1354 |
+ child = node_new (parent, token);
|
|
1355 |
+ if (child) {
|
|
1356 |
+ children_add (parent, child);
|
|
1357 |
+ parent = child;
|
|
1358 |
+ continue;
|
|
1359 |
+ } else {
|
|
1360 |
+ FN_W ("%s create %s failed", __func__, token);
|
|
1361 |
+ }
|
|
1362 |
+ } else {
|
|
1363 |
+ break;
|
|
1364 |
+ }
|
|
1365 |
+ }
|
|
1366 |
+
|
|
1367 |
+ g_free (str);
|
|
1368 |
+ return child;
|
|
1369 |
+}
|
|
1370 |
+
|
|
1371 |
+gint
|
|
1372 |
+node_lstat(node_t *f)
|
|
1373 |
+{
|
|
1374 |
+ struct stat buf;
|
|
1375 |
+
|
|
1376 |
+ g_assert(!NODE_HAS_STATE(f, NODE_STATE_ASSOCIATED));
|
|
1377 |
+
|
|
1378 |
+ if (lstat(NODE_NAME(f), &buf) == 0) {
|
|
1379 |
+ FN_W ("%s %s\n", __func__, NODE_NAME(f));
|
|
1380 |
+ FILE_OBJECT(f)->fo_atime = buf.st_atim;
|
|
1381 |
+ FILE_OBJECT(f)->fo_mtime = buf.st_mtim;
|
|
1382 |
+ FILE_OBJECT(f)->fo_ctime = buf.st_ctim;
|
|
1383 |
+ NODE_SET_FLAG(f, NODE_FLAG_STAT_UPDATED |
|
|
1384 |
+ (S_ISDIR (buf.st_mode) ? NODE_FLAG_DIR : NODE_FLAG_NONE));
|
|
1385 |
+ return 0;
|
|
1386 |
+ } else {
|
|
1387 |
+ FN_W ("%s(lstat) %s %s\n", __func__, NODE_NAME(f), g_strerror (errno));
|
|
1388 |
+ }
|
|
1389 |
+ return errno;
|
|
1390 |
+}
|
|
1391 |
+
|
|
1392 |
+void
|
|
1393 |
+node_create_children_snapshot(node_t *f, gint created_event, gboolean emit)
|
11099
|
1394 |
+{
|
17812
|
1395 |
+ GDir *dir;
|
|
1396 |
+ GError *err = NULL;
|
|
1397 |
+
|
|
1398 |
+ FN_W ("%s %s [0x%p]\n", __func__, NODE_NAME(f), f);
|
|
1399 |
+
|
|
1400 |
+ dir = g_dir_open (NODE_NAME(f), 0, &err);
|
|
1401 |
+ if (dir) {
|
|
1402 |
+ const char *basename;
|
|
1403 |
+ node_t *child = NULL;
|
|
1404 |
+
|
|
1405 |
+ while ((basename = g_dir_read_name (dir))) {
|
|
1406 |
+ node_t* data;
|
|
1407 |
+ GList *idx;
|
|
1408 |
+
|
|
1409 |
+ child = node_get_child (f, basename);
|
|
1410 |
+ if (child == NULL) {
|
|
1411 |
+ gchar *filename;
|
|
1412 |
+
|
|
1413 |
+ child = node_new (f, basename);
|
|
1414 |
+ children_add (f, child);
|
|
1415 |
+ }
|
|
1416 |
+
|
|
1417 |
+ if (f->dir_subs) {
|
|
1418 |
+ /* We need monitor the new children, or the existed child which
|
|
1419 |
+ * is in the DELETED mode.
|
|
1420 |
+ */
|
|
1421 |
+ if (!NODE_HAS_STATE(child, NODE_STATE_ASSOCIATED) &&
|
|
1422 |
+ node_lstat(child) == 0 && port_add(child) == 0) {
|
|
1423 |
+ if (emit) {
|
|
1424 |
+ /* Emit the whatever event for the new found file. */
|
|
1425 |
+ node_emit_one_event(child, child->dir_subs, NULL, created_event);
|
|
1426 |
+ node_emit_one_event(child, child->subs, NULL, created_event);
|
|
1427 |
+ node_emit_one_event(child, f->dir_subs, NULL, created_event);
|
|
1428 |
+ node_emit_one_event(child, f->subs, NULL, created_event);
|
|
1429 |
+ }
|
|
1430 |
+ }
|
|
1431 |
+ /* else ignore, because it may be deleted. */
|
|
1432 |
+ }
|
|
1433 |
+ }
|
|
1434 |
+ g_dir_close (dir);
|
|
1435 |
+
|
|
1436 |
+ /* We have finished children snapshot. Any other new added subs should
|
|
1437 |
+ * directory iterate the snapshot instead of scan directory again.
|
|
1438 |
+ */
|
|
1439 |
+ NODE_SET_FLAG(f, NODE_FLAG_SNAPSHOT_UPDATED);
|
|
1440 |
+
|
|
1441 |
+ } else {
|
|
1442 |
+ FN_W (err->message);
|
|
1443 |
+ g_error_free (err);
|
|
1444 |
+ }
|
|
1445 |
+}
|
|
1446 |
+
|
|
1447 |
+/**
|
|
1448 |
+ * If all active children nodes are ported, then cancel monitor the parent
|
|
1449 |
+ * node. If we know how many children are created, then we can stop accordingly.
|
|
1450 |
+ *
|
|
1451 |
+ * Unsafe, need lock.
|
|
1452 |
+ */
|
|
1453 |
+static void
|
|
1454 |
+foreach_known_children_scan(gpointer key, gpointer value, gpointer user_data)
|
|
1455 |
+{
|
|
1456 |
+ node_t* f = (node_t*)value;
|
|
1457 |
+
|
|
1458 |
+ FN_W ("%s 0x%p %s\n", __func__, f, NODE_NAME(f));
|
|
1459 |
+
|
|
1460 |
+ if (!NODE_HAS_STATE(f, NODE_STATE_ASSOCIATED)) {
|
|
1461 |
+ if (node_lstat(f) == 0 && port_add(f) == 0) {
|
|
1462 |
+ node_emit_one_event(f, f->dir_subs, NULL, FN_EVENT_CREATED);
|
|
1463 |
+ node_emit_one_event(f, f->subs, NULL, FN_EVENT_CREATED);
|
|
1464 |
+ if (NODE_PARENT(f)) {
|
|
1465 |
+ node_emit_one_event(f, NODE_PARENT(f)->dir_subs, NULL, FN_EVENT_CREATED);
|
|
1466 |
+ node_emit_one_event(f, NODE_PARENT(f)->subs, NULL, FN_EVENT_CREATED);
|
|
1467 |
+ }
|
|
1468 |
+ }
|
|
1469 |
+ }
|
|
1470 |
+}
|
|
1471 |
+
|
|
1472 |
+gboolean
|
|
1473 |
+node_try_delete(node_t* node)
|
|
1474 |
+{
|
|
1475 |
+ g_assert (node);
|
|
1476 |
+
|
|
1477 |
+ FN_W ("%s 0x%p %s\n", __func__, node, NODE_NAME(node));
|
|
1478 |
+
|
|
1479 |
+ /* Try clean children */
|
|
1480 |
+ if (node_children_num (node) > 0) {
|
|
1481 |
+ g_hash_table_foreach_remove(node->children, children_remove_cb, NULL);
|
|
1482 |
+ }
|
|
1483 |
+ if (!NODE_NEED_MONITOR(node)) {
|
|
1484 |
+ /* Clean some flags. */
|
|
1485 |
+ /* NODE_CLE_FLAG(node, NODE_FLAG_HAS_SNAPSHOT | NODE_FLAG_STAT_DONE); */
|
|
1486 |
+ node->flag = 0;
|
|
1487 |
+
|
|
1488 |
+ /* Now we handle the state. */
|
|
1489 |
+ if (NODE_HAS_STATE(node, NODE_STATE_ASSOCIATED)) {
|
|
1490 |
+ port_remove(node);
|
|
1491 |
+ }
|
|
1492 |
+ /* Actually ignore the ROOT node. */
|
|
1493 |
+ if (node->state == 0 && NODE_PARENT(node)) {
|
|
1494 |
+ children_remove(NODE_PARENT(node), node);
|
|
1495 |
+ /* Do clean instead of returning TRUE. */
|
|
1496 |
+ node_delete (node);
|
|
1497 |
+ }
|
|
1498 |
+ /* else, we have events, clean event queue? */
|
|
1499 |
+ }
|
|
1500 |
+ return FALSE;
|
|
1501 |
+}
|
|
1502 |
+
|
|
1503 |
+static node_t*
|
|
1504 |
+node_new (node_t* parent, const gchar* basename)
|
|
1505 |
+{
|
|
1506 |
+ node_t *f = NULL;
|
|
1507 |
+
|
|
1508 |
+ g_assert (basename && basename[0]);
|
|
1509 |
+
|
|
1510 |
+ if ((f = g_new0(node_t, 1)) != NULL) {
|
|
1511 |
+ if (parent) {
|
|
1512 |
+ NODE_NAME(f) = g_build_filename(NODE_NAME(parent), basename, NULL);
|
|
1513 |
+ } else {
|
|
1514 |
+ NODE_NAME(f) = g_strdup(G_DIR_SEPARATOR_S);
|
|
1515 |
+ }
|
|
1516 |
+ f->basename = g_strdup (basename);
|
|
1517 |
+ /* f->children = g_hash_table_new_full (g_str_hash, g_str_equal, */
|
|
1518 |
+ /* NULL, (GDestroyNotify)node_delete); */
|
|
1519 |
+ f->children = g_hash_table_new_full (g_str_hash, g_str_equal,
|
|
1520 |
+ NULL, NULL);
|
|
1521 |
+#ifdef GIO_COMPILATION
|
|
1522 |
+ f->gfile = g_file_new_for_path (NODE_NAME(f));
|
|
1523 |
+#endif
|
|
1524 |
+ FN_W ("%s 0x%p %s\n", __func__, f, NODE_NAME(f));
|
|
1525 |
+ }
|
|
1526 |
+ return f;
|
|
1527 |
+}
|
|
1528 |
+
|
|
1529 |
+static void
|
|
1530 |
+node_delete (node_t *f)
|
|
1531 |
+{
|
|
1532 |
+ FN_W ("%s 0x%p %s\n", __func__, f, NODE_NAME(f));
|
|
1533 |
+ g_assert(f->state == 0);
|
|
1534 |
+ g_assert(!NODE_IS_ACTIVE(f));
|
|
1535 |
+ g_assert(g_hash_table_size (f->children) == 0);
|
|
1536 |
+ g_assert(NODE_PARENT(f) == NULL);
|
|
1537 |
+ g_hash_table_unref(f->children);
|
|
1538 |
+#ifdef GIO_COMPILATION
|
|
1539 |
+ g_object_unref (f->gfile);
|
|
1540 |
+#endif
|
|
1541 |
+ g_free(f->basename);
|
|
1542 |
+ g_free(NODE_NAME(f));
|
|
1543 |
+ g_free (f);
|
|
1544 |
+}
|
|
1545 |
+
|
|
1546 |
+static void
|
|
1547 |
+children_add (node_t *p, node_t *f)
|
|
1548 |
+{
|
|
1549 |
+ FN_W ("%s %s %s\n", __func__, NODE_NAME(p), f->basename);
|
|
1550 |
+ g_hash_table_insert (p->children, f->basename, f);
|
|
1551 |
+ NODE_PARENT(f) = p;
|
|
1552 |
+}
|
|
1553 |
+
|
|
1554 |
+static void
|
|
1555 |
+children_remove (node_t *p, node_t *f)
|
|
1556 |
+{
|
|
1557 |
+ FN_W ("%s %s %s\n", __func__, NODE_NAME(p), f->basename);
|
|
1558 |
+ g_hash_table_steal (p->children, f->basename);
|
|
1559 |
+ NODE_PARENT(f) = NULL;
|
|
1560 |
+}
|
|
1561 |
+
|
|
1562 |
+static node_t *
|
|
1563 |
+node_get_child (node_t *f, const gchar *basename)
|
|
1564 |
+{
|
|
1565 |
+ if (f->children) {
|
|
1566 |
+ return (node_t *) g_hash_table_lookup (f->children, (gpointer)basename);
|
|
1567 |
+ }
|
|
1568 |
+ return NULL;
|
|
1569 |
+}
|
|
1570 |
+
|
|
1571 |
+static guint
|
|
1572 |
+node_children_num (node_t *f)
|
|
1573 |
+{
|
|
1574 |
+ return g_hash_table_size (f->children);
|
|
1575 |
+}
|
|
1576 |
+
|
|
1577 |
+/**
|
|
1578 |
+ * depth first delete recursively
|
|
1579 |
+ */
|
|
1580 |
+static gboolean
|
|
1581 |
+children_remove_cb (gpointer key, gpointer value, gpointer user_data)
|
|
1582 |
+{
|
|
1583 |
+ return node_try_delete ((node_t*)value);
|
|
1584 |
+}
|
|
1585 |
+
|
|
1586 |
+gboolean
|
|
1587 |
+node_class_init()
|
|
1588 |
+{
|
|
1589 |
+ ROOT = node_new (NULL, G_DIR_SEPARATOR_S);
|
|
1590 |
+ if (ROOT == NULL) {
|
|
1591 |
+ FN_W ("[node] Create ROOT node failed.\n");
|
11824
|
1592 |
+ return FALSE;
|
|
1593 |
+ }
|
17812
|
1594 |
+
|
|
1595 |
+ return port_class_init (node_add_event);
|
|
1596 |
+}
|
|
1597 |
+
|
|
1598 |
+/**
|
|
1599 |
+ * Adjust self on failing to Port
|
|
1600 |
+ */
|
|
1601 |
+void
|
|
1602 |
+node_adjust_deleted(node_t* f)
|
|
1603 |
+{
|
|
1604 |
+ node_t *ancestor;
|
|
1605 |
+
|
|
1606 |
+ FN_W ("%s %s\n", __func__, NODE_NAME(f));
|
|
1607 |
+
|
18141
|
1608 |
+ for (ancestor = NODE_PARENT(f);
|
|
1609 |
+ ancestor != NULL;
|
|
1610 |
+ ancestor = NODE_PARENT(ancestor)) {
|
|
1611 |
+ /* Stop if we find a node which been already associated or is existed
|
|
1612 |
+ * and can be associated.
|
|
1613 |
+ */
|
|
1614 |
+ if (NODE_HAS_STATE(ancestor, NODE_STATE_ASSOCIATED) ||
|
|
1615 |
+ (node_lstat(ancestor) == 0 && port_add(ancestor) == 0)) {
|
|
1616 |
+ break;
|
|
1617 |
+ }
|
|
1618 |
+ }
|
|
1619 |
+
|
|
1620 |
+ /* We assume we shouldn't reach here, because Root is always existed and
|
|
1621 |
+ * associated. But given bugster#6955199, if PORT FS has problems on root,
|
|
1622 |
+ * we may reach here. So just return ROOT and the whole GIO fen backend will
|
|
1623 |
+ * fail.
|
|
1624 |
+ */
|
|
1625 |
+ /* g_assert(ancestor != NULL); */
|
17812
|
1626 |
+}
|
|
1627 |
+
|
|
1628 |
+
|
|
1629 |
+static void
|
|
1630 |
+node_emit_events(node_t *f, const node_event_t *ne)
|
|
1631 |
+{
|
|
1632 |
+ gsize num = sizeof(concern_events)/sizeof(int);
|
|
1633 |
+ gint i;
|
|
1634 |
+ int translated_e;
|
|
1635 |
+ node_t *p;
|
|
1636 |
+
|
|
1637 |
+ if (node_timeval_lt(&f->atv, &ne->ctv)) {
|
|
1638 |
+ int event = ne->e;
|
|
1639 |
+
|
|
1640 |
+ /* Emit DELETED on the pair_data */
|
|
1641 |
+ if (ne->pair_data) {
|
|
1642 |
+ node_t *from = ne->pair_data;
|
|
1643 |
+ node_emit_one_event(from, from->dir_subs, NULL, node_event_translate(FILE_DELETE, FALSE));
|
|
1644 |
+ node_emit_one_event(from, from->subs, NULL, node_event_translate(FILE_DELETE, FALSE));
|
|
1645 |
+ }
|
|
1646 |
+
|
|
1647 |
+ for (i = 0; i < num; i++) {
|
|
1648 |
+ if (event & concern_events[i]) {
|
|
1649 |
+ translated_e = node_event_translate(concern_events[i], FALSE);
|
|
1650 |
+ /* Neither GIO or gamin cares about modified events on a
|
|
1651 |
+ * directory.
|
|
1652 |
+ */
|
|
1653 |
+#ifdef GIO_COMPILATION
|
|
1654 |
+ if ((concern_events[i] & FILE_MODIFIED) == 0) {
|
|
1655 |
+ node_emit_one_event(f, f->dir_subs, NULL, translated_e);
|
|
1656 |
+ }
|
|
1657 |
+#else
|
|
1658 |
+ /* Gamin doesn't care about attrib changed events on a directory
|
|
1659 |
+ * either.
|
|
1660 |
+ */
|
|
1661 |
+ if ((concern_events[i] & (FILE_MODIFIED | FILE_ATTRIB)) == 0) {
|
|
1662 |
+ node_emit_one_event(f, f->dir_subs, NULL, translated_e);
|
|
1663 |
+ }
|
|
1664 |
+#endif
|
|
1665 |
+ node_emit_one_event(f, f->subs, NULL, translated_e);
|
|
1666 |
+ }
|
|
1667 |
+ event &= ~concern_events[i];
|
|
1668 |
+ }
|
11824
|
1669 |
+ }
|
17812
|
1670 |
+
|
|
1671 |
+ p = NODE_PARENT(f);
|
|
1672 |
+ if (p != NULL && node_timeval_lt(&p->atv, &ne->ctv)) {
|
|
1673 |
+ int event = ne->e;
|
|
1674 |
+ for (i = 0; i < num; i++) {
|
|
1675 |
+ if (event & concern_events[i]) {
|
|
1676 |
+ translated_e = node_event_translate(concern_events[i], ne->pair_data != NULL);
|
|
1677 |
+ node_emit_one_event(f, p->dir_subs, ne->pair_data, translated_e);
|
|
1678 |
+ node_emit_one_event(f, p->subs, ne->pair_data, translated_e);
|
|
1679 |
+ }
|
|
1680 |
+ event &= ~concern_events[i];
|
|
1681 |
+ }
|
11824
|
1682 |
+ }
|
|
1683 |
+}
|
|
1684 |
+
|
17812
|
1685 |
+/**
|
|
1686 |
+ * node_add_event:
|
|
1687 |
+ *
|
|
1688 |
+ */
|
|
1689 |
+static void
|
|
1690 |
+node_add_event (node_t *f, node_event_t *ev)
|
|
1691 |
+{
|
|
1692 |
+ FN_W ("%s %d\n", __func__, ev->e);
|
|
1693 |
+
|
|
1694 |
+ /* Clean the events flag early, because all received events need be
|
|
1695 |
+ * processed in this function.
|
|
1696 |
+ */
|
|
1697 |
+ NODE_CLE_STATE(f, NODE_STATE_HAS_EVENTS);
|
|
1698 |
+
|
|
1699 |
+ /*
|
|
1700 |
+ * Node the node has been created, so we can delete create event in
|
|
1701 |
+ * optimizing. To reduce the statings, we add it to Port on discoving
|
|
1702 |
+ * it then emit CREATED event. So we don't need to do anything here.
|
|
1703 |
+ */
|
|
1704 |
+ if (NODE_NEED_MONITOR(f)) {
|
|
1705 |
+ if (HAS_NO_EXCEPTION_EVENTS(ev->e)) {
|
|
1706 |
+ if (NODE_HAS_STATE(f, NODE_STATE_ASSOCIATED) || port_add(f) == 0) {
|
|
1707 |
+ if ((ev->e & FILE_MODIFIED) && NODE_HAS_FLAG(f, NODE_FLAG_DIR)) {
|
|
1708 |
+ if (f->dir_subs) {
|
|
1709 |
+ node_create_children_snapshot(f, FN_EVENT_CREATED, TRUE);
|
|
1710 |
+ } else {
|
|
1711 |
+ g_hash_table_foreach(f->children, foreach_known_children_scan, NULL);
|
|
1712 |
+ }
|
|
1713 |
+ }
|
|
1714 |
+ } else {
|
|
1715 |
+ /* Emit delete event */
|
|
1716 |
+ ev->e |= FILE_DELETE;
|
|
1717 |
+
|
|
1718 |
+ node_adjust_deleted(f);
|
|
1719 |
+ }
|
|
1720 |
+
|
|
1721 |
+ } else {
|
|
1722 |
+ node_adjust_deleted(f);
|
|
1723 |
+ }
|
|
1724 |
+
|
|
1725 |
+ /* Send events to clients. */
|
|
1726 |
+ node_emit_events (f, ev);
|
|
1727 |
+
|
|
1728 |
+ } else {
|
|
1729 |
+ /* Send events to clients. */
|
|
1730 |
+ node_emit_events (f, ev);
|
|
1731 |
+
|
|
1732 |
+ node_try_delete(f);
|
|
1733 |
+ }
|
|
1734 |
+
|
|
1735 |
+ if (ev->pair_data) {
|
|
1736 |
+ node_t *from = ev->pair_data;
|
|
1737 |
+ g_assert(ev->e == FILE_RENAME_TO);
|
|
1738 |
+
|
|
1739 |
+ if (NODE_NEED_MONITOR(from)) {
|
|
1740 |
+ /* Clean the events flag, since it may block free this node. */
|
|
1741 |
+ NODE_CLE_STATE(from, NODE_STATE_HAS_EVENTS);
|
|
1742 |
+ node_adjust_deleted(from);
|
|
1743 |
+ } else {
|
|
1744 |
+ node_try_delete(from);
|
|
1745 |
+ }
|
|
1746 |
+ }
|
|
1747 |
+
|
|
1748 |
+ node_event_delete (ev);
|
|
1749 |
+}
|
|
1750 |
+
|
|
1751 |
+static void
|
|
1752 |
+node_emit_one_event(node_t *f, GList *subs, node_t *other, int event)
|
11824
|
1753 |
+{
|
17812
|
1754 |
+ GList* idx;
|
11824
|
1755 |
+
|
17812
|
1756 |
+ FN_W ("%s %s %d\n", __func__, NODE_NAME(f), event);
|
|
1757 |
+
|
|
1758 |
+#ifdef GIO_COMPILATION
|
|
1759 |
+ for (idx = subs; idx; idx = idx->next) {
|
|
1760 |
+ g_file_monitor_emit_event(G_FILE_MONITOR(idx->data), f->gfile,
|
|
1761 |
+ (other == NULL ? NULL : other->gfile), event);
|
|
1762 |
+ }
|
|
1763 |
+#else
|
|
1764 |
+ for (idx = subs; idx; idx = idx->next) {
|
|
1765 |
+ gam_server_emit_one_event(NODE_NAME(f), gam_subscription_is_dir(idx->data), event, idx->data, 1);
|
|
1766 |
+ }
|
|
1767 |
+#endif
|
|
1768 |
+}
|
|
1769 |
+
|
|
1770 |
+static int
|
|
1771 |
+node_event_translate(int event, gboolean pair)
|
|
1772 |
+{
|
|
1773 |
+#ifdef GIO_COMPILATION
|
|
1774 |
+ switch (event) {
|
|
1775 |
+ case FILE_DELETE:
|
|
1776 |
+ case FILE_RENAME_FROM:
|
|
1777 |
+ return G_FILE_MONITOR_EVENT_DELETED;
|
|
1778 |
+ case UNMOUNTED:
|
|
1779 |
+ return G_FILE_MONITOR_EVENT_UNMOUNTED;
|
|
1780 |
+ case FILE_ATTRIB:
|
|
1781 |
+ return G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED;
|
|
1782 |
+ case MOUNTEDOVER:
|
|
1783 |
+ case FILE_MODIFIED:
|
|
1784 |
+ return G_FILE_MONITOR_EVENT_CHANGED;
|
|
1785 |
+ case FILE_RENAME_TO:
|
|
1786 |
+ if (pair) {
|
|
1787 |
+ return G_FILE_MONITOR_EVENT_MOVED;
|
|
1788 |
+ } else {
|
|
1789 |
+ return G_FILE_MONITOR_EVENT_CREATED;
|
|
1790 |
+ }
|
|
1791 |
+ default:
|
|
1792 |
+ /* case FILE_ACCESS: */
|
|
1793 |
+ g_assert_not_reached ();
|
|
1794 |
+ return -1;
|
|
1795 |
+ }
|
|
1796 |
+#else
|
|
1797 |
+ switch (event) {
|
|
1798 |
+ case FILE_DELETE:
|
|
1799 |
+ case FILE_RENAME_FROM:
|
|
1800 |
+ return GAMIN_EVENT_DELETED;
|
|
1801 |
+ case MOUNTEDOVER:
|
|
1802 |
+ case UNMOUNTED:
|
|
1803 |
+ return GAMIN_EVENT_CHANGED;
|
|
1804 |
+ case FILE_RENAME_TO:
|
|
1805 |
+ if (pair) {
|
|
1806 |
+ return GAMIN_EVENT_MOVED;
|
|
1807 |
+ } else {
|
|
1808 |
+ return GAMIN_EVENT_CREATED;
|
|
1809 |
+ }
|
|
1810 |
+ default:
|
|
1811 |
+ if (event & (FILE_ATTRIB | FILE_MODIFIED)) {
|
|
1812 |
+ return GAMIN_EVENT_CHANGED;
|
|
1813 |
+ }
|
|
1814 |
+ /* case FILE_ACCESS: */
|
|
1815 |
+ g_assert_not_reached ();
|
|
1816 |
+ return -1;
|
|
1817 |
+ }
|
|
1818 |
+#endif
|
|
1819 |
+}
|
|
1820 |
+
|
|
1821 |
+node_event_t*
|
|
1822 |
+node_event_new (int event, gpointer user_data)
|
|
1823 |
+{
|
|
1824 |
+ node_event_t *ev;
|
|
1825 |
+
|
|
1826 |
+ if ((ev = g_new (node_event_t, 1)) != NULL) {
|
11824
|
1827 |
+ g_assert (ev);
|
|
1828 |
+ ev->e = event;
|
|
1829 |
+ ev->user_data = user_data;
|
17812
|
1830 |
+ ev->pair_data = NULL; /* For renamed file. */
|
|
1831 |
+ /* Created timestamp */
|
|
1832 |
+ g_get_current_time(&ev->ctv);
|
|
1833 |
+ ev->rename_tv = ev->ctv;
|
11824
|
1834 |
+ }
|
|
1835 |
+ return ev;
|
|
1836 |
+}
|
|
1837 |
+
|
|
1838 |
+void
|
17812
|
1839 |
+node_event_delete (node_event_t* ev)
|
11824
|
1840 |
+{
|
|
1841 |
+ g_free (ev);
|
11099
|
1842 |
+}
|
14665
|
1843 |
+
|
17812
|
1844 |
diff --git a/server/fen-node.h b/server/fen-node.h
|
|
1845 |
new file mode 100644
|
|
1846 |
index 0000000..7e99032
|
|
1847 |
--- /dev/null
|
|
1848 |
+++ b/server/fen-node.h
|
|
1849 |
@@ -0,0 +1,104 @@
|
11099
|
1850 |
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
1851 |
+/* vim:set expandtab ts=4 shiftwidth=4: */
|
11877
|
1852 |
+/*
|
17812
|
1853 |
+ * Copyright (c) 2008, 2010 Oracle and/or its affiliates, Inc. All rights
|
|
1854 |
+ * reserved.
|
11877
|
1855 |
+ *
|
|
1856 |
+ * This library is free software; you can redistribute it and/or
|
|
1857 |
+ * modify it under the terms of the GNU Lesser General Public
|
|
1858 |
+ * License as published by the Free Software Foundation; either
|
|
1859 |
+ * version 2 of the License, or (at your option) any later version.
|
|
1860 |
+ *
|
|
1861 |
+ * This library is distributed in the hope that it will be useful,
|
|
1862 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
1863 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
1864 |
+ * Lesser General Public License for more details.
|
|
1865 |
+ *
|
|
1866 |
+ * You should have received a copy of the GNU Lesser General
|
|
1867 |
+ * Public License along with this library; if not, write to the
|
|
1868 |
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
1869 |
+ * Boston, MA 02111-1307, USA.
|
|
1870 |
+ *
|
|
1871 |
+ * Authors: Lin Ma <[email protected]>
|
|
1872 |
+ */
|
11099
|
1873 |
+
|
|
1874 |
+#include <port.h>
|
17812
|
1875 |
+#include <gio/gio.h>
|
|
1876 |
+
|
|
1877 |
+#ifndef _FEN_NODE_H_
|
|
1878 |
+#define _FEN_NODE_H_
|
|
1879 |
+
|
|
1880 |
+#ifdef GIO_COMPILATION
|
|
1881 |
+#define FN_EVENT_CREATED G_FILE_MONITOR_EVENT_CREATED
|
|
1882 |
+#else
|
|
1883 |
+#define FN_EVENT_CREATED GAMIN_EVENT_CREATED
|
|
1884 |
+#endif
|
|
1885 |
+
|
|
1886 |
+#define NODE_STATE_NONE 0x00000000
|
|
1887 |
+#define NODE_STATE_ASSOCIATED 0x00000001 /* This is a confilct to NODE_FLAG_STAT_DONE */
|
|
1888 |
+#define NODE_STATE_HAS_EVENTS 0x00000002
|
|
1889 |
+
|
|
1890 |
+#define NODE_FLAG_NONE 0x00000000
|
|
1891 |
+#define NODE_FLAG_SNAPSHOT_UPDATED 0x00000001
|
|
1892 |
+#define NODE_FLAG_DIR 0x00000002
|
|
1893 |
+#define NODE_FLAG_STAT_UPDATED 0x00000004
|
|
1894 |
+
|
|
1895 |
+#define NODE_CLE_STATE(f, st) (f->state &= ~(st))
|
|
1896 |
+#define NODE_SET_STATE(f, st) (f->state = ((f->state & ~(st)) | (st)))
|
|
1897 |
+#define NODE_HAS_STATE(f, st) (f->state & (st))
|
|
1898 |
+
|
|
1899 |
+#define NODE_CLE_FLAG(f, fl) (f->flag &= ~(fl))
|
|
1900 |
+#define NODE_SET_FLAG(f, fl) (f->flag = ((f->flag & ~(fl)) | (fl)))
|
|
1901 |
+#define NODE_HAS_FLAG(f, fl) (f->flag & (fl))
|
11099
|
1902 |
+
|
17812
|
1903 |
+typedef struct node node_t;
|
|
1904 |
+struct node
|
|
1905 |
+{
|
|
1906 |
+ file_obj_t fobj; /* Inherit from file_obj_t, must be the first. */
|
|
1907 |
+ GSource *source;
|
|
1908 |
+ gchar *basename;
|
|
1909 |
+ guint32 state;
|
|
1910 |
+ guint32 flag;
|
|
1911 |
+ GTimeVal atv; /* Timestamp for the first added sub. */
|
|
1912 |
+
|
|
1913 |
+ /* the parent and children of node */
|
|
1914 |
+ node_t *parent;
|
|
1915 |
+ GHashTable *children; /* children in basename */
|
|
1916 |
+
|
|
1917 |
+ /* List of subscriptions monitoring this fdata/path */
|
|
1918 |
+ GList *subs;
|
|
1919 |
+ GList *dir_subs;
|
11099
|
1920 |
+
|
17812
|
1921 |
+#ifdef GIO_COMPILATION
|
|
1922 |
+ GFile* gfile;
|
|
1923 |
+#endif
|
|
1924 |
+};
|
|
1925 |
+
|
|
1926 |
+#define FILE_OBJECT(f) ((file_obj_t *)(f))
|
|
1927 |
+#define NODE_NAME(f) (FILE_OBJECT(f)->fo_name)
|
|
1928 |
+#define NODE_PARENT(f) (((node_t *)f)->parent)
|
|
1929 |
+#define NODE_IS_ACTIVE(f) (f->dir_subs || f->subs)
|
|
1930 |
+#define NODE_IS_REQUIRED_BY_PARENT(f) (NODE_PARENT(f) && NODE_PARENT(f)->dir_subs)
|
11824
|
1931 |
+
|
17812
|
1932 |
+gboolean node_timeval_lt(const GTimeVal *val1, const GTimeVal *val2);
|
|
1933 |
+gboolean node_try_delete(node_t* node);
|
|
1934 |
+void node_traverse(node_t* node, void(*traverse_cb)(node_t*, gpointer), gpointer user_data);
|
|
1935 |
+node_t* node_find(node_t* node, const gchar* filename, gboolean create_on_missing);
|
|
1936 |
+gint node_lstat(node_t *f);
|
|
1937 |
+void node_create_children_snapshot(node_t *f, gint created_event, gboolean emit);
|
|
1938 |
+void node_adjust_deleted(node_t *f);
|
|
1939 |
+gboolean node_class_init();
|
|
1940 |
+
|
|
1941 |
+typedef struct node_event
|
11824
|
1942 |
+{
|
|
1943 |
+ int e;
|
|
1944 |
+ gpointer user_data;
|
17812
|
1945 |
+ gpointer pair_data;
|
|
1946 |
+ GTimeVal ctv; /* Created timestamp */
|
|
1947 |
+ GTimeVal rename_tv; /* Possible rename timestamp */
|
|
1948 |
+} node_event_t;
|
|
1949 |
+
|
|
1950 |
+node_event_t* node_event_new (int event, gpointer user_data);
|
|
1951 |
+void node_event_delete (node_event_t* ev);
|
11099
|
1952 |
+
|
17812
|
1953 |
+#endif /* _FEN_NODE_H_ */
|
|
1954 |
diff --git a/server/gam_channel.c b/server/gam_channel.c
|
|
1955 |
index 56c3ea7..6db1692 100644
|
|
1956 |
--- a/server/gam_channel.c
|
|
1957 |
+++ b/server/gam_channel.c
|
|
1958 |
@@ -7,6 +7,12 @@
|
|
1959 |
#include <sys/stat.h>
|
|
1960 |
#include <sys/un.h>
|
|
1961 |
#include <sys/uio.h>
|
|
1962 |
+#if defined(sun)
|
|
1963 |
+#include <string.h>
|
|
1964 |
+#endif
|
|
1965 |
+#if defined(HAVE_UCRED_H)
|
|
1966 |
+#include <ucred.h>
|
|
1967 |
+#endif defined(HAVE_UCRED_H)
|
|
1968 |
#include "gam_error.h"
|
|
1969 |
#include "gam_connection.h"
|
|
1970 |
#include "gam_channel.h"
|
|
1971 |
@@ -101,6 +107,10 @@ gam_client_conn_check_cred(GIOChannel * source, int fd,
|
|
1972 |
} cmsg;
|
|
1973 |
#endif
|
|
1974 |
|
|
1975 |
+#if defined(HAVE_GETPEERUCRED)
|
|
1976 |
+ ucred_t *creds;
|
|
1977 |
+#endif
|
11824
|
1978 |
+
|
17812
|
1979 |
s_uid = getuid();
|
|
1980 |
|
|
1981 |
#if defined(LOCAL_CREDS) && defined(HAVE_CMSGCRED)
|
|
1982 |
@@ -167,11 +177,25 @@ gam_client_conn_check_cred(GIOChannel * source, int fd,
|
|
1983 |
fd, cr_len, (int) sizeof(cr));
|
|
1984 |
goto failed;
|
|
1985 |
}
|
|
1986 |
+#elif defined(HAVE_GETPEERUCRED)
|
|
1987 |
+ if ((creds = (ucred_t *)malloc(ucred_size()))==(ucred_t *)NULL){
|
|
1988 |
+ GAM_DEBUG(DEBUG_INFO,"Malloc failed for ucreds");
|
|
1989 |
+ goto failed;
|
|
1990 |
+ }
|
11099
|
1991 |
+
|
17812
|
1992 |
+ if (getpeerucred(fd, &creds)!=0){
|
|
1993 |
+ GAM_DEBUG(DEBUG_INFO,"getpeerucred call failed");
|
|
1994 |
+ goto failed;
|
|
1995 |
+ }
|
|
1996 |
+ c_uid = ucred_getruid(creds);
|
|
1997 |
+ c_gid = ucred_getrgid(creds);
|
|
1998 |
+ c_pid = ucred_getpid(creds);
|
|
1999 |
+ ucred_free(creds);
|
|
2000 |
#elif defined(HAVE_CMSGCRED)
|
|
2001 |
c_pid = cmsg.cred.cmcred_pid;
|
|
2002 |
c_uid = cmsg.cred.cmcred_euid;
|
|
2003 |
c_gid = cmsg.cred.cmcred_groups[0];
|
|
2004 |
-#else /* !SO_PEERCRED && !HAVE_CMSGCRED */
|
|
2005 |
+#else /* !SO_PEERCRED && !HAVE_CMSGCRED && !HAVE_GETPEERUCRED */
|
|
2006 |
GAM_DEBUG(DEBUG_INFO,
|
|
2007 |
"Socket credentials not supported on this OS\n");
|
|
2008 |
goto failed;
|
|
2009 |
diff --git a/server/gam_fen.c b/server/gam_fen.c
|
|
2010 |
new file mode 100644
|
|
2011 |
index 0000000..21476e1
|
|
2012 |
--- /dev/null
|
|
2013 |
+++ b/server/gam_fen.c
|
11952
|
2014 |
@@ -0,0 +1,140 @@
|
11099
|
2015 |
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
2016 |
+/* vim:set expandtab ts=4 shiftwidth=4: */
|
11952
|
2017 |
+/*
|
|
2018 |
+ * Copyright (C) 2008 Sun Microsystems, Inc. All rights reserved.
|
|
2019 |
+ * Use is subject to license terms.
|
|
2020 |
+ *
|
|
2021 |
+ * This library is free software; you can redistribute it and/or
|
|
2022 |
+ * modify it under the terms of the GNU Lesser General Public
|
|
2023 |
+ * License as published by the Free Software Foundation; either
|
|
2024 |
+ * version 2 of the License, or (at your option) any later version.
|
|
2025 |
+ *
|
|
2026 |
+ * This library is distributed in the hope that it will be useful,
|
|
2027 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
2028 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
2029 |
+ * Lesser General Public License for more details.
|
|
2030 |
+ *
|
|
2031 |
+ * You should have received a copy of the GNU Lesser General
|
|
2032 |
+ * Public License along with this library; if not, write to the
|
|
2033 |
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
2034 |
+ * Boston, MA 02111-1307, USA.
|
|
2035 |
+ *
|
|
2036 |
+ * Authors: Lin Ma <[email protected]>
|
|
2037 |
+ */
|
11099
|
2038 |
+/*
|
|
2039 |
+ * Design:
|
|
2040 |
+ * A Solaris port has a resource limit of events (port_max_events) which
|
|
2041 |
+ * limits the number of objects (fds) that can be actively associated objects
|
|
2042 |
+ * whith the port. The default is (65536), but can be changed.
|
|
2043 |
+ *
|
|
2044 |
+ * project.max-port-ids identify the max number of ports
|
|
2045 |
+ * process.max-port-events identify the max objs of a port
|
|
2046 |
+ * process.max-file-descriptor identify the max fds of a process
|
|
2047 |
+ *
|
|
2048 |
+ * For a user server process, process.max-file-descriptor seems a bottleneck.
|
|
2049 |
+ * I will use a port list for monitor fds to avoid process.max-file-descriptor
|
|
2050 |
+ * is greater than process.max-port-events.
|
|
2051 |
+ */
|
|
2052 |
+#include "config.h"
|
|
2053 |
+#include "gam_error.h"
|
|
2054 |
+#include "gam_fen.h"
|
|
2055 |
+#include "gam_event.h"
|
|
2056 |
+#include "gam_server.h"
|
|
2057 |
+#include "gam_protocol.h"
|
|
2058 |
+#include <glib.h>
|
11824
|
2059 |
+#include "fen-helper.h"
|
11099
|
2060 |
+
|
|
2061 |
+/**
|
|
2062 |
+ * Initializes the FEN system. This must be called before
|
|
2063 |
+ * any other functions in this module.
|
|
2064 |
+ *
|
|
2065 |
+ * @returns TRUE if initialization succeeded, FALSE otherwise
|
|
2066 |
+ */
|
|
2067 |
+
|
|
2068 |
+gboolean
|
|
2069 |
+gam_fen_init (void)
|
|
2070 |
+{
|
11824
|
2071 |
+ if (!fen_init ())
|
|
2072 |
+ return FALSE;
|
11099
|
2073 |
+
|
11824
|
2074 |
+ gam_server_install_kernel_hooks (GAMIN_K_FEN,
|
|
2075 |
+ gam_fen_add_subscription,
|
|
2076 |
+ gam_fen_remove_subscription,
|
|
2077 |
+ gam_fen_remove_all_for,
|
|
2078 |
+ NULL, NULL);
|
11099
|
2079 |
+ return TRUE;
|
|
2080 |
+}
|
|
2081 |
+
|
|
2082 |
+/**
|
|
2083 |
+ * Adds a subscription to be monitored.
|
|
2084 |
+ *
|
|
2085 |
+ * @param sub a #GamSubscription to be polled
|
|
2086 |
+ * @returns TRUE if adding the subscription succeeded, FALSE otherwise
|
|
2087 |
+ */
|
|
2088 |
+
|
|
2089 |
+gboolean
|
|
2090 |
+gam_fen_add_subscription (GamSubscription *sub)
|
|
2091 |
+{
|
11824
|
2092 |
+ g_debug ("[ %s ] sub[0x%p]\n", __func__, sub);
|
11099
|
2093 |
+
|
11824
|
2094 |
+ gam_listener_add_subscription (gam_subscription_get_listener (sub), sub);
|
|
2095 |
+ fen_add (gam_subscription_get_path(sub),
|
|
2096 |
+ sub,
|
|
2097 |
+ gam_subscription_is_dir (sub));
|
|
2098 |
+ return TRUE;
|
11099
|
2099 |
+}
|
|
2100 |
+
|
|
2101 |
+/**
|
|
2102 |
+ * Removes a subscription which was being monitored.
|
|
2103 |
+ *
|
|
2104 |
+ * @param sub a #GamSubscription to remove
|
|
2105 |
+ * @returns TRUE if removing the subscription succeeded, FALSE otherwise
|
|
2106 |
+ */
|
|
2107 |
+
|
|
2108 |
+gboolean
|
|
2109 |
+gam_fen_remove_subscription (GamSubscription *sub)
|
|
2110 |
+{
|
11824
|
2111 |
+ g_debug ("[ %s ] sub[0x%p]\n", __func__, sub);
|
11099
|
2112 |
+
|
11824
|
2113 |
+ fen_remove (gam_subscription_get_path(sub),
|
|
2114 |
+ sub,
|
|
2115 |
+ gam_subscription_is_dir (sub));
|
11099
|
2116 |
+ /* free subscription */
|
11824
|
2117 |
+ gam_subscription_cancel(sub);
|
11099
|
2118 |
+ gam_subscription_free(sub);
|
|
2119 |
+ return TRUE;
|
|
2120 |
+}
|
|
2121 |
+
|
|
2122 |
+/**
|
|
2123 |
+ * Stop monitoring all subscriptions for a given listener.
|
|
2124 |
+ *
|
|
2125 |
+ * @param listener a #GamListener
|
|
2126 |
+ * @returns TRUE if removing the subscriptions succeeded, FALSE otherwise
|
|
2127 |
+ */
|
|
2128 |
+
|
|
2129 |
+gboolean
|
|
2130 |
+gam_fen_remove_all_for (GamListener *listener)
|
|
2131 |
+{
|
|
2132 |
+ GList *subs;
|
|
2133 |
+ GList *idx;
|
|
2134 |
+ gboolean success = TRUE;
|
|
2135 |
+
|
|
2136 |
+ subs = gam_listener_get_subscriptions (listener);
|
|
2137 |
+
|
|
2138 |
+ if (subs == NULL)
|
|
2139 |
+ return FALSE;
|
|
2140 |
+
|
|
2141 |
+ for (idx = subs; idx != NULL; idx = idx->next) {
|
|
2142 |
+ GamSubscription *sub = (GamSubscription *)idx->data;
|
|
2143 |
+ g_assert (sub);
|
|
2144 |
+ if (!gam_fen_remove_subscription (sub))
|
|
2145 |
+ success = FALSE;
|
|
2146 |
+ }
|
|
2147 |
+
|
|
2148 |
+ if (subs) {
|
|
2149 |
+ g_list_free (subs);
|
|
2150 |
+ return TRUE;
|
|
2151 |
+ } else {
|
|
2152 |
+ return FALSE;
|
|
2153 |
+ }
|
|
2154 |
+}
|
17812
|
2155 |
diff --git a/server/gam_fen.h b/server/gam_fen.h
|
|
2156 |
new file mode 100644
|
|
2157 |
index 0000000..47e952d
|
|
2158 |
--- /dev/null
|
|
2159 |
+++ b/server/gam_fen.h
|
|
2160 |
@@ -0,0 +1,40 @@
|
|
2161 |
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
2162 |
+/* vim:set expandtab ts=4 shiftwidth=4: */
|
|
2163 |
+/*
|
|
2164 |
+ * Copyright (C) 2008 Sun Microsystems, Inc. All rights reserved.
|
|
2165 |
+ * Use is subject to license terms.
|
|
2166 |
+ *
|
|
2167 |
+ * This library is free software; you can redistribute it and/or
|
|
2168 |
+ * modify it under the terms of the GNU Lesser General Public
|
|
2169 |
+ * License as published by the Free Software Foundation; either
|
|
2170 |
+ * version 2 of the License, or (at your option) any later version.
|
|
2171 |
+ *
|
|
2172 |
+ * This library is distributed in the hope that it will be useful,
|
|
2173 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
2174 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
2175 |
+ * Lesser General Public License for more details.
|
|
2176 |
+ *
|
|
2177 |
+ * You should have received a copy of the GNU Lesser General
|
|
2178 |
+ * Public License along with this library; if not, write to the
|
|
2179 |
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
2180 |
+ * Boston, MA 02111-1307, USA.
|
|
2181 |
+ *
|
|
2182 |
+ * Authors: Lin Ma <[email protected]>
|
|
2183 |
+ */
|
|
2184 |
+
|
|
2185 |
+#ifndef __GAM_FEN_H__
|
|
2186 |
+#define __GAM_FEN_H__
|
|
2187 |
+
|
|
2188 |
+#include <glib.h>
|
|
2189 |
+#include "gam_subscription.h"
|
|
2190 |
+
|
|
2191 |
+G_BEGIN_DECLS
|
|
2192 |
+
|
|
2193 |
+gboolean gam_fen_init (void);
|
|
2194 |
+gboolean gam_fen_add_subscription (GamSubscription *sub);
|
|
2195 |
+gboolean gam_fen_remove_subscription (GamSubscription *sub);
|
|
2196 |
+gboolean gam_fen_remove_all_for (GamListener *listener);
|
|
2197 |
+
|
|
2198 |
+G_END_DECLS
|
|
2199 |
+
|
|
2200 |
+#endif /* __GAM_FEN_H__ */
|
|
2201 |
diff --git a/server/gam_fs.c b/server/gam_fs.c
|
|
2202 |
index c8ca704..1d2f2c8 100644
|
|
2203 |
--- a/server/gam_fs.c
|
|
2204 |
+++ b/server/gam_fs.c
|
|
2205 |
@@ -7,9 +7,20 @@
|
|
2206 |
#include <string.h>
|
|
2207 |
#include <errno.h>
|
|
2208 |
#include <glib.h>
|
|
2209 |
+#ifdef HAVE_SYS_MNTTAB_H
|
|
2210 |
+#include <sys/mnttab.h>
|
|
2211 |
+#endif
|
|
2212 |
#include "gam_error.h"
|
|
2213 |
#include "gam_fs.h"
|
|
2214 |
|
|
2215 |
+#ifdef HAVE_SYS_MNTTAB_H
|
|
2216 |
+#define MTAB MNTTAB
|
|
2217 |
+#define MTABDEL "\t"
|
|
2218 |
+#else
|
|
2219 |
+#define MTAB "/etc/mtab"
|
|
2220 |
+#define MTABDEL "\t"
|
|
2221 |
+#endif
|
|
2222 |
+
|
|
2223 |
#define DEFAULT_POLL_TIMEOUT 0
|
|
2224 |
|
|
2225 |
typedef struct _gam_fs_properties {
|
|
2226 |
@@ -119,7 +130,7 @@ gam_fs_scan_mtab (void)
|
|
2227 |
gam_fs *fs = NULL;
|
|
2228 |
int i;
|
|
2229 |
|
|
2230 |
- g_file_get_contents ("/etc/mtab", &contents, &len, NULL);
|
|
2231 |
+ g_file_get_contents (MTAB, &contents, &len, NULL);
|
|
2232 |
if (contents == NULL)
|
|
2233 |
return;
|
|
2234 |
|
|
2235 |
@@ -133,7 +144,7 @@ gam_fs_scan_mtab (void)
|
|
2236 |
if (line[0] == '\0')
|
|
2237 |
continue;
|
|
2238 |
|
|
2239 |
- words = g_strsplit (line, " ", 0);
|
|
2240 |
+ words = g_strsplit (line, MTABDEL, 0);
|
|
2241 |
|
|
2242 |
if (words == NULL)
|
|
2243 |
continue;
|
|
2244 |
@@ -176,19 +187,25 @@ gam_fs_init (void)
|
|
2245 |
gam_fs_set ("ext2", GFS_MT_DEFAULT, 0);
|
|
2246 |
gam_fs_set ("reiser4", GFS_MT_DEFAULT, 0);
|
|
2247 |
gam_fs_set ("reiserfs", GFS_MT_DEFAULT, 0);
|
|
2248 |
+ gam_fs_set ("zfs", GFS_MT_DEFAULT, 0);
|
|
2249 |
+ gam_fs_set ("ufs", GFS_MT_DEFAULT, 0);
|
|
2250 |
gam_fs_set ("novfs", GFS_MT_POLL, 30);
|
|
2251 |
+#ifdef ENABLE_FEN
|
|
2252 |
+ gam_fs_set ("nfs", GFS_MT_DEFAULT, 0);
|
|
2253 |
+#else
|
|
2254 |
gam_fs_set ("nfs", GFS_MT_POLL, 5);
|
|
2255 |
- if (stat("/etc/mtab", &mtab_sbuf) != 0)
|
|
2256 |
+#endif
|
|
2257 |
+ if (stat(MTAB, &mtab_sbuf) != 0)
|
|
2258 |
{
|
|
2259 |
- GAM_DEBUG(DEBUG_INFO, "Could not stat /etc/mtab\n");
|
|
2260 |
+ GAM_DEBUG(DEBUG_INFO, "Could not stat %s\n",MTAB);
|
|
2261 |
}
|
|
2262 |
gam_fs_scan_mtab ();
|
|
2263 |
} else {
|
|
2264 |
struct stat sbuf;
|
|
2265 |
|
|
2266 |
- if (stat("/etc/mtab", &sbuf) != 0)
|
|
2267 |
+ if (stat(MTAB, &sbuf) != 0)
|
|
2268 |
{
|
|
2269 |
- GAM_DEBUG(DEBUG_INFO, "Could not stat /etc/mtab\n");
|
|
2270 |
+ GAM_DEBUG(DEBUG_INFO, "Could not stat %s\n",MTAB);
|
|
2271 |
}
|
|
2272 |
|
|
2273 |
/* /etc/mtab has changed */
|
|
2274 |
diff --git a/server/gam_fs.h b/server/gam_fs.h
|
|
2275 |
index bc2d538..94e70fd 100644
|
|
2276 |
--- a/server/gam_fs.h
|
|
2277 |
+++ b/server/gam_fs.h
|
|
2278 |
@@ -8,6 +8,7 @@ typedef enum {
|
|
2279 |
#if !defined(ENABLE_DNOTIFY) && \
|
|
2280 |
!defined(ENABLE_INOTIFY) && \
|
|
2281 |
!defined(ENABLE_KQUEUE) && \
|
|
2282 |
+ !defined(ENABLE_FEN) && \
|
|
2283 |
!defined(ENABLE_HURD_MACH_NOTIFY)
|
|
2284 |
GFS_MT_DEFAULT = GFS_MT_POLL,
|
|
2285 |
#else
|
|
2286 |
diff --git a/server/gam_server.c b/server/gam_server.c
|
|
2287 |
index f92a691..e5da29f 100644
|
|
2288 |
--- a/server/gam_server.c
|
|
2289 |
+++ b/server/gam_server.c
|
|
2290 |
@@ -45,6 +45,9 @@
|
|
2291 |
#ifdef ENABLE_HURD_MACH_NOTIFY
|
|
2292 |
#include "gam_hurd_mach_notify.h"
|
|
2293 |
#endif
|
|
2294 |
+#ifdef ENABLE_FEN
|
|
2295 |
+#include "gam_fen.h"
|
|
2296 |
+#endif
|
|
2297 |
#include "gam_excludes.h"
|
|
2298 |
#include "gam_fs.h"
|
|
2299 |
#include "gam_conf.h"
|
|
2300 |
@@ -162,6 +165,12 @@ gam_init_subscriptions(void)
|
|
2301 |
return(TRUE);
|
|
2302 |
}
|
|
2303 |
#endif
|
|
2304 |
+#ifdef ENABLE_FEN
|
|
2305 |
+ if (gam_fen_init()) {
|
|
2306 |
+ GAM_DEBUG(DEBUG_INFO, "Using fen as backend\n");
|
|
2307 |
+ return(TRUE);
|
|
2308 |
+ }
|
|
2309 |
+#endif
|
|
2310 |
}
|
|
2311 |
|
|
2312 |
if (gam_poll_basic_init()) {
|
|
2313 |
@@ -627,6 +636,10 @@ main(int argc, const char *argv[])
|
|
2314 |
signal(SIGQUIT, gam_exit);
|
|
2315 |
signal(SIGTERM, gam_exit);
|
|
2316 |
signal(SIGPIPE, SIG_IGN);
|
|
2317 |
+#ifdef ENABLE_FEN
|
|
2318 |
+ signal(SIGUSR1, SIG_IGN);
|
|
2319 |
+ signal(SIGUSR2, SIG_IGN);
|
|
2320 |
+#endif
|
|
2321 |
|
|
2322 |
if (!gam_init_subscriptions()) {
|
|
2323 |
GAM_DEBUG(DEBUG_INFO, "Could not initialize the subscription system.\n");
|
|
2324 |
diff --git a/server/gam_server.h b/server/gam_server.h
|
|
2325 |
index bc99e09..313dd84 100644
|
|
2326 |
--- a/server/gam_server.h
|
|
2327 |
+++ b/server/gam_server.h
|
|
2328 |
@@ -16,7 +16,8 @@ typedef enum {
|
|
2329 |
GAMIN_K_INOTIFY = 2,
|
|
2330 |
GAMIN_K_KQUEUE = 3,
|
|
2331 |
GAMIN_K_MACH = 4,
|
|
2332 |
- GAMIN_K_INOTIFY2 = 5
|
|
2333 |
+ GAMIN_K_INOTIFY2 = 5,
|
|
2334 |
+ GAMIN_K_FEN = 6
|
|
2335 |
} GamKernelHandler;
|
|
2336 |
|
|
2337 |
typedef enum {
|
|
2338 |
diff --git a/tests/testing.c b/tests/testing.c
|
|
2339 |
index 9926c0a..4c08740 100644
|
|
2340 |
--- a/tests/testing.c
|
|
2341 |
+++ b/tests/testing.c
|
|
2342 |
@@ -1,3 +1,4 @@
|
|
2343 |
+#include "config.h"
|
|
2344 |
#include <stdio.h>
|
|
2345 |
#include <stdlib.h>
|
|
2346 |
#include <unistd.h>
|
|
2347 |
@@ -31,6 +32,11 @@ static struct testState {
|
|
2348 |
|
|
2349 |
#define IS_BLANK(p) ((*(p) == ' ') || (*(p) == '\t') || \
|
|
2350 |
(*(p) == '\n') || (*(p) == '\r'))
|
|
2351 |
+#ifdef ENABLE_FEN
|
|
2352 |
+#define KILLCMD "pkill"
|
|
2353 |
+#else
|
|
2354 |
+#define KILLCMD "killall"
|
|
2355 |
+#endif
|
|
2356 |
|
|
2357 |
static int
|
|
2358 |
scanCommand(char *line, char **command, char **arg, char **arg2)
|
|
2359 |
@@ -268,7 +274,7 @@ processCommand(char *line, int no)
|
|
2360 |
* okay, it's heavy but that's the simplest way since we do not have
|
|
2361 |
* the pid(s) of the servers running.
|
|
2362 |
*/
|
|
2363 |
- ret = system("killall gam_server");
|
|
2364 |
+ ret = system(KILLCMD" gam_server");
|
|
2365 |
if (ret < 0) {
|
|
2366 |
fprintf(stderr, "kill line %d: failed to killall gam_server\n",
|
|
2367 |
no);
|