Re: [gamin] Re: [Patch 0.0.10] Cleanup ENABLE_DNOTIFY and HAVE_LINUX and fix build error [u]



On Fri, 2004-09-24 at 01:30 +0200, Martin Schlemmer wrote:
> On Thu, 2004-09-23 at 19:17 -0400, Daniel Veillard wrote:
> 
> > > to do it. So if you are interested in working on it that would be
> > > wicked! I can answer any questions you have about inotify.
> > 
> >   inotify relies on kernel support, this can be checked at runtime
> > I think one of the best thing to do to get more inotify testing is to 
> > get rid of the inotify configure option, always compile it in and make
> > its init routine check at runtime, if not present then use dnotify.
> > That way it's only a kernel option, and users/testers are quite more
> > familiar to installing and booting a new kernel than replacing a 
> > component of their infrastructure after having recompiled it with a different
> > option. 
> > 
> 
> Will work for me - then I can drop some magic I have to do.  Possible
> problem though, is that you need inotify.h.  One solution is to check
> if we can include it, but seeing that many out there will not have
> it in /usr/include/linux, and using current kernel sources have sticky
> issues, I do not know if that is such a good idea.  The other possible
> solution is to ship our own, and use that if it is not
> in /usr/include ... ?  Then you can enable it for the same checks as
> dnotify.  
> 

How about attached patch?


-- 
Martin Schlemmer
Gentoo Linux Developer, Desktop/System Team Developer
Cape Town, South Africa

diff -x CVS -urpN gamin/configure.in gamin-inotify/configure.in
--- gamin/configure.in	2004-09-24 12:38:48.127978176 +0200
+++ gamin-inotify/configure.in	2004-09-24 12:51:20.160651832 +0200
@@ -167,39 +167,50 @@ esac],[os=${target_os}])
 dnl check what OS we're on
 AM_CONDITIONAL(HAVE_LINUX, test x$os = xlinux-gnu)
 
+# We use polling no matter what.
+AC_DEFINE(ENABLE_POLLING,1,[Use polling as backend])
+backends="polling"
+
 if test x$os = xlinux-gnu; then
 	AC_DEFINE([HAVE_LINUX],[],[Whether we are using linux or not])
-	
-	# We enable dnotify no matter what.  If the user enables
-	# inotify, he will still have dnotify to fall back on ...
+fi	
+
+if test x$os = xlinux-gnu; then
+	AC_ARG_ENABLE(dnotify,
+	[  --disable-dnotify Disable the DNotify backend],
+	[case "${enableval}" in
+	  yes) dnotify=true ;;
+	  no)  dnotify=false ;;
+	  *) AC_MSG_ERROR(bad value ${enableval} for --disable-dnotify) ;;
+	esac],[dnotify=true])
+fi
+
+dnl check if dnotify backend is enabled
+AM_CONDITIONAL(ENABLE_DNOTIFY, test x$dnotify = xtrue)
+
+if test x$dnotify = xtrue; then
 	AC_DEFINE(ENABLE_DNOTIFY,1,[Use dnotify as backend])
-	backend="dnotify"
-else
-	backend="polling"
-fi
-
-# We do not care about inotify for now - if the user enables
-# it, we still want to build dnotify support ...
-AM_CONDITIONAL(ENABLE_DNOTIFY, test x$backend = xdnotify)
-
-AC_ARG_ENABLE(inotify,
-[  --enable-inotify Uses inotify as backend],
-[case "${enableval}" in
-  yes) backend="inotify" ;;
-  no) ;;
-  *) AC_MSG_ERROR(bad value ${enableval} for --enable-inotify) ;;
-esac])
-
-if test x$backend = xinotify; then
-    AC_DEFINE(ENABLE_INOTIFY,1,[Use inotify as backend])
-else
-    # If all else fails, use polling
-    if test x$backend = xpolling; then
-        AC_DEFINE(ENABLE_POLLING,1,[Use polling as backend])
-    fi
+	backends="${backends}, dnotify"
 fi
 
-AM_CONDITIONAL(ENABLE_INOTIFY, test x$backend = xinotify)
+if test x$os = xlinux-gnu; then
+	AC_ARG_ENABLE(inotify,
+	[  --disable-inotify Disable the INotify backend],
+	[case "${enableval}" in
+	  yes) inotify=true ;;
+	  no) inotify=false;;
+	  *) AC_MSG_ERROR(bad value ${enableval} for --disable-inotify) ;;
+	esac],[inotify=true])
+fi
+
+dnl check if inotify backend is enabled
+AM_CONDITIONAL(ENABLE_INOTIFY, test x$inotify = xtrue)
+
+if test x$inotify = xtrue; then
+	AC_CHECK_HEADERS(linux/inotify.h)
+	AC_DEFINE(ENABLE_INOTIFY,1,[Use inotify as backend])
+	backends="${backends}, inotify"
+fi
 
 dnl check for flavours of varargs macros (test from GLib)
 AC_MSG_CHECKING(for ISO C99 varargs macros in C)
@@ -326,6 +337,6 @@ gamin-$VERSION:
         source code location:     ${srcdir}
         compiler:                 ${CC}
                                                                                 
-	backend:                  ${backend}
+	backends:                 ${backends}
 	build documentation:      ${build_docs}
 "
