following some valuable observations by carlos, take two.

this needs to be wildly tested, primarily on non-linux platforms. if 
you don't have any non-linux desktop, find someone who does, and

 ____ _____  _    ____ _____   _____ _____ ____ _____ ___ _   _  ____ _ 
/ ___|_   _|/ \  |  _ \_   _| |_   _| ____/ ___|_   _|_ _| \ | |/ ___| |
\___ \ | | / _ \ | |_) || |     | | |  _| \___ \ | |  | ||  \| | |  _| |
 ___) || |/ ___ \|  _ < | |     | | | |___ ___) || |  | || |\  | |_| |_|
|____/ |_/_/   \_\_| \_\|_|     |_| |_____|____/ |_| |___|_| \_|\____(_)


>From a46370222e85b833f190affefafede506070e75e Mon Sep 17 00:00:00 2001
From: Tamas TEVESZ <[email protected]>
Date: Thu, 18 Mar 2010 19:18:18 +0100
Subject: [PATCH] Make inotify optional

This time keeping the ability to fall back to the old polling method.
---
 WINGs/userdefaults.c |   24 ++++++++++++++++++++++++
 configure.ac         |    4 +++-
 src/WindowMaker.h    |    3 +++
 src/defaults.c       |    6 +++++-
 src/defaults.h       |    2 +-
 src/event.c          |   20 ++++++++++++++------
 src/main.c           |   21 ++++++++++++++++++---
 src/shutdown.c       |    6 ++++++
 src/startup.c        |   39 +++++++++++++++++++++++++++++++++++++++
 src/wconfig.h.in     |    5 +++++
 10 files changed, 118 insertions(+), 12 deletions(-)

diff --git a/WINGs/userdefaults.c b/WINGs/userdefaults.c
index 742b614..7f2c7ab 100644
--- a/WINGs/userdefaults.c
+++ b/WINGs/userdefaults.c
@@ -39,6 +39,11 @@ static void synchronizeUserDefaults(void *foo);
 extern char *WMGetApplicationName();
 
 #define DEFAULTS_DIR "/Defaults"
+#ifndef HAVE_INOTIFY
+/* Check defaults database for changes every this many milliseconds */
+/* XXX: this is shared with src/ stuff, put it in some common header */
+#define UD_SYNC_INTERVAL       2000
+#endif
 
 char *wusergnusteppath()
 {
@@ -117,6 +122,19 @@ static void synchronizeUserDefaults(void *foo)
        }
 }
 
+#ifndef HAVE_INOTIFY
+static void addSynchronizeTimerHandler(void)
+{
+       static Bool initialized = False;
+
+       if (!initialized) {
+               WMAddPersistentTimerHandler(UD_SYNC_INTERVAL,
+                   synchronizeUserDefaults, NULL);
+               initialized = True;
+       }
+}
+#endif
+
 void WMEnableUDPeriodicSynchronization(WMUserDefaults * database, Bool enable)
 {
        database->dontSync = !enable;
@@ -293,6 +311,9 @@ WMUserDefaults *WMGetStandardUserDefaults(void)
                defaults->next = sharedUserDefaults;
        sharedUserDefaults = defaults;
 
+#ifndef HAVE_INOTIFY
+       addSynchronizeTimerHandler();
+#endif
        registerSaveOnExit();
 
        return defaults;
@@ -366,6 +387,9 @@ WMUserDefaults *WMGetDefaultsFromPath(char *path)
                defaults->next = sharedUserDefaults;
        sharedUserDefaults = defaults;
 
+#ifndef HAVE_INOTIFY
+       addSynchronizeTimerHandler();
+#endif
        registerSaveOnExit();
 
        return defaults;
diff --git a/configure.ac b/configure.ac
index 7992179..a4be3a6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -128,7 +128,9 @@ if test "x$HAVEDL" = xyes; then
     AC_CHECK_HEADERS(dlfcn.h)
 fi
 
-
+dnl Check for inotify
+dnl =================
+AC_CHECK_HEADERS(sys/inotify.h, AC_DEFINE(HAVE_INOTIFY, 1, Check for inotify))
 
 dnl Check CPP
 dnl =========
diff --git a/src/WindowMaker.h b/src/WindowMaker.h
index cad1739..1a5b323 100644
--- a/src/WindowMaker.h
+++ b/src/WindowMaker.h
@@ -425,6 +425,9 @@ typedef struct WPreferences {
         unsigned int noautolaunch:1;   /* don't autolaunch apps */
         unsigned int norestore:1;      /* don't restore session */
         unsigned int create_stdcmap:1; /* create std colormap */
+#ifndef HAVE_INOTIFY
+       unsigned int nopolling:1;      /* don't poll the defaults database for 
changes */
+#endif
         unsigned int restarting:2;
     } flags;                          /* internal flags */
 } WPreferences;
