- verboser log, faster start
[oweals/gnunet.git] / src / arm / arm_api.c
index 7c18c617e4c8716fa14856ac9aea27348dcf40c1..fd49a18a5aaded165b29a6005c44e51d37703636 100644 (file)
  */
 #include "platform.h"
 #include "gnunet_arm_service.h"
-#include "gnunet_client_lib.h"
-#include "gnunet_getopt_lib.h"
-#include "gnunet_os_lib.h"
+#include "gnunet_util_lib.h"
 #include "gnunet_protocols.h"
-#include "gnunet_server_lib.h"
 #include "arm.h"
 
 #define LOG(kind,...) GNUNET_log_from (kind, "arm-api",__VA_ARGS__)
@@ -319,6 +316,7 @@ arm_service_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct RequestContext *pos = cls;
   struct GNUNET_OS_Process *proc;
+  char *cbinary;
   char *binary;
   char *config;
   char *loprefix;
@@ -347,7 +345,7 @@ arm_service_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     lopostfix = GNUNET_strdup ("");
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_string (pos->h->cfg, "arm", "BINARY",
-                                            &binary))
+                                            &cbinary))
   {
     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
                               "arm", "BINARY");
@@ -361,17 +359,9 @@ arm_service_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_filename (pos->h->cfg, "arm", "CONFIG",
                                               &config))
-  {
-    GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
-                              "arm", "CONFIG");
-    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;
-  }
+    config = NULL;
+  binary = GNUNET_OS_get_libexec_binary_path (cbinary);
+  GNUNET_free (cbinary);
   if ((GNUNET_YES ==
        GNUNET_CONFIGURATION_have_value (pos->h->cfg, "TESTING", "WEAKRANDOM"))
       && (GNUNET_YES ==
@@ -383,28 +373,39 @@ arm_service_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   {
     /* Means we are ONLY running locally */
     /* we're clearly running a test, don't daemonize */
-    proc = do_start_process (GNUNET_NO, pos->std_inheritance,
-                            NULL, loprefix, binary, "-c", config,
-                            /* no daemonization! */
-                            lopostfix, NULL);
+    if (NULL == config)
+      proc = do_start_process (GNUNET_NO, pos->std_inheritance,
+                              NULL, loprefix, binary,
+                              /* no daemonization! */
+                              lopostfix, NULL);
+    else
+      proc = do_start_process (GNUNET_NO, pos->std_inheritance,
+                              NULL, loprefix, binary, "-c", config,
+                              /* no daemonization! */
+                              lopostfix, NULL);
   }
   else
   {
-    proc = do_start_process (GNUNET_NO, pos->std_inheritance,
-                            NULL, loprefix, binary, "-c", config,
-                            "-d", lopostfix, NULL);
+    if (NULL == config)
+      proc = do_start_process (GNUNET_NO, pos->std_inheritance,
+                              NULL, loprefix, binary,
+                              "-d", lopostfix, NULL);
+    else
+      proc = do_start_process (GNUNET_NO, pos->std_inheritance,
+                              NULL, loprefix, binary, "-c", config,
+                              "-d", lopostfix, NULL);
   }
   GNUNET_free (binary);
-  GNUNET_free (config);
+  GNUNET_free_non_null (config);
   GNUNET_free (loprefix);
   GNUNET_free (lopostfix);
-  if (proc == NULL)
-    {
-      if (pos->callback != NULL)
-       pos->callback (pos->cls, GNUNET_ARM_PROCESS_FAILURE);
-      GNUNET_free (pos);
-      return;
-    }
+  if (NULL == proc)
+  {
+    if (pos->callback != NULL)
+      pos->callback (pos->cls, GNUNET_ARM_PROCESS_FAILURE);
+    GNUNET_free (pos);
+    return;
+  }
   if (pos->callback != NULL)
     pos->callback (pos->cls, GNUNET_ARM_PROCESS_STARTING);
   GNUNET_free (proc);
@@ -533,7 +534,7 @@ GNUNET_ARM_start_service (struct GNUNET_ARM_Handle *h,
 
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Asked to start service `%s' within %s\n", service_name,
-       GNUNET_STRINGS_relative_time_to_string (timeout));
+       GNUNET_STRINGS_relative_time_to_string (timeout, GNUNET_NO));
   if (0 == strcasecmp ("arm", service_name))
   {
     slen = strlen ("arm") + 1;
@@ -607,7 +608,7 @@ GNUNET_ARM_stop_service (struct GNUNET_ARM_Handle *h,
   LOG (GNUNET_ERROR_TYPE_DEBUG, 
        "Stopping service `%s' within %s\n",
        service_name, 
-       GNUNET_STRINGS_relative_time_to_string (timeout));
+       GNUNET_STRINGS_relative_time_to_string (timeout, GNUNET_NO));
   if (h->client == NULL)
   {
     client = GNUNET_CLIENT_connect ("arm", h->cfg);
@@ -771,7 +772,7 @@ GNUNET_ARM_list_running_services (struct GNUNET_ARM_Handle *h,
   
   LOG (GNUNET_ERROR_TYPE_DEBUG, 
        "Requesting LIST from ARM service with timeout: %s\n", 
-       GNUNET_STRINGS_relative_time_to_string (timeout));
+       GNUNET_STRINGS_relative_time_to_string (timeout, GNUNET_YES));
   
   if (GNUNET_OK !=
       GNUNET_CLIENT_transmit_and_get_response (sctx->h->client,