diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-07-16 18:58:55 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-07-16 18:58:55 +0000 |
commit | 717bd5e03fbc05b7bb1f621033eabb785750d03f (patch) | |
tree | cbc6b337381d93d3ef6d23ae98632e553fa35f14 /src/util/helper.c | |
parent | 5b0b4975c8c863e5948cfadafcfeb166655e4561 (diff) | |
download | gnunet-717bd5e03fbc05b7bb1f621033eabb785750d03f.tar.gz gnunet-717bd5e03fbc05b7bb1f621033eabb785750d03f.zip |
extended HELPER api to notify when child crashes
Diffstat (limited to 'src/util/helper.c')
-rw-r--r-- | src/util/helper.c | 54 |
1 files changed, 45 insertions, 9 deletions
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 | */ |
367 | struct GNUNET_HELPER_Handle* | 398 | struct GNUNET_HELPER_Handle * |
368 | GNUNET_HELPER_start (const char *binary_name, | 399 | GNUNET_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 | { |