gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r22707 - in gnunet/src: dns exit fs include testbed transpo


From: gnunet
Subject: [GNUnet-SVN] r22707 - in gnunet/src: dns exit fs include testbed transport util vpn
Date: Mon, 16 Jul 2012 20:58:55 +0200

Author: harsha
Date: 2012-07-16 20:58:55 +0200 (Mon, 16 Jul 2012)
New Revision: 22707

Modified:
   gnunet/src/dns/gnunet-service-dns.c
   gnunet/src/exit/gnunet-daemon-exit.c
   gnunet/src/fs/fs_dirmetascan.c
   gnunet/src/include/gnunet_helper_lib.h
   gnunet/src/testbed/test_gnunet_testbed_helper.c
   gnunet/src/transport/plugin_transport_wlan.c
   gnunet/src/util/helper.c
   gnunet/src/vpn/gnunet-service-vpn.c
Log:
extended HELPER api to notify when child crashes

Modified: gnunet/src/dns/gnunet-service-dns.c
===================================================================
--- gnunet/src/dns/gnunet-service-dns.c 2012-07-16 17:50:51 UTC (rev 22706)
+++ gnunet/src/dns/gnunet-service-dns.c 2012-07-16 18:58:55 UTC (rev 22707)
@@ -1656,7 +1656,7 @@
   hijacker = GNUNET_HELPER_start ("gnunet-helper-dns",
                                  helper_argv,
                                  &process_helper_messages,
-                                 NULL);
+                                 NULL, NULL);
   GNUNET_SERVER_add_handlers (server, handlers);
   GNUNET_SERVER_disconnect_notify (server, &client_disconnect, NULL);
 }

Modified: gnunet/src/exit/gnunet-daemon-exit.c
===================================================================
--- gnunet/src/exit/gnunet-daemon-exit.c        2012-07-16 17:50:51 UTC (rev 
22706)
+++ gnunet/src/exit/gnunet-daemon-exit.c        2012-07-16 18:58:55 UTC (rev 
22707)
@@ -3213,7 +3213,8 @@
   }
   helper_handle = GNUNET_HELPER_start ("gnunet-helper-exit", 
                                       exit_argv,
-                                      &message_token, NULL);
+                                      &message_token,
+                                      NULL, NULL);
 }
 
 

Modified: gnunet/src/fs/fs_dirmetascan.c
===================================================================
--- gnunet/src/fs/fs_dirmetascan.c      2012-07-16 17:50:51 UTC (rev 22706)
+++ gnunet/src/fs/fs_dirmetascan.c      2012-07-16 18:58:55 UTC (rev 22707)
@@ -457,7 +457,7 @@
   ds->helper = GNUNET_HELPER_start ("gnunet-helper-fs-publish",
                                    ds->args,
                                    &process_helper_msgs,
-                                   ds);
+                                   NULL, ds);
   if (NULL == ds->helper)
   {
     GNUNET_free (filename_expanded);

Modified: gnunet/src/include/gnunet_helper_lib.h
===================================================================
--- gnunet/src/include/gnunet_helper_lib.h      2012-07-16 17:50:51 UTC (rev 
22706)
+++ gnunet/src/include/gnunet_helper_lib.h      2012-07-16 18:58:55 UTC (rev 
22707)
@@ -24,6 +24,7 @@
  * @author Philipp Toelke
  * @author Christian Grothoff
  */
+
 #ifndef GNUNET_HELPER_LIB_H
 #define GNUNET_HELPER_LIB_H
 
@@ -37,24 +38,43 @@
 
 
 /**
- * @brief Starts a helper and begins reading from it
+ * Callback that will be called when the helper process dies. This is not 
called
+ * when the helper process is stoped using GNUNET_HELPER_stop()
  *
+ * @param cls the closure from GNUNET_HELPER_start()
+ * @param h the handle representing the helper process. This handle is invalid
+ *          in this callback. It is only presented for reference. No operations
+ *          can be performed using it.
+ */
+typedef void (*GNUNET_HELPER_ExceptionCallback) (void *cls,
+                                                const struct 
GNUNET_HELPER_Handle *h);
+
+
+/**
+ * Starts a helper and begins reading from it. The helper process is
+ * restarted when it dies except when it is stopped using GNUNET_HELPER_stop()
+ * or when the exp_cb callback is not NULL.
+ *
  * @param binary_name name of the binary to run
  * @param binary_argv NULL-terminated list of arguments to give when starting 
the binary (this
  *                    argument must not be modified by the client for
  *                     the lifetime of the helper handle)
  * @param cb function to call if we get messages from the helper
- * @param cb_cls Closure for the callback
+ * @param exp_cb the exception callback to call. Set this to NULL if the helper
+ *          process has to be restarted automatically when it dies/crashes
+ * @param cb_cls closure for the above callbacks
  * @return the new Handle, NULL on error
  */
 struct GNUNET_HELPER_Handle *
 GNUNET_HELPER_start (const char *binary_name,
                     char *const binary_argv[],
-                    GNUNET_SERVER_MessageTokenizerCallback cb, void *cb_cls);
+                    GNUNET_SERVER_MessageTokenizerCallback cb,
+                    GNUNET_HELPER_ExceptionCallback exp_cb,
+                    void *cb_cls);
 
 
 /**
- * @brief Kills the helper, closes the pipe and frees the handle
+ * Kills the helper, closes the pipe and frees the handle
  *
  * @param h handle to helper to stop
  */

