gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r21042 - gnunet/src/arm


From: gnunet
Subject: [GNUnet-SVN] r21042 - gnunet/src/arm
Date: Thu, 19 Apr 2012 20:51:22 +0200

Author: grothoff
Date: 2012-04-19 20:51:22 +0200 (Thu, 19 Apr 2012)
New Revision: 21042

Modified:
   gnunet/src/arm/arm_api.c
   gnunet/src/arm/gnunet-service-arm.c
   gnunet/src/arm/test_exponential_backoff.c
Log:
-fixes

Modified: gnunet/src/arm/arm_api.c
===================================================================
--- gnunet/src/arm/arm_api.c    2012-04-19 17:10:46 UTC (rev 21041)
+++ gnunet/src/arm/arm_api.c    2012-04-19 18:51:22 UTC (rev 21042)
@@ -116,16 +116,8 @@
   {
     if (shutdown_ctx->cont != NULL)
     {
-      if (shutdown_ctx->confirmed == GNUNET_ARM_PROCESS_SHUTDOWN)
-      {
-       /* shutdown is now complete, as we waited for the network disconnect... 
*/
-       shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_ARM_PROCESS_DOWN);
-      }
-      else
-      {
-       /* communication error */
-       shutdown_ctx->cont (shutdown_ctx->cont_cls, 
GNUNET_ARM_PROCESS_COMMUNICATION_ERROR);
-      }
+      /* shutdown is now complete, as we waited for the network disconnect... 
*/
+      shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_ARM_PROCESS_DOWN);
     }
     GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task);
     GNUNET_CLIENT_disconnect (shutdown_ctx->sock);
@@ -187,15 +179,14 @@
 
   shutdown_ctx->th = NULL;
   if (size < sizeof (struct GNUNET_MessageHeader))
-    {
-      LOG (GNUNET_ERROR_TYPE_WARNING,
-          _("Failed to transmit shutdown request to client.\n"));
-      shutdown_ctx->cont (shutdown_ctx->cont_cls, 
GNUNET_ARM_PROCESS_COMMUNICATION_ERROR);
-      GNUNET_CLIENT_disconnect (shutdown_ctx->sock);
-      GNUNET_free (shutdown_ctx);
-      return 0;                        /* client disconnected */
-    }
-
+  {
+    LOG (GNUNET_ERROR_TYPE_WARNING,
+        _("Failed to transmit shutdown request to client.\n"));
+    shutdown_ctx->cont (shutdown_ctx->cont_cls, 
GNUNET_ARM_PROCESS_COMMUNICATION_ERROR);
+    GNUNET_CLIENT_disconnect (shutdown_ctx->sock);
+    GNUNET_free (shutdown_ctx);
+    return 0;                  /* client disconnected */
+  }
   GNUNET_CLIENT_receive (shutdown_ctx->sock, &service_shutdown_handler,
                         shutdown_ctx, GNUNET_TIME_UNIT_FOREVER_REL);
   shutdown_ctx->cancel_task =
@@ -349,22 +340,18 @@
   char *lopostfix;
 
   if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
