]> sourceware.org Git - newlib-cygwin.git/blobdiff - winsup/cygwin/cygheap.cc
* cygheap.cc (init_cygheap::etc_changed): New method to signal
[newlib-cygwin.git] / winsup / cygwin / cygheap.cc
index 8c45b1bce83dd7c05377ef7b58805ed804510024..be52f0446b01c785fe9ddf1bf649421fcbda37f6 100644 (file)
@@ -16,6 +16,7 @@
 #include "security.h"
 #include "fhandler.h"
 #include "dtable.h"
+#include "path.h"
 #include "cygheap.h"
 #include "child_info.h"
 #include "heap.h"
@@ -136,7 +137,7 @@ cygheap_fixup_in_child (child_info *ci, bool execed)
       for (_cmalloc_entry *rvc = cygheap->chain; rvc; rvc = rvc->prev)
        {
          cygheap_entry *ce = (cygheap_entry *) rvc->data;
-         if (rvc->b >= NBUCKETS || ce->type <= HEAP_1_START)
+         if (!rvc->ptr || rvc->b >= NBUCKETS || ce->type <= HEAP_1_START)
            continue;
          else if (ce->type < HEAP_1_MAX)
            ce->type += HEAP_1_MAX;     /* Mark for freeing after next exec */
@@ -345,6 +346,39 @@ cstrdup1 (const char *s)
   return p;
 }
 
+bool
+init_cygheap::etc_changed ()
+{
+  bool res = 0;
+
+  if (!etc_changed_h)
+    {
+      path_conv pwd ("/etc");
+      etc_changed_h = FindFirstChangeNotification (pwd, FALSE,
+                                             FILE_NOTIFY_CHANGE_LAST_WRITE);
+      if (etc_changed_h == INVALID_HANDLE_VALUE)
+       system_printf ("Can't open /etc for checking, %E", (char *) pwd,
+                      etc_changed_h);
+      else if (!DuplicateHandle (hMainProc, etc_changed_h, hMainProc,
+                                &etc_changed_h, 0, TRUE,
+                                DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE))
+       {
+         system_printf ("Can't inherit /etc handle, %E", (char *) pwd,
+                        etc_changed_h);
+         etc_changed_h = INVALID_HANDLE_VALUE;
+       }
+    }
+
+   if (etc_changed_h != INVALID_HANDLE_VALUE
+       && WaitForSingleObject (etc_changed_h, 0) == WAIT_OBJECT_0)
+     {
+       (void) FindNextChangeNotification (etc_changed_h);
+       res = 1;
+     }
+
+  return res;
+}
+
 void
 cygheap_root::set (const char *posix, const char *native)
 {
This page took 0.022492 seconds and 5 git commands to generate.