diff -x CVS -urpN gamin/server/gam_inotify.c gamin-inotify/server/gam_inotify.c
--- gamin/server/gam_inotify.c	2004-09-24 12:38:48.176970728 +0200
+++ gamin-inotify/server/gam_inotify.c	2004-09-24 12:38:07.755115784 +0200
@@ -27,7 +27,11 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <glib.h>
-#include "/usr/src/linux/include/linux/inotify.h"
+#ifdef HAVE_LINUX_INOTIFY_H
+#include <linux/inotify.h>
+#else
+#include "local_inotify.h"
+#endif
 #include "gam_error.h"
 #include "gam_inotify.h"
 #include "gam_tree.h"
diff -x CVS -urpN gamin/server/local_inotify.h gamin-inotify/server/local_inotify.h
--- gamin/server/local_inotify.h	1970-01-01 02:00:00.000000000 +0200
+++ gamin-inotify/server/local_inotify.h	2004-09-24 12:38:07.755115784 +0200
@@ -0,0 +1,100 @@
+/*
+ * Inode based directory notification for Linux
+ *
+ * Copyright (C) 2004 John McCutchan
+ *
+ * Signed-off-by: John McCutchan ttb tentacle dhs org
+ */
+
+#ifndef _LINUX_INOTIFY_H
+#define _LINUX_INOTIFY_H
+
+#include <linux/limits.h>
+
+/* this size could limit things, since technically we could need PATH_MAX */
+#define INOTIFY_FILENAME_MAX	256
+
+/*
+ * struct inotify_event - structure read from the inotify device for each event
+ *
+ * When you are watching a directory, you will receive the filename for events
+ * such as IN_CREATE, IN_DELETE, IN_OPEN, IN_CLOSE, ...
+ *
+ * Note: When reading from the device you must provide a buffer that is a
+ * multiple of sizeof(struct inotify_event)
+ */
+struct inotify_event {
+	int wd;
+	int mask;
+	char filename[INOTIFY_FILENAME_MAX];
+};
+
+/* the following are legal, implemented events */
+#define IN_ACCESS	0x00000001	/* File was accessed */
+#define IN_MODIFY	0x00000002	/* File was modified */
+#define IN_CREATE	0x00000004	/* File was created */
+#define IN_DELETE	0x00000008	/* File was deleted */
+#define IN_RENAME	0x00000010	/* File was renamed */
+#define IN_UNMOUNT	0x00000080	/* Backing filesystem was unmounted */
+#define IN_CLOSE	0x00000100	/* File was closed */
+#define IN_OPEN		0x00000200	/* File was opened */
+#define IN_MOVEDFROM	0x00000400	/* File was moved from X */
+#define IN_MOVEDTO	0x00000800	/* File was moved to Y */
+#define IN_Q_OVERFLOW	0x00001000	/* The event queued overflowed */
+
+/* the following are legal, but not yet implemented, events */
+#define IN_ATTRIB	0x00000020	/* File changed attributes */
+#define IN_MOVE		0x00000040	/* File was moved */
+
+/* special flags */
+#define IN_IGNORED	0x00000400	/* File was ignored */
+#define IN_ALL_EVENTS	0xffffffff	/* All the events */
+
+/*
+ * struct inotify_watch_request - represents a watch request
+ *
+ * Pass to the inotify device via the INOTIFY_WATCH ioctl
+ */
+struct inotify_watch_request {
+	char *dirname;		/* directory name */
+	unsigned long mask;	/* event mask */
+};
+
+#define INOTIFY_IOCTL_MAGIC	'Q'
+#define INOTIFY_IOCTL_MAXNR	4
+
+#define INOTIFY_WATCH  		_IOR(INOTIFY_IOCTL_MAGIC, 1, struct inotify_watch_request)
+#define INOTIFY_IGNORE 		_IOR(INOTIFY_IOCTL_MAGIC, 2, int)
+#define INOTIFY_STATS		_IOR(INOTIFY_IOCTL_MAGIC, 3, int)
+#define INOTIFY_SETDEBUG	_IOR(INOTIFY_IOCTL_MAGIC, 4, int)
+
+#define INOTIFY_DEBUG_NONE	0x00000000
+#define INOTIFY_DEBUG_ALLOC	0x00000001
+#define INOTIFY_DEBUG_EVENTS	0x00000002
+#define INOTIFY_DEBUG_INODE	0x00000004
+#define INOTIFY_DEBUG_ERRORS	0x00000008
+#define INOTIFY_DEBUG_FILEN	0x00000010
+#define INOTIFY_DEBUG_ALL	0xffffffff
+
+#ifdef __KERNEL__
+
+#include <linux/dcache.h>
+#include <linux/fs.h>
+
+/* Adds events to all watchers on inode that are interested in mask */
+void inotify_inode_queue_event (struct inode *inode, unsigned long mask,
+		const char *filename);
+
+/* Same as above but uses dentry's inode */
+void inotify_dentry_parent_queue_event (struct dentry *dentry,
+		unsigned long mask, const char *filename);
+
+/* This will remove all watchers from all inodes on the superblock */
+void inotify_super_block_umount (struct super_block *sb);
+
+/* Call this when an inode is dead, and inotify should ignore it */
+void inotify_inode_is_dead (struct inode *inode);
+
+#endif	/* __KERNEL __ */
+
+#endif	/* _LINUX_INOTIFY_H */

Attachment: signature.asc
Description: This is a digitally signed message part



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]