-    {
-#if DEBUG_ARM
-      LOG (GNUNET_ERROR_TYPE_DEBUG, "Looks like `%s' is already running.\n",
-          "gnunet-service-arm");
-#endif
-      /* arm is running! */
-      if (pos->callback != NULL)
-       pos->callback (pos->cls, GNUNET_ARM_PROCESS_ALREADY_RUNNING);
-      GNUNET_free (pos);
-      return;
-    }
-#if DEBUG_ARM
+  {
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "Looks like `%s' is already running.\n",
+        "gnunet-service-arm");
+    /* arm is running! */
+    if (pos->callback != NULL)
+      pos->callback (pos->cls, GNUNET_ARM_PROCESS_ALREADY_RUNNING);
+    GNUNET_free (pos);
+    return;
+  }
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Looks like `%s' is not running, will start it.\n",
        "gnunet-service-arm");
-#endif
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_string (pos->h->cfg, "arm", "PREFIX",
                                             &loprefix))
@@ -376,33 +363,33 @@
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_string (pos->h->cfg, "arm", "BINARY",
                                             &binary))
-    {
-      LOG (GNUNET_ERROR_TYPE_WARNING,
-          _
-          ("Configuration failes to specify option `%s' in section `%s'!\n"),
-          "BINARY", "arm");
-      if (pos->callback != NULL)
-       pos->callback (pos->cls, GNUNET_ARM_PROCESS_UNKNOWN);
-      GNUNET_free (pos);
-      GNUNET_free (loprefix);
-      GNUNET_free (lopostfix);
-      return;
-    }
+  {
+    LOG (GNUNET_ERROR_TYPE_WARNING,
+        _
+        ("Configuration failes to specify option `%s' in section `%s'!\n"),
+        "BINARY", "arm");
+    if (pos->callback != NULL)
+      pos->callback (pos->cls, GNUNET_ARM_PROCESS_UNKNOWN);
+    GNUNET_free (pos);
+    GNUNET_free (loprefix);
+    GNUNET_free (lopostfix);
+    return;
+  }
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_filename (pos->h->cfg, "arm", "CONFIG",
                                               &config))
