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