Fix segfault if http/telnet port is not available
authorHenning Rogge <hrogge@googlemail.com>
Thu, 26 Nov 2009 19:33:01 +0000 (20:33 +0100)
committerHenning Rogge <hrogge@googlemail.com>
Thu, 26 Nov 2009 19:33:01 +0000 (20:33 +0100)
src/main.c
src/olsr_comport.c
src/olsr_comport.h

index 66d2e52..0a010eb 100644 (file)
@@ -236,7 +236,7 @@ main(int argc, char *argv[])
   olsr_init_tables();
 
   /* initialize built in server services */
-  olsr_com_init();
+  olsr_com_init(true);
 
   /* Load plugins */
   olsr_init_pluginsystem(true);
index 23513aa..4272938 100644 (file)
@@ -94,7 +94,7 @@ static void olsr_com_parse_txt(struct comport_connection *con,
 
 static void olsr_com_timeout_handler(void *);
 
-void olsr_com_init(void) {
+void olsr_com_init(bool failfast) {
   connection_cookie = olsr_alloc_cookie("comport connections",
       OLSR_COOKIE_TYPE_MEMORY);
   olsr_cookie_set_memory_size(connection_cookie,
@@ -103,30 +103,36 @@ void olsr_com_init(void) {
   connection_timeout = olsr_alloc_cookie("comport timout",
       OLSR_COOKIE_TYPE_TIMER);
 
+  connection_http_count = 0;
+  connection_txt_count = 0;
+
+  list_head_init(&olsr_comport_head);
+
+  olsr_com_init_http();
+  olsr_com_init_txt();
+
   if (olsr_cnf->comport_http > 0) {
     if ((comsocket_http = olsr_com_openport(olsr_cnf->comport_http)) == -1) {
-      return;
+      if (failfast) {
+        olsr_exit(1);
+      }
+    }
+    else {
+      add_olsr_socket(comsocket_http, &olsr_com_parse_request, NULL, NULL,
+          SP_PR_READ);
     }
-
-    add_olsr_socket(comsocket_http, &olsr_com_parse_request, NULL, NULL,
-        SP_PR_READ);
   }
   if (olsr_cnf->comport_txt > 0) {
     if ((comsocket_txt = olsr_com_openport(olsr_cnf->comport_txt)) == -1) {
-      return;
+      if (failfast) {
+        olsr_exit(1);
+      }
+    }
+    else {
+      add_olsr_socket(comsocket_txt, &olsr_com_parse_request, NULL, NULL,
+          SP_PR_READ);
     }
-
-    add_olsr_socket(comsocket_txt, &olsr_com_parse_request, NULL, NULL,
-        SP_PR_READ);
   }
-
-  connection_http_count = 0;
-  connection_txt_count = 0;
-
-  list_head_init(&olsr_comport_head);
-
-  olsr_com_init_http();
-  olsr_com_init_txt();
 }
 
 void olsr_com_destroy(void) {
index 8bb0392..8230975 100644 (file)
@@ -101,7 +101,7 @@ struct comport_connection {
 
 LISTNODE2STRUCT(comport_node2con, struct comport_connection, node);
 
-void olsr_com_init(void);
+void olsr_com_init(bool);
 void olsr_com_destroy(void);
 
 void EXPORT(olsr_com_activate_output) (struct comport_connection *con);