-    {
-      LOG (GNUNET_ERROR_TYPE_WARNING,
-          _("Configuration fails to specify option `%s' in section `%s'!\n"),
-          "CONFIG", "arm");
-      if (pos->callback != NULL)
-       pos->callback (pos->cls, GNUNET_ARM_PROCESS_UNKNOWN);
-      GNUNET_free (binary);
-      GNUNET_free (pos);
-      GNUNET_free (loprefix);
-      GNUNET_free (lopostfix);
-      return;
-    }
+  {
+    LOG (GNUNET_ERROR_TYPE_WARNING,
+        _("Configuration fails to specify option `%s' in section `%s'!\n"),
+        "CONFIG", "arm");
+    if (pos->callback != NULL)
+      pos->callback (pos->cls, GNUNET_ARM_PROCESS_UNKNOWN);
+    GNUNET_free (binary);
+    GNUNET_free (pos);
+    GNUNET_free (loprefix);
+    GNUNET_free (lopostfix);
+    return;
+  }
   if ((GNUNET_YES ==
        GNUNET_CONFIGURATION_have_value (pos->h->cfg, "TESTING", "WEAKRANDOM"))
       && (GNUNET_YES ==
@@ -411,26 +398,26 @@
       && (GNUNET_NO ==
          GNUNET_CONFIGURATION_have_value (pos->h->cfg, "TESTING",
                                           "HOSTFILE")))
-    {
-      /* Means we are ONLY running locally */
-      /* we're clearly running a test, don't daemonize */
-      proc = do_start_process (GNUNET_NO,
-                              NULL, loprefix, binary, "-c", config,
+  {
+    /* Means we are ONLY running locally */
+    /* we're clearly running a test, don't daemonize */
+    proc = do_start_process (GNUNET_NO,
+                            NULL, loprefix, binary, "-c", config,
 #if DEBUG_ARM
-                              "-L", "DEBUG",
+                            "-L", "DEBUG",
 #endif
-                              /* no daemonization! */
-                              lopostfix, NULL);
-    }
+                            /* no daemonization! */
+                            lopostfix, NULL);
+  }
   else
-    {
-      proc = do_start_process (GNUNET_NO,
-                              NULL, loprefix, binary, "-c", config,
+  {
+    proc = do_start_process (GNUNET_NO,
+                            NULL, loprefix, binary, "-c", config,
 #if DEBUG_ARM
-                              "-L", "DEBUG",
+                            "-L", "DEBUG",
 #endif
-                              "-d", lopostfix, NULL);
-    }
+                            "-d", lopostfix, NULL);
+  }
   GNUNET_free (binary);
   GNUNET_free (config);
   GNUNET_free (loprefix);
@@ -465,26 +452,24 @@
 
   if ((msg == NULL) ||
       (ntohs (msg->size) != sizeof (struct GNUNET_ARM_ResultMessage)))
-    {
-      LOG (GNUNET_ERROR_TYPE_WARNING,
-          _
-          ("Error receiving response to `%s' request from ARM for service 
`%s'\n"),
-          (sc->type == GNUNET_MESSAGE_TYPE_ARM_START) ? "START" : "STOP",
-          (const char *) &sc[1]);
-      GNUNET_CLIENT_disconnect (sc->h->client);
-      sc->h->client = GNUNET_CLIENT_connect ("arm", sc->h->cfg);
-      GNUNET_assert (NULL != sc->h->client);
-      if (sc->callback != NULL)
-       sc->callback (sc->cls, GNUNET_ARM_PROCESS_COMMUNICATION_ERROR);
-      GNUNET_free (sc);
-      return;
-    }
+  {
+    LOG (GNUNET_ERROR_TYPE_WARNING,
+        _
+        ("Error receiving response to `%s' request from ARM for service 
`%s'\n"),
+        (sc->type == GNUNET_MESSAGE_TYPE_ARM_START) ? "START" : "STOP",
+        (const char *) &sc[1]);
+    GNUNET_CLIENT_disconnect (sc->h->client);
+    sc->h->client = GNUNET_CLIENT_connect ("arm", sc->h->cfg);
+    GNUNET_assert (NULL != sc->h->client);
+    if (sc->callback != NULL)
+      sc->callback (sc->cls, GNUNET_ARM_PROCESS_COMMUNICATION_ERROR);
+    GNUNET_free (sc);
+    return;
+  }
   res = (const struct GNUNET_ARM_ResultMessage *) msg;
-#if DEBUG_ARM
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Received response from ARM for service `%s': %u\n",
        (const char *) &sc[1], ntohs (msg->type));
-#endif
   status = (enum GNUNET_ARM_ProcessStatus) ntohl (res->status);
   if (sc->callback != NULL)
     sc->callback (sc->cls, status);
@@ -514,19 +499,17 @@
   slen = strlen (service_name) + 1;
   if (slen + sizeof (struct GNUNET_MessageHeader) >=
       GNUNET_SERVER_MAX_MESSAGE_SIZE)
-    {
-      GNUNET_break (0);
-      if (cb != NULL)
-       cb (cb_cls, GNUNET_NO);
-      return;
-    }
-#if DEBUG_ARM
+  {
+    GNUNET_break (0);
+    if (cb != NULL)
+      cb (cb_cls, GNUNET_NO);
+    return;
+  }
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        (type ==
        GNUNET_MESSAGE_TYPE_ARM_START) ?
        _("Requesting start of service `%s'.\n") :
        _("Requesting termination of service `%s'.\n"), service_name);
-#endif
   sctx = GNUNET_malloc (sizeof (struct RequestContext) + slen);
   sctx->h = h;
   sctx->callback = cb;
@@ -543,20 +526,19 @@
                                               
GNUNET_TIME_absolute_get_remaining
                                               (sctx->timeout), GNUNET_YES,
                                               &handle_response, sctx))
-    {
-      LOG (GNUNET_ERROR_TYPE_WARNING,
-          (type ==
-           GNUNET_MESSAGE_TYPE_ARM_START) ?
-          _("Error while trying to transmit request to start `%s' to ARM\n")
-          :
-          _("Error while trying to transmit request to stop `%s' to ARM\n"),
-          (const char *) &service_name);
-      if (cb != NULL)
-       cb (cb_cls, GNUNET_SYSERR);
-      GNUNET_free (sctx);
-      GNUNET_free (msg);
-      return;
-    }
+  {
+    LOG (GNUNET_ERROR_TYPE_WARNING,
+        (type ==
+         GNUNET_MESSAGE_TYPE_ARM_START)
+        ? _("Error while trying to transmit request to start `%s' to ARM\n")   
 
+        : _("Error while trying to transmit request to stop `%s' to ARM\n"),
+        (const char *) &service_name);
+    if (cb != NULL)
+      cb (cb_cls, GNUNET_SYSERR);
+    GNUNET_free (sctx);
+    GNUNET_free (msg);
+    return;
+  }
   GNUNET_free (msg);
 }
 
