use c99
[oweals/gnunet.git] / src / arm / arm_api.c
index 116b3a5171d2272608d5cc6a2fe5290bc49837aa..5fb2a811a9cefde27bbb4f361b7d2c4a0bd2e933 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2009, 2010, 2012, 2013 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2009, 2010, 2012, 2013 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -14,8 +14,8 @@
 
      You should have received a copy of the GNU General Public License
      along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
 */
 
 /**
@@ -25,8 +25,8 @@
  * @author LRN
  */
 #include "platform.h"
-#include "gnunet_arm_service.h"
 #include "gnunet_util_lib.h"
+#include "gnunet_arm_service.h"
 #include "gnunet_protocols.h"
 #include "arm.h"
 
@@ -91,7 +91,7 @@ struct GNUNET_ARM_Handle
   /**
    * ID of the reconnect task (if any).
    */
-  GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
+  struct GNUNET_SCHEDULER_Task *reconnect_task;
 
   /**
    * Current delay we use for re-trying to connect to core.
@@ -109,7 +109,7 @@ struct GNUNET_ARM_Handle
   unsigned char currently_down;
 
   /**
-   * GNUNET_YES if we're running a service test.
+   * #GNUNET_YES if we're running a service test.
    */
   unsigned char service_test_is_active;
 };
@@ -154,7 +154,7 @@ struct ARMControlMessage
   GNUNET_ARM_ServiceListCallback list_cont;
 
   /**
-   * Closure for 'result_cont' or 'list_cont'.
+   * Closure for @e result_cont' or @e list_cont'.
    */
   void *cont_cls;
 
@@ -166,7 +166,7 @@ struct ARMControlMessage
   /**
    * Task to run when request times out.
    */
-  GNUNET_SCHEDULER_TaskIdentifier timeout_task_id;
+  struct GNUNET_SCHEDULER_Task * timeout_task_id;
 
   /**
    * Flags for passing std descriptors to ARM (when starting ARM).
@@ -184,7 +184,7 @@ struct ARMControlMessage
  * Connect to arm.
  *
  * @param h arm handle
- * @return GNUNET_OK on success, GNUNET_SYSERR on failure
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
  */
 static int
 reconnect_arm (struct GNUNET_ARM_Handle *h);
@@ -205,14 +205,13 @@ trigger_next_request (struct GNUNET_ARM_Handle *h, int ignore_currently_down);
  * Task scheduled to try to re-connect to arm.
  *
  * @param cls the 'struct GNUNET_ARM_Handle'
- * @param tc task context
  */
 static void
-reconnect_arm_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+reconnect_arm_task (void *cls)
 {
   struct GNUNET_ARM_Handle *h = cls;
 
-  h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
+  h->reconnect_task = NULL;
   LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to ARM service after delay\n");
   reconnect_arm (h);
 }
@@ -240,10 +239,12 @@ reconnect_arm_later (struct GNUNET_ARM_Handle *h)
     h->client = NULL;
   }
   h->currently_down = GNUNET_YES;
-  GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->reconnect_task);
+  GNUNET_assert (NULL == h->reconnect_task);
   h->reconnect_task =
-      GNUNET_SCHEDULER_add_delayed (h->retry_backoff, &reconnect_arm_task, h);
-  /* Don't clear pending messages on disconnection, deliver them later 
+      GNUNET_SCHEDULER_add_delayed (h->retry_backoff,
+                                   &reconnect_arm_task,
+                                   h);
+  /* Don't clear pending messages on disconnection, deliver them later
   clear_pending_messages (h, GNUNET_ARM_REQUEST_DISCONNECTED);
   GNUNET_assert (NULL == h->control_pending_head);
   */