diff --git a/src/defaults.c b/src/defaults.c
index 6e588ad..4acf51a 100644
--- a/src/defaults.c
+++ b/src/defaults.c
@@ -897,7 +897,7 @@ void wReadStaticDefaults(WMPropList * dict)
        }
 }
 
-void wDefaultsCheckDomains(void)
+void wDefaultsCheckDomains(void* arg)
 {
        WScreen *scr;
        struct stat stbuf;
@@ -1016,6 +1016,10 @@ void wDefaultsCheckDomains(void)
                }
                WDRootMenu->timestamp = stbuf.st_mtime;
        }
+#ifndef HAVE_INOTIFY
+       if (!arg)
+               WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, 
wDefaultsCheckDomains, arg);
+#endif
 }
 
 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
diff --git a/src/defaults.h b/src/defaults.h
index b557846..b61fe5d 100644
--- a/src/defaults.h
+++ b/src/defaults.h
@@ -46,7 +46,7 @@ void wDefaultUpdateIcons(WScreen *scr);
 
 void wReadStaticDefaults(WMPropList *dict);
 
-void wDefaultsCheckDomains(void);
+void wDefaultsCheckDomains(void *arg);
 
 void wSaveDefaults(WScreen *scr);
 
diff --git a/src/event.c b/src/event.c
index d29cafc..633f58e 100644
--- a/src/event.c
+++ b/src/event.c
@@ -20,9 +20,12 @@
  *  USA.
  */
 
-#include <sys/inotify.h>
 #include "wconfig.h"
 
+#ifdef HAVE_INOTIFY
+#include <sys/inotify.h>
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -198,7 +201,7 @@ void DispatchEvent(XEvent * event)
                Restart(NULL, True);
        } else if (WCHECK_STATE(WSTATE_NEED_REREAD)) {
                WCHANGE_STATE(WSTATE_NORMAL);
-               wDefaultsCheckDomains();
+               wDefaultsCheckDomains(NULL);
        }
 
        /* for the case that all that is wanted to be dispatched is
@@ -282,6 +285,7 @@ void DispatchEvent(XEvent * event)
        }
 }
 
+#ifdef HAVE_INOTIFY
 /*
  *----------------------------------------------------------------------
  * inotifyHandleEvents-
@@ -299,7 +303,7 @@ void DispatchEvent(XEvent * event)
 #define BUFF_SIZE ((sizeof(struct inotify_event) + 64)*5)
 void inotifyHandleEvents(int fd, int wd)
 {
-       extern void wDefaultsCheckDomains(void);
+       extern void wDefaultsCheckDomains(void *);
        ssize_t eventQLength, i = 0;
        char buff[BUFF_SIZE] = { 0 };
        /* Check config only once per read of the event queue */
@@ -335,13 +339,14 @@ void inotifyHandleEvents(int fd, int wd)
                }
                if ((pevent->mask & IN_MODIFY) && oneShotFlag == 0) {
                        fprintf(stdout, "wmaker: reading config files in 
defaults database.\n");
-                       wDefaultsCheckDomains();
+                       wDefaultsCheckDomains(NULL);
                }
 
                /* move to next event in the buffer */
                i += sizeof(struct inotify_event) + pevent->len;
        }
 }