@@ -580,38 +562,36 @@
   struct GNUNET_CLIENT_Connection *client;
   size_t slen;
 
-#if DEBUG_ARM
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        _("Asked to start service `%s' within %llu ms\n"), service_name,
        (unsigned long long) timeout.rel_value);
-#endif
   if (0 == strcasecmp ("arm", service_name))
-    {
-      slen = strlen ("arm") + 1;
-      sctx = GNUNET_malloc (sizeof (struct RequestContext) + slen);
-      sctx->h = h;
-      sctx->callback = cb;
-      sctx->cls = cb_cls;
-      sctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
-      memcpy (&sctx[1], service_name, slen);
-      GNUNET_CLIENT_service_test ("arm", h->cfg, timeout, &arm_service_report,
-                                 sctx);
-      return;
-    }
+  {
+    slen = strlen ("arm") + 1;
+    sctx = GNUNET_malloc (sizeof (struct RequestContext) + slen);
+    sctx->h = h;
+    sctx->callback = cb;
+    sctx->cls = cb_cls;
+    sctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
+    memcpy (&sctx[1], service_name, slen);
+    GNUNET_CLIENT_service_test ("arm", h->cfg, timeout, &arm_service_report,
+                               sctx);
+    return;
+  }
   if (h->client == NULL)
+  {
+    client = GNUNET_CLIENT_connect ("arm", h->cfg);
+    if (client == NULL)
     {
-      client = GNUNET_CLIENT_connect ("arm", h->cfg);
-      if (client == NULL)
-       {
-         LOG (GNUNET_ERROR_TYPE_DEBUG,
-              "arm_api, GNUNET_CLIENT_connect returned NULL\n");
-         cb (cb_cls, GNUNET_ARM_PROCESS_COMMUNICATION_ERROR);
-         return;
-       }
       LOG (GNUNET_ERROR_TYPE_DEBUG,
-          "arm_api, GNUNET_CLIENT_connect returned non-NULL\n");
-      h->client = client;
+          "arm_api, GNUNET_CLIENT_connect returned NULL\n");
+      cb (cb_cls, GNUNET_ARM_PROCESS_COMMUNICATION_ERROR);
+      return;
     }
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+        "arm_api, GNUNET_CLIENT_connect returned non-NULL\n");
+    h->client = client;
+  }
   LOG (GNUNET_ERROR_TYPE_DEBUG, "arm_api, h->client non-NULL\n");
   change_service (h, service_name, timeout, cb, cb_cls,
                  GNUNET_MESSAGE_TYPE_ARM_START);
@@ -658,25 +638,25 @@
   LOG (GNUNET_ERROR_TYPE_INFO, _("Stopping service `%s' within %llu ms\n"),
        service_name, (unsigned long long) timeout.rel_value);
   if (h->client == NULL)
