From: Christophe CURIS <[email protected]>

---
 src/WindowMaker.h |  7 +++++++
 src/event.c       | 15 +++++++--------
 src/main.c        | 17 +++++++----------
 src/shutdown.c    | 13 ++++++++-----
 4 files changed, 29 insertions(+), 23 deletions(-)

diff --git a/src/WindowMaker.h b/src/WindowMaker.h
index bcd128d..27003d0 100644
--- a/src/WindowMaker.h
+++ b/src/WindowMaker.h
@@ -522,6 +522,13 @@ extern struct wmaker_global_variables {
                struct WMenu *drawer_menu;      /* menu for the drawers */
        } dock;
 
+#ifdef HAVE_INOTIFY
+       struct {
+               int fd_event_queue;   /* Inotify's queue file descriptor */
+               int wd_defaults;   /* Watch Descriptor for the 'Defaults' 
configuration file */
+       } inotify;
+#endif
+
        /* definition for X Atoms */
        struct {
 
diff --git a/src/event.c b/src/event.c
index a68e619..8629c6c 100644
--- a/src/event.c
+++ b/src/event.c
@@ -358,13 +358,11 @@ noreturn void EventLoop(void)
 {
        XEvent event;
 #ifdef HAVE_INOTIFY
-       extern int inotifyFD;
-       extern int inotifyWD;
        struct timeval time;
        fd_set rfds;
        int retVal = 0;
 
-       if (inotifyFD < 0 || inotifyWD < 0)
+       if (w_global.inotify.fd_event_queue < 0 || w_global.inotify.wd_defaults 
< 0)
                retVal = -1;
 #endif
 
@@ -377,20 +375,21 @@ noreturn void EventLoop(void)
                        time.tv_sec = 0;
                        time.tv_usec = 0;
                        FD_ZERO(&rfds);
-                       FD_SET(inotifyFD, &rfds);
+                       FD_SET(w_global.inotify.fd_event_queue, &rfds);
 
                        /* check for available read data from inotify - don't 
block! */
-                       retVal = select(inotifyFD + 1, &rfds, NULL, NULL, 
&time);
+                       retVal = select(w_global.inotify.fd_event_queue + 1, 
&rfds, NULL, NULL, &time);
 
                        if (retVal < 0) {       /* an error has occured */
                                wwarning(_("select failed. The inotify instance 
will be closed."
                                           " Changes to the defaults database 
will require"
                                           " a restart to take effect."));
-                               close(inotifyFD);
+                               close(w_global.inotify.fd_event_queue);
+                               w_global.inotify.fd_event_queue = -1;
                                continue;
                        }
-                       if (FD_ISSET(inotifyFD, &rfds))
-                               handle_inotify_events(inotifyFD, inotifyWD);
+                       if (FD_ISSET(w_global.inotify.fd_event_queue, &rfds))
+                               
handle_inotify_events(w_global.inotify.fd_event_queue, 
w_global.inotify.wd_defaults);
                }
 #endif
        }
diff --git a/src/main.c b/src/main.c
index f4c6d1a..bddffac 100644
--- a/src/main.c
+++ b/src/main.c
@@ -74,11 +74,6 @@ char *ProgName;
 
 unsigned int ValidModMask = 0xff;
 
-#ifdef HAVE_INOTIFY
-int inotifyFD;
-int inotifyWD;
-#endif
-
 struct WPreferences wPreferences;
 
 WShortKey wKeyBindings[WKBD_LAST];
@@ -474,8 +469,9 @@ static void check_defaults(void)
 static void inotifyWatchConfig(void)
 {
        char *watchPath = NULL;
-       inotifyFD = inotify_init();     /* Initialise an inotify instance */
-       if (inotifyFD < 0) {
+
+       w_global.inotify.fd_event_queue = inotify_init();       /* Initialise 
an inotify instance */
+       if (w_global.inotify.fd_event_queue < 0) {
                wwarning(_("could not initialise an inotify instance."
                           " Changes to the defaults database will require"
                           " a restart to take effect. Check your kernel!"));
@@ -485,12 +481,13 @@ static void inotifyWatchConfig(void)
                 * but we might want more in the future so check all events for 
now.
                 * The individual events are checked for in event.c.
                 */
-               inotifyWD = inotify_add_watch(inotifyFD, watchPath, 
IN_ALL_EVENTS);
-               if (inotifyWD < 0) {
+               w_global.inotify.wd_defaults = 
inotify_add_watch(w_global.inotify.fd_event_queue, watchPath, IN_ALL_EVENTS);
+               if (w_global.inotify.wd_defaults < 0) {
                        wwarning(_("could not add an inotify watch on path %s."
                                   "Changes to the defaults database will 
require"
                                   " a restart to take effect."), watchPath);
-                       close(inotifyFD);
+                       close(w_global.inotify.fd_event_queue);
+                       w_global.inotify.fd_event_queue = -1;
                }
        }
        wfree(watchPath);
diff --git a/src/shutdown.c b/src/shutdown.c
index e6d3503..300a269 100644
--- a/src/shutdown.c
+++ b/src/shutdown.c
@@ -54,9 +54,6 @@ static void wipeDesktop(WScreen * scr);
 void Shutdown(WShutdownMode mode)
 {
        int i;
-#ifdef HAVE_INOTIFY
-       extern int inotifyFD;
-#endif
 
        switch (mode) {
        case WSLogoutMode:
@@ -65,7 +62,10 @@ void Shutdown(WShutdownMode mode)
                /* if there is no session manager, send SAVE_YOURSELF to
                 * the clients */
 #ifdef HAVE_INOTIFY
-               close(inotifyFD);
+               if (w_global.inotify.fd_event_queue >= 0) {
+                       close(w_global.inotify.fd_event_queue);
+                       w_global.inotify.fd_event_queue = -1;
+               }
 #endif
                for (i = 0; i < w_global.screen_count; i++) {
                        WScreen *scr;
@@ -92,7 +92,10 @@ void Shutdown(WShutdownMode mode)
                        WScreen *scr;
 
 #ifdef HAVE_INOTIFY
-                       close(inotifyFD);
+                       if (w_global.inotify.fd_event_queue >= 0) {
+                               close(w_global.inotify.fd_event_queue);
+                               w_global.inotify.fd_event_queue = -1;
+                       }
 #endif
                        scr = wScreenWithNumber(i);
                        if (scr) {
-- 
1.8.4.rc3


-- 
To unsubscribe, send mail to [email protected].

Reply via email to