+#endif /* HAVE_INOTIFY */
 
 /*
  *----------------------------------------------------------------------
@@ -359,6 +364,7 @@ void inotifyHandleEvents(int fd, int wd)
 void EventLoop(void)
 {
        XEvent event;
+#ifdef HAVE_INOTIFY
        extern int inotifyFD;
        extern int inotifyWD;
        struct timeval time;
@@ -367,12 +373,13 @@ void EventLoop(void)
 
        if (inotifyFD < 0 || inotifyWD < 0)
                retVal = -1;
+#endif
 
        for (;;) {
 
                WMNextEvent(dpy, &event);       /* Blocks here */
                WMHandleEvent(&event);
-
+#ifdef HAVE_INOTIFY
                if (retVal != -1) {
                        time.tv_sec = 0;
                        time.tv_usec = 0;
@@ -392,6 +399,7 @@ void EventLoop(void)
                        if (FD_ISSET(inotifyFD, &rfds))
                                inotifyHandleEvents(inotifyFD, inotifyWD);
                }
+#endif
        }
 }
 
@@ -918,7 +926,7 @@ static void handleClientMessage(XEvent * event)
                }
        } else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
 
-               wDefaultsCheckDomains();
+               wDefaultsCheckDomains(NULL);
 
        } else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
                WApplication *wapp;
diff --git a/src/main.c b/src/main.c
index 225ce4b..bd59b68 100644
--- a/src/main.c
+++ b/src/main.c
@@ -19,10 +19,12 @@
  *  USA.
  */
 
-#include <sys/inotify.h>
-
 #include "wconfig.h"
 
+#ifdef HAVE_INOTIFY
+#include <sys/inotify.h>
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -67,8 +69,10 @@ char *ProgName;
 
 unsigned int ValidModMask = 0xff;
 
+#ifdef HAVE_INOTIFY
 int inotifyFD;
 int inotifyWD;
+#endif
 /* locale to use. NULL==POSIX or C */
 char *Locale = NULL;
 
