fix scheduler when add_select is called with 0 ready fds
authorSchanzenbach, Martin <martin.schanzenbach@aisec.fraunhofer.de>
Wed, 10 Jan 2018 03:29:06 +0000 (04:29 +0100)
committerSchanzenbach, Martin <martin.schanzenbach@aisec.fraunhofer.de>
Wed, 10 Jan 2018 03:29:06 +0000 (04:29 +0100)
src/identity/plugin_rest_identity.c
src/rest/gnunet-rest-server.c
src/util/scheduler.c

index 33804143d4a43a74a545f62d4f898cb20ec4dd20..6044d064180ff440d4f3fbb2a6e87cb9b5d6d22c 100644 (file)
@@ -241,7 +241,10 @@ cleanup_handle (struct RequestHandle *handle)
   if (NULL != handle->name)
     GNUNET_free (handle->name);
   if (NULL != handle->timeout_task)
+  {
     GNUNET_SCHEDULER_cancel (handle->timeout_task);
+    handle->timeout_task = NULL;
+  }
   if (NULL != handle->identity_handle)
     GNUNET_IDENTITY_disconnect (handle->identity_handle);
   if (NULL != handle->subsys)
index 5b92c6c43dfa84a1adda5f3fa7b7c9b20d7d9f35..b08aee389df951a8f67966e63f6c675621266376 100644 (file)
@@ -154,11 +154,14 @@ do_httpd (void *cls);
 static void
 run_mhd_now ()
 {
-  if (NULL !=
-      httpd_task)
+  if (NULL != httpd_task)
+  {
     GNUNET_SCHEDULER_cancel (httpd_task);
+    httpd_task = NULL;
+  }
   httpd_task = GNUNET_SCHEDULER_add_now (&do_httpd,
                                          NULL);
+
 }
 
 /**
@@ -410,7 +413,18 @@ kill_httpd ()
     GNUNET_SCHEDULER_cancel (ltask6);
     ltask6 = NULL;
   }
-}
+
+  if (NULL != lsock4)
+  {
+    GNUNET_NETWORK_socket_close (lsock4);
+    lsock4 = NULL;
+  }
+  if (NULL != lsock6)
+  {
+    GNUNET_NETWORK_socket_close (lsock6);
+    lsock6 = NULL;
+  }
+  }
 
 
 /**
@@ -460,7 +474,10 @@ schedule_httpd ()
     wws = NULL;
   }
   if (NULL != httpd_task)
+  {
     GNUNET_SCHEDULER_cancel (httpd_task);
+    httpd_task = NULL;
+  }
   if ( (MHD_YES == haveto) ||
        (-1 != max))
   {
@@ -468,6 +485,7 @@ schedule_httpd ()
       GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
                                    tv, wrs, wws,
                                    &do_httpd, NULL);
+    
   }
   if (NULL != wrs)
     GNUNET_NETWORK_fdset_destroy (wrs);
@@ -504,18 +522,23 @@ do_accept (void *cls)
   const struct sockaddr *addr;
   socklen_t len;
 
+  GNUNET_assert (NULL != lsock);
   if (lsock == lsock4)
-    ltask4 = NULL;
-  else
-    ltask6 = NULL;
-  if (lsock == lsock4)
+  {
     ltask4 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
                                             lsock,
                                             &do_accept, lsock);
-  else
+
+  }
+  else if (lsock == lsock6)
+  {
     ltask6 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
                                             lsock,
                                             &do_accept, lsock);
+
+  }
+  else
+    GNUNET_assert (0);
   s = GNUNET_NETWORK_socket_accept (lsock, NULL, NULL);
   if (NULL == s)
   {
@@ -720,6 +743,7 @@ run (void *cls,
     {
       ltask6 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
                                               lsock6, &do_accept, lsock6);
+
     }
   }
   lsock4 = bind_v4 ();
@@ -739,6 +763,7 @@ run (void *cls,
     {
       ltask4 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
                                               lsock4, &do_accept, lsock4);
+
     }
   }
   if ( (NULL == lsock4) &&
@@ -785,10 +810,10 @@ main (int argc, char *const *argv)
 {
   struct GNUNET_GETOPT_CommandLineOption options[] = {
     GNUNET_GETOPT_option_ulong ('p',
-                                    "port",
-                                    "PORT",
-                                    gettext_noop ("listen on specified port (default: 7776)"),
-                                    &port),
+                                "port",
+                                "PORT",
+                                gettext_noop ("listen on specified port (default: 7776)"),
+                                &port),
     GNUNET_GETOPT_OPTION_END
   };
   static const char* err_page =
index 9d37231e7855edbb44c5fc2bffd6a67b5b434f57..c2061b50fc73c0eee9b80b529f52743640ba9ce1 100644 (file)
@@ -2006,7 +2006,7 @@ GNUNET_SCHEDULER_run_from_driver (struct GNUNET_SCHEDULER_Handle *sh)
       if (GNUNET_OK != del_result)
       {
         LOG (GNUNET_ERROR_TYPE_ERROR,
-             "driver could not delete task\n");
+           "driver could not delete task %p\n", pos);
         GNUNET_assert (0);
       }
     }
@@ -2187,6 +2187,8 @@ select_del (void *cls,
   context = cls;
   ret = GNUNET_SYSERR;
   pos = context->scheduled_head;
+  if (0 == task->fds_len)
+    return GNUNET_OK;
   while (NULL != pos)
   {
     struct Scheduled *next = pos->next;