@@ -285,7 +286,7 @@ arm_termination_handler (void *cls, const struct GNUNET_MessageHeader *msg)
 
   if (NULL != msg)
   {
-    GNUNET_break (0);   
+    GNUNET_break (0);
     GNUNET_CLIENT_receive (h->client, &arm_termination_handler, h,
                           GNUNET_TIME_UNIT_FOREVER_REL);
     return;
@@ -296,10 +297,10 @@ arm_termination_handler (void *cls, const struct GNUNET_MessageHeader *msg)
   GNUNET_CLIENT_disconnect (h->client);
   h->client = NULL;
   if (NULL != cm->result_cont)
-    cm->result_cont (cm->cont_cls, 
+    cm->result_cont (cm->cont_cls,
                     GNUNET_ARM_REQUEST_SENT_OK,
-                    (const char *) &cm->msg[1], 
-                    GNUNET_ARM_RESULT_STOPPED); 
+                    (const char *) &cm->msg[1],
+                    GNUNET_ARM_RESULT_STOPPED);
   GNUNET_free (cm->msg);
   GNUNET_free (cm);
 }
@@ -308,11 +309,12 @@ arm_termination_handler (void *cls, const struct GNUNET_MessageHeader *msg)
 /**
  * Handler for ARM replies.
  *
- * @param cls our "struct GNUNET_ARM_Handle"
+ * @param cls our `struct GNUNET_ARM_Handle`
  * @param msg the message received from the arm service
  */
 static void
-client_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
+client_notify_handler (void *cls,
+                       const struct GNUNET_MessageHeader *msg)
 {
   struct GNUNET_ARM_Handle *h = cls;
   const struct GNUNET_ARM_Message *arm_msg;
@@ -348,13 +350,16 @@ client_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
     return;
   }
   arm_msg = (const struct GNUNET_ARM_Message *) msg;
+  GNUNET_break (0 == ntohl (arm_msg->reserved));
   id = GNUNET_ntohll (arm_msg->request_id);
   cm = find_cm_by_id (h, id);
   if (NULL == cm)
   {
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "Message with unknown id %llu\n", id);
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+         "Message with unknown id %llu\n",
+         id);
     return;
-  }  
+  }
   fail = GNUNET_NO;
   switch (ntohs (msg->type))
   {
@@ -377,7 +382,7 @@ client_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
     rcount = ntohs (lres->count);
     {
       unsigned int i;
-      
+
       list = GNUNET_malloc (sizeof (const char *) * rcount);
       pos = (const char *)&lres[1];
       for (i = 0; i < rcount; i++)
@@ -404,7 +409,7 @@ client_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
     fail = GNUNET_YES;
     break;
   }
-  GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != cm->timeout_task_id);
+  GNUNET_assert (NULL != cm->timeout_task_id);
   GNUNET_SCHEDULER_cancel (cm->timeout_task_id);
   GNUNET_CONTAINER_DLL_remove (h->control_sent_head,
                                h->control_sent_tail, cm);
@@ -429,9 +434,9 @@ client_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
     if (NULL != h->thm)
     {
       GNUNET_break (0);
-      cm->result_cont (h->thm->cont_cls, 
+      cm->result_cont (h->thm->cont_cls,
                       GNUNET_ARM_REQUEST_SENT_OK,
-                       (const char *) &h->thm->msg[1], 
+                       (const char *) &h->thm->msg[1],
                       GNUNET_ARM_RESULT_IS_NOT_KNOWN);
       GNUNET_free (h->thm->msg);
       GNUNET_free (h->thm);
@@ -440,12 +445,12 @@ client_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
     GNUNET_CLIENT_receive (h->client, &arm_termination_handler, h,
                           GNUNET_TIME_UNIT_FOREVER_REL);
     return;
-  }       
+  }
   GNUNET_CLIENT_receive (h->client, &client_notify_handler, h,
                          GNUNET_TIME_UNIT_FOREVER_REL);
   switch (ntohs (msg->type))
   {
-  case GNUNET_MESSAGE_TYPE_ARM_RESULT:  
+  case GNUNET_MESSAGE_TYPE_ARM_RESULT:
     res = (const struct GNUNET_ARM_ResultMessage *) msg;
     LOG (GNUNET_ERROR_TYPE_DEBUG,
          "Received response from ARM for service `%s': %u\n",
@@ -459,9 +464,9 @@ client_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
     if (NULL != cm->list_cont)
         cm->list_cont (cm->cont_cls, GNUNET_ARM_REQUEST_SENT_OK, rcount,
                        list);
-    GNUNET_free (list);
+    GNUNET_free_non_null (list);
     break;
-  }  
+  }
   GNUNET_free (cm->msg);
   GNUNET_free (cm);
 }