+  {
+    client = GNUNET_CLIENT_connect ("arm", h->cfg);
+    if (client == NULL)
     {
-      client = GNUNET_CLIENT_connect ("arm", h->cfg);
-      if (client == NULL)
-       {
-         cb (cb_cls, GNUNET_SYSERR);
-         return;
-       }
-      h->client = client;
-    }
-  if (0 == strcasecmp ("arm", service_name))
-    {
-      arm_shutdown_ctx = GNUNET_malloc (sizeof (struct ARM_ShutdownContext));
-      arm_shutdown_ctx->cb = cb;
-      arm_shutdown_ctx->cb_cls = cb_cls;
-      arm_service_shutdown (h->client, timeout, &arm_shutdown_callback,
-                           arm_shutdown_ctx);
-      h->client = NULL;
+      cb (cb_cls, GNUNET_SYSERR);
       return;
     }
+    h->client = client;
+  }
+  if (0 == strcasecmp ("arm", service_name))
+  {
+    arm_shutdown_ctx = GNUNET_malloc (sizeof (struct ARM_ShutdownContext));
+    arm_shutdown_ctx->cb = cb;
+    arm_shutdown_ctx->cb_cls = cb_cls;
+    arm_service_shutdown (h->client, timeout, &arm_shutdown_callback,
+                         arm_shutdown_ctx);
+    h->client = NULL;
+    return;
+  }
   change_service (h, service_name, timeout, cb, cb_cls,
                  GNUNET_MESSAGE_TYPE_ARM_STOP);
 }
@@ -799,21 +779,21 @@
   struct GNUNET_MessageHeader msg;
   struct GNUNET_CLIENT_Connection *client;
   
-    if (h->client == NULL)
+  if (h->client == NULL)
+  {
+    client = GNUNET_CLIENT_connect ("arm", h->cfg);
+    if (client == NULL)
     {
-      client = GNUNET_CLIENT_connect ("arm", h->cfg);
-      if (client == NULL)
-        {
-          LOG (GNUNET_ERROR_TYPE_DEBUG,
-               "arm_api, GNUNET_CLIENT_connect returned NULL\n");
-          cb (cb_cls, GNUNET_ARM_PROCESS_COMMUNICATION_ERROR, 0, NULL);
-          return;
-        }
       LOG (GNUNET_ERROR_TYPE_DEBUG,
-           "arm_api, GNUNET_CLIENT_connect returned non-NULL\n");
-      h->client = client;
+          "arm_api, GNUNET_CLIENT_connect returned NULL\n");
+      cb (cb_cls, GNUNET_ARM_PROCESS_COMMUNICATION_ERROR, 0, NULL);
+      return;
     }
-
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+        "arm_api, GNUNET_CLIENT_connect returned non-NULL\n");
+    h->client = client;
+  }
+  
   sctx = GNUNET_malloc (sizeof (struct RequestContext));
   sctx->h = h;
   sctx->callback = cb;
@@ -826,7 +806,7 @@
        "Requesting LIST from ARM service with timeout: %llu ms\n", 
        (unsigned long long)timeout.rel_value);
   
-    if (GNUNET_OK !=
+  if (GNUNET_OK !=
       GNUNET_CLIENT_transmit_and_get_response (sctx->h->client, 
                                                &msg,
                                                
GNUNET_TIME_absolute_get_remaining
@@ -834,14 +814,14 @@
                                                GNUNET_YES,
                                                &handle_list_response, 
                                                sctx))
-    {
-      LOG (GNUNET_ERROR_TYPE_WARNING, 
-           "Error while trying to transmit request to list services to ARM\n");
-      if (cb != NULL)
-        cb (cb_cls, GNUNET_SYSERR, 0, NULL);
-      GNUNET_free (sctx);
-      return;
-    }
+  {
+    LOG (GNUNET_ERROR_TYPE_WARNING, 
+        "Error while trying to transmit request to list services to ARM\n");
+    if (cb != NULL)
+      cb (cb_cls, GNUNET_SYSERR, 0, NULL);
+    GNUNET_free (sctx);
+    return;
+  }
 }
 
 /* end of arm_api.c */

Modified: gnunet/src/arm/gnunet-service-arm.c
===================================================================
--- gnunet/src/arm/gnunet-service-arm.c 2012-04-19 17:10:46 UTC (rev 21041)
+++ gnunet/src/arm/gnunet-service-arm.c 2012-04-19 18:51:22 UTC (rev 21042)
@@ -314,11 +314,9 @@
   use_debug = GNUNET_CONFIGURATION_get_value_yesno (cfg, sl->name, "DEBUG");
 
   /* actually start process */
