projects
/
oweals
/
gnunet.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add test code, but it's still segfaulting.
[oweals/gnunet.git]
/
src
/
util
/
helper.c
diff --git
a/src/util/helper.c
b/src/util/helper.c
index 105ccf0577c03f947df9acaffff978b08eba98f4..f0123460b9fec29e506b688cba617b8044619ab8 100644
(file)
--- a/
src/util/helper.c
+++ b/
src/util/helper.c
@@
-1,6
+1,6
@@
/*
This file is part of GNUnet.
/*
This file is part of GNUnet.
- (C) 2011, 2012 Christian Grothoff
+
Copyright
(C) 2011, 2012 Christian Grothoff
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
@@
-14,8
+14,8
@@
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 5
9 Temple Place - Suite 330
,
- Boston, MA 0211
1-1307
, USA.
+ Free Software Foundation, Inc., 5
1 Franklin Street, Fifth Floor
,
+ Boston, MA 0211
0-1301
, USA.
*/
/**
*/
/**
@@
-142,23
+142,27
@@
struct GNUNET_HELPER_Handle
/**
* Task to read from the helper.
*/
/**
* Task to read from the helper.
*/
-
GNUNET_SCHEDULER_TaskIdentifier
read_task;
+
struct GNUNET_SCHEDULER_Task *
read_task;
/**
* Task to read from the helper.
*/
/**
* Task to read from the helper.
*/
-
GNUNET_SCHEDULER_TaskIdentifier
write_task;
+
struct GNUNET_SCHEDULER_Task *
write_task;
/**
* Restart task.
*/
/**
* Restart task.
*/
-
GNUNET_SCHEDULER_TaskIdentifier
restart_task;
+
struct GNUNET_SCHEDULER_Task *
restart_task;
/**
* Does the helper support the use of a control pipe for signalling?
*/
int with_control_pipe;
/**
* Does the helper support the use of a control pipe for signalling?
*/
int with_control_pipe;
+ /**
+ * Count start attempts to increase linear back off
+ */
+ unsigned int retry_back_off;
};
};
@@
-187,15
+191,15
@@
GNUNET_HELPER_kill (struct GNUNET_HELPER_Handle *h,
sh->cont (sh->cont_cls, GNUNET_NO);
GNUNET_free (sh);
}
sh->cont (sh->cont_cls, GNUNET_NO);
GNUNET_free (sh);
}
- if (
GNUNET_SCHEDULER_NO_TASK
!= h->restart_task)
+ if (
NULL
!= h->restart_task)
{
GNUNET_SCHEDULER_cancel (h->restart_task);
{
GNUNET_SCHEDULER_cancel (h->restart_task);
- h->restart_task =
GNUNET_SCHEDULER_NO_TASK
;
+ h->restart_task =
NULL
;
}
}
- if (
GNUNET_SCHEDULER_NO_TASK
!= h->read_task)
+ if (
NULL
!= h->read_task)
{
GNUNET_SCHEDULER_cancel (h->read_task);
{
GNUNET_SCHEDULER_cancel (h->read_task);
- h->read_task =
GNUNET_SCHEDULER_NO_TASK
;
+ h->read_task =
NULL
;
}
if (NULL == h->helper_proc)
return GNUNET_SYSERR;
}
if (NULL == h->helper_proc)
return GNUNET_SYSERR;
@@
-235,15
+239,15
@@
GNUNET_HELPER_wait (struct GNUNET_HELPER_Handle *h)
GNUNET_OS_process_destroy (h->helper_proc);
h->helper_proc = NULL;
}
GNUNET_OS_process_destroy (h->helper_proc);
h->helper_proc = NULL;
}
- if (
GNUNET_SCHEDULER_NO_TASK
!= h->read_task)
+ if (
NULL
!= h->read_task)
{
GNUNET_SCHEDULER_cancel (h->read_task);
{
GNUNET_SCHEDULER_cancel (h->read_task);
- h->read_task =
GNUNET_SCHEDULER_NO_TASK
;
+ h->read_task =
NULL
;
}
}
- if (
GNUNET_SCHEDULER_NO_TASK
!= h->write_task)
+ if (
NULL
!= h->write_task)
{
GNUNET_SCHEDULER_cancel (h->write_task);
{
GNUNET_SCHEDULER_cancel (h->write_task);
- h->write_task =
GNUNET_SCHEDULER_NO_TASK
;
+ h->write_task =
NULL
;
}
if (NULL != h->helper_in)
{
}
if (NULL != h->helper_in)
{
@@
-284,10
+288,10
@@
static void
stop_helper (struct GNUNET_HELPER_Handle *h,
int soft_kill)
{
stop_helper (struct GNUNET_HELPER_Handle *h,
int soft_kill)
{
- if (
GNUNET_SCHEDULER_NO_TASK
!= h->restart_task)
+ if (
NULL
!= h->restart_task)
{
GNUNET_SCHEDULER_cancel (h->restart_task);
{
GNUNET_SCHEDULER_cancel (h->restart_task);
- h->restart_task =
GNUNET_SCHEDULER_NO_TASK
;
+ h->restart_task =
NULL
;
}
else
{
}
else
{
@@
-322,7
+326,7
@@
helper_read (void *cls,
char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE] GNUNET_ALIGN;
ssize_t t;
char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE] GNUNET_ALIGN;
ssize_t t;
- h->read_task =
GNUNET_SCHEDULER_NO_TASK
;
+ h->read_task =
NULL
;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
{
/* try again */
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
{
/* try again */
@@
-346,8
+350,9
@@
helper_read (void *cls,
}
stop_helper (h, GNUNET_NO);
/* Restart the helper */
}
stop_helper (h, GNUNET_NO);
/* Restart the helper */
- h->restart_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &restart_task, h);
+ h->restart_task = GNUNET_SCHEDULER_add_delayed(
+ GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
+ h->retry_back_off), &restart_task, h);
return;
}
if (0 == t)
return;
}
if (0 == t)
@@
-365,9
+370,9
@@
helper_read (void *cls,
}
stop_helper (h, GNUNET_NO);
/* Restart the helper */
}
stop_helper (h, GNUNET_NO);
/* Restart the helper */
- h->restart_task =
-
GNUNET_SCHEDULER_add_delayed
(GNUNET_TIME_UNIT_SECONDS,
-
&restart_task, h);
+ h->restart_task =
GNUNET_SCHEDULER_add_delayed(
+
GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS,
+
h->retry_back_off),
&restart_task, h);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@
-390,9
+395,9
@@
helper_read (void *cls,
}
stop_helper (h, GNUNET_NO);
/* Restart the helper */
}
stop_helper (h, GNUNET_NO);
/* Restart the helper */
- h->restart_task =
- GNUNET_
SCHEDULER_add_delayed
(GNUNET_TIME_UNIT_SECONDS,
-
&restart_task, h);
+ h->restart_task =
GNUNET_SCHEDULER_add_delayed(
+ GNUNET_
TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS,
+
h->retry_back_off),
&restart_task, h);
return;
}
}
return;
}
}
@@
-413,8
+418,9
@@
start_helper (struct GNUNET_HELPER_Handle *h)
/* out of file descriptors? try again later... */
stop_helper (h, GNUNET_NO);
h->restart_task =
/* out of file descriptors? try again later... */
stop_helper (h, GNUNET_NO);
h->restart_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
- &restart_task, h);
+ GNUNET_SCHEDULER_add_delayed(
+ GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
+ h->retry_back_off), &restart_task, h);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@
-433,9
+439,9
@@
start_helper (struct GNUNET_HELPER_Handle *h)
{
/* failed to start process? try again later... */
stop_helper (h, GNUNET_NO);
{
/* failed to start process? try again later... */
stop_helper (h, GNUNET_NO);
- h->restart_task =
-
GNUNET_SCHEDULER_add_delayed
(GNUNET_TIME_UNIT_SECONDS,
-
&restart_task, h);
+ h->restart_task =
GNUNET_SCHEDULER_add_delayed(
+
GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS,
+
h->retry_back_off),
&restart_task, h);
return;
}
GNUNET_DISK_pipe_close_end (h->helper_out, GNUNET_DISK_PIPE_END_WRITE);
return;
}
GNUNET_DISK_pipe_close_end (h->helper_out, GNUNET_DISK_PIPE_END_WRITE);
@@
-460,7
+466,11
@@
restart_task (void *cls,
{
struct GNUNET_HELPER_Handle*h = cls;
{
struct GNUNET_HELPER_Handle*h = cls;
- h->restart_task = GNUNET_SCHEDULER_NO_TASK;
+ h->restart_task = NULL;
+ h->retry_back_off++;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Restarting helper with back-off %u\n",
+ h->retry_back_off);
start_helper (h);
}
start_helper (h);
}
@@
-498,7
+508,7
@@
GNUNET_HELPER_start (int with_control_pipe,
if (NULL != strstr (binary_name, "gnunet"))
h->binary_name = GNUNET_OS_get_libexec_binary_path (binary_name);
else
if (NULL != strstr (binary_name, "gnunet"))
h->binary_name = GNUNET_OS_get_libexec_binary_path (binary_name);
else
- h->binary_name = strdup (binary_name);
+ h->binary_name =
GNUNET_
strdup (binary_name);
for (c = 0; NULL != binary_argv[c]; c++);
h->binary_argv = GNUNET_malloc (sizeof (char *) * (c + 1));
for (c = 0; NULL != binary_argv[c]; c++)
for (c = 0; NULL != binary_argv[c]; c++);
h->binary_argv = GNUNET_malloc (sizeof (char *) * (c + 1));
for (c = 0; NULL != binary_argv[c]; c++)
@@
-508,6
+518,7
@@
GNUNET_HELPER_start (int with_control_pipe,
if (NULL != cb)
h->mst = GNUNET_SERVER_mst_create (cb, h->cb_cls);
h->exp_cb = exp_cb;
if (NULL != cb)
h->mst = GNUNET_SERVER_mst_create (cb, h->cb_cls);
h->exp_cb = exp_cb;
+ h->retry_back_off = 0;
start_helper (h);
return h;
}
start_helper (h);
return h;
}
@@
-524,13
+535,13
@@
GNUNET_HELPER_destroy (struct GNUNET_HELPER_Handle *h)
unsigned int c;
struct GNUNET_HELPER_SendHandle *sh;
unsigned int c;
struct GNUNET_HELPER_SendHandle *sh;
- if (
GNUNET_SCHEDULER_NO_TASK
!= h->write_task)
+ if (
NULL
!= h->write_task)
{
GNUNET_SCHEDULER_cancel (h->write_task);
{
GNUNET_SCHEDULER_cancel (h->write_task);
- h->write_task =
GNUNET_SCHEDULER_NO_TASK
;
+ h->write_task =
NULL
;
}
}
- GNUNET_assert (
GNUNET_SCHEDULER_NO_TASK
== h->read_task);
- GNUNET_assert (
GNUNET_SCHEDULER_NO_TASK
== h->restart_task);
+ GNUNET_assert (
NULL
== h->read_task);
+ GNUNET_assert (
NULL
== h->restart_task);
while (NULL != (sh = h->sh_head))
{
GNUNET_CONTAINER_DLL_remove (h->sh_head,
while (NULL != (sh = h->sh_head))
{
GNUNET_CONTAINER_DLL_remove (h->sh_head,
@@
-582,7
+593,7
@@
helper_write (void *cls,
const char *buf;
ssize_t t;
const char *buf;
ssize_t t;
- h->write_task =
GNUNET_SCHEDULER_NO_TASK
;
+ h->write_task =
NULL
;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
{
/* try again */
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
{
/* try again */
@@
-619,9
+630,9
@@
helper_write (void *cls,
"Stopping and restarting helper task!\n");
stop_helper (h, GNUNET_NO);
/* Restart the helper */
"Stopping and restarting helper task!\n");
stop_helper (h, GNUNET_NO);
/* Restart the helper */
- h->restart_task =
-
GNUNET_SCHEDULER_add_delayed
(GNUNET_TIME_UNIT_SECONDS,
-
&restart_task, h);
+ h->restart_task = GNUNET_SCHEDULER_add_delayed(
+
GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS,
+
h->retry_back_off),
&restart_task, h);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@
-684,7
+695,7
@@
GNUNET_HELPER_send (struct GNUNET_HELPER_Handle *h,
GNUNET_CONTAINER_DLL_insert_tail (h->sh_head,
h->sh_tail,
sh);
GNUNET_CONTAINER_DLL_insert_tail (h->sh_head,
h->sh_tail,
sh);
- if (
GNUNET_SCHEDULER_NO_TASK
== h->write_task)
+ if (
NULL
== h->write_task)
h->write_task = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
h->fh_to_helper,
&helper_write,
h->write_task = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
h->fh_to_helper,
&helper_write,
@@
-714,7
+725,7
@@
GNUNET_HELPER_send_cancel (struct GNUNET_HELPER_SendHandle *sh)
if (NULL == h->sh_head)
{
GNUNET_SCHEDULER_cancel (h->write_task);
if (NULL == h->sh_head)
{
GNUNET_SCHEDULER_cancel (h->write_task);
- h->write_task =
GNUNET_SCHEDULER_NO_TASK
;
+ h->write_task =
NULL
;
}
}
}
}
}
}