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

Ferry Huberts (spam-protected)
Fri Nov 6 16:28:56 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)>
---
 lib/httpinfo/src/olsrd_httpinfo.c | 3 +--
 lib/httpinfo/src/olsrd_plugin.c   | 8 ++++----
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/lib/httpinfo/src/olsrd_httpinfo.c b/lib/httpinfo/src/olsrd_httpinfo.c
index f1a5bab..5e493e0 100644
--- a/lib/httpinfo/src/olsrd_httpinfo.c
+++ b/lib/httpinfo/src/olsrd_httpinfo.c
@@ -321,8 +321,7 @@ olsrd_plugin_init(void)
   http_socket = get_http_socket(http_port != 0 ? http_port : DEFAULT_TCP_PORT);
 
   if (http_socket < 0) {
-    fprintf(stderr, "(HTTPINFO) could not initialize HTTP socket\n");
-    exit(1);
+    olsr_exit("HTTPINFO: could not initialize HTTP socket", 1);
   }
 
   /* Register socket */
diff --git a/lib/httpinfo/src/olsrd_plugin.c b/lib/httpinfo/src/olsrd_plugin.c
index 03bf573..71469d4 100644
--- a/lib/httpinfo/src/olsrd_plugin.c
+++ b/lib/httpinfo/src/olsrd_plugin.c
@@ -125,14 +125,14 @@ add_plugin_access(const char *value, void *data, set_plugin_parameter_addon addo
   struct allowed_net *an;
 
   if (olsr_string_to_prefix(olsr_cnf->ip_version, &prefix, value)) {
-    fprintf(stderr, "(HTTPINFO) unknown access restriction parameter: %s!\n", value);
-    exit(0);
+    char buf[1024];
+    snprintf(buf, sizeof(buf), "HTTPINFO: unknown access restriction parameter: %s", value);
+    olsr_exit(buf, 0);
   }
 
   an = olsr_malloc(sizeof(*an), __func__);
   if (an == NULL) {
-    fprintf(stderr, "(HTTPINFO) register param net out of memory!\n");
-    exit(0);
+    olsr_exit("HTTPINFO: register param net out of memory", 0);
   }
 
   an->prefix = prefix;
-- 
2.5.0




More information about the Olsr-dev mailing list