-#if DEBUG_ARM
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Starting service `%s' using binary `%s' and configuration 
`%s'\n",
              sl->name, sl->binary, sl->config);
-#endif
   GNUNET_assert (NULL == sl->proc);
   if (GNUNET_YES == use_debug)
     sl->proc =
@@ -363,10 +361,8 @@
                _("Could not send status result to client\n"));
     return 0;                  /* error, not much we can do */
   }
-#if DEBUG_ARM
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Sending status response %u to client\n", (unsigned int) *res);
-#endif
   GNUNET_assert (size >= sizeof (struct GNUNET_ARM_ResultMessage));
   msg = buf;
   msg->header.size = htons (sizeof (struct GNUNET_ARM_ResultMessage));
@@ -695,11 +691,9 @@
       signal_result (client, servicename, GNUNET_ARM_PROCESS_ALREADY_DOWN);
       return;
     }
-#if DEBUG_ARM
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Sending kill signal to service `%s', waiting for process to 
die.\n",
              servicename);
-#endif
   sl->killed_at = GNUNET_TIME_absolute_get ();
   if (0 != GNUNET_OS_process_kill (sl->proc, SIGTERM))
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
@@ -799,47 +793,47 @@
   struct ServiceListeningInfo *sli;
 
   if (GNUNET_SCHEDULER_NO_TASK != child_restart_task)
-    {
-      GNUNET_SCHEDULER_cancel (child_restart_task);
-      child_restart_task = GNUNET_SCHEDULER_NO_TASK;
-    }
+  {
+    GNUNET_SCHEDULER_cancel (child_restart_task);
+    child_restart_task = GNUNET_SCHEDULER_NO_TASK;
+  }
   in_shutdown = GNUNET_YES;
   /* first, stop listening */
   for (pos = running_head; NULL != pos; pos = pos->next)
-    {
-      while (NULL != (sli = pos->listen_head))
-       {
-         GNUNET_CONTAINER_DLL_remove (pos->listen_head,
-                                      pos->listen_tail, sli);
-         if (sli->accept_task != GNUNET_SCHEDULER_NO_TASK)
-           {
-             GNUNET_SCHEDULER_cancel (sli->accept_task);
-             sli->accept_task = GNUNET_SCHEDULER_NO_TASK;
-           }
-         GNUNET_break (GNUNET_OK ==
-                       GNUNET_NETWORK_socket_close (sli->listen_socket));
-         GNUNET_free (sli->service_addr);
-         GNUNET_free (sli);
-       }
-    }
+  {
+    while (NULL != (sli = pos->listen_head))
+      {
+       GNUNET_CONTAINER_DLL_remove (pos->listen_head,
+                                    pos->listen_tail, sli);
+       if (sli->accept_task != GNUNET_SCHEDULER_NO_TASK)
+         {
+           GNUNET_SCHEDULER_cancel (sli->accept_task);
+           sli->accept_task = GNUNET_SCHEDULER_NO_TASK;
+         }
+       GNUNET_break (GNUNET_OK ==
+                     GNUNET_NETWORK_socket_close (sli->listen_socket));
+       GNUNET_free (sli->service_addr);
+       GNUNET_free (sli);
+      }
+  }
   /* then, shutdown all existing service processes */
   nxt = running_head;
   while (NULL != (pos = nxt))
+  {
+    nxt = pos->next;
+    if (pos->proc != NULL)
     {
-      nxt = pos->next;
-      if (pos->proc != NULL)
-       {
-         GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stopping service `%s'\n",
-                     pos->name);
-         pos->killed_at = GNUNET_TIME_absolute_get ();
-         if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM))
-           GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
-       }
-      else
-       {
-         free_service (pos);
-       }
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stopping service `%s'\n",
+                 pos->name);
+      pos->killed_at = GNUNET_TIME_absolute_get ();
+      if (0 != GNUNET_OS_process_kill (pos->proc, SIGTERM))
+       GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
     }
+    else
+    {
+      free_service (pos);
+    }
+  }
   /* finally, should all service processes be already gone, terminate for real 
*/
   if (running_head == NULL)
     do_shutdown ();
