-remove trailing whitespace
[oweals/gnunet.git] / src / arm / gnunet-service-arm.c
index 1acb82f72fb5fdf0a372f9c9ced4cecb9f1f6b34..1196b20aa7242716a4bc1910348684d70a92a9c0 100644 (file)
@@ -240,10 +240,10 @@ static struct GNUNET_SERVER_NotificationContext *notifier;
 /**
  * Transmit a status result message.
  *
- * @param cls pointer to "unit16_t*" with message type
- * @param size number of bytes available in buf
+ * @param cls a `unit16_t *` with message type
+ * @param size number of bytes available in @a buf
  * @param buf where to copy the message, NULL on error
- * @return number of bytes copied to buf
+ * @return number of bytes copied to @a buf
  */
 static size_t
 write_result (void *cls, size_t size, void *buf)
@@ -259,7 +259,8 @@ write_result (void *cls, size_t size, void *buf)
     return 0;                  /* error, not much we can do */
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Sending status response %u to client\n", (unsigned int) msg->result);
+             "Sending status response %u to client\n",
+             (unsigned int) msg->result);
   msize = msg->arm_msg.header.size;
   GNUNET_assert (size >= msize);
   msg->arm_msg.header.size = htons (msg->arm_msg.header.size);
@@ -271,20 +272,21 @@ write_result (void *cls, size_t size, void *buf)
   return msize;
 }
 
+
 /**
  * Transmit the list of running services.
- * 
- * @param cls pointer to struct GNUNET_ARM_ListResultMessage with the message
- * @param size number of bytes available in buf
+ *
+ * @param cls pointer to `struct GNUNET_ARM_ListResultMessage` with the message
+ * @param size number of bytes available in @a buf
  * @param buf where to copy the message, NULL on error
- * @return number of bytes copied to buf
+ * @return number of bytes copied to @a buf
  */
 static size_t
 write_list_result (void *cls, size_t size, void *buf)
 {
   struct GNUNET_ARM_ListResultMessage *msg = cls;
   size_t rslt_size;
-  
+
   if (buf == NULL)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -292,14 +294,14 @@ write_list_result (void *cls, size_t size, void *buf)
     GNUNET_free (msg);
     return 0;                   /* error, not much we can do */
   }
-  
+
   rslt_size = msg->arm_msg.header.size;
   GNUNET_assert (size >= rslt_size);
   msg->arm_msg.header.size = htons (msg->arm_msg.header.size);
   msg->arm_msg.header.type = htons (msg->arm_msg.header.type);
   msg->arm_msg.request_id = GNUNET_htonll (msg->arm_msg.request_id);
   msg->count = htons (msg->count);
-  
+
   memcpy (buf, msg, rslt_size);
   GNUNET_free (msg);
   return rslt_size;
@@ -317,8 +319,10 @@ write_list_result (void *cls, size_t size, void *buf)
  * @return NULL if it was not found
  */
 static void
-signal_result (struct GNUNET_SERVER_Client *client, const char *name,
-              uint64_t request_id, enum GNUNET_ARM_Result result)
+signal_result (struct GNUNET_SERVER_Client *client,
+              const char *name,
+              uint64_t request_id,
+              enum GNUNET_ARM_Result result)
 {
   struct GNUNET_ARM_ResultMessage *msg;
   size_t msize;
@@ -331,7 +335,8 @@ signal_result (struct GNUNET_SERVER_Client *client, const char *name,
   msg->arm_msg.request_id = request_id;
 
   GNUNET_SERVER_notify_transmit_ready (client, msize,
-      GNUNET_TIME_UNIT_FOREVER_REL, write_result, msg);
+                                      GNUNET_TIME_UNIT_FOREVER_REL,
+                                      write_result, msg);
 }
 
 