@@ -436,6 +440,9 @@ void print_help()
        puts(_(" --create-stdcmap       create the standard colormap hint in 
PseudoColor visuals"));
        puts(_(" --visual-id visualid   visual id of visual to use"));
        puts(_(" --static               do not update or save configurations"));
+#ifndef HAVE_INOTIFY
+       puts(_(" --no-polling           do not periodically check for 
configuration updates"));
+#endif
        puts(_(" --version              print version and exit"));
        puts(_(" --help                 show this message"));
 }
@@ -460,6 +467,7 @@ void check_defaults()
        wfree(path);
 }
 
+#ifdef HAVE_INOTIFY
 /*
  * Add watch here, used to notify if configuration
  * files have changed, using linux kernel inotify mechanism
@@ -490,6 +498,7 @@ static void inotifyWatchConfig()
        }
        wfree(watchPath);
 }
+#endif /* HAVE_INOTIFY */
 
 static void execInitScript()
 {
@@ -661,7 +670,11 @@ static int real_main(int argc, char **argv)
                                        wwarning(_("bad value for visualid: 
\"%s\""), argv[i]);
                                        exit(0);
                                }
-                       } else if (strcmp(argv[i], "-static") == 0 || 
strcmp(argv[i], "--static") == 0) {
+                       } else if (strcmp(argv[i], "-static") == 0 || 
strcmp(argv[i], "--static") == 0
+#ifndef HAVE_INOTIFY
+                                   || strcmp(argv[i], "--no-polling") == 0
+#endif
+                                   ) {
                                wPreferences.flags.noupdates = 1;
                        } else if (strcmp(argv[i], "--help") == 0) {
                                print_help();
@@ -762,7 +775,9 @@ static int real_main(int argc, char **argv)
                multiHead = False;
 
        execInitScript();
+#ifdef HAVE_INOTIFY
        inotifyWatchConfig();
+#endif
        EventLoop();
        return -1;
 }
diff --git a/src/shutdown.c b/src/shutdown.c
index f6f6c27..8b5e86b 100644
--- a/src/shutdown.c
+++ b/src/shutdown.c
@@ -56,7 +56,9 @@ static void wipeDesktop(WScreen * scr);
 void Shutdown(WShutdownMode mode)
 {
        int i;
+#ifdef HAVE_INOTIFY
        extern int inotifyFD;
+#endif
 
        switch (mode) {
        case WSLogoutMode:
@@ -64,7 +66,9 @@ void Shutdown(WShutdownMode mode)
        case WSExitMode:
                /* if there is no session manager, send SAVE_YOURSELF to
                 * the clients */
+#ifdef HAVE_INOTIFY
                close(inotifyFD);
+#endif
                for (i = 0; i < wScreenCount; i++) {
                        WScreen *scr;
 
@@ -92,7 +96,9 @@ void Shutdown(WShutdownMode mode)
                for (i = 0; i < wScreenCount; i++) {
                        WScreen *scr;
 
+#ifdef HAVE_INOTIFY
                        close(inotifyFD);
+#endif
                        scr = wScreenWithNumber(i);
                        if (scr) {
                                if (scr->helper_pid)
diff --git a/src/startup.c b/src/startup.c
index 817173a..f4ae9ba 100644
--- a/src/startup.c
+++ b/src/startup.c
@@ -134,6 +134,11 @@ extern Atom _XA_WM_IGNORE_FOCUS_EVENTS;
 /* cursors */
 extern Cursor wCursor[WCUR_LAST];
 
+#ifndef HAVE_INOTIFY
+/* special flags */
+extern char WDelayedActionSet;
+#endif
+
 /***** Local *****/
 
 static WScreen **wScreen = NULL;
@@ -187,6 +192,28 @@ static int handleXIO(Display * xio_dpy)
        return 0;
 }
 
+#ifndef HAVE_INOTIFY
+/*
+ *----------------------------------------------------------------------
+ * delayedAction-
+ *      Action to be executed after the signal() handler is exited.
+ *----------------------------------------------------------------------
+ */
+static void delayedAction(void *cdata)
+{
+       if (WDelayedActionSet == 0)
+               return;
+
+       WDelayedActionSet--;
+       /*
+        * Make the event dispatcher do whatever it needs to do,
+        * including handling zombie processes, restart and exit
+        * signals.
+        */
+       DispatchEvent(NULL);
+}
+#endif
+
 /*
  *----------------------------------------------------------------------
  * handleExitSig--
@@ -574,6 +601,11 @@ void StartUp(Bool defaultScreenOnly)
                XFreePixmap(dpy, cur);
        }
 
+#ifndef HAVE_INOTIFY
+       /* signal handler stuff that gets called when a signal is caught */
+       WMAddPersistentTimerHandler(500, delayedAction, NULL);
+#endif
+
        /* emergency exit... */
        sig_action.sa_handler = handleSig;
        sigemptyset(&sig_action.sa_mask);
@@ -757,6 +789,13 @@ void StartUp(Bool defaultScreenOnly)
                Exit(1);
        }
 
+#ifndef HAVE_INOTIFY
+       if (!wPreferences.flags.nopolling && !wPreferences.flags.noupdates) {
+               /* setup defaults file polling */
+               WMAddTimerHandler(3000, wDefaultsCheckDomains, NULL);
+       }
+#endif
+
 }
 
 static Bool windowInList(Window window, Window * list, int count)
diff --git a/src/wconfig.h.in b/src/wconfig.h.in
index 0277474..d3b38a5 100644
--- a/src/wconfig.h.in
+++ b/src/wconfig.h.in
@@ -347,6 +347,11 @@
 /* max width of window title in window list */
 #define MAX_WINDOWLIST_WIDTH   160
 
+#ifndef HAVE_INOTIFY
+/* Check defaults database for changes every this many milliseconds */
+#define DEFAULTS_CHECK_INTERVAL        2000
+#endif
+
 #define KEY_CONTROL_WINDOW_WEIGHT 1
 
 /* if your keyboard don't have arrow keys */
-- 
1.7.0


-- 
[-]

mkdir /nonexistent
From a46370222e85b833f190affefafede506070e75e Mon Sep 17 00:00:00 2001
From: Tamas TEVESZ <[email protected]>
Date: Thu, 18 Mar 2010 19:18:18 +0100
Subject: [PATCH] Make inotify optional

This time keeping the ability to fall back to the old polling method.
---
 WINGs/userdefaults.c |   24 ++++++++++++++++++++++++
 configure.ac         |    4 +++-
 src/WindowMaker.h    |    3 +++
 src/defaults.c       |    6 +++++-
 src/defaults.h       |    2 +-
 src/event.c          |   20 ++++++++++++++------
 src/main.c           |   21 ++++++++++++++++++---
 src/shutdown.c       |    6 ++++++
 src/startup.c        |   39 +++++++++++++++++++++++++++++++++++++++
 src/wconfig.h.in     |    5 +++++
 10 files changed, 118 insertions(+), 12 deletions(-)

diff --git a/WINGs/userdefaults.c b/WINGs/userdefaults.c
index 742b614..7f2c7ab 100644
--- a/WINGs/userdefaults.c
+++ b/WINGs/userdefaults.c
@@ -39,6 +39,11 @@ static void synchronizeUserDefaults(void *foo);
 extern char *WMGetApplicationName();
 
 #define DEFAULTS_DIR "/Defaults"
+#ifndef HAVE_INOTIFY
+/* Check defaults database for changes every this many milliseconds */
+/* XXX: this is shared with src/ stuff, put it in some common header */
+#define UD_SYNC_INTERVAL	2000
+#endif
 
 char *wusergnusteppath()
 {
@@ -117,6 +122,19 @@ static void synchronizeUserDefaults(void *foo)
 	}
 }
 
+#ifndef HAVE_INOTIFY
+static void addSynchronizeTimerHandler(void)
+{
+	static Bool initialized = False;
+
+	if (!initialized) {
+		WMAddPersistentTimerHandler(UD_SYNC_INTERVAL,
+		    synchronizeUserDefaults, NULL);
+		initialized = True;
+	}
+}
+#endif
+
 void WMEnableUDPeriodicSynchronization(WMUserDefaults * database, Bool enable)
 {
 	database->dontSync = !enable;
@@ -293,6 +311,9 @@ WMUserDefaults *WMGetStandardUserDefaults(void)
 		defaults->next = sharedUserDefaults;
 	sharedUserDefaults = defaults;
 
+#ifndef HAVE_INOTIFY
+	addSynchronizeTimerHandler();
+#endif
 	registerSaveOnExit();
 
 	return defaults;
@@ -366,6 +387,9 @@ WMUserDefaults *WMGetDefaultsFromPath(char *path)
 		defaults->next = sharedUserDefaults;
 	sharedUserDefaults = defaults;
 
+#ifndef HAVE_INOTIFY
+	addSynchronizeTimerHandler();
+#endif
 	registerSaveOnExit();
 
 	return defaults;
diff --git a/configure.ac b/configure.ac
index 7992179..a4be3a6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -128,7 +128,9 @@ if test "x$HAVEDL" = xyes; then
     AC_CHECK_HEADERS(dlfcn.h)
 fi
 
-
+dnl Check for inotify
+dnl =================
+AC_CHECK_HEADERS(sys/inotify.h, AC_DEFINE(HAVE_INOTIFY, 1, Check for inotify))
 
 dnl Check CPP
 dnl =========
diff --git a/src/WindowMaker.h b/src/WindowMaker.h
index cad1739..1a5b323 100644
--- a/src/WindowMaker.h
+++ b/src/WindowMaker.h
@@ -425,6 +425,9 @@ typedef struct WPreferences {
         unsigned int noautolaunch:1;   /* don't autolaunch apps */
         unsigned int norestore:1;      /* don't restore session */
         unsigned int create_stdcmap:1; /* create std colormap */
+#ifndef HAVE_INOTIFY
+	unsigned int nopolling:1;      /* don't poll the defaults database for changes */
+#endif
         unsigned int restarting:2;
     } flags;			       /* internal flags */
 } WPreferences;
diff --git a/src/defaults.c b/src/defaults.c
index 6e588ad..4acf51a 100644
--- a/src/defaults.c
+++ b/src/defaults.c
@@ -897,7 +897,7 @@ void wReadStaticDefaults(WMPropList * dict)
 	}
 }
 