@@ -869,56 +863,53 @@
   /* check for services that need to be restarted due to
    * configuration changes or because the last restart failed */
   for (sl = running_head; NULL != sl; sl = sl->next)
+  {
+    if (NULL != sl->proc)
+      continue;
+    /* service is currently not running */
+    if (GNUNET_TIME_absolute_get_remaining (sl->restart_at).rel_value ==
+       0)
     {
-      if (sl->proc == NULL)
-       {
-         /* service is currently not running */
-         if (GNUNET_TIME_absolute_get_remaining (sl->restart_at).rel_value ==
-             0)
-           {
-             /* restart is now allowed */
-             if (sl->is_default)
-               {
-                 /* process should run by default, start immediately */
-                 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                             _("Restarting service `%s'.\n"), sl->name);
-                 start_process (sl);
-               }
-             else
-               {
-                 /* process is run on-demand, ensure it is re-started if there 
is demand */
-                 for (sli = sl->listen_head; NULL != sli; sli = sli->next)
-                   if (GNUNET_SCHEDULER_NO_TASK == sli->accept_task)
-                     {
-                       /* accept was actually paused, so start it again */
-                       sli->accept_task =
-                         GNUNET_SCHEDULER_add_read_net
-                         (GNUNET_TIME_UNIT_FOREVER_REL, sli->listen_socket,
-                          &accept_connection, sli);
-                     }
-               }
-           }
-         else
-           {
-             /* update calculation for earliest time to reactivate a service */
-             lowestRestartDelay =
-               GNUNET_TIME_relative_min (lowestRestartDelay,
-                                         GNUNET_TIME_absolute_get_remaining
-                                         (sl->restart_at));
-           }
-       }
+      /* restart is now allowed */
+      if (sl->is_default)
+      {
+       /* process should run by default, start immediately */
+       GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                   _("Restarting service `%s'.\n"), sl->name);
+       start_process (sl);
+      }
+      else
+      {
+       /* process is run on-demand, ensure it is re-started if there is demand 
*/
+       for (sli = sl->listen_head; NULL != sli; sli = sli->next)
+         if (GNUNET_SCHEDULER_NO_TASK == sli->accept_task)
+         {
+           /* accept was actually paused, so start it again */
+           sli->accept_task =
+             GNUNET_SCHEDULER_add_read_net
+             (GNUNET_TIME_UNIT_FOREVER_REL, sli->listen_socket,
+              &accept_connection, sli);
+         }
+      }
     }
-  if (lowestRestartDelay.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
+    else
     {
-#if DEBUG_ARM
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Will restart process in %llums\n",
-                 (unsigned long long) lowestRestartDelay.rel_value);
-#endif
-      child_restart_task =
-       GNUNET_SCHEDULER_add_delayed_with_priority (lowestRestartDelay,
-                                                   
GNUNET_SCHEDULER_PRIORITY_IDLE, 
-                                                   &delayed_restart_task, 
NULL);
+      /* update calculation for earliest time to reactivate a service */
+      lowestRestartDelay =
+       GNUNET_TIME_relative_min (lowestRestartDelay,
+                                 GNUNET_TIME_absolute_get_remaining
+                                 (sl->restart_at));
     }
+  }
+  if (lowestRestartDelay.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Will restart process in %llums\n",
+               (unsigned long long) lowestRestartDelay.rel_value);
+    child_restart_task =
+      GNUNET_SCHEDULER_add_delayed_with_priority (lowestRestartDelay,
+                                                 
GNUNET_SCHEDULER_PRIORITY_IDLE, 
+                                                 &delayed_restart_task, NULL);
+  }
 }
 
 

