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);
}
}
helper_handle = GNUNET_HELPER_start ("gnunet-helper-exit",
exit_argv,
- &message_token, NULL);
+ &message_token,
+ NULL, NULL);
}
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);
* @author Philipp Toelke
* @author Christian Grothoff
*/
+
#ifndef GNUNET_HELPER_LIB_H
#define GNUNET_HELPER_LIB_H
/**
- * @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
*/
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);
plugin->suid_helper = GNUNET_HELPER_start ("gnunet-helper-transport-wlan",
plugin->helper_argv,
&handle_helper_message,
+ NULL,
plugin);
break;
case 1: /* testmode, peer 1 */
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 */
plugin->suid_helper = GNUNET_HELPER_start ("gnunet-helper-transport-wlan-dummy",
plugin->helper_argv,
&handle_helper_message,
+ NULL,
plugin);
break;
default:
*/
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.
*/
_("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)
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 =
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 =
/**
- * @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;
}
{
struct GNUNET_HELPER_SendHandle *sh;
+ h->exp_cb = NULL;
/* signal pending writes that we were stopped */
while (NULL != (sh = h->sh_head))
{
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);