-void wDefaultsCheckDomains(void)
+void wDefaultsCheckDomains(void* arg)
 {
 	WScreen *scr;
 	struct stat stbuf;
@@ -1016,6 +1016,10 @@ void wDefaultsCheckDomains(void)
 		}
 		WDRootMenu->timestamp = stbuf.st_mtime;
 	}
+#ifndef HAVE_INOTIFY
+	if (!arg)
+		WMAddTimerHandler(DEFAULTS_CHECK_INTERVAL, wDefaultsCheckDomains, arg);
+#endif
 }
 
 void wReadDefaults(WScreen * scr, WMPropList * new_dict)
diff --git a/src/defaults.h b/src/defaults.h
index b557846..b61fe5d 100644
--- a/src/defaults.h
+++ b/src/defaults.h
@@ -46,7 +46,7 @@ void wDefaultUpdateIcons(WScreen *scr);
 
 void wReadStaticDefaults(WMPropList *dict);
 
-void wDefaultsCheckDomains(void);
+void wDefaultsCheckDomains(void *arg);
 
 void wSaveDefaults(WScreen *scr);
 
diff --git a/src/event.c b/src/event.c
index d29cafc..633f58e 100644
--- a/src/event.c
+++ b/src/event.c
@@ -20,9 +20,12 @@
  *  USA.
  */
 
