[gamin] some portability stuff
- From: Michael Banck <mbanck debian org>
- To: gamin-list gnome org
- Subject: [gamin] some portability stuff
- Date: Sat, 18 Sep 2004 15:12:50 +0200
Hello,
While trying to build gamin on GNU/Hurd, I noticed a couple of minor
problems:
1. gam_dnotify.c always gets compiled and results in build errors if not
building on Linux.
The best thing for this would probably be a configure test, but I could
not figure out how to do really do this. So I suggest to define
ENABLE_DNOTIFY (similar to ENABLE_INOTIFY) (as well as ENABLE_POLLING)
and only conditionally compile gam_dnotify.c in Makefile.am, just like
with gam_inotify.c
2. in gam_poll.c, some calls to st_mtim.tv_nsec are outside of #ifdef
linux.
As this does not appear to be Linux-specific I suggest to add a
configure test (from coreutils/make) for the st_mtim.tv_nsec struct
member. Along this, the second call to this struct should be moved
inside the #ifdef.
I have attached a patch for these suggestions. The actual naming of
things might be not to your taste.
Another problem I have not yet tackled is the unconditional use of
PATH_MAX in fam.h and gam_poll.c. POSIX only says PATH_MAX should define
the maximum path if the system actually has a limit. The GNU project
does not impose arbitrary system limit. This means PATH_MAX is not
defined on the GNU system, resulting in a build failure.
The clean way would be to allocate memory dynamically for char *filename
and char *real, as filenames and paths seem to be a core business of
gamin (other projects just #define PATH_MAX to something arbitrary if it
is not defined). I do not know whether my C is good enough to produce a
proper patch for this, so I would like to know what you think about this
issue.
thanks,
Michael
Sat Sep 18 14:57:33 CEST 2004 Michael Banck <mbanck debian org>
* configure.in (AC_STRUCT_ST_MTIM_NSEC): New macro.
(ENABLE_DNOTIFY): New define.
(ENABLE_POLLING): Likewise.
(AM_CONDITIONAL(ENABLE_DNOTIFY)): New automake conditional.
* acinclude.m4: New file, including AC_STRUCT_ST_MTIM_NSEC
macro.
* config.h.in: Regenerated.
* server/Makefile.am (gam_server_SOURCES): Only add
gam_dnotify.c and gam_dnotify.h if ENABLE_DNOTIFY is set.
* server/gam_poll.c (GaminEventType) [linux]: Removed
conditional and ...
(GaminEventType) [ST_MTIM_NSEC]: ... replaced with this.
(GaminEventType): Move all calls to st_mtim.tv_sec and
st_mtim.tv_nsec into ST_MTIM_NSEC conditional.
diff -Nuar gamin-0.0.9/acinclude.m4 gamin-0.0.9.new/acinclude.m4
--- gamin-0.0.9/acinclude.m4 1970-01-01 01:00:00.000000000 +0100
+++ gamin-0.0.9.new/acinclude.m4 2004-09-16 01:46:45.000000000 +0200
@@ -0,0 +1,27 @@
+dnl ---------------------------------------------------------------------------
+dnl From Paul Eggert <eggert twinsun com>
+
+AC_DEFUN(AC_STRUCT_ST_MTIM_NSEC,
+ [AC_CACHE_CHECK([for nanoseconds field of struct stat.st_mtim],
+ ac_cv_struct_st_mtim_nsec,
+ [ac_save_CPPFLAGS="$CPPFLAGS"
+ ac_cv_struct_st_mtim_nsec=no
+ # tv_nsec -- the usual case
+ # _tv_nsec -- Solaris 2.6, if
+ # (defined _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED == 1
+ # && !defined __EXTENSIONS__)
+ # st__tim.tv_nsec -- UnixWare 2.1.2
+ for ac_val in tv_nsec _tv_nsec st__tim.tv_nsec; do
+ CPPFLAGS="$ac_save_CPPFLAGS -DST_MTIM_NSEC=$ac_val"
+ AC_TRY_COMPILE([#include <sys/types.h>
+#include <sys/stat.h>], [struct stat s; s.st_mtim.ST_MTIM_NSEC;],
+ [ac_cv_struct_st_mtim_nsec=$ac_val; break])
+ done
+ CPPFLAGS="$ac_save_CPPFLAGS"])
+
+ if test $ac_cv_struct_st_mtim_nsec != no; then
+ AC_DEFINE_UNQUOTED(ST_MTIM_NSEC, $ac_cv_struct_st_mtim_nsec, [Define if 'struct stat' contains a nanoseconds field])
+ fi
+ ]
+)
+
diff -Nuar gamin-0.0.9/config.h.in gamin-0.0.9.new/config.h.in
--- gamin-0.0.9/config.h.in 2004-09-01 17:31:19.000000000 +0200
+++ gamin-0.0.9.new/config.h.in 2004-09-16 03:02:29.000000000 +0200
@@ -1,8 +1,14 @@
/* config.h.in. Generated from configure.in by autoheader. */
+/* Use dnotify as backend */
+#undef ENABLE_DNOTIFY
+
/* Use inotify as backend */
#undef ENABLE_INOTIFY
+/* Use polling as backend */
+#undef ENABLE_POLLING
+
/* Enable debugging messages */
#undef GAMIN_DEBUG
@@ -81,5 +87,8 @@
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
+/* Define if 'struct stat' contains a nanoseconds field */
+#undef ST_MTIM_NSEC
+
/* Version number of package */
#undef VERSION
diff -Nuar gamin-0.0.9/configure.in gamin-0.0.9.new/configure.in
--- gamin-0.0.9/configure.in 2004-09-01 17:22:46.000000000 +0200
+++ gamin-0.0.9.new/configure.in 2004-09-16 03:01:51.000000000 +0200
@@ -76,6 +76,7 @@
AM_CONDITIONAL(ENABLE_GTK_DOC, test x$enable_gtk_doc = xyes)
AC_CHECK_FUNCS(usleep setsid getlogin_r)
+AC_STRUCT_ST_MTIM_NSEC
dnl
dnl Start of pkg-config checks
@@ -183,9 +184,17 @@
if test x$backend = xinotify; then
AC_DEFINE(ENABLE_INOTIFY,1,[Use inotify as backend])
+else
+ if test x$backend = xdnotify; then
+ AC_DEFINE(ENABLE_DNOTIFY,1,[Use dnotify as backend])
+ else if test x$backend = xpolling; then
+ AC_DEFINE(ENABLE_POLLING,1,[Use polling as backend])
+ fi
+ fi
fi
AM_CONDITIONAL(ENABLE_INOTIFY, test x$backend = xinotify)
+AM_CONDITIONAL(ENABLE_DNOTIFY, test x$backend = xdnotify)
dnl check for flavours of varargs macros (test from GLib)
AC_MSG_CHECKING(for ISO C99 varargs macros in C)
diff -Nuar gamin-0.0.9/server/Makefile.am gamin-0.0.9.new/server/Makefile.am
--- gamin-0.0.9/server/Makefile.am 2004-09-01 12:37:36.000000000 +0200
+++ gamin-0.0.9.new/server/Makefile.am 2004-09-16 03:15:16.000000000 +0200
@@ -28,8 +28,6 @@
gam_tree.h \
gam_poll.c \
gam_poll.h \
- gam_dnotify.c \
- gam_dnotify.h \
gam_channel.c \
gam_channel.h \
gam_connection.c \
@@ -41,6 +39,10 @@
gam_server_SOURCES += gam_inotify.c gam_inotify.h
endif
+if ENABLE_DNOTIFY
+gam_server_SOURCES += gam_dnotify.c gam_dnotify.h
+endif
+
gam_server_LDFLAGS =
gam_server_DEPENDENCIES = $(DEPS)
gam_server_LDADD= $(top_builddir)/lib/libgamin_shared.a $(LDADDS) $(LIBGAMIN_LIBS)
diff -Nuar gamin-0.0.9/server/gam_poll.c gamin-0.0.9.new/server/gam_poll.c
--- gamin-0.0.9/server/gam_poll.c 2004-09-01 15:37:31.000000000 +0200
+++ gamin-0.0.9.new/server/gam_poll.c 2004-09-16 02:25:58.000000000 +0200
@@ -253,24 +253,26 @@
/* created */
data->flags &= ~MON_MISSING;
event = GAMIN_EVENT_CREATED;
-#ifdef linux
+#ifdef ST_MTIM_NSEC
} else if ((data->sbuf.st_mtim.tv_sec != sbuf.st_mtim.tv_sec) ||
(data->sbuf.st_mtim.tv_nsec != sbuf.st_mtim.tv_nsec) ||
(data->sbuf.st_size != sbuf.st_size) ||
(data->sbuf.st_ctim.tv_sec != sbuf.st_ctim.tv_sec) ||
(data->sbuf.st_ctim.tv_nsec != sbuf.st_ctim.tv_nsec)) {
event = GAMIN_EVENT_CHANGED;
+ } else {
+ gam_debug(DEBUG_INFO, "Poll: poll_file %s unchanged\n", path);
+ gam_debug(DEBUG_INFO, "%d %d : %d %d\n", data->sbuf.st_mtim.tv_sec,
+ data->sbuf.st_mtim.tv_nsec, sbuf.st_mtim.tv_sec,
+ sbuf.st_mtim.tv_nsec);
#else
} else if ((data->sbuf.st_mtime != sbuf.st_mtime) ||
(data->sbuf.st_size != sbuf.st_size) ||
(data->sbuf.st_ctime != sbuf.st_ctime)) {
event = GAMIN_EVENT_CHANGED;
+ gam_debug(DEBUG_INFO, "%d : %d\n", data->sbuf.st_mtime,
+ sbuf.st_mtime);
#endif
- } else {
- gam_debug(DEBUG_INFO, "Poll: poll_file %s unchanged\n", path);
- gam_debug(DEBUG_INFO, "%d %d : %d %d\n", data->sbuf.st_mtim.tv_sec,
- data->sbuf.st_mtim.tv_nsec, sbuf.st_mtim.tv_sec,
- sbuf.st_mtim.tv_nsec);
}
data->sbuf = sbuf;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]