-extending defaults
[oweals/gnunet.git] / src / arm / gnunet-service-arm.c
index cfe164fa6bf2112980b25cf391d644e61ad0e2ba..091d5ae54550f0e8b99d833c8250abc41a26ab34 100644 (file)
@@ -145,6 +145,12 @@ struct ServiceList
    */
   struct GNUNET_TIME_Absolute restart_at;
 
+  /**
+   * Time we asked the service to shut down (used to calculate time it took
+   * the service to terminate).
+   */
+  struct GNUNET_TIME_Absolute killed_at;
+
   /**
    * Is this service to be started by default (or did a client tell us explicitly
    * to start it)?  GNUNET_NO if the service is started only upon 'accept' on a
@@ -694,6 +700,7 @@ handle_stop (void *cls, struct GNUNET_SERVER_Client *client,
              "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");
   sl->killing_client = client;
@@ -728,8 +735,8 @@ handle_list (void *cls, struct GNUNET_SERVER_Client *client,
     if (sl->proc != NULL)
     {
       string_list_size += strlen (sl->name);
-      string_list_size += 3;
-      string_list_size += strlen (sl->binary) + 1;
+      string_list_size += strlen (sl->binary);
+      string_list_size += 4;
       count++;
     }
   }
@@ -745,9 +752,8 @@ handle_list (void *cls, struct GNUNET_SERVER_Client *client,
   {
     if (sl->proc != NULL)
     {
-      //memcpy (pos, sl->name, strlen (sl->name) + 1);
       size_t s = strlen (sl->name) + strlen (sl->binary) + 4;
-      snprintf(pos, s, "%s (%s)", sl->name, sl->binary);
+      GNUNET_snprintf(pos, s, "%s (%s)", sl->name, sl->binary);
       pos += s;
     }
   }
@@ -825,6 +831,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
        {
          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");
        }
@@ -956,11 +963,11 @@ maint_child_death (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
       next = pos->next;
 
       if (pos->proc == NULL)
-       {
-         if (GNUNET_YES == in_shutdown)
-           free_service (pos);
-         continue;
-       }
+      {
+       if (GNUNET_YES == in_shutdown)
+         free_service (pos);
+       continue;
+      }
       if ((GNUNET_SYSERR ==
           (ret =
            GNUNET_OS_process_status (pos->proc, &statusType, &statusCode)))
@@ -968,20 +975,27 @@ maint_child_death (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
              || (statusType == GNUNET_OS_PROCESS_RUNNING)))
        continue;
       if (statusType == GNUNET_OS_PROCESS_EXITED)
-       {
-         statstr = _( /* process termination method */ "exit");
-         statcode = statusCode;
-       }
+      {
+       statstr = _( /* process termination method */ "exit");
+       statcode = statusCode;
+      }
       else if (statusType == GNUNET_OS_PROCESS_SIGNALED)
-       {
-         statstr = _( /* process termination method */ "signal");
-         statcode = statusCode;
-       }
+      {
+       statstr = _( /* process termination method */ "signal");
+       statcode = statusCode;
+      }
       else
-       {
-         statstr = _( /* process termination method */ "unknown");
-         statcode = 0;
-       }
+      {
+       statstr = _( /* process termination method */ "unknown");
+       statcode = 0;
+      }
+      if (0 != pos->killed_at.abs_value)
+      {
+       GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                   _("Service `%s' took %llu ms to terminate\n"),
+                   pos->name,
+                   GNUNET_TIME_absolute_get_duration (pos->killed_at).rel_value);
+      }
       GNUNET_OS_process_close (pos->proc);
       pos->proc = NULL;
       if (NULL != pos->killing_client)