Modified: gnunet/src/testbed/test_gnunet_testbed_helper.c
===================================================================
--- gnunet/src/testbed/test_gnunet_testbed_helper.c     2012-07-16 17:50:51 UTC 
(rev 22706)
+++ gnunet/src/testbed/test_gnunet_testbed_helper.c     2012-07-16 18:58:55 UTC 
(rev 22707)
@@ -151,7 +151,7 @@
 
   helper = GNUNET_HELPER_start ("gnunet-testbed-helper", 
                                binary_argv,
-                                NULL, NULL);
+                                NULL, NULL, NULL);
   GNUNET_assert (NULL != helper);
   cfg = GNUNET_CONFIGURATION_dup (cfg2);  
   config = GNUNET_CONFIGURATION_serialize (cfg, &config_size);

Modified: gnunet/src/transport/plugin_transport_wlan.c
===================================================================
--- gnunet/src/transport/plugin_transport_wlan.c        2012-07-16 17:50:51 UTC 
(rev 22706)
+++ gnunet/src/transport/plugin_transport_wlan.c        2012-07-16 18:58:55 UTC 
(rev 22707)
@@ -1713,6 +1713,7 @@
     plugin->suid_helper = GNUNET_HELPER_start ("gnunet-helper-transport-wlan",
                                               plugin->helper_argv,
                                               &handle_helper_message,
+                                              NULL,
                                               plugin);
     break;
   case 1: /* testmode, peer 1 */
@@ -1722,6 +1723,7 @@
     plugin->suid_helper = GNUNET_HELPER_start 
("gnunet-helper-transport-wlan-dummy",
                                               plugin->helper_argv,
                                               &handle_helper_message,
+                                              NULL,
                                               plugin);
     break;
   case 2: /* testmode, peer 2 */
@@ -1731,6 +1733,7 @@
     plugin->suid_helper = GNUNET_HELPER_start 
("gnunet-helper-transport-wlan-dummy",
                                               plugin->helper_argv,
                                               &handle_helper_message,
+                                              NULL,
                                               plugin);
     break;
   default:

Modified: gnunet/src/util/helper.c
===================================================================
--- gnunet/src/util/helper.c    2012-07-16 17:50:51 UTC (rev 22706)
+++ gnunet/src/util/helper.c    2012-07-16 18:58:55 UTC (rev 22707)
@@ -109,6 +109,16 @@
   struct GNUNET_SERVER_MessageStreamTokenizer *mst;
 
   /**
+   * The exception callback
+   */
+  GNUNET_HELPER_ExceptionCallback exp_cb;
+
+  /**
+   * The closure for callbacks
+   */
+  void *cb_cls;
+
+  /**
    * First message queued for transmission to helper.
    */
   struct GNUNET_HELPER_SendHandle *sh_head;
@@ -244,11 +254,16 @@
                 _("Error reading from `%s': %s\n"),
                h->binary_name,
                STRERROR (errno));