@@ -470,10 +475,10 @@ client_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
 /**
  * Transmit the next message to the arm service.
  *
- * @param cls closure with the 'struct GNUNET_ARM_Handle'
- * @param size number of bytes available in buf
+ * @param cls closure with the `struct GNUNET_ARM_Handle`
+ * @param size number of bytes available in @a buf
  * @param buf where the callee should write the message
- * @return number of bytes written to buf 
+ * @return number of bytes written to @a buf
  */
 static size_t
 transmit_arm_message (void *cls, size_t size, void *buf)
@@ -487,10 +492,10 @@ transmit_arm_message (void *cls, size_t size, void *buf)
 
   notify_connection = GNUNET_NO;
   LOG (GNUNET_ERROR_TYPE_DEBUG,
-      "transmit_arm_message is running with %p buffer of size %lu. ARM is known to be %s\n",
-      buf, size, h->currently_down ? "unconnected" : "connected");
-  GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == h->reconnect_task);
-  h->cth = NULL;  
+       "transmit_arm_message is running with %p buffer of size %lu. ARM is known to be %s\n",
+       buf, size, h->currently_down ? "unconnected" : "connected");
+  GNUNET_assert (NULL == h->reconnect_task);
+  h->cth = NULL;
   if ((GNUNET_YES == h->currently_down) && (NULL != buf))
   {
     h->currently_down = GNUNET_NO;
@@ -508,7 +513,8 @@ transmit_arm_message (void *cls, size_t size, void *buf)
   }
   if (NULL == (cm = h->control_pending_head))
   {
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "Queue is empty, not sending anything\n");
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+         "Queue is empty, not sending anything\n");
     msize = 0;
     goto end;
   }
@@ -529,6 +535,7 @@ transmit_arm_message (void *cls, size_t size, void *buf)
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Transmitting control message with %u bytes of type %u to arm with id %llu\n",
        (unsigned int) msize, (unsigned int) ntohs (cm->msg->header.type), request_id);
+  arm_msg->reserved = htonl (0);
   arm_msg->request_id = GNUNET_htonll (request_id);
   memcpy (buf, cm->msg, msize);
   /* Otherwise we won't be able to find it later! */
@@ -630,14 +637,15 @@ reconnect_arm (struct GNUNET_ARM_Handle *h)
  */
 struct GNUNET_ARM_Handle *
 GNUNET_ARM_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                    GNUNET_ARM_ConnectionStatusCallback conn_status, void *cls)