-#include <sys/inotify.h>
 #include "wconfig.h"
 
+#ifdef HAVE_INOTIFY
+#include <sys/inotify.h>
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -198,7 +201,7 @@ void DispatchEvent(XEvent * event)
 		Restart(NULL, True);
 	} else if (WCHECK_STATE(WSTATE_NEED_REREAD)) {
 		WCHANGE_STATE(WSTATE_NORMAL);
-		wDefaultsCheckDomains();
+		wDefaultsCheckDomains(NULL);
 	}
 
 	/* for the case that all that is wanted to be dispatched is
@@ -282,6 +285,7 @@ void DispatchEvent(XEvent * event)
 	}
 }
 
+#ifdef HAVE_INOTIFY
 /*
  *----------------------------------------------------------------------
  * inotifyHandleEvents-
@@ -299,7 +303,7 @@ void DispatchEvent(XEvent * event)
 #define BUFF_SIZE ((sizeof(struct inotify_event) + 64)*5)
 void inotifyHandleEvents(int fd, int wd)
 {
-	extern void wDefaultsCheckDomains(void);
+	extern void wDefaultsCheckDomains(void *);
 	ssize_t eventQLength, i = 0;
 	char buff[BUFF_SIZE] = { 0 };
 	/* Check config only once per read of the event queue */
@@ -335,13 +339,14 @@ void inotifyHandleEvents(int fd, int wd)
 		}
 		if ((pevent->mask & IN_MODIFY) && oneShotFlag == 0) {
 			fprintf(stdout, "wmaker: reading config files in defaults database.\n");
-			wDefaultsCheckDomains();
+			wDefaultsCheckDomains(NULL);
 		}
 
 		/* move to next event in the buffer */
 		i += sizeof(struct inotify_event) + pevent->len;
 	}
 }
