-dce
[oweals/gnunet.git] / src / util / helper.c
index 9faf2ee50c1ae2cb67d126a06e6b813844baa0be..03e71585c07330a428902459445ade51ec609b4c 100644 (file)
@@ -136,7 +136,7 @@ struct GNUNET_HELPER_Handle
   /**
    * NULL-terminated list of command-line arguments.
    */
-  char *const *binary_argv;
+  char **binary_argv;
                    
   /**
    * Task to read from the helper.
@@ -276,8 +276,8 @@ helper_read (void *cls,
   {
     /* this happens if the helper is shut down via a 
        signal, so it is not a "hard" error */
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO
-               _("Got 0 bytes from helper `%s' (EOF)\n"),
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG
+               "Got 0 bytes from helper `%s' (EOF)\n",
                h->binary_name);
     if (NULL != h->exp_cb)
     {
@@ -292,8 +292,8 @@ helper_read (void *cls,
                                    &restart_task, h);
     return;
   }
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO
-             _("Got %u bytes from helper `%s'\n"),
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG
+             "Got %u bytes from helper `%s'\n",
              (unsigned int) t,
              h->binary_name);
   h->read_task = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
@@ -339,8 +339,8 @@ start_helper (struct GNUNET_HELPER_Handle *h)
                                    &restart_task, h);    
     return;
   }
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-             _("Starting HELPER process `%s'\n"),
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Starting HELPER process `%s'\n",
              h->binary_name);
   h->fh_from_helper =
       GNUNET_DISK_pipe_handle (h->helper_out, GNUNET_DISK_PIPE_END_READ);
@@ -411,11 +411,18 @@ GNUNET_HELPER_start (int with_control_pipe,
                     void *cb_cls)
 {
   struct GNUNET_HELPER_Handle*h;
-
+  int c = 0;
   h =  GNUNET_malloc (sizeof (struct GNUNET_HELPER_Handle));
   h->with_control_pipe = with_control_pipe;
-  h->binary_name = binary_name;
-  h->binary_argv = binary_argv;
+  h->binary_name = GNUNET_strdup (binary_name);
+
+  for (c = 0; binary_argv[c] != NULL; c++)
+    c ++;
+  h->binary_argv = GNUNET_malloc (sizeof (char *[c + 1]));
+  for (c = 0; binary_argv[c] != NULL; c++)
+    h->binary_argv[c] = GNUNET_strdup (binary_argv[c]);
+  h->binary_argv[c] = NULL;
+
   h->cb_cls = cb_cls;
   h->mst = GNUNET_SERVER_mst_create (cb, h->cb_cls);
   h->exp_cb = exp_cb;
@@ -433,7 +440,7 @@ void
 GNUNET_HELPER_stop (struct GNUNET_HELPER_Handle *h)
 {
   struct GNUNET_HELPER_SendHandle *sh;
-
+  int c;
   h->exp_cb = NULL;
   /* signal pending writes that we were stopped */
   while (NULL != (sh = h->sh_head))
@@ -447,6 +454,10 @@ GNUNET_HELPER_stop (struct GNUNET_HELPER_Handle *h)
   }
   stop_helper (h);
   GNUNET_SERVER_mst_destroy (h->mst);
+  GNUNET_free ((char *) h->binary_name);
+  for (c = 0; h->binary_argv[c] != NULL; c++)
+    GNUNET_free (h->binary_argv[c]);
+  GNUNET_free (h->binary_argv);
   GNUNET_free (h);
 }
 
@@ -485,6 +496,12 @@ helper_write (void *cls,
                 _("Error writing to `%s': %s\n"),
                h->binary_name,
                STRERROR (errno));
+    if (NULL != h->exp_cb)
+    {
+      h->exp_cb (h->cb_cls);
+      GNUNET_HELPER_stop (h);
+      return;
+    }
     stop_helper (h);
     /* Restart the helper */
     h->restart_task =