+    if (NULL != h->exp_cb)
+    {
+      h->exp_cb (h->cb_cls, h);
+      GNUNET_HELPER_stop (h);
+      return;
+    }
     stop_helper (h);
     /* Restart the helper */
     h->restart_task =
-      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
-                                   &restart_task, h);
+       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &restart_task, 
h);
     return;
   }
   if (0 == t)
@@ -258,6 +273,12 @@
     GNUNET_log (GNUNET_ERROR_TYPE_INFO, 
                _("Got 0 bytes from helper `%s' (EOF)\n"),
                h->binary_name);
+    if (NULL != h->exp_cb)
+    {
+      h->exp_cb (h->cb_cls, h);
+      GNUNET_HELPER_stop (h);
+      return;
+    }
     stop_helper (h);
     /* Restart the helper */
     h->restart_task =
@@ -277,6 +298,12 @@
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 
                _("Failed to parse inbound message from helper `%s'\n"),
                h->binary_name);
+    if (NULL != h->exp_cb)
+    {
+      h->exp_cb (h->cb_cls, h);
+      GNUNET_HELPER_stop (h);
+      return;
+    }     
     stop_helper (h);
     /* Restart the helper */
     h->restart_task =
@@ -354,27 +381,35 @@
 
 
 /**
- * @brief Starts a helper and begins reading from it
+ * Starts a helper and begins reading from it. The helper process is
+ * restarted when it dies except when it is stopped using GNUNET_HELPER_stop()
+ * or when the exp_cb callback is not NULL.
  *
  * @param binary_name name of the binary to run
  * @param binary_argv NULL-terminated list of arguments to give when starting 
the binary (this
  *                    argument must not be modified by the client for
- *                     the lifetime of the helper h)
+ *                     the lifetime of the helper handle)
  * @param cb function to call if we get messages from the helper
- * @param cb_cls Closure for the callback
- * @return the new H, NULL on error
+ * @param exp_cb the exception callback to call. Set this to NULL if the helper
+ *          process has to be restarted automatically when it dies/crashes
+ * @param cb_cls closure for the above callback
+ * @return the new Handle, NULL on error
  */
-struct GNUNET_HELPER_Handle*
+struct GNUNET_HELPER_Handle *
 GNUNET_HELPER_start (const char *binary_name,
                     char *const binary_argv[],
-                    GNUNET_SERVER_MessageTokenizerCallback cb, void *cb_cls)
+                    GNUNET_SERVER_MessageTokenizerCallback cb,
+                    GNUNET_HELPER_ExceptionCallback exp_cb,
+                    void *cb_cls)
 {
   struct GNUNET_HELPER_Handle*h;
 
   h =  GNUNET_malloc (sizeof (struct GNUNET_HELPER_Handle));
   h->binary_name = binary_name;
   h->binary_argv = binary_argv;
-  h->mst = GNUNET_SERVER_mst_create (cb, cb_cls);
+  h->cb_cls = cb_cls;
+  h->mst = GNUNET_SERVER_mst_create (cb, h->cb_cls);
+  h->exp_cb = exp_cb;
   start_helper (h);
   return h;
 }
@@ -390,6 +425,7 @@
 {
   struct GNUNET_HELPER_SendHandle *sh;
 
+  h->exp_cb = NULL;
   /* signal pending writes that we were stopped */
   while (NULL != (sh = h->sh_head))
   {

Modified: gnunet/src/vpn/gnunet-service-vpn.c
===================================================================
--- gnunet/src/vpn/gnunet-service-vpn.c 2012-07-16 17:50:51 UTC (rev 22706)
+++ gnunet/src/vpn/gnunet-service-vpn.c 2012-07-16 18:58:55 UTC (rev 22707)
@@ -3183,7 +3183,7 @@
                         mesh_handlers,
                         types);
   helper_handle = GNUNET_HELPER_start ("gnunet-helper-vpn", vpn_argv,
-                                      &message_token, NULL);
+                                      &message_token, NULL, NULL);
   nc = GNUNET_SERVER_notification_context_create (server, 1);
   GNUNET_SERVER_add_handlers (server, service_handlers);
   GNUNET_SERVER_disconnect_notify (server, &client_disconnect, NULL);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]