+#endif /* HAVE_INOTIFY */
 
 /*
  *----------------------------------------------------------------------
@@ -359,6 +364,7 @@ void inotifyHandleEvents(int fd, int wd)
 void EventLoop(void)
 {
 	XEvent event;
+#ifdef HAVE_INOTIFY
 	extern int inotifyFD;
 	extern int inotifyWD;
 	struct timeval time;
@@ -367,12 +373,13 @@ void EventLoop(void)
 
 	if (inotifyFD < 0 || inotifyWD < 0)
 		retVal = -1;
+#endif
 
 	for (;;) {
 
 		WMNextEvent(dpy, &event);	/* Blocks here */
 		WMHandleEvent(&event);
-
+#ifdef HAVE_INOTIFY
 		if (retVal != -1) {
 			time.tv_sec = 0;
 			time.tv_usec = 0;
@@ -392,6 +399,7 @@ void EventLoop(void)
 			if (FD_ISSET(inotifyFD, &rfds))
 				inotifyHandleEvents(inotifyFD, inotifyWD);
 		}
+#endif
 	}
 }
 
@@ -918,7 +926,7 @@ static void handleClientMessage(XEvent * event)
 		}
 	} else if (event->xclient.message_type == _XA_WINDOWMAKER_COMMAND) {
 
-		wDefaultsCheckDomains();
+		wDefaultsCheckDomains(NULL);
 
 	} else if (event->xclient.message_type == _XA_WINDOWMAKER_WM_FUNCTION) {
 		WApplication *wapp;
diff --git a/src/main.c b/src/main.c
index 225ce4b..bd59b68 100644
--- a/src/main.c
+++ b/src/main.c
@@ -19,10 +19,12 @@
  *  USA.
  */
 
-#include <sys/inotify.h>
-
 #include "wconfig.h"
 
+#ifdef HAVE_INOTIFY
+#include <sys/inotify.h>
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -67,8 +69,10 @@ char *ProgName;
 
 unsigned int ValidModMask = 0xff;
 
+#ifdef HAVE_INOTIFY
 int inotifyFD;
 int inotifyWD;
+#endif
 /* locale to use. NULL==POSIX or C */
 char *Locale = NULL;
 
@@ -436,6 +440,9 @@ void print_help()
 	puts(_(" --create-stdcmap	create the standard colormap hint in PseudoColor visuals"));
 	puts(_(" --visual-id visualid	visual id of visual to use"));
 	puts(_(" --static		do not update or save configurations"));
+#ifndef HAVE_INOTIFY
+	puts(_(" --no-polling		do not periodically check for configuration updates"));
+#endif
 	puts(_(" --version		print version and exit"));
 	puts(_(" --help			show this message"));
 }
@@ -460,6 +467,7 @@ void check_defaults()
 	wfree(path);
 }
 
+#ifdef HAVE_INOTIFY
 /*
  * Add watch here, used to notify if configuration
  * files have changed, using linux kernel inotify mechanism
@@ -490,6 +498,7 @@ static void inotifyWatchConfig()
 	}
 	wfree(watchPath);
 }
+#endif /* HAVE_INOTIFY */
 
 static void execInitScript()
 {
@@ -661,7 +670,11 @@ static int real_main(int argc, char **argv)
 					wwarning(_("bad value for visualid: \"%s\""), argv[i]);
 					exit(0);
 				}
-			} else if (strcmp(argv[i], "-static") == 0 || strcmp(argv[i], "--static") == 0) {
+			} else if (strcmp(argv[i], "-static") == 0 || strcmp(argv[i], "--static") == 0
+#ifndef HAVE_INOTIFY
+				    || strcmp(argv[i], "--no-polling") == 0
+#endif
+				    ) {
 				wPreferences.flags.noupdates = 1;
 			} else if (strcmp(argv[i], "--help") == 0) {
 				print_help();
@@ -762,7 +775,9 @@ static int real_main(int argc, char **argv)
 		multiHead = False;
 
 	execInitScript();
+#ifdef HAVE_INOTIFY
 	inotifyWatchConfig();
+#endif
 	EventLoop();
 	return -1;
 }