+                    GNUNET_ARM_ConnectionStatusCallback conn_status,
+                   void *cls)
 {
   struct GNUNET_ARM_Handle *h;
 
-  h = GNUNET_malloc (sizeof (struct GNUNET_ARM_Handle));
+  h = GNUNET_new (struct GNUNET_ARM_Handle);
   h->cfg = GNUNET_CONFIGURATION_dup (cfg);
   h->currently_down = GNUNET_YES;
-  h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
+  h->reconnect_task = NULL;
   h->conn_status = conn_status;
   h->conn_status_cls = cls;
   if (GNUNET_OK != reconnect_arm (h))
@@ -658,14 +666,14 @@ void
 GNUNET_ARM_disconnect_and_free (struct GNUNET_ARM_Handle *h)
 {
   struct ARMControlMessage *cm;
-  
+
   LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from ARM service\n");
   if (NULL != h->cth)
   {
     GNUNET_CLIENT_notify_transmit_ready_cancel (h->cth);
     h->cth = NULL;
   }
-  while ((NULL != (cm = h->control_pending_head)) 
+  while ((NULL != (cm = h->control_pending_head))
          || (NULL != (cm = h->control_sent_head)) )
   {
     if (NULL != h->control_pending_head)
@@ -674,7 +682,7 @@ GNUNET_ARM_disconnect_and_free (struct GNUNET_ARM_Handle *h)
     else
       GNUNET_CONTAINER_DLL_remove (h->control_sent_head,
                                    h->control_sent_tail, cm);
-    GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != cm->timeout_task_id);
+    GNUNET_assert (NULL != cm->timeout_task_id);
     GNUNET_SCHEDULER_cancel (cm->timeout_task_id);
     if (NULL != cm->result_cont)
       cm->result_cont (cm->cont_cls, GNUNET_ARM_REQUEST_DISCONNECTED,
@@ -688,10 +696,10 @@ GNUNET_ARM_disconnect_and_free (struct GNUNET_ARM_Handle *h)
     GNUNET_CLIENT_disconnect (h->client);
     h->client = NULL;
   }
-  if (GNUNET_SCHEDULER_NO_TASK != h->reconnect_task)
+  if (NULL != h->reconnect_task)
   {
     GNUNET_SCHEDULER_cancel (h->reconnect_task);
-    h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
+    h->reconnect_task = NULL;
   }
   if (GNUNET_NO == h->service_test_is_active)
   {
@@ -705,13 +713,13 @@ GNUNET_ARM_disconnect_and_free (struct GNUNET_ARM_Handle *h)
  * Message timed out. Remove it from the queue.
  *
  * @param cls the message (struct ARMControlMessage *)
- * @param tc task context
  */
 static void
-control_message_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+control_message_timeout (void *cls)
 {
   struct ARMControlMessage *cm = cls;
   struct GNUNET_ARM_Message *arm_msg;
+
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Control message timed out\n");
   arm_msg = cm->msg;
@@ -734,9 +742,6 @@ control_message_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *t
 }
 
 
-#include "do_start_process.c"
-
-
 /**
  * A client specifically requested starting of ARM itself.
  * This function is called with information about whether
@@ -744,7 +749,7 @@ control_message_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *t
  * it is not, start the ARM process.
  *
  * @param cls the context for the request that we will report on (struct ARMControlMessage *)
- * @param result GNUNET_YES if ARM is running
+ * @param result #GNUNET_YES if ARM is running
  */
 static void
 arm_service_report (void *cls,
@@ -756,6 +761,7 @@ arm_service_report (void *cls,
   unsigned char test_is_active;
   char *cbinary;
   char *binary;
+  char *quotedbinary;
   char *config;
   char *loprefix;
   char *lopostfix;
@@ -764,13 +770,13 @@ arm_service_report (void *cls,
   if ((GNUNET_YES == test_is_active) &&
       (GNUNET_YES == result))
   {
-    LOG (GNUNET_ERROR_TYPE_DEBUG, 
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
         "Looks like `%s' is already running.\n",
         "gnunet-service-arm");
     /* arm is running! */
     if (cm->result_cont)
-      cm->result_cont (cm->cont_cls, 
-                      GNUNET_ARM_REQUEST_SENT_OK, "arm", 
+      cm->result_cont (cm->cont_cls,
+                      GNUNET_ARM_REQUEST_SENT_OK, "arm",
                       GNUNET_ARM_RESULT_IS_STARTED_ALREADY);
   }
   if (GNUNET_NO == test_is_active)
@@ -797,70 +803,90 @@ arm_service_report (void *cls,
   if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (
       cm->h->cfg, "arm", "OPTIONS", &lopostfix))
     lopostfix = GNUNET_strdup ("");
-  if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (
-      cm->h->cfg, "arm", "BINARY", &cbinary))
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_string (cm->h->cfg,
+                                             "arm",
+                                             "BINARY",
+                                             &cbinary))
   {
-    GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, "arm", "BINARY");
+    GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
+                               "arm",
+                               "BINARY");
     if (cm->result_cont)
-      cm->result_cont (cm->cont_cls, 
-                      GNUNET_ARM_REQUEST_SENT_OK, "arm", 
+      cm->result_cont (cm->cont_cls,
+                      GNUNET_ARM_REQUEST_SENT_OK, "arm",
                       GNUNET_ARM_RESULT_IS_NOT_KNOWN);
     GNUNET_free (cm);
     GNUNET_free (loprefix);
     GNUNET_free (lopostfix);
     return;
   }
-  if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (
-      cm->h->cfg, "arm", "CONFIG", &config))
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_filename (cm->h->cfg,
+                                               "arm", "CONFIG",
+                                               &config))
     config = NULL;
   binary = GNUNET_OS_get_libexec_binary_path (cbinary);
+  GNUNET_asprintf (&quotedbinary,
+                  "\"%s\"",
+                  binary);
   GNUNET_free (cbinary);
-  if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (
-          cm->h->cfg, "TESTING", "WEAKRANDOM")) &&
-      (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (
-          cm->h->cfg, "TESTING", "WEAKRANDOM")) &&
-      (GNUNET_NO == GNUNET_CONFIGURATION_have_value (
-          cm->h->cfg, "TESTING", "HOSTFILE")))
+  if ( (GNUNET_YES ==
+        GNUNET_CONFIGURATION_have_value (cm->h->cfg,
+                                         "TESTING",
+                                         "WEAKRANDOM")) &&
+       (GNUNET_YES ==
+        GNUNET_CONFIGURATION_get_value_yesno (cm->h->cfg,
+                                              "TESTING",
+                                              "WEAKRANDOM")) &&
+       (GNUNET_NO ==
+        GNUNET_CONFIGURATION_have_value (cm->h->cfg,
+                                         "TESTING",
+                                         "HOSTFILE")))
   {
     /* Means we are ONLY running locally */
     /* we're clearly running a test, don't daemonize */
     if (NULL == config)
-      proc = do_start_process (GNUNET_NO, cm->std_inheritance,
-                              NULL, loprefix, binary,
-                              /* no daemonization! */
-                              lopostfix, NULL);
+      proc = GNUNET_OS_start_process_s (GNUNET_NO, cm->std_inheritance,
+                                        NULL, loprefix, quotedbinary,
+                                        /* no daemonization! */
+                                        lopostfix, NULL);
     else
-      proc = do_start_process (GNUNET_NO, cm->std_inheritance,
-                              NULL, loprefix, binary, "-c", config,
-                              /* no daemonization! */
-                              lopostfix, NULL);
+      proc = GNUNET_OS_start_process_s (GNUNET_NO, cm->std_inheritance,
+                                        NULL, loprefix, quotedbinary, "-c", config,
+                                        /* no daemonization! */
+                                        lopostfix, NULL);
   }
   else
   {
     if (NULL == config)
-      proc = do_start_process (GNUNET_NO, cm->std_inheritance,
-                              NULL, loprefix, binary,
-                              "-d", lopostfix, NULL);
+      proc = GNUNET_OS_start_process_s (GNUNET_NO, cm->std_inheritance,
+                                        NULL, loprefix, quotedbinary,
+                                        "-d", lopostfix, NULL);
     else
-      proc = do_start_process (GNUNET_NO, cm->std_inheritance,
-                              NULL, loprefix, binary, "-c", config,
-                              "-d", lopostfix, NULL);
+      proc = GNUNET_OS_start_process_s (GNUNET_NO, cm->std_inheritance,
+                                        NULL, loprefix, quotedbinary, "-c",
+                                        config,
+                                        "-d", lopostfix, NULL);
   }
   GNUNET_free (binary);
+  GNUNET_free (quotedbinary);
   GNUNET_free_non_null (config);
   GNUNET_free (loprefix);
   GNUNET_free (lopostfix);
   if (NULL == proc)
   {
     if (cm->result_cont)
-      cm->result_cont (cm->cont_cls, GNUNET_ARM_REQUEST_SENT_OK, "arm",
-          GNUNET_ARM_RESULT_START_FAILED);
+      cm->result_cont (cm->cont_cls,
+                       GNUNET_ARM_REQUEST_SENT_OK, "arm",
+                       GNUNET_ARM_RESULT_START_FAILED);
     GNUNET_free (cm);
     return;
   }
   if (cm->result_cont)
-    cm->result_cont (cm->cont_cls, GNUNET_ARM_REQUEST_SENT_OK, "arm",
-        GNUNET_ARM_RESULT_STARTING);
+    cm->result_cont (cm->cont_cls,
+                     GNUNET_ARM_REQUEST_SENT_OK, "arm",
+                     GNUNET_ARM_RESULT_STARTING);
   GNUNET_OS_process_destroy (proc);
   h = cm->h;
   GNUNET_free (cm);
@@ -908,6 +934,7 @@ change_service (struct GNUNET_ARM_Handle *h, const char *service_name,
   msg = GNUNET_malloc (sizeof (struct GNUNET_ARM_Message) + slen);
   msg->header.size = htons (sizeof (struct GNUNET_ARM_Message) + slen);
   msg->header.type = htons (type);
+  msg->reserved = htonl (0);
   memcpy (&msg[1], service_name, slen);
   cm->msg = msg;
   LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -918,7 +945,8 @@ change_service (struct GNUNET_ARM_Handle *h, const char *service_name,
                                     h->control_pending_tail, cm);
   cm->timeout_task_id =
       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
-                                    (cm->timeout), &control_message_timeout, cm);
+                                    (cm->timeout),
+                                   &control_message_timeout, cm);
   trigger_next_request (h, GNUNET_NO);
 }
 
