aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/gnunet-helper-testbed.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testbed/gnunet-helper-testbed.c')
-rw-r--r--src/testbed/gnunet-helper-testbed.c83
1 files changed, 27 insertions, 56 deletions
diff --git a/src/testbed/gnunet-helper-testbed.c b/src/testbed/gnunet-helper-testbed.c
index b43f10983..e27e21588 100644
--- a/src/testbed/gnunet-helper-testbed.c
+++ b/src/testbed/gnunet-helper-testbed.c
@@ -124,12 +124,12 @@ static struct GNUNET_DISK_PipeHandle *sigpipe;
124/** 124/**
125 * Task identifier for the read task 125 * Task identifier for the read task
126 */ 126 */
127static struct GNUNET_SCHEDULER_Task * read_task_id; 127static struct GNUNET_SCHEDULER_Task *read_task_id;
128 128
129/** 129/**
130 * Task identifier for the write task 130 * Task identifier for the write task
131 */ 131 */
132static struct GNUNET_SCHEDULER_Task * write_task_id; 132static struct GNUNET_SCHEDULER_Task *write_task_id;
133 133
134/** 134/**
135 * Task to kill the child 135 * Task to kill the child
@@ -137,11 +137,6 @@ static struct GNUNET_SCHEDULER_Task * write_task_id;
137static struct GNUNET_SCHEDULER_Task * child_death_task_id; 137static struct GNUNET_SCHEDULER_Task * child_death_task_id;
138 138
139/** 139/**
140 * shutdown task id
141 */
142static struct GNUNET_SCHEDULER_Task * shutdown_task_id;
143
144/**
145 * Are we done reading messages from stdin? 140 * Are we done reading messages from stdin?
146 */ 141 */
147static int done_reading; 142static int done_reading;
@@ -161,7 +156,6 @@ static void
161shutdown_task (void *cls) 156shutdown_task (void *cls)
162{ 157{
163 LOG_DEBUG ("Shutting down\n"); 158 LOG_DEBUG ("Shutting down\n");
164 shutdown_task_id = NULL;
165 if (NULL != testbed) 159 if (NULL != testbed)
166 { 160 {
167 LOG_DEBUG ("Killing testbed\n"); 161 LOG_DEBUG ("Killing testbed\n");
@@ -174,8 +168,12 @@ shutdown_task (void *cls)
174 } 168 }
175 if (NULL != write_task_id) 169 if (NULL != write_task_id)
176 { 170 {
177 GNUNET_SCHEDULER_cancel (write_task_id); 171 struct WriteContext *wc;
172
173 wc = GNUNET_SCHEDULER_cancel (write_task_id);
178 write_task_id = NULL; 174 write_task_id = NULL;
175 GNUNET_free (wc->data);
176 GNUNET_free (wc);
179 } 177 }
180 if (NULL != child_death_task_id) 178 if (NULL != child_death_task_id)
181 { 179 {
@@ -203,18 +201,6 @@ shutdown_task (void *cls)
203 201
204 202
205/** 203/**
206 * Scheduler shutdown task to be run now.
207 */
208static void
209shutdown_now (void)
210{
211 if (NULL != shutdown_task_id)
212 GNUNET_SCHEDULER_cancel (shutdown_task_id);
213 shutdown_task_id = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
214}
215
216
217/**
218 * Task to write to the standard out 204 * Task to write to the standard out
219 * 205 *
220 * @param cls the WriteContext 206 * @param cls the WriteContext
@@ -224,23 +210,16 @@ write_task (void *cls)
224{ 210{
225 struct WriteContext *wc = cls; 211 struct WriteContext *wc = cls;
226 ssize_t bytes_wrote; 212 ssize_t bytes_wrote;
227 const struct GNUNET_SCHEDULER_TaskContext *tc;
228 213
229 GNUNET_assert (NULL != wc); 214 GNUNET_assert (NULL != wc);
230 write_task_id = NULL; 215 write_task_id = NULL;
231 tc = GNUNET_SCHEDULER_get_task_context ();
232 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
233 {
234 GNUNET_free (wc->data);
235 GNUNET_free (wc);
236 return;
237 }
238 bytes_wrote = 216 bytes_wrote =
239 GNUNET_DISK_file_write (stdout_fd, wc->data + wc->pos, 217 GNUNET_DISK_file_write (stdout_fd, wc->data + wc->pos,
240 wc->length - wc->pos); 218 wc->length - wc->pos);
241 if (GNUNET_SYSERR == bytes_wrote) 219 if (GNUNET_SYSERR == bytes_wrote)
242 { 220 {
243 LOG (GNUNET_ERROR_TYPE_WARNING, "Cannot reply back configuration\n"); 221 LOG (GNUNET_ERROR_TYPE_WARNING,
222 "Cannot reply back configuration\n");
244 GNUNET_free (wc->data); 223 GNUNET_free (wc->data);
245 GNUNET_free (wc); 224 GNUNET_free (wc);
246 return; 225 return;
@@ -253,7 +232,8 @@ write_task (void *cls)
253 return; 232 return;
254 } 233 }
255 write_task_id = 234 write_task_id =
256 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, stdout_fd, 235 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
236 stdout_fd,
257 &write_task, wc); 237 &write_task, wc);
258} 238}
259 239
@@ -272,18 +252,9 @@ child_death_task (void *cls)
272 enum GNUNET_OS_ProcessStatusType type; 252 enum GNUNET_OS_ProcessStatusType type;
273 unsigned long code; 253 unsigned long code;
274 int ret; 254 int ret;
275 const struct GNUNET_SCHEDULER_TaskContext *tc;
276 255
277 pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ); 256 pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ);
278 child_death_task_id = NULL; 257 child_death_task_id = NULL;
279 tc = GNUNET_SCHEDULER_get_task_context ();
280 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
281 {
282 child_death_task_id =
283 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
284 pr, &child_death_task, NULL);
285 return;
286 }
287 /* consume the signal */ 258 /* consume the signal */
288 GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c))); 259 GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c)));
289 LOG_DEBUG ("Got SIGCHLD\n"); 260 LOG_DEBUG ("Got SIGCHLD\n");
@@ -302,7 +273,7 @@ child_death_task (void *cls)
302 if (0 != PLIBC_KILL (0, GNUNET_TERM_SIG)) 273 if (0 != PLIBC_KILL (0, GNUNET_TERM_SIG))
303 { 274 {
304 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "signal"); 275 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "signal");
305 shutdown_now (); /* Couldn't send the signal, we shutdown frowning */ 276 GNUNET_SCHEDULER_shutdown (); /* Couldn't send the signal, we shutdown frowning */
306 } 277 }
307 return; 278 return;
308 } 279 }
@@ -499,7 +470,8 @@ tokenizer_cb (void *cls, void *client,
499 reply->config_size = htons ((uint16_t) config_size); 470 reply->config_size = htons ((uint16_t) config_size);
500 wc->data = reply; 471 wc->data = reply;
501 write_task_id = 472 write_task_id =
502 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, stdout_fd, 473 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
474 stdout_fd,
503 &write_task, wc); 475 &write_task, wc);
504 child_death_task_id = 476 child_death_task_id =
505 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 477 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
@@ -510,7 +482,7 @@ tokenizer_cb (void *cls, void *client,
510 482
511error: 483error:
512 status = GNUNET_SYSERR; 484 status = GNUNET_SYSERR;
513 shutdown_now (); 485 GNUNET_SCHEDULER_shutdown ();
514 return GNUNET_SYSERR; 486 return GNUNET_SYSERR;
515} 487}
516 488
@@ -525,24 +497,20 @@ read_task (void *cls)
525{ 497{
526 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE]; 498 char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE];
527 ssize_t sread; 499 ssize_t sread;
528 const struct GNUNET_SCHEDULER_TaskContext *tc;
529 500
530 read_task_id = NULL; 501 read_task_id = NULL;
531 tc = GNUNET_SCHEDULER_get_task_context ();
532 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
533 return;
534 sread = GNUNET_DISK_file_read (stdin_fd, buf, sizeof (buf)); 502 sread = GNUNET_DISK_file_read (stdin_fd, buf, sizeof (buf));
535 if ((GNUNET_SYSERR == sread) || (0 == sread)) 503 if ((GNUNET_SYSERR == sread) || (0 == sread))
536 { 504 {
537 LOG_DEBUG ("STDIN closed\n"); 505 LOG_DEBUG ("STDIN closed\n");
538 shutdown_now (); 506 GNUNET_SCHEDULER_shutdown ();
539 return; 507 return;
540 } 508 }
541 if (GNUNET_YES == done_reading) 509 if (GNUNET_YES == done_reading)
542 { 510 {
543 /* didn't expect any more data! */ 511 /* didn't expect any more data! */
544 GNUNET_break_op (0); 512 GNUNET_break_op (0);
545 shutdown_now (); 513 GNUNET_SCHEDULER_shutdown ();
546 return; 514 return;
547 } 515 }
548 LOG_DEBUG ("Read %u bytes\n", sread); 516 LOG_DEBUG ("Read %u bytes\n", sread);
@@ -551,11 +519,12 @@ read_task (void *cls)
551 GNUNET_NO)) 519 GNUNET_NO))
552 { 520 {
553 GNUNET_break (0); 521 GNUNET_break (0);
554 shutdown_now (); 522 GNUNET_SCHEDULER_shutdown ();
555 return; 523 return;
556 } 524 }
557 read_task_id = /* No timeout while reading */ 525 read_task_id = /* No timeout while reading */
558 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, stdin_fd, 526 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
527 stdin_fd,
559 &read_task, NULL); 528 &read_task, NULL);
560} 529}
561 530
@@ -569,7 +538,9 @@ read_task (void *cls)
569 * @param cfg configuration 538 * @param cfg configuration
570 */ 539 */
571static void 540static void
572run (void *cls, char *const *args, const char *cfgfile, 541run (void *cls,
542 char *const *args,
543 const char *cfgfile,
573 const struct GNUNET_CONFIGURATION_Handle *cfg) 544 const struct GNUNET_CONFIGURATION_Handle *cfg)
574{ 545{
575 LOG_DEBUG ("Starting testbed helper...\n"); 546 LOG_DEBUG ("Starting testbed helper...\n");
@@ -577,11 +548,11 @@ run (void *cls, char *const *args, const char *cfgfile,
577 stdin_fd = GNUNET_DISK_get_handle_from_native (stdin); 548 stdin_fd = GNUNET_DISK_get_handle_from_native (stdin);
578 stdout_fd = GNUNET_DISK_get_handle_from_native (stdout); 549 stdout_fd = GNUNET_DISK_get_handle_from_native (stdout);
579 read_task_id = 550 read_task_id =
580 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, stdin_fd, 551 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
552 stdin_fd,
581 &read_task, NULL); 553 &read_task, NULL);
582 shutdown_task_id = 554 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
583 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, 555 NULL);
584 NULL);
585} 556}
586 557
587 558