diff --git a/src/shutdown.c b/src/shutdown.c
index f6f6c27..8b5e86b 100644
--- a/src/shutdown.c
+++ b/src/shutdown.c
@@ -56,7 +56,9 @@ static void wipeDesktop(WScreen * scr);
 void Shutdown(WShutdownMode mode)
 {
 	int i;
+#ifdef HAVE_INOTIFY
 	extern int inotifyFD;
+#endif
 
 	switch (mode) {
 	case WSLogoutMode:
@@ -64,7 +66,9 @@ void Shutdown(WShutdownMode mode)
 	case WSExitMode:
 		/* if there is no session manager, send SAVE_YOURSELF to
 		 * the clients */
+#ifdef HAVE_INOTIFY
 		close(inotifyFD);
+#endif
 		for (i = 0; i < wScreenCount; i++) {
 			WScreen *scr;
 
@@ -92,7 +96,9 @@ void Shutdown(WShutdownMode mode)
 		for (i = 0; i < wScreenCount; i++) {
 			WScreen *scr;
 
+#ifdef HAVE_INOTIFY
 			close(inotifyFD);
+#endif
 			scr = wScreenWithNumber(i);
 			if (scr) {
 				if (scr->helper_pid)
diff --git a/src/startup.c b/src/startup.c
index 817173a..f4ae9ba 100644
--- a/src/startup.c
+++ b/src/startup.c
@@ -134,6 +134,11 @@ extern Atom _XA_WM_IGNORE_FOCUS_EVENTS;
 /* cursors */
 extern Cursor wCursor[WCUR_LAST];
 
+#ifndef HAVE_INOTIFY
+/* special flags */
+extern char WDelayedActionSet;
+#endif
+
 /***** Local *****/
 
 static WScreen **wScreen = NULL;
@@ -187,6 +192,28 @@ static int handleXIO(Display * xio_dpy)
 	return 0;
 }
 
+#ifndef HAVE_INOTIFY
+/*
+ *----------------------------------------------------------------------
+ * delayedAction-
+ *      Action to be executed after the signal() handler is exited.
+ *----------------------------------------------------------------------
+ */
+static void delayedAction(void *cdata)
+{
+	if (WDelayedActionSet == 0)
+		return;
+
+	WDelayedActionSet--;
+	/*
+	 * Make the event dispatcher do whatever it needs to do,
+	 * including handling zombie processes, restart and exit
+	 * signals.
+	 */
+	DispatchEvent(NULL);
+}
+#endif
+
 /*
  *----------------------------------------------------------------------
  * handleExitSig--
@@ -574,6 +601,11 @@ void StartUp(Bool defaultScreenOnly)
 		XFreePixmap(dpy, cur);
 	}
 
+#ifndef HAVE_INOTIFY
+	/* signal handler stuff that gets called when a signal is caught */
+	WMAddPersistentTimerHandler(500, delayedAction, NULL);
+#endif
+
 	/* emergency exit... */
 	sig_action.sa_handler = handleSig;
 	sigemptyset(&sig_action.sa_mask);
@@ -757,6 +789,13 @@ void StartUp(Bool defaultScreenOnly)
 		Exit(1);
 	}
 
+#ifndef HAVE_INOTIFY
+	if (!wPreferences.flags.nopolling && !wPreferences.flags.noupdates) {
+		/* setup defaults file polling */
+		WMAddTimerHandler(3000, wDefaultsCheckDomains, NULL);
+	}
+#endif
+
 }
 
 static Bool windowInList(Window window, Window * list, int count)
diff --git a/src/wconfig.h.in b/src/wconfig.h.in
index 0277474..d3b38a5 100644
--- a/src/wconfig.h.in
+++ b/src/wconfig.h.in
@@ -347,6 +347,11 @@
 /* max width of window title in window list */
 #define MAX_WINDOWLIST_WIDTH	160
 
+#ifndef HAVE_INOTIFY
+/* Check defaults database for changes every this many milliseconds */
+#define DEFAULTS_CHECK_INTERVAL	2000
+#endif
+
 #define KEY_CONTROL_WINDOW_WEIGHT 1
 
 /* if your keyboard don't have arrow keys */
-- 
1.7.0

Reply via email to