@@ -344,8 +349,9 @@ signal_result (struct GNUNET_SERVER_Client *client, const char *name,
  *                otherwise, send to all clients in the notifier
  */
 static void
-broadcast_status (const char *name, enum GNUNET_ARM_ServiceStatus status,
-    struct GNUNET_SERVER_Client *unicast)
+broadcast_status (const char *name,
+                 enum GNUNET_ARM_ServiceStatus status,
+                 struct GNUNET_SERVER_Client *unicast)
 {
   struct GNUNET_ARM_StatusMessage *msg;
   size_t namelen;
@@ -486,7 +492,7 @@ start_process (struct ServiceList *sl, struct GNUNET_SERVER_Client *client, uint
     if (NULL == sl->config)
       sl->proc =
        do_start_process (sl->pipe_control, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
-                         lsocks, loprefix, binary, 
+                         lsocks, loprefix, binary,
                          options, NULL);
     else
       sl->proc =
@@ -544,7 +550,7 @@ find_service (const char *name)
  * First connection has come to the listening socket associated with the service,
  * create the service in order to relay the incoming connection to it
  *
- * @param cls callback data, struct ServiceListeningInfo describing a listen socket
+ * @param cls callback data, `struct ServiceListeningInfo` describing a listen socket
  * @param tc context
  */
 static void
@@ -566,7 +572,7 @@ accept_connection (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * wait for the first incoming connection to it
  *
  * @param sa address associated with the service
- * @param addr_len length of sa
+ * @param addr_len length of @a sa
  * @param sl service entry for the service in question
  */
 static void
@@ -674,8 +680,8 @@ free_service (struct ServiceList *sl)
  * @param cls closure (always NULL)
  * @param client identification of the client
  * @param message the actual message
- * @return GNUNET_OK to keep the connection open,
- *         GNUNET_SYSERR to close it (signal serious error)
+ * @return #GNUNET_OK to keep the connection open,
+ *         #GNUNET_SYSERR to close it (signal serious error)
  */
 static void
 handle_start (void *cls, struct GNUNET_SERVER_Client *client,
@@ -687,7 +693,7 @@ handle_start (void *cls, struct GNUNET_SERVER_Client *client,
   uint64_t request_id;
   struct GNUNET_ARM_Message *amsg;
 
-  amsg = (struct GNUNET_ARM_Message *) message;  
+  amsg = (struct GNUNET_ARM_Message *) message;
   request_id = GNUNET_ntohll (amsg->request_id);
   size = ntohs (amsg->header.size);
   size -= sizeof (struct GNUNET_ARM_Message);
@@ -743,8 +749,8 @@ trigger_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * @param cls closure (always NULL)
  * @param client identification of the client
  * @param message the actual message
- * @return GNUNET_OK to keep the connection open,
- *         GNUNET_SYSERR to close it (signal serious error)
+ * @return #GNUNET_OK to keep the connection open,
+ *         #GNUNET_SYSERR to close it (signal serious error)
  */
 static void
 handle_stop (void *cls, struct GNUNET_SERVER_Client *client,
@@ -756,7 +762,7 @@ handle_stop (void *cls, struct GNUNET_SERVER_Client *client,
   uint64_t request_id;
   struct GNUNET_ARM_Message *amsg;
 
-  amsg = (struct GNUNET_ARM_Message *) message;  
+  amsg = (struct GNUNET_ARM_Message *) message;
   request_id = GNUNET_ntohll (amsg->request_id);
   size = ntohs (amsg->header.size);
   size -= sizeof (struct GNUNET_ARM_Message);
@@ -823,6 +829,7 @@ handle_stop (void *cls, struct GNUNET_SERVER_Client *client,
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
 
+
 /**
  * Handle LIST-message.
  *
@@ -840,10 +847,10 @@ handle_list (void *cls, struct GNUNET_SERVER_Client *client,
   size_t total_size;
   struct ServiceList *sl;
   uint16_t count;
-  
+
   if (NULL == client)
     return;
-  
+
   request = (struct GNUNET_ARM_Message *) message;
   count = 0;
   string_list_size = 0;
@@ -859,16 +866,16 @@ handle_list (void *cls, struct GNUNET_SERVER_Client *client,
     }
   }
 
-  total_size = sizeof (struct GNUNET_ARM_ListResultMessage) 
+  total_size = sizeof (struct GNUNET_ARM_ListResultMessage)
                + string_list_size;
   msg = GNUNET_malloc (total_size);
   msg->arm_msg.header.size = total_size;
   msg->arm_msg.header.type = GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT;
   msg->arm_msg.request_id = GNUNET_ntohll (request->request_id);
   msg->count = count;
-  
+
   char *pos = (char *)&msg[1];
-  for (sl = running_head; sl != NULL; sl = sl->next) 
+  for (sl = running_head; sl != NULL; sl = sl->next)
   {
     if (sl->proc != NULL)
     {
@@ -877,7 +884,7 @@ handle_list (void *cls, struct GNUNET_SERVER_Client *client,
       pos += s;
     }
   }
-  
+
   GNUNET_SERVER_notify_transmit_ready (client,
                                        total_size,
                                        GNUNET_TIME_UNIT_FOREVER_REL,
@@ -885,6 +892,7 @@ handle_list (void *cls, struct GNUNET_SERVER_Client *client,
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
 
+
 /**
  * We are done with everything.  Stop remaining
  * tasks, signal handler and the server.
@@ -910,16 +918,21 @@ do_shutdown ()
     }
 }
 
-unsigned int
+
+static unsigned int
 list_count (struct ServiceList *running_head)
 {
   struct ServiceList *i;
   unsigned int res = 0;
+
   for (res = 0, i = running_head; i; i = i->next, res++)
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s\n", i->name);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+               "%s\n",
+               i->name);
   return res;
 }
 
+
 /**
  * Task run for shutdown.
  *
@@ -933,7 +946,8 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   struct ServiceList *nxt;
   struct ServiceListeningInfo *sli;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "First shutdown phase\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "First shutdown phase\n");
   if (GNUNET_SCHEDULER_NO_TASK != child_restart_task)
   {
     GNUNET_SCHEDULER_cancel (child_restart_task);
@@ -965,7 +979,8 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     nxt = pos->next;
     if (pos->proc != NULL)
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stopping service `%s'\n",
+      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))
@@ -981,7 +996,8 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     do_shutdown ();
   else
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-        "Delaying shutdown, have %u childs still running\n", list_count (running_head));
+               "Delaying shutdown, have %u childs still running\n",
+               list_count (running_head));
 }
 
 
@@ -1012,8 +1028,7 @@ delayed_restart_task (void *cls,
     if (NULL != sl->proc)
       continue;
     /* service is currently not running */
-    if (GNUNET_TIME_absolute_get_remaining (sl->restart_at).rel_value ==
-       0)
+    if (0 == GNUNET_TIME_absolute_get_remaining (sl->restart_at).rel_value_us)
     {
       /* restart is now allowed */
       if (sl->is_default)
@@ -1046,14 +1061,14 @@ delayed_restart_task (void *cls,
                                  (sl->restart_at));
     }
   }
-  if (lowestRestartDelay.rel_value != GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
+  if (lowestRestartDelay.rel_value_us != GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "Will restart process in %s\n",
                GNUNET_STRINGS_relative_time_to_string (lowestRestartDelay, GNUNET_YES));
     child_restart_task =
       GNUNET_SCHEDULER_add_delayed_with_priority (lowestRestartDelay,
-                                                 GNUNET_SCHEDULER_PRIORITY_IDLE, 
+                                                 GNUNET_SCHEDULER_PRIORITY_IDLE,
                                                  &delayed_restart_task, NULL);
   }
 }
@@ -1126,7 +1141,7 @@ maint_child_death (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
        statstr = _( /* process termination method */ "unknown");
        statcode = 0;
       }
-      if (0 != pos->killed_at.abs_value)
+      if (0 != pos->killed_at.abs_value_us)
       {
        GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                    _("Service `%s' took %s to terminate\n"),
@@ -1149,7 +1164,7 @@ maint_child_death (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
         if ((statusType == GNUNET_OS_PROCESS_EXITED) && (statcode == 0))
         {
           /* process terminated normally, allow restart at any time */
-          pos->restart_at.abs_value = 0;
+          pos->restart_at.abs_value_us = 0;
           GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               _("Service `%s' terminated normally, will restart at any time\n"),
               pos->name);
@@ -1219,7 +1234,7 @@ sighandler_child_death ()
  *
  * @param cls unused
  * @param section a section in the configuration file
- * @return GNUNET_OK (continue)
+ * @return #GNUNET_OK (continue)
  */
 static void
 setup_service (void *cls, const char *section)
@@ -1260,14 +1275,14 @@ setup_service (void *cls, const char *section)
   {
     if (NULL != config)
     {
-      GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_WARNING, 
+      GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_WARNING,
                                 section, "CONFIG",
                                 STRERROR (errno));
       GNUNET_free (config);
       config = NULL;
     }
   }
-  sl = GNUNET_malloc (sizeof (struct ServiceList));
+  sl = GNUNET_new (struct ServiceList);
   sl->name = GNUNET_strdup (section);
   sl->binary = binary;
   sl->config = config;
@@ -1278,7 +1293,7 @@ setup_service (void *cls, const char *section)
 #else
   if (GNUNET_CONFIGURATION_have_value (cfg, section, "PIPECONTROL"))
     sl->pipe_control = GNUNET_CONFIGURATION_get_value_yesno (cfg, section, "PIPECONTROL");
-#endif  
+#endif
   GNUNET_CONTAINER_DLL_insert (running_head, running_tail, sl);
   if (GNUNET_YES !=
       GNUNET_CONFIGURATION_get_value_yesno (cfg, section, "AUTOSTART"))
@@ -1310,14 +1325,15 @@ handle_client_connecting (void *cls, struct GNUNET_SERVER_Client *client)
     GNUNET_SERVER_client_mark_monitor (client);
 }
 
+
 /**
  * Handle MONITOR-message.
  *
  * @param cls closure (always NULL)
  * @param client identification of the client
  * @param message the actual message
- * @return GNUNET_OK to keep the connection open,
- *         GNUNET_SYSERR to close it (signal serious error)
+ * @return #GNUNET_OK to keep the connection open,
+ *         #GNUNET_SYSERR to close it (signal serious error)
  */
 static void
 handle_monitor (void *cls, struct GNUNET_SERVER_Client *client,
@@ -1332,6 +1348,7 @@ handle_monitor (void *cls, struct GNUNET_SERVER_Client *client,
   }
 }
 
+
 /**
  * Process arm requests.
  *
@@ -1346,9 +1363,9 @@ run (void *cls, struct GNUNET_SERVER_Handle *serv,
   static const struct GNUNET_SERVER_MessageHandler handlers[] = {
     {&handle_start, NULL, GNUNET_MESSAGE_TYPE_ARM_START, 0},
     {&handle_stop, NULL, GNUNET_MESSAGE_TYPE_ARM_STOP, 0},
-    {&handle_monitor, NULL, GNUNET_MESSAGE_TYPE_ARM_MONITOR, 
+    {&handle_monitor, NULL, GNUNET_MESSAGE_TYPE_ARM_MONITOR,
      sizeof (struct GNUNET_MessageHeader)},
-    {&handle_list, NULL, GNUNET_MESSAGE_TYPE_ARM_LIST, 
+    {&handle_list, NULL, GNUNET_MESSAGE_TYPE_ARM_LIST,
      sizeof (struct GNUNET_ARM_Message)},
     {NULL, NULL, 0, 0}
   };
@@ -1439,7 +1456,7 @@ main (int argc, char *const *argv)
     GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death);
   ret =
     (GNUNET_OK ==
-     GNUNET_SERVICE_run (argc, argv, "arm", 
+     GNUNET_SERVICE_run (argc, argv, "arm",
                         GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN, &run, NULL)) ? 0 : 1;
   GNUNET_SIGNAL_handler_uninstall (shc_chld);
   shc_chld = NULL;