aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-07-16 18:58:55 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-07-16 18:58:55 +0000
commit717bd5e03fbc05b7bb1f621033eabb785750d03f (patch)
treecbc6b337381d93d3ef6d23ae98632e553fa35f14
parent5b0b4975c8c863e5948cfadafcfeb166655e4561 (diff)
downloadgnunet-717bd5e03fbc05b7bb1f621033eabb785750d03f.tar.gz
gnunet-717bd5e03fbc05b7bb1f621033eabb785750d03f.zip
extended HELPER api to notify when child crashes
-rw-r--r--src/dns/gnunet-service-dns.c2
-rw-r--r--src/exit/gnunet-daemon-exit.c3
-rw-r--r--src/fs/fs_dirmetascan.c2
-rw-r--r--src/include/gnunet_helper_lib.h28
-rw-r--r--src/testbed/test_gnunet_testbed_helper.c2
-rw-r--r--src/transport/plugin_transport_wlan.c3
-rw-r--r--src/util/helper.c54
-rw-r--r--src/vpn/gnunet-service-vpn.c2
8 files changed, 78 insertions, 18 deletions
diff --git a/src/dns/gnunet-service-dns.c b/src/dns/gnunet-service-dns.c
index 644f2e1c8..570f742d8 100644
--- a/src/dns/gnunet-service-dns.c
+++ b/src/dns/gnunet-service-dns.c
@@ -1656,7 +1656,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
1656 hijacker = GNUNET_HELPER_start ("gnunet-helper-dns", 1656 hijacker = GNUNET_HELPER_start ("gnunet-helper-dns",
1657 helper_argv, 1657 helper_argv,
1658 &process_helper_messages, 1658 &process_helper_messages,
1659 NULL); 1659 NULL, NULL);
1660 GNUNET_SERVER_add_handlers (server, handlers); 1660 GNUNET_SERVER_add_handlers (server, handlers);
1661 GNUNET_SERVER_disconnect_notify (server, &client_disconnect, NULL); 1661 GNUNET_SERVER_disconnect_notify (server, &client_disconnect, NULL);
1662} 1662}
diff --git a/src/exit/gnunet-daemon-exit.c b/src/exit/gnunet-daemon-exit.c
index e9e961fd5..2614ba908 100644
--- a/src/exit/gnunet-daemon-exit.c
+++ b/src/exit/gnunet-daemon-exit.c
@@ -3213,7 +3213,8 @@ run (void *cls, char *const *args GNUNET_UNUSED,
3213 } 3213 }
3214 helper_handle = GNUNET_HELPER_start ("gnunet-helper-exit", 3214 helper_handle = GNUNET_HELPER_start ("gnunet-helper-exit",
3215 exit_argv, 3215 exit_argv,
3216 &message_token, NULL); 3216 &message_token,
3217 NULL, NULL);
3217} 3218}
3218 3219
3219 3220
diff --git a/src/fs/fs_dirmetascan.c b/src/fs/fs_dirmetascan.c
index 6dac690ff..3e2512206 100644
--- a/src/fs/fs_dirmetascan.c
+++ b/src/fs/fs_dirmetascan.c
@@ -457,7 +457,7 @@ GNUNET_FS_directory_scan_start (const char *filename,
457 ds->helper = GNUNET_HELPER_start ("gnunet-helper-fs-publish", 457 ds->helper = GNUNET_HELPER_start ("gnunet-helper-fs-publish",
458 ds->args, 458 ds->args,
459 &process_helper_msgs, 459 &process_helper_msgs,
460 ds); 460 NULL, ds);
461 if (NULL == ds->helper) 461 if (NULL == ds->helper)
462 { 462 {
463 GNUNET_free (filename_expanded); 463 GNUNET_free (filename_expanded);
diff --git a/src/include/gnunet_helper_lib.h b/src/include/gnunet_helper_lib.h
index 9c1bc21e2..2756cdf4e 100644
--- a/src/include/gnunet_helper_lib.h
+++ b/src/include/gnunet_helper_lib.h
@@ -24,6 +24,7 @@
24 * @author Philipp Toelke 24 * @author Philipp Toelke
25 * @author Christian Grothoff 25 * @author Christian Grothoff
26 */ 26 */
27
27#ifndef GNUNET_HELPER_LIB_H 28#ifndef GNUNET_HELPER_LIB_H
28#define GNUNET_HELPER_LIB_H 29#define GNUNET_HELPER_LIB_H
29 30
@@ -37,24 +38,43 @@ struct GNUNET_HELPER_Handle;
37 38
38 39
39/** 40/**
40 * @brief Starts a helper and begins reading from it 41 * Callback that will be called when the helper process dies. This is not called
42 * when the helper process is stoped using GNUNET_HELPER_stop()
43 *
44 * @param cls the closure from GNUNET_HELPER_start()
45 * @param h the handle representing the helper process. This handle is invalid
46 * in this callback. It is only presented for reference. No operations
47 * can be performed using it.
48 */
49typedef void (*GNUNET_HELPER_ExceptionCallback) (void *cls,
50 const struct GNUNET_HELPER_Handle *h);
51
52
53/**
54 * Starts a helper and begins reading from it. The helper process is
55 * restarted when it dies except when it is stopped using GNUNET_HELPER_stop()
56 * or when the exp_cb callback is not NULL.
41 * 57 *
42 * @param binary_name name of the binary to run 58 * @param binary_name name of the binary to run
43 * @param binary_argv NULL-terminated list of arguments to give when starting the binary (this 59 * @param binary_argv NULL-terminated list of arguments to give when starting the binary (this
44 * argument must not be modified by the client for 60 * argument must not be modified by the client for
45 * the lifetime of the helper handle) 61 * the lifetime of the helper handle)
46 * @param cb function to call if we get messages from the helper 62 * @param cb function to call if we get messages from the helper
47 * @param cb_cls Closure for the callback 63 * @param exp_cb the exception callback to call. Set this to NULL if the helper
64 * process has to be restarted automatically when it dies/crashes
65 * @param cb_cls closure for the above callbacks
48 * @return the new Handle, NULL on error 66 * @return the new Handle, NULL on error
49 */ 67 */
50struct GNUNET_HELPER_Handle * 68struct GNUNET_HELPER_Handle *
51GNUNET_HELPER_start (const char *binary_name, 69GNUNET_HELPER_start (const char *binary_name,
52 char *const binary_argv[], 70 char *const binary_argv[],
53 GNUNET_SERVER_MessageTokenizerCallback cb, void *cb_cls); 71 GNUNET_SERVER_MessageTokenizerCallback cb,
72 GNUNET_HELPER_ExceptionCallback exp_cb,
73 void *cb_cls);
54 74
55 75
56/** 76/**
57 * @brief Kills the helper, closes the pipe and frees the handle 77 * Kills the helper, closes the pipe and frees the handle
58 * 78 *
59 * @param h handle to helper to stop 79 * @param h handle to helper to stop
60 */ 80 */
diff --git a/src/testbed/test_gnunet_testbed_helper.c b/src/testbed/test_gnunet_testbed_helper.c
index a2f8936ab..654e5dd3e 100644
--- a/src/testbed/test_gnunet_testbed_helper.c
+++ b/src/testbed/test_gnunet_testbed_helper.c
@@ -151,7 +151,7 @@ run (void *cls, char *const *args, const char *cfgfile,
151 151
152 helper = GNUNET_HELPER_start ("gnunet-testbed-helper", 152 helper = GNUNET_HELPER_start ("gnunet-testbed-helper",
153 binary_argv, 153 binary_argv,
154 NULL, NULL); 154 NULL, NULL, NULL);
155 GNUNET_assert (NULL != helper); 155 GNUNET_assert (NULL != helper);
156 cfg = GNUNET_CONFIGURATION_dup (cfg2); 156 cfg = GNUNET_CONFIGURATION_dup (cfg2);
157 config = GNUNET_CONFIGURATION_serialize (cfg, &config_size); 157 config = GNUNET_CONFIGURATION_serialize (cfg, &config_size);
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c
index c2565a4a8..2d786e2a9 100644
--- a/src/transport/plugin_transport_wlan.c
+++ b/src/transport/plugin_transport_wlan.c
@@ -1713,6 +1713,7 @@ libgnunet_plugin_transport_wlan_init (void *cls)
1713 plugin->suid_helper = GNUNET_HELPER_start ("gnunet-helper-transport-wlan", 1713 plugin->suid_helper = GNUNET_HELPER_start ("gnunet-helper-transport-wlan",
1714 plugin->helper_argv, 1714 plugin->helper_argv,
1715 &handle_helper_message, 1715 &handle_helper_message,
1716 NULL,
1716 plugin); 1717 plugin);
1717 break; 1718 break;
1718 case 1: /* testmode, peer 1 */ 1719 case 1: /* testmode, peer 1 */
@@ -1722,6 +1723,7 @@ libgnunet_plugin_transport_wlan_init (void *cls)
1722 plugin->suid_helper = GNUNET_HELPER_start ("gnunet-helper-transport-wlan-dummy", 1723 plugin->suid_helper = GNUNET_HELPER_start ("gnunet-helper-transport-wlan-dummy",
1723 plugin->helper_argv, 1724 plugin->helper_argv,
1724 &handle_helper_message, 1725 &handle_helper_message,
1726 NULL,
1725 plugin); 1727 plugin);
1726 break; 1728 break;
1727 case 2: /* testmode, peer 2 */ 1729 case 2: /* testmode, peer 2 */
@@ -1731,6 +1733,7 @@ libgnunet_plugin_transport_wlan_init (void *cls)
1731 plugin->suid_helper = GNUNET_HELPER_start ("gnunet-helper-transport-wlan-dummy", 1733 plugin->suid_helper = GNUNET_HELPER_start ("gnunet-helper-transport-wlan-dummy",
1732 plugin->helper_argv, 1734 plugin->helper_argv,
1733 &handle_helper_message, 1735 &handle_helper_message,
1736 NULL,
1734 plugin); 1737 plugin);
1735 break; 1738 break;
1736 default: 1739 default:
diff --git a/src/util/helper.c b/src/util/helper.c
index 16b3465c0..3fe3705b1 100644
--- a/src/util/helper.c
+++ b/src/util/helper.c
@@ -109,6 +109,16 @@ struct GNUNET_HELPER_Handle
109 struct GNUNET_SERVER_MessageStreamTokenizer *mst; 109 struct GNUNET_SERVER_MessageStreamTokenizer *mst;
110 110
111 /** 111 /**
112 * The exception callback
113 */
114 GNUNET_HELPER_ExceptionCallback exp_cb;
115
116 /**
117 * The closure for callbacks
118 */
119 void *cb_cls;
120
121 /**
112 * First message queued for transmission to helper. 122 * First message queued for transmission to helper.
113 */ 123 */
114 struct GNUNET_HELPER_SendHandle *sh_head; 124 struct GNUNET_HELPER_SendHandle *sh_head;
@@ -244,11 +254,16 @@ helper_read (void *cls,
244 _("Error reading from `%s': %s\n"), 254 _("Error reading from `%s': %s\n"),
245 h->binary_name, 255 h->binary_name,
246 STRERROR (errno)); 256 STRERROR (errno));
257 if (NULL != h->exp_cb)
258 {
259 h->exp_cb (h->cb_cls, h);
260 GNUNET_HELPER_stop (h);
261 return;
262 }
247 stop_helper (h); 263 stop_helper (h);
248 /* Restart the helper */ 264 /* Restart the helper */
249 h->restart_task = 265 h->restart_task =
250 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 266 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &restart_task, h);
251 &restart_task, h);
252 return; 267 return;
253 } 268 }
254 if (0 == t) 269 if (0 == t)
@@ -258,6 +273,12 @@ helper_read (void *cls,
258 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 273 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
259 _("Got 0 bytes from helper `%s' (EOF)\n"), 274 _("Got 0 bytes from helper `%s' (EOF)\n"),
260 h->binary_name); 275 h->binary_name);
276 if (NULL != h->exp_cb)
277 {
278 h->exp_cb (h->cb_cls, h);
279 GNUNET_HELPER_stop (h);
280 return;
281 }
261 stop_helper (h); 282 stop_helper (h);
262 /* Restart the helper */ 283 /* Restart the helper */
263 h->restart_task = 284 h->restart_task =
@@ -277,6 +298,12 @@ helper_read (void *cls,
277 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 298 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
278 _("Failed to parse inbound message from helper `%s'\n"), 299 _("Failed to parse inbound message from helper `%s'\n"),
279 h->binary_name); 300 h->binary_name);
301 if (NULL != h->exp_cb)
302 {
303 h->exp_cb (h->cb_cls, h);
304 GNUNET_HELPER_stop (h);
305 return;
306 }
280 stop_helper (h); 307 stop_helper (h);
281 /* Restart the helper */ 308 /* Restart the helper */
282 h->restart_task = 309 h->restart_task =
@@ -354,27 +381,35 @@ restart_task (void *cls,
354 381
355 382
356/** 383/**
357 * @brief Starts a helper and begins reading from it 384 * Starts a helper and begins reading from it. The helper process is
385 * restarted when it dies except when it is stopped using GNUNET_HELPER_stop()
386 * or when the exp_cb callback is not NULL.
358 * 387 *
359 * @param binary_name name of the binary to run 388 * @param binary_name name of the binary to run
360 * @param binary_argv NULL-terminated list of arguments to give when starting the binary (this 389 * @param binary_argv NULL-terminated list of arguments to give when starting the binary (this
361 * argument must not be modified by the client for 390 * argument must not be modified by the client for
362 * the lifetime of the helper h) 391 * the lifetime of the helper handle)
363 * @param cb function to call if we get messages from the helper 392 * @param cb function to call if we get messages from the helper
364 * @param cb_cls Closure for the callback 393 * @param exp_cb the exception callback to call. Set this to NULL if the helper
365 * @return the new H, NULL on error 394 * process has to be restarted automatically when it dies/crashes
395 * @param cb_cls closure for the above callback
396 * @return the new Handle, NULL on error
366 */ 397 */
367struct GNUNET_HELPER_Handle* 398struct GNUNET_HELPER_Handle *
368GNUNET_HELPER_start (const char *binary_name, 399GNUNET_HELPER_start (const char *binary_name,
369 char *const binary_argv[], 400 char *const binary_argv[],
370 GNUNET_SERVER_MessageTokenizerCallback cb, void *cb_cls) 401 GNUNET_SERVER_MessageTokenizerCallback cb,
402 GNUNET_HELPER_ExceptionCallback exp_cb,
403 void *cb_cls)
371{ 404{
372 struct GNUNET_HELPER_Handle*h; 405 struct GNUNET_HELPER_Handle*h;
373 406
374 h = GNUNET_malloc (sizeof (struct GNUNET_HELPER_Handle)); 407 h = GNUNET_malloc (sizeof (struct GNUNET_HELPER_Handle));
375 h->binary_name = binary_name; 408 h->binary_name = binary_name;
376 h->binary_argv = binary_argv; 409 h->binary_argv = binary_argv;
377 h->mst = GNUNET_SERVER_mst_create (cb, cb_cls); 410 h->cb_cls = cb_cls;
411 h->mst = GNUNET_SERVER_mst_create (cb, h->cb_cls);
412 h->exp_cb = exp_cb;
378 start_helper (h); 413 start_helper (h);
379 return h; 414 return h;
380} 415}
@@ -390,6 +425,7 @@ GNUNET_HELPER_stop (struct GNUNET_HELPER_Handle *h)
390{ 425{
391 struct GNUNET_HELPER_SendHandle *sh; 426 struct GNUNET_HELPER_SendHandle *sh;
392 427
428 h->exp_cb = NULL;
393 /* signal pending writes that we were stopped */ 429 /* signal pending writes that we were stopped */
394 while (NULL != (sh = h->sh_head)) 430 while (NULL != (sh = h->sh_head))
395 { 431 {
diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c
index 219949bd3..0b9a4dcb2 100644
--- a/src/vpn/gnunet-service-vpn.c
+++ b/src/vpn/gnunet-service-vpn.c
@@ -3183,7 +3183,7 @@ run (void *cls,
3183 mesh_handlers, 3183 mesh_handlers,
3184 types); 3184 types);
3185 helper_handle = GNUNET_HELPER_start ("gnunet-helper-vpn", vpn_argv, 3185 helper_handle = GNUNET_HELPER_start ("gnunet-helper-vpn", vpn_argv,
3186 &message_token, NULL); 3186 &message_token, NULL, NULL);
3187 nc = GNUNET_SERVER_notification_context_create (server, 1); 3187 nc = GNUNET_SERVER_notification_context_create (server, 1);
3188 GNUNET_SERVER_add_handlers (server, service_handlers); 3188 GNUNET_SERVER_add_handlers (server, service_handlers);
3189 GNUNET_SERVER_disconnect_notify (server, &client_disconnect, NULL); 3189 GNUNET_SERVER_disconnect_notify (server, &client_disconnect, NULL);