Modified: gnunet/src/arm/test_exponential_backoff.c
===================================================================
--- gnunet/src/arm/test_exponential_backoff.c   2012-04-19 17:10:46 UTC (rev 
21041)
+++ gnunet/src/arm/test_exponential_backoff.c   2012-04-19 18:51:22 UTC (rev 
21042)
@@ -113,59 +113,47 @@
 {
   struct ShutdownContext *shutdown_ctx = cls;
 
-  if ((msg == NULL) && (shutdown_ctx->confirmed != GNUNET_YES))
-    {
-      /* Means the other side closed the connection and never confirmed a 
shutdown */
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                 "Service handle shutdown before ACK!\n");
-      if (shutdown_ctx->cont != NULL)
-       shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_SYSERR);
-      GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task);
-      GNUNET_CLIENT_disconnect (shutdown_ctx->sock);
-      GNUNET_free (shutdown_ctx);
-    }
-  else if ((msg == NULL) && (shutdown_ctx->confirmed == GNUNET_YES))
-    {
+  if (msg == NULL) 
+  {
 #if VERBOSE
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service shutdown complete.\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service shutdown complete.\n");
 #endif
-      if (shutdown_ctx->cont != NULL)
-       shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_NO);
-
-      GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task);
-      GNUNET_CLIENT_disconnect (shutdown_ctx->sock);
-      GNUNET_free (shutdown_ctx);
-    }
-  else
-    {
-      GNUNET_assert (ntohs (msg->size) ==
-                    sizeof (struct GNUNET_MessageHeader));
-      switch (ntohs (msg->type))
-       {
-       case GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN:
+    if (shutdown_ctx->cont != NULL)
+      shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_NO);
+    
+    GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task);
+    GNUNET_CLIENT_disconnect (shutdown_ctx->sock);
+    GNUNET_free (shutdown_ctx);
+    return;
+  }
+  GNUNET_assert (ntohs (msg->size) ==
+                sizeof (struct GNUNET_MessageHeader));
+  switch (ntohs (msg->type))
+  {
+  case GNUNET_MESSAGE_TYPE_ARM_SHUTDOWN:
 #if VERBOSE
-         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                     "Received confirmation for service shutdown.\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+               "Received confirmation for service shutdown.\n");
 #endif
-         shutdown_ctx->confirmed = GNUNET_YES;
-         GNUNET_CLIENT_receive (shutdown_ctx->sock,
-                                &service_shutdown_handler, shutdown_ctx,
-                                GNUNET_TIME_UNIT_FOREVER_REL);
-         break;
-       default:                /* Fall through */
-         GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                     "Service shutdown refused!\n");
-         if (shutdown_ctx->cont != NULL)
-           shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_YES);
-
-         GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task);
-         GNUNET_CLIENT_disconnect (shutdown_ctx->sock);
-         GNUNET_free (shutdown_ctx);
-         break;
-       }
-    }
+    shutdown_ctx->confirmed = GNUNET_YES;
+    GNUNET_CLIENT_receive (shutdown_ctx->sock,
+                          &service_shutdown_handler, shutdown_ctx,
+                          GNUNET_TIME_UNIT_FOREVER_REL);
+    break;
+  default:             /* Fall through */
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+               "Service shutdown refused!\n");
+    if (shutdown_ctx->cont != NULL)
+      shutdown_ctx->cont (shutdown_ctx->cont_cls, GNUNET_YES);
+    
+    GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task);
+    GNUNET_CLIENT_disconnect (shutdown_ctx->sock);
+    GNUNET_free (shutdown_ctx);
+    break;
+  }
 }
 
+
 /**
  * Shutting down took too long, cancel receive and return error.
  *




reply via email to

[Prev in Thread] Current Thread [Next in Thread]