[Olsr-dev] [PATCH v1 09/23] win32: call olsr_exit() instead of exit()

Ferry Huberts (spam-protected)
Fri Nov 6 16:29:01 CET 2015


From: Ferry Huberts <(spam-protected)>

olsr_exit tries to do proper shutdown that cleans up data structures
by raise()ing the SIGTERM signal. This signal then causes olsr_shutdown
to be invoked (only when the signal handler is setup), which will do
the cleanup of the data structures.

According to the man page of raise():
  If the signal causes a handler to be called, raise() will return
  only after the signal handler has returned.

And since olsr_exit() invokes exit() after raise()ing the signal, there
is no harm in calling it.

Signed-off-by: Ferry Huberts <(spam-protected)>
---
 src/win32/ifnet.c | 6 ++----
 src/win32/net.c   | 3 ++-
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/win32/ifnet.c b/src/win32/ifnet.c
index a4e2060..9f6fd94 100644
--- a/src/win32/ifnet.c
+++ b/src/win32/ifnet.c
@@ -546,8 +546,7 @@ add_hemu_if(struct olsr_if *iface)
     ifp->olsr_socket = gethemusocket(&sin);
 
     if (ifp->olsr_socket < 0) {
-      fprintf(stderr, "Could not initialize socket... exiting!\n\n");
-      exit(1);
+      olsr_exit("Could not initialize socket", 1);
     }
 
   } else {
@@ -842,8 +841,7 @@ chk_if_up(struct olsr_if *iface, int debuglvl __attribute__ ((unused)))
   New->send_socket = getsocket(0, New);
 
   if (New->olsr_socket < 0) {
-    fprintf(stderr, "Could not initialize socket... exiting!\n\n");
-    exit(1);
+    olsr_exit("Could not initialize socket", 1);
   }
 
   add_olsr_socket(New->olsr_socket, &olsr_input, NULL, NULL, SP_PR_READ);
diff --git a/src/win32/net.c b/src/win32/net.c
index b012191..012fa4f 100644
--- a/src/win32/net.c
+++ b/src/win32/net.c
@@ -58,6 +58,7 @@
 #include "net_os.h"
 #include "net_olsr.h"
 #include "ipcalc.h"
+#include "olsr.h"
 
 #if defined WINCE
 #define WIDE_STRING(s) L##s
@@ -324,7 +325,7 @@ DisableIcmpRedirects(void)
   fprintf(stderr, "I have disabled ICMP redirect processing in the registry for you.\n");
   fprintf(stderr, "REBOOT NOW, so that these changes take effect. Exiting...\n\n");
 
-  exit(0);
+  olsr_exit(NULL, 0);
 }
 
 int
-- 
2.5.0




More information about the Olsr-dev mailing list