@@ -935,9 +963,9 @@ change_service (struct GNUNET_ARM_Handle *h, const char *service_name,
  */
 void
 GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h,
-                                 const char *service_name, 
+                                 const char *service_name,
                                  enum GNUNET_OS_InheritStdioFlags std_inheritance,
-                                 struct GNUNET_TIME_Relative timeout, 
+                                 struct GNUNET_TIME_Relative timeout,
                                  GNUNET_ARM_ResultCallback cont,
                                  void *cont_cls)
 {
@@ -957,9 +985,13 @@ GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h,
      */
     if (GNUNET_NO == h->currently_down)
     {
-      LOG (GNUNET_ERROR_TYPE_DEBUG, "ARM is already running\n");
+      LOG (GNUNET_ERROR_TYPE_DEBUG,
+           "ARM is already running\n");
       if (NULL != cont)
-        cont (cont_cls, GNUNET_ARM_REQUEST_SENT_OK, "arm", GNUNET_ARM_RESULT_IS_STARTED_ALREADY);
+        cont (cont_cls,
+              GNUNET_ARM_REQUEST_SENT_OK,
+              "arm",
+              GNUNET_ARM_RESULT_IS_STARTED_ALREADY);
     }
     else if (GNUNET_NO == h->service_test_is_active)
     {
@@ -973,10 +1005,10 @@ GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h,
         GNUNET_CLIENT_disconnect (h->client);
         h->client = NULL;
       }
-      if (GNUNET_SCHEDULER_NO_TASK != h->reconnect_task)
+      if (NULL != h->reconnect_task)
       {
         GNUNET_SCHEDULER_cancel (h->reconnect_task);
-        h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
+        h->reconnect_task = NULL;
       }
 
       LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -991,7 +1023,10 @@ GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h,
       cm->std_inheritance = std_inheritance;
       memcpy (&cm[1], service_name, slen);
       h->service_test_is_active = GNUNET_YES;
-      GNUNET_CLIENT_service_test ("arm", h->cfg, timeout, &arm_service_report,
+      GNUNET_CLIENT_service_test ("arm",
+                                  h->cfg,
+                                  timeout,
+                                  &arm_service_report,
                                  cm);
     }
     else
@@ -999,7 +1034,8 @@ GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h,
       /* Service test is already running - tell user to chill out and try
        * again later.
        */
-      LOG (GNUNET_ERROR_TYPE_DEBUG, "Service test is already in progress, we're busy\n");
+      LOG (GNUNET_ERROR_TYPE_DEBUG,
+           "Service test is already in progress, we're busy\n");
       if (NULL != cont)
         cont (cont_cls, GNUNET_ARM_REQUEST_BUSY, NULL, 0);
     }
@@ -1015,7 +1051,7 @@ GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h,
  * Stopping arm itself will not invalidate its handle, and
  * ARM API will try to restore connection to the ARM service,
  * even if ARM connection was lost because you asked for ARM to be stopped.
- * Call GNUNET_ARM_disconnect_and_free () to free the handle and prevent
+ * Call #GNUNET_ARM_disconnect_and_free() to free the handle and prevent
  * further connection attempts.
  *
  * @param h handle to ARM
@@ -1026,14 +1062,14 @@ GNUNET_ARM_request_service_start (struct GNUNET_ARM_Handle *h,
  */
 void
 GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h,
-                                const char *service_name, 
+                                const char *service_name,
                                 struct GNUNET_TIME_Relative timeout,
-                                GNUNET_ARM_ResultCallback cont, 
+                                GNUNET_ARM_ResultCallback cont,
                                 void *cont_cls)
 {
-  LOG (GNUNET_ERROR_TYPE_DEBUG, 
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Stopping service `%s' within %s\n",
-       service_name, 
+       service_name,
        GNUNET_STRINGS_relative_time_to_string (timeout, GNUNET_NO));
   change_service (h, service_name, timeout, cont, cont_cls,
                  GNUNET_MESSAGE_TYPE_ARM_STOP);
@@ -1051,16 +1087,16 @@ GNUNET_ARM_request_service_stop (struct GNUNET_ARM_Handle *h,
 void
 GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h,
                                  struct GNUNET_TIME_Relative timeout,
-                                 GNUNET_ARM_ServiceListCallback cont, 
+                                 GNUNET_ARM_ServiceListCallback cont,
                                  void *cont_cls)
 {
   struct ARMControlMessage *cm;
   struct GNUNET_ARM_Message *msg;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, 
-       "Requesting LIST from ARM service with timeout: %s\n", 
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Requesting LIST from ARM service with timeout: %s\n",
        GNUNET_STRINGS_relative_time_to_string (timeout, GNUNET_YES));
-  cm = GNUNET_malloc (sizeof (struct ARMControlMessage));
+  cm = GNUNET_new (struct ARMControlMessage);
   cm->h = h;
   cm->list_cont = cont;
   cm->cont_cls = cont_cls;
@@ -1068,12 +1104,14 @@ GNUNET_ARM_request_service_list (struct GNUNET_ARM_Handle *h,
   msg = GNUNET_malloc (sizeof (struct GNUNET_ARM_Message));
   msg->header.size = htons (sizeof (struct GNUNET_ARM_Message));
   msg->header.type = htons (GNUNET_MESSAGE_TYPE_ARM_LIST);
+  msg->reserved = htonl (0);
   cm->msg = msg;
   GNUNET_CONTAINER_DLL_insert_tail (h->control_pending_head,
                                     h->control_pending_tail, cm);
   cm->timeout_task_id =
       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
-                                    (cm->timeout), &control_message_timeout, cm);
+                                    (cm->timeout),
+                                   &control_message_timeout, cm);
   trigger_next_request (h, GNUNET_NO);
 }