aboutsummaryrefslogtreecommitdiff
path: root/src/testbed
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-04-30 08:17:37 +0000
committerChristian Grothoff <christian@grothoff.org>2016-04-30 08:17:37 +0000
commit95f9076a2139f5fb042b944a0658b6cda2fa35db (patch)
treeb0826a2a1dcf812e6b4450fe6b05d47cd53ae49d /src/testbed
parent7746f68db77b9ca3c4aaca24ab2ce5253461240b (diff)
downloadgnunet-95f9076a2139f5fb042b944a0658b6cda2fa35db.tar.gz
gnunet-95f9076a2139f5fb042b944a0658b6cda2fa35db.zip
implementing new scheduler shutdown semantics
Diffstat (limited to 'src/testbed')
-rw-r--r--src/testbed/gnunet-daemon-latency-logger.c13
-rw-r--r--src/testbed/gnunet-daemon-testbed-blacklist.c69
-rw-r--r--src/testbed/gnunet-daemon-testbed-underlay.c9
-rw-r--r--src/testbed/gnunet-helper-testbed.c83
-rw-r--r--src/testbed/gnunet-service-test-barriers.c43
-rw-r--r--src/testbed/gnunet-service-testbed-logger.c66
-rw-r--r--src/testbed/gnunet-service-testbed.c30
-rw-r--r--src/testbed/gnunet-service-testbed_cpustatus.c4
-rw-r--r--src/testbed/gnunet-service-testbed_oc.c4
-rw-r--r--src/testbed/gnunet-testbed-profiler.c22
-rw-r--r--src/testbed/gnunet_testbed_mpi_spawn.c16
-rw-r--r--src/testbed/test_testbed_api_3peers_3controllers.c8
-rw-r--r--src/testbed/test_testbed_api_hosts.c7
-rw-r--r--src/testbed/test_testbed_api_testbed_run.c20
-rw-r--r--src/testbed/test_testbed_logger_api.c30
-rw-r--r--src/testbed/testbed_api_testbed.c15
16 files changed, 178 insertions, 261 deletions
diff --git a/src/testbed/gnunet-daemon-latency-logger.c b/src/testbed/gnunet-daemon-latency-logger.c
index 9652721a1..b2c7b1043 100644
--- a/src/testbed/gnunet-daemon-latency-logger.c
+++ b/src/testbed/gnunet-daemon-latency-logger.c
@@ -89,17 +89,12 @@ static struct sqlite3 *db;
89/** 89/**
90 * Handle to the ATS performance subsystem 90 * Handle to the ATS performance subsystem
91 */ 91 */
92struct GNUNET_ATS_PerformanceHandle *ats; 92static struct GNUNET_ATS_PerformanceHandle *ats;
93 93
94/** 94/**
95 * Prepared statement for inserting values into the database table 95 * Prepared statement for inserting values into the database table
96 */ 96 */
97struct sqlite3_stmt *stmt_insert; 97static struct sqlite3_stmt *stmt_insert;
98
99/**
100 * Shutdown task identifier
101 */
102struct GNUNET_SCHEDULER_Task * shutdown_task;
103 98
104 99
105/** 100/**
@@ -136,7 +131,6 @@ free_iterator (void *cls,
136static void 131static void
137do_shutdown (void *cls) 132do_shutdown (void *cls)
138{ 133{
139 shutdown_task = NULL;
140 GNUNET_ATS_performance_done (ats); 134 GNUNET_ATS_performance_done (ats);
141 ats = NULL; 135 ats = NULL;
142 if (NULL != stmt_insert) 136 if (NULL != stmt_insert)
@@ -298,8 +292,7 @@ run (void *cls, char *const *args, const char *cfgfile,
298 dbfile = NULL; 292 dbfile = NULL;
299 ats = GNUNET_ATS_performance_init (c, &addr_info_cb, NULL); 293 ats = GNUNET_ATS_performance_init (c, &addr_info_cb, NULL);
300 map = GNUNET_CONTAINER_multipeermap_create (30, GNUNET_YES); 294 map = GNUNET_CONTAINER_multipeermap_create (30, GNUNET_YES);
301 shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 295 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
302 &do_shutdown, NULL);
303} 296}
304 297
305 298
diff --git a/src/testbed/gnunet-daemon-testbed-blacklist.c b/src/testbed/gnunet-daemon-testbed-blacklist.c
index 0e0c7ebd5..0cb83aacf 100644
--- a/src/testbed/gnunet-daemon-testbed-blacklist.c
+++ b/src/testbed/gnunet-daemon-testbed-blacklist.c
@@ -67,12 +67,7 @@ static struct GNUNET_PeerIdentity *ilist;
67 * The blacklist handle we obtain from transport when we register ourselves for 67 * The blacklist handle we obtain from transport when we register ourselves for
68 * access control 68 * access control
69 */ 69 */
70struct GNUNET_TRANSPORT_Blacklist *bh; 70static struct GNUNET_TRANSPORT_Blacklist *bh;
71
72/**
73 * Task for shutdown
74 */
75static struct GNUNET_SCHEDULER_Task * shutdown_task;
76 71
77/** 72/**
78 * Are we allowing or denying access from peers 73 * Are we allowing or denying access from peers
@@ -81,26 +76,6 @@ static int mode;
81 76
82 77
83/** 78/**
84 * @ingroup hashmap
85 * Iterator over hash map entries.
86 *
87 * @param cls closure
88 * @param key current key code
89 * @param value value in the hash map
90 * @return #GNUNET_YES if we should continue to
91 * iterate,
92 * #GNUNET_NO if not.
93 */
94static int
95iterator (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
96{
97 GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (map, key,
98 value));
99 return GNUNET_YES;
100}
101
102
103/**
104 * Cleaup and destroy the map 79 * Cleaup and destroy the map
105 */ 80 */
106static void 81static void
@@ -108,9 +83,6 @@ cleanup_map ()
108{ 83{
109 if (NULL != map) 84 if (NULL != map)
110 { 85 {
111 GNUNET_assert (GNUNET_SYSERR != GNUNET_CONTAINER_multipeermap_iterate (map,
112 &iterator,
113 NULL));
114 GNUNET_CONTAINER_multipeermap_destroy (map); 86 GNUNET_CONTAINER_multipeermap_destroy (map);
115 map = NULL; 87 map = NULL;
116 } 88 }
@@ -161,14 +133,16 @@ check_access (void *cls, const struct GNUNET_PeerIdentity * pid)
161 * @param cfg the configuration for connecting to the peer's transport service 133 * @param cfg the configuration for connecting to the peer's transport service
162 */ 134 */
163static void 135static void
164setup_ac (const char *fname, const struct GNUNET_CONFIGURATION_Handle *cfg) 136setup_ac (const char *fname,
137 const struct GNUNET_CONFIGURATION_Handle *cfg)
165{ 138{
166 uint64_t fsize; 139 uint64_t fsize;
167 unsigned int npeers; 140 unsigned int npeers;
168 unsigned int cnt; 141 unsigned int cnt;
169 142
170 GNUNET_assert (GNUNET_OK != GNUNET_DISK_file_size (fname, &fsize, GNUNET_NO, 143 GNUNET_assert (GNUNET_OK !=
171 GNUNET_YES)); 144 GNUNET_DISK_file_size (fname, &fsize, GNUNET_NO,
145 GNUNET_YES));
172 if (0 != (fsize % sizeof (struct GNUNET_PeerIdentity))) 146 if (0 != (fsize % sizeof (struct GNUNET_PeerIdentity)))
173 { 147 {
174 GNUNET_break (0); 148 GNUNET_break (0);
@@ -183,17 +157,17 @@ setup_ac (const char *fname, const struct GNUNET_CONFIGURATION_Handle *cfg)
183 } 157 }
184 for (cnt = 0; cnt < npeers; cnt++) 158 for (cnt = 0; cnt < npeers; cnt++)
185 { 159 {
186 if (GNUNET_SYSERR == GNUNET_CONTAINER_multipeermap_put (map, &ilist[cnt], 160 if (GNUNET_SYSERR ==
187 &ilist[cnt], 161 GNUNET_CONTAINER_multipeermap_put (map, &ilist[cnt],
188 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 162 &ilist[cnt],
163 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
189 { 164 {
190 cleanup_map (); 165 cleanup_map ();
191 GNUNET_free (ilist); 166 GNUNET_free (ilist);
192 return; 167 return;
193 } 168 }
194 } 169 }
195 shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 170 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
196 &do_shutdown, NULL);
197 bh = GNUNET_TRANSPORT_blacklist (cfg, &check_access, NULL); 171 bh = GNUNET_TRANSPORT_blacklist (cfg, &check_access, NULL);
198} 172}
199 173
@@ -207,15 +181,18 @@ setup_ac (const char *fname, const struct GNUNET_CONFIGURATION_Handle *cfg)
207 * @param c configuration 181 * @param c configuration
208 */ 182 */
209static void 183static void
210run (void *cls, char *const *args, const char *cfgfile, 184run (void *cls,
185 char *const *args,
186 const char *cfgfile,
211 const struct GNUNET_CONFIGURATION_Handle *c) 187 const struct GNUNET_CONFIGURATION_Handle *c)
212{ 188{
213 char *shome; 189 char *shome;
214 char *fname; 190 char *fname;
215 191
216 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, "PATHS", 192 if (GNUNET_OK !=
217 "GNUNET_HOME", 193 GNUNET_CONFIGURATION_get_value_filename (c, "PATHS",
218 &shome)) 194 "GNUNET_HOME",
195 &shome))
219 { 196 {
220 GNUNET_break (0); 197 GNUNET_break (0);
221 return; 198 return;
@@ -260,13 +237,15 @@ main (int argc, char *const *argv)
260 }; 237 };
261 int ret; 238 int ret;
262 239
263 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 240 if (GNUNET_OK !=
241 GNUNET_STRINGS_get_utf8_args (argc, argv,
242 &argc, &argv))
264 return 2; 243 return 2;
265 ret = 244 ret =
266 (GNUNET_OK == 245 (GNUNET_OK ==
267 GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-testbed-blacklist", 246 GNUNET_PROGRAM_run (argc, argv,
268 _ 247 "gnunet-daemon-testbed-blacklist",
269 ("Daemon to restrict incoming transport layer connections during testbed deployments"), 248 _("Daemon to restrict incoming transport layer connections during testbed deployments"),
270 options, &run, NULL)) ? 0 : 1; 249 options, &run, NULL)) ? 0 : 1;
271 GNUNET_free ((void*) argv); 250 GNUNET_free ((void*) argv);
272 return ret; 251 return ret;
diff --git a/src/testbed/gnunet-daemon-testbed-underlay.c b/src/testbed/gnunet-daemon-testbed-underlay.c
index ce0cc46d9..663ab2d08 100644
--- a/src/testbed/gnunet-daemon-testbed-underlay.c
+++ b/src/testbed/gnunet-daemon-testbed-underlay.c
@@ -101,11 +101,6 @@ static struct GNUNET_TRANSPORT_Handle *transport;
101 */ 101 */
102static unsigned int num_hostkeys; 102static unsigned int num_hostkeys;
103 103
104/**
105 * Task for shutdown
106 */
107static struct GNUNET_SCHEDULER_Task * shutdown_task;
108
109 104
110/** 105/**
111 * @ingroup hashmap 106 * @ingroup hashmap
@@ -439,12 +434,10 @@ run (void *cls, char *const *args, const char *cfgfile,
439 GNUNET_free (wl_entry); 434 GNUNET_free (wl_entry);
440 } 435 }
441 bh = GNUNET_TRANSPORT_blacklist (c, &check_access, NULL); 436 bh = GNUNET_TRANSPORT_blacklist (c, &check_access, NULL);
442 shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 437 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
443 &do_shutdown, NULL);
444 438
445 close_db: 439 close_db:
446 GNUNET_break (SQLITE_OK == sqlite3_close (db)); 440 GNUNET_break (SQLITE_OK == sqlite3_close (db));
447 return;
448} 441}
449 442
450 443
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
diff --git a/src/testbed/gnunet-service-test-barriers.c b/src/testbed/gnunet-service-test-barriers.c
index 281172cbf..ce5249696 100644
--- a/src/testbed/gnunet-service-test-barriers.c
+++ b/src/testbed/gnunet-service-test-barriers.c
@@ -39,7 +39,9 @@
39/** 39/**
40 * Our barrier wait handle 40 * Our barrier wait handle
41 */ 41 */
42struct GNUNET_TESTBED_BarrierWaitHandle *wh; 42static struct GNUNET_TESTBED_BarrierWaitHandle *wh;
43
44static struct GNUNET_SCHEDULER_Task *tt;
43 45
44 46
45/** 47/**
@@ -51,8 +53,15 @@ static void
51do_shutdown (void *cls) 53do_shutdown (void *cls)
52{ 54{
53 if (NULL != wh) 55 if (NULL != wh)
56 {
54 GNUNET_TESTBED_barrier_wait_cancel (wh); 57 GNUNET_TESTBED_barrier_wait_cancel (wh);
55 wh = NULL; 58 wh = NULL;
59 }
60 if (NULL != tt)
61 {
62 GNUNET_SCHEDULER_cancel (tt);
63 tt = NULL;
64 }
56} 65}
57 66
58 67
@@ -63,8 +72,8 @@ do_shutdown (void *cls)
63 * 72 *
64 * @param cls NULL 73 * @param cls NULL
65 * @param name the barrier name 74 * @param name the barrier name
66 * @param status GNUNET_SYSERR in case of error while waiting for the barrier; 75 * @param status #GNUNET_SYSERR in case of error while waiting for the barrier;
67 * GNUNET_OK if the barrier is crossed 76 * #GNUNET_OK if the barrier is crossed
68 */ 77 */
69static void 78static void
70barrier_wait_cb (void *cls, const char *name, int status) 79barrier_wait_cb (void *cls, const char *name, int status)
@@ -84,12 +93,10 @@ barrier_wait_cb (void *cls, const char *name, int status)
84static void 93static void
85do_wait (void *cls) 94do_wait (void *cls)
86{ 95{
87 const struct GNUNET_SCHEDULER_TaskContext *tc; 96 tt = NULL;
88 97 wh = GNUNET_TESTBED_barrier_wait (TEST_BARRIER_NAME,
89 tc = GNUNET_SCHEDULER_get_task_context (); 98 &barrier_wait_cb,
90 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) 99 NULL);
91 return;
92 wh = GNUNET_TESTBED_barrier_wait (TEST_BARRIER_NAME, &barrier_wait_cb, NULL);
93 GNUNET_break (NULL != wh); 100 GNUNET_break (NULL != wh);
94} 101}
95 102
@@ -103,17 +110,18 @@ do_wait (void *cls)
103 * @param config the configuration file handle 110 * @param config the configuration file handle
104 */ 111 */
105static void 112static void
106run (void *cls, char *const *args, const char *cfgfile, 113run (void *cls,
114 char *const *args,
115 const char *cfgfile,
107 const struct GNUNET_CONFIGURATION_Handle *config) 116 const struct GNUNET_CONFIGURATION_Handle *config)
108{ 117{
109 unsigned int rsec; 118 unsigned int rsec;
110 119
111 rsec = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 10); 120 rsec = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 10);
112 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 121 tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
113 (GNUNET_TIME_UNIT_SECONDS, rsec), 122 (GNUNET_TIME_UNIT_SECONDS, rsec),
114 &do_wait, NULL); 123 &do_wait, NULL);
115 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 124 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
116 &do_shutdown, NULL);
117} 125}
118 126
119 127
@@ -121,7 +129,8 @@ run (void *cls, char *const *args, const char *cfgfile,
121/** 129/**
122 * Main 130 * Main
123 */ 131 */
124int main (int argc, char **argv) 132int
133main (int argc, char **argv)
125{ 134{
126 struct GNUNET_GETOPT_CommandLineOption options[] = { 135 struct GNUNET_GETOPT_CommandLineOption options[] = {
127 GNUNET_GETOPT_OPTION_END 136 GNUNET_GETOPT_OPTION_END
diff --git a/src/testbed/gnunet-service-testbed-logger.c b/src/testbed/gnunet-service-testbed-logger.c
index ab5b17460..0f9fab01b 100644
--- a/src/testbed/gnunet-service-testbed-logger.c
+++ b/src/testbed/gnunet-service-testbed-logger.c
@@ -81,11 +81,6 @@ static struct MessageQueue *mq_tail;
81struct GNUNET_BIO_WriteHandle *bio; 81struct GNUNET_BIO_WriteHandle *bio;
82 82
83/** 83/**
84 * The shutdown task handle
85 */
86static struct GNUNET_SCHEDULER_Task * shutdown_task_id;
87
88/**
89 * The number of connections we have 84 * The number of connections we have
90 */ 85 */
91static unsigned int nconn; 86static unsigned int nconn;
@@ -95,15 +90,17 @@ static unsigned int nconn;
95 */ 90 */
96static int in_shutdown; 91static int in_shutdown;
97 92
93
98/** 94/**
99 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages 95 * Message handler for #GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
100 * 96 *
101 * @param cls NULL 97 * @param cls NULL
102 * @param client identification of the client 98 * @param client identification of the client
103 * @param msg the actual message 99 * @param msg the actual message
104 */ 100 */
105static void 101static void
106handle_log_msg (void *cls, struct GNUNET_SERVER_Client *client, 102handle_log_msg (void *cls,
103 struct GNUNET_SERVER_Client *client,
107 const struct GNUNET_MessageHeader *msg) 104 const struct GNUNET_MessageHeader *msg)
108{ 105{
109 uint16_t ms; 106 uint16_t ms;
@@ -125,21 +122,20 @@ shutdown_task (void *cls)
125{ 122{
126 struct MessageQueue *mq_entry; 123 struct MessageQueue *mq_entry;
127 124
128 shutdown_task_id = NULL;
129 in_shutdown = GNUNET_YES; 125 in_shutdown = GNUNET_YES;
130 if (0 != nconn) 126 if (0 != nconn)
131 { 127 {
132 /* Delay shutdown if there are active connections */ 128 /* Delay shutdown if there are active connections */
133 shutdown_task_id = GNUNET_SCHEDULER_add_delayed 129 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
134 (GNUNET_TIME_UNIT_FOREVER_REL,
135 &shutdown_task, NULL);
136 return; 130 return;
137 } 131 }
138 while (NULL != (mq_entry = mq_head)) 132 while (NULL != (mq_entry = mq_head))
139 { 133 {
140 GNUNET_free (mq_entry->msg); 134 GNUNET_free (mq_entry->msg);
141 GNUNET_SERVER_client_drop (mq_entry->client); 135 GNUNET_SERVER_client_drop (mq_entry->client);
142 GNUNET_CONTAINER_DLL_remove (mq_head, mq_tail, mq_entry); 136 GNUNET_CONTAINER_DLL_remove (mq_head,
137 mq_tail,
138 mq_entry);
143 GNUNET_free (mq_entry); 139 GNUNET_free (mq_entry);
144 } 140 }
145 GNUNET_break (GNUNET_OK == GNUNET_BIO_write_close (bio)); 141 GNUNET_break (GNUNET_OK == GNUNET_BIO_write_close (bio));
@@ -147,7 +143,7 @@ shutdown_task (void *cls)
147 143
148 144
149/** 145/**
150 * Functions with this signature are called whenever a client 146x * Functions with this signature are called whenever a client
151 * is disconnected on the network level. 147 * is disconnected on the network level.
152 * 148 *
153 * @param cls closure 149 * @param cls closure
@@ -155,7 +151,8 @@ shutdown_task (void *cls)
155 * for the last call when the server is destroyed 151 * for the last call when the server is destroyed
156 */ 152 */
157static void 153static void
158client_disconnected (void *cls, struct GNUNET_SERVER_Client *client) 154client_disconnected (void *cls,
155 struct GNUNET_SERVER_Client *client)
159{ 156{
160 if (NULL == client) 157 if (NULL == client)
161 { 158 {
@@ -163,11 +160,8 @@ client_disconnected (void *cls, struct GNUNET_SERVER_Client *client)
163 return; 160 return;
164 } 161 }
165 nconn--; 162 nconn--;
166 if (GNUNET_YES != in_shutdown) 163 if (GNUNET_YES == in_shutdown)
167 return; 164 GNUNET_SCHEDULER_shutdown ();
168 GNUNET_assert (NULL != shutdown_task_id);
169 GNUNET_SCHEDULER_cancel (shutdown_task_id);
170 shutdown_task_id = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
171} 165}
172 166
173 167
@@ -179,7 +173,8 @@ client_disconnected (void *cls, struct GNUNET_SERVER_Client *client)
179 * @param client identification of the client 173 * @param client identification of the client
180 */ 174 */
181static void 175static void
182client_connected (void *cls, struct GNUNET_SERVER_Client *client) 176client_connected (void *cls,
177 struct GNUNET_SERVER_Client *client)
183{ 178{
184 if (NULL == client) 179 if (NULL == client)
185 { 180 {
@@ -199,8 +194,9 @@ client_connected (void *cls, struct GNUNET_SERVER_Client *client)
199 * @param cfg configuration to use 194 * @param cfg configuration to use
200 */ 195 */
201static void 196static void
202logger_run (void *cls, struct GNUNET_SERVER_Handle *server, 197logger_run (void *cls,
203 const struct GNUNET_CONFIGURATION_Handle *cfg) 198 struct GNUNET_SERVER_Handle *server,
199 const struct GNUNET_CONFIGURATION_Handle *cfg)
204{ 200{
205 static const struct GNUNET_SERVER_MessageHandler message_handlers[] = { 201 static const struct GNUNET_SERVER_MessageHandler message_handlers[] = {
206 {&handle_log_msg, NULL, GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG, 0}, 202 {&handle_log_msg, NULL, GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG, 0},
@@ -213,10 +209,14 @@ logger_run (void *cls, struct GNUNET_SERVER_Handle *server,
213 pid_t pid; 209 pid_t pid;
214 210
215 if (GNUNET_OK != 211 if (GNUNET_OK !=
216 GNUNET_CONFIGURATION_get_value_filename (cfg, "TESTBED-LOGGER", "DIR", 212 GNUNET_CONFIGURATION_get_value_filename (cfg,
213 "TESTBED-LOGGER",
214 "DIR",
217 &dir)) 215 &dir))
218 { 216 {
219 LOG (GNUNET_ERROR_TYPE_ERROR, "Not logging directory definied. Exiting\n"); 217 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
218 "TESTBED-LOGGER",
219 "DIR");
220 GNUNET_SCHEDULER_shutdown (); 220 GNUNET_SCHEDULER_shutdown ();
221 return; 221 return;
222 } 222 }
@@ -225,14 +225,19 @@ logger_run (void *cls, struct GNUNET_SERVER_Handle *server,
225 hname = GNUNET_malloc (hname_len); 225 hname = GNUNET_malloc (hname_len);
226 if (0 != gethostname (hname, hname_len)) 226 if (0 != gethostname (hname, hname_len))
227 { 227 {
228 LOG (GNUNET_ERROR_TYPE_ERROR, "Cannot get hostname. Exiting\n"); 228 LOG (GNUNET_ERROR_TYPE_ERROR,
229 "Cannot get hostname. Exiting\n");
229 GNUNET_free (hname); 230 GNUNET_free (hname);
230 GNUNET_free (dir); 231 GNUNET_free (dir);
231 GNUNET_SCHEDULER_shutdown (); 232 GNUNET_SCHEDULER_shutdown ();
232 return; 233 return;
233 } 234 }
234 (void) GNUNET_asprintf (&fn, "%s/%.*s_%jd.dat", dir, hname_len, hname, 235 GNUNET_asprintf (&fn,
235 (intmax_t) pid); 236 "%s/%.*s_%jd.dat",
237 dir,
238 hname_len,
239 hname,
240 (intmax_t) pid);
236 GNUNET_free (hname); 241 GNUNET_free (hname);
237 GNUNET_free (dir); 242 GNUNET_free (dir);
238 if (NULL == (bio = GNUNET_BIO_write_open (fn))) 243 if (NULL == (bio = GNUNET_BIO_write_open (fn)))
@@ -245,9 +250,7 @@ logger_run (void *cls, struct GNUNET_SERVER_Handle *server,
245 GNUNET_SERVER_add_handlers (server, message_handlers); 250 GNUNET_SERVER_add_handlers (server, message_handlers);
246 GNUNET_SERVER_connect_notify (server, &client_connected, NULL); 251 GNUNET_SERVER_connect_notify (server, &client_connected, NULL);
247 GNUNET_SERVER_disconnect_notify (server, &client_disconnected, NULL); 252 GNUNET_SERVER_disconnect_notify (server, &client_disconnected, NULL);
248 shutdown_task_id = 253 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
249 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
250 &shutdown_task, NULL);
251 LOG_DEBUG ("TESTBED-LOGGER startup complete\n"); 254 LOG_DEBUG ("TESTBED-LOGGER startup complete\n");
252} 255}
253 256
@@ -258,11 +261,10 @@ logger_run (void *cls, struct GNUNET_SERVER_Handle *server,
258int 261int
259main (int argc, char *const *argv) 262main (int argc, char *const *argv)
260{ 263{
261 //sleep (15); /* Debugging */
262 return (GNUNET_OK == 264 return (GNUNET_OK ==
263 GNUNET_SERVICE_run (argc, argv, "testbed-logger", 265 GNUNET_SERVICE_run (argc, argv, "testbed-logger",
264 GNUNET_SERVICE_OPTION_NONE, 266 GNUNET_SERVICE_OPTION_NONE,
265 &logger_run, NULL)) ? 0 : 1; 267 &logger_run, NULL)) ? 0 : 1;
266} 268}
267 269
268/* end of gnunet-service-testbed.c */ 270/* end of gnunet-service-testbed-logger.c */
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c
index e4fe87fcd..8a286742c 100644
--- a/src/testbed/gnunet-service-testbed.c
+++ b/src/testbed/gnunet-service-testbed.c
@@ -130,12 +130,6 @@ static struct MessageQueue *mq_tail;
130 130
131 131
132/** 132/**
133 * The shutdown task handle
134 */
135static struct GNUNET_SCHEDULER_Task * shutdown_task_id;
136
137
138/**
139 * Function called to notify a client about the connection begin ready to queue 133 * Function called to notify a client about the connection begin ready to queue
140 * more data. "buf" will be NULL and "size" zero if the connection was closed 134 * more data. "buf" will be NULL and "size" zero if the connection was closed
141 * for writing in the meantime. 135 * for writing in the meantime.
@@ -480,7 +474,8 @@ parse_shared_services (char *ss_str, struct GNUNET_CONFIGURATION_Handle *cfg)
480 * @param message the actual message 474 * @param message the actual message
481 */ 475 */
482static void 476static void
483handle_init (void *cls, struct GNUNET_SERVER_Client *client, 477handle_init (void *cls,
478 struct GNUNET_SERVER_Client *client,
484 const struct GNUNET_MessageHeader *message) 479 const struct GNUNET_MessageHeader *message)
485{ 480{
486 const struct GNUNET_TESTBED_InitMessage *msg; 481 const struct GNUNET_TESTBED_InitMessage *msg;
@@ -553,14 +548,15 @@ handle_init (void *cls, struct GNUNET_SERVER_Client *client,
553 548
554 549
555/** 550/**
556 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages 551 * Message handler for #GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages
557 * 552 *
558 * @param cls NULL 553 * @param cls NULL
559 * @param client identification of the client 554 * @param client identification of the client
560 * @param message the actual message 555 * @param message the actual message
561 */ 556 */
562static void 557static void
563handle_add_host (void *cls, struct GNUNET_SERVER_Client *client, 558handle_add_host (void *cls,
559 struct GNUNET_SERVER_Client *client,
564 const struct GNUNET_MessageHeader *message) 560 const struct GNUNET_MessageHeader *message)
565{ 561{
566 struct GNUNET_TESTBED_Host *host; 562 struct GNUNET_TESTBED_Host *host;
@@ -669,14 +665,15 @@ handle_add_host (void *cls, struct GNUNET_SERVER_Client *client,
669 665
670 666
671/** 667/**
672 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG messages 668 * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_GETSLAVECONFIG messages
673 * 669 *
674 * @param cls NULL 670 * @param cls NULL
675 * @param client identification of the client 671 * @param client identification of the client
676 * @param message the actual message 672 * @param message the actual message
677 */ 673 */
678static void 674static void
679handle_slave_get_config (void *cls, struct GNUNET_SERVER_Client *client, 675handle_slave_get_config (void *cls,
676 struct GNUNET_SERVER_Client *client,
680 const struct GNUNET_MessageHeader *message) 677 const struct GNUNET_MessageHeader *message)
681{ 678{
682 struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg; 679 struct GNUNET_TESTBED_SlaveGetConfigurationMessage *msg;
@@ -781,7 +778,6 @@ shutdown_task (void *cls)
781 struct MessageQueue *mq_entry; 778 struct MessageQueue *mq_entry;
782 uint32_t id; 779 uint32_t id;
783 780
784 shutdown_task_id = NULL;
785 LOG_DEBUG ("Shutting down testbed service\n"); 781 LOG_DEBUG ("Shutting down testbed service\n");
786 /* cleanup any remaining forwarded operations */ 782 /* cleanup any remaining forwarded operations */
787 GST_clear_fopcq (); 783 GST_clear_fopcq ();
@@ -939,10 +935,7 @@ testbed_run (void *cls, struct GNUNET_SERVER_Handle *server,
939 GST_config = GNUNET_CONFIGURATION_dup (cfg); 935 GST_config = GNUNET_CONFIGURATION_dup (cfg);
940 GNUNET_SERVER_add_handlers (server, message_handlers); 936 GNUNET_SERVER_add_handlers (server, message_handlers);
941 GNUNET_SERVER_disconnect_notify (server, &client_disconnect_cb, NULL); 937 GNUNET_SERVER_disconnect_notify (server, &client_disconnect_cb, NULL);
942 shutdown_task_id = 938 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
943 GNUNET_SCHEDULER_add_delayed_with_priority (GNUNET_TIME_UNIT_FOREVER_REL,
944 GNUNET_SCHEDULER_PRIORITY_IDLE,
945 &shutdown_task, NULL);
946 LOG_DEBUG ("Testbed startup complete\n"); 939 LOG_DEBUG ("Testbed startup complete\n");
947 GST_stats_init (GST_config); 940 GST_stats_init (GST_config);
948 GST_barriers_init (GST_config); 941 GST_barriers_init (GST_config);
@@ -955,9 +948,10 @@ testbed_run (void *cls, struct GNUNET_SERVER_Handle *server,
955int 948int
956main (int argc, char *const *argv) 949main (int argc, char *const *argv)
957{ 950{
958 //sleep (15); /* Debugging */
959 return (GNUNET_OK == 951 return (GNUNET_OK ==
960 GNUNET_SERVICE_run (argc, argv, "testbed", GNUNET_SERVICE_OPTION_NONE, 952 GNUNET_SERVICE_run (argc, argv,
953 "testbed",
954 GNUNET_SERVICE_OPTION_NONE,
961 &testbed_run, NULL)) ? 0 : 1; 955 &testbed_run, NULL)) ? 0 : 1;
962} 956}
963 957
diff --git a/src/testbed/gnunet-service-testbed_cpustatus.c b/src/testbed/gnunet-service-testbed_cpustatus.c
index cda669caa..ae49e31f9 100644
--- a/src/testbed/gnunet-service-testbed_cpustatus.c
+++ b/src/testbed/gnunet-service-testbed_cpustatus.c
@@ -655,12 +655,8 @@ sample_load_task (void *cls)
655 int ld_disk; 655 int ld_disk;
656 unsigned int mem_usage; 656 unsigned int mem_usage;
657 unsigned int nproc; 657 unsigned int nproc;
658 const struct GNUNET_SCHEDULER_TaskContext *tc;
659 658
660 sample_load_task_id = NULL; 659 sample_load_task_id = NULL;
661 tc = GNUNET_SCHEDULER_get_task_context ();
662 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
663 return;
664 ld_cpu = cpu_get_load (); 660 ld_cpu = cpu_get_load ();
665 ld_disk = disk_get_load (); 661 ld_disk = disk_get_load ();
666 if ( (-1 == ld_cpu) || (-1 == ld_disk) ) 662 if ( (-1 == ld_cpu) || (-1 == ld_disk) )
diff --git a/src/testbed/gnunet-service-testbed_oc.c b/src/testbed/gnunet-service-testbed_oc.c
index 34bf8e047..55dd5cad9 100644
--- a/src/testbed/gnunet-service-testbed_oc.c
+++ b/src/testbed/gnunet-service-testbed_oc.c
@@ -879,13 +879,9 @@ send_hello (void *cls)
879 struct OverlayConnectContext *occ = cls; 879 struct OverlayConnectContext *occ = cls;
880 struct LocalPeer2Context *lp2c; 880 struct LocalPeer2Context *lp2c;
881 char *other_peer_str; 881 char *other_peer_str;
882 const struct GNUNET_SCHEDULER_TaskContext *tc;
883 882
884 occ->send_hello_task = NULL; 883 occ->send_hello_task = NULL;
885 GNUNET_assert (NULL != occ->timeout_task); 884 GNUNET_assert (NULL != occ->timeout_task);
886 tc = GNUNET_SCHEDULER_get_task_context ();
887 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
888 return;
889 GNUNET_assert (NULL != occ->hello); 885 GNUNET_assert (NULL != occ->hello);
890 if (OCC_TYPE_LOCAL != occ->type) 886 if (OCC_TYPE_LOCAL != occ->type)
891 { 887 {
diff --git a/src/testbed/gnunet-testbed-profiler.c b/src/testbed/gnunet-testbed-profiler.c
index 308ec0386..9468b3c91 100644
--- a/src/testbed/gnunet-testbed-profiler.c
+++ b/src/testbed/gnunet-testbed-profiler.c
@@ -55,12 +55,7 @@ static char *hosts_file;
55/** 55/**
56 * Abort task identifier 56 * Abort task identifier
57 */ 57 */
58static struct GNUNET_SCHEDULER_Task * abort_task; 58static struct GNUNET_SCHEDULER_Task *abort_task;
59
60/**
61 * Shutdown task identifier
62 */
63static struct GNUNET_SCHEDULER_Task * shutdown_task;
64 59
65/** 60/**
66 * Global event mask for all testbed events 61 * Global event mask for all testbed events
@@ -111,7 +106,6 @@ static int noninteractive;
111static void 106static void
112do_shutdown (void *cls) 107do_shutdown (void *cls)
113{ 108{
114 shutdown_task = NULL;
115 if (NULL != abort_task) 109 if (NULL != abort_task)
116 { 110 {
117 GNUNET_SCHEDULER_cancel (abort_task); 111 GNUNET_SCHEDULER_cancel (abort_task);
@@ -122,7 +116,6 @@ do_shutdown (void *cls)
122 GNUNET_CONFIGURATION_destroy (cfg); 116 GNUNET_CONFIGURATION_destroy (cfg);
123 cfg = NULL; 117 cfg = NULL;
124 } 118 }
125 GNUNET_SCHEDULER_shutdown (); /* Stop scheduler to shutdown testbed run */
126} 119}
127 120
128 121
@@ -134,12 +127,11 @@ do_shutdown (void *cls)
134static void 127static void
135do_abort (void *cls) 128do_abort (void *cls)
136{ 129{
137 LOG (GNUNET_ERROR_TYPE_WARNING, "Aborting\n");
138 abort_task = NULL; 130 abort_task = NULL;
131 LOG (GNUNET_ERROR_TYPE_WARNING,
132 "Aborting\n");
139 result = GNUNET_SYSERR; 133 result = GNUNET_SYSERR;
140 if (NULL != shutdown_task) 134 GNUNET_SCHEDULER_shutdown ();
141 GNUNET_SCHEDULER_cancel (shutdown_task);
142 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
143} 135}
144 136
145 137
@@ -228,12 +220,11 @@ test_run (void *cls,
228 result = GNUNET_OK; 220 result = GNUNET_OK;
229 fprintf (stdout, "\n"); 221 fprintf (stdout, "\n");
230 print_overlay_links_summary (); 222 print_overlay_links_summary ();
223 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
231 if (noninteractive) 224 if (noninteractive)
232 { 225 {
233 GNUNET_SCHEDULER_cancel (abort_task); 226 GNUNET_SCHEDULER_cancel (abort_task);
234 abort_task = NULL; 227 abort_task = NULL;
235 shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
236 &do_shutdown, NULL);
237 return; 228 return;
238 } 229 }
239#if (!ENABLE_SUPERMUC) 230#if (!ENABLE_SUPERMUC)
@@ -243,8 +234,7 @@ test_run (void *cls,
243#endif 234#endif
244 fprintf (stdout, "Shutting down. Please wait\n"); 235 fprintf (stdout, "Shutting down. Please wait\n");
245 fflush (stdout); 236 fflush (stdout);
246 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 237 GNUNET_SCHEDULER_shutdown ();
247 return;
248} 238}
249 239
250 240
diff --git a/src/testbed/gnunet_testbed_mpi_spawn.c b/src/testbed/gnunet_testbed_mpi_spawn.c
index 191f658b7..d69812cd2 100644
--- a/src/testbed/gnunet_testbed_mpi_spawn.c
+++ b/src/testbed/gnunet_testbed_mpi_spawn.c
@@ -56,11 +56,6 @@ static unsigned long child_exit_code;
56static enum GNUNET_OS_ProcessStatusType child_status; 56static enum GNUNET_OS_ProcessStatusType child_status;
57 57
58/** 58/**
59 * The shutdown task
60 */
61static struct GNUNET_SCHEDULER_Task * shutdown_task_id;
62
63/**
64 * Task to kill the child 59 * Task to kill the child
65 */ 60 */
66static struct GNUNET_SCHEDULER_Task * terminate_task_id; 61static struct GNUNET_SCHEDULER_Task * terminate_task_id;
@@ -76,7 +71,6 @@ static struct GNUNET_SCHEDULER_Task * child_death_task_id;
76static void 71static void
77shutdown_task (void *cls) 72shutdown_task (void *cls)
78{ 73{
79 shutdown_task_id = NULL;
80 if (0 != child_exit_code) 74 if (0 != child_exit_code)
81 { 75 {
82 LOG (GNUNET_ERROR_TYPE_WARNING, "Child exited with error code: %lu\n", 76 LOG (GNUNET_ERROR_TYPE_WARNING, "Child exited with error code: %lu\n",
@@ -102,8 +96,7 @@ terminate_task (void *cls)
102 96
103 GNUNET_assert (NULL != child); 97 GNUNET_assert (NULL != child);
104 terminate_task_id = 98 terminate_task_id =
105 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 99 GNUNET_SCHEDULER_add_shutdown (&terminate_task, NULL);
106 &terminate_task, NULL);
107 if (0 != hard_kill) 100 if (0 != hard_kill)
108 { 101 {
109 switch (hard_kill) 102 switch (hard_kill)
@@ -159,7 +152,7 @@ child_death_task (void *cls)
159 &child_exit_code)); 152 &child_exit_code));
160 GNUNET_OS_process_destroy (child); 153 GNUNET_OS_process_destroy (child);
161 child = NULL; 154 child = NULL;
162 shutdown_task_id = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 155 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
163} 156}
164 157
165 158
@@ -253,13 +246,12 @@ run (void *cls)
253 { 246 {
254 GNUNET_break (0); 247 GNUNET_break (0);
255 ret = GNUNET_SYSERR; 248 ret = GNUNET_SYSERR;
256 shutdown_task_id = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 249 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
257 return; 250 return;
258 } 251 }
259 ret = GNUNET_OK; 252 ret = GNUNET_OK;
260 terminate_task_id = 253 terminate_task_id =
261 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 254 GNUNET_SCHEDULER_add_shutdown (&terminate_task, NULL);
262 &terminate_task, NULL);
263 child_death_task_id = 255 child_death_task_id =
264 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 256 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
265 GNUNET_DISK_pipe_handle (sigpipe, 257 GNUNET_DISK_pipe_handle (sigpipe,
diff --git a/src/testbed/test_testbed_api_3peers_3controllers.c b/src/testbed/test_testbed_api_3peers_3controllers.c
index a728048f3..0ee1fc566 100644
--- a/src/testbed/test_testbed_api_3peers_3controllers.c
+++ b/src/testbed/test_testbed_api_3peers_3controllers.c
@@ -301,6 +301,7 @@ do_abort (void *cls)
301 do_shutdown (cls); 301 do_shutdown (cls);
302} 302}
303 303
304
304static void 305static void
305abort_test () 306abort_test ()
306{ 307{
@@ -842,10 +843,11 @@ status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config,
842 * @param cls NULL 843 * @param cls NULL
843 * @param host the host whose status is being reported; will be NULL if the host 844 * @param host the host whose status is being reported; will be NULL if the host
844 * given to GNUNET_TESTBED_is_host_habitable() is NULL 845 * given to GNUNET_TESTBED_is_host_habitable() is NULL
845 * @param status GNUNET_YES if it is habitable; GNUNET_NO if not 846 * @param status #GNUNET_YES if it is habitable; #GNUNET_NO if not
846 */ 847 */
847static void 848static void
848host_habitable_cb (void *cls, const struct GNUNET_TESTBED_Host *_host, 849host_habitable_cb (void *cls,
850 const struct GNUNET_TESTBED_Host *_host,
849 int status) 851 int status)
850{ 852{
851 hc_handle = NULL; 853 hc_handle = NULL;
@@ -857,7 +859,7 @@ host_habitable_cb (void *cls, const struct GNUNET_TESTBED_Host *_host,
857 "Skipping test\n"); 859 "Skipping test\n");
858 GNUNET_SCHEDULER_cancel (abort_task); 860 GNUNET_SCHEDULER_cancel (abort_task);
859 abort_task = NULL; 861 abort_task = NULL;
860 (void) GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 862 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
861 result = SKIP; 863 result = SKIP;
862 return; 864 return;
863 } 865 }
diff --git a/src/testbed/test_testbed_api_hosts.c b/src/testbed/test_testbed_api_hosts.c
index 2141dc46f..0999020a8 100644
--- a/src/testbed/test_testbed_api_hosts.c
+++ b/src/testbed/test_testbed_api_hosts.c
@@ -58,10 +58,6 @@ static unsigned int num_hosts;
58 */ 58 */
59static int status; 59static int status;
60 60
61/**
62 * Shutdown task identifier
63 */
64struct GNUNET_SCHEDULER_Task * shutdown_id;
65 61
66/** 62/**
67 * The shutdown task 63 * The shutdown task
@@ -159,8 +155,7 @@ run (void *cls, char *const *args, const char *cfgfile,
159 } 155 }
160 } 156 }
161 status = GNUNET_YES; 157 status = GNUNET_YES;
162 shutdown_id = 158 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
163 GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (0), &do_shutdown, NULL);
164} 159}
165 160
166 161
diff --git a/src/testbed/test_testbed_api_testbed_run.c b/src/testbed/test_testbed_api_testbed_run.c
index 10beebc1f..45c9f5adf 100644
--- a/src/testbed/test_testbed_api_testbed_run.c
+++ b/src/testbed/test_testbed_api_testbed_run.c
@@ -86,9 +86,10 @@ do_shutdown (void *cls)
86static void 86static void
87do_abort (void *cls) 87do_abort (void *cls)
88{ 88{
89 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
90 abort_task = NULL; 89 abort_task = NULL;
91 (void) GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 90 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
91 "Test timed out -- Aborting\n");
92 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
92} 93}
93 94
94 95
@@ -119,8 +120,7 @@ test_master (void *cls,
119 return; /* abort already scheduled */ 120 return; /* abort already scheduled */
120 GNUNET_SCHEDULER_cancel (abort_task); 121 GNUNET_SCHEDULER_cancel (abort_task);
121 abort_task = NULL; 122 abort_task = NULL;
122 (void) GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 123 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
123 &do_shutdown, NULL);
124 return; 124 return;
125 } 125 }
126 GNUNET_assert (NULL != peers[0]); 126 GNUNET_assert (NULL != peers[0]);
@@ -168,7 +168,9 @@ controller_event_cb (void *cls,
168 * @param cfg the configuration file handle 168 * @param cfg the configuration file handle
169 */ 169 */
170static void 170static void
171run (void *cls, char *const *args, const char *cfgfile, 171run (void *cls,
172 char *const *args,
173 const char *cfgfile,
172 const struct GNUNET_CONFIGURATION_Handle *config) 174 const struct GNUNET_CONFIGURATION_Handle *config)
173{ 175{
174 uint64_t event_mask; 176 uint64_t event_mask;
@@ -176,11 +178,13 @@ run (void *cls, char *const *args, const char *cfgfile,
176 event_mask = 0; 178 event_mask = 0;
177 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START); 179 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
178 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP); 180 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP);
179 GNUNET_TESTBED_run (NULL, config, NUM_PEERS, event_mask, &controller_event_cb, 181 GNUNET_TESTBED_run (NULL, config, NUM_PEERS, event_mask,
180 NULL, &test_master, NULL); 182 &controller_event_cb, NULL,
183 &test_master, NULL);
181 abort_task = 184 abort_task =
182 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 185 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
183 (GNUNET_TIME_UNIT_SECONDS, 300), &do_abort, 186 (GNUNET_TIME_UNIT_SECONDS, 300),
187 &do_abort,
184 NULL); 188 NULL);
185} 189}
186 190
diff --git a/src/testbed/test_testbed_logger_api.c b/src/testbed/test_testbed_logger_api.c
index 30740c94d..f140dfbad 100644
--- a/src/testbed/test_testbed_logger_api.c
+++ b/src/testbed/test_testbed_logger_api.c
@@ -113,39 +113,39 @@ do_abort (void *cls)
113 * 113 *
114 * @param cls closure 114 * @param cls closure
115 * @param filename complete filename (absolute path) 115 * @param filename complete filename (absolute path)
116 * @return #GNUNET_OK to continue to iterate,
117 * #GNUNET_NO to stop iteration with no error,
118 * #GNUNET_SYSERR to abort iteration with error!
116 */ 119 */
117static void 120static int
118iterator_cb (void *cls, 121iterator_cb (void *cls,
119 const char *filename) 122 const char *filename)
120{ 123{
121 const char *fn; 124 const char *fn;
122 size_t len; 125 size_t len;
123 uint64_t fs; 126 uint64_t fs;
124 int cancel;
125 127
126 cancel = GNUNET_NO;
127 if (NULL == filename)
128 return;
129 len = strlen (filename); 128 len = strlen (filename);
130 if (len < 5) /* log file: `pid'.dat */ 129 if (len < 5) /* log file: `pid'.dat */
131 return; 130 return GNUNET_OK;
131
132 fn = filename + len; 132 fn = filename + len;
133 if (0 != strcasecmp (".dat", fn - 4)) 133 if (0 != strcasecmp (".dat", fn - 4))
134 return; 134 return GNUNET_OK;
135 if (GNUNET_OK != GNUNET_DISK_file_size (filename, &fs, 135 if (GNUNET_OK !=
136 GNUNET_NO, GNUNET_YES)) 136 GNUNET_DISK_file_size (filename, &fs,
137 return; 137 GNUNET_NO, GNUNET_YES))
138 return GNUNET_SYSERR;
138 if ((BSIZE * 2) != fs) /* The file size should be equal to what we 139 if ((BSIZE * 2) != fs) /* The file size should be equal to what we
139 have written */ 140 have written */
140 return; 141 return GNUNET_SYSERR;
141 cancel = GNUNET_YES; 142 return GNUNET_OK;
142 result = GNUNET_OK;
143} 143}
144 144
145 145
146/** 146/**
147 * Functions of this type are called to notify a successful transmission of the 147 * Functions of this type are called to notify a successful
148 * message to the logger service 148 * transmission of the message to the logger service
149 * 149 *
150 * @param cls the closure given to GNUNET_TESTBED_LOGGER_send() 150 * @param cls the closure given to GNUNET_TESTBED_LOGGER_send()
151 * @param size the amount of data sent 151 * @param size the amount of data sent
diff --git a/src/testbed/testbed_api_testbed.c b/src/testbed/testbed_api_testbed.c
index de99fb5a3..b3b2c3987 100644
--- a/src/testbed/testbed_api_testbed.c
+++ b/src/testbed/testbed_api_testbed.c
@@ -263,7 +263,7 @@ struct GNUNET_TESTBED_RunHandle
263 /** 263 /**
264 * Task run upon shutdown interrupts 264 * Task run upon shutdown interrupts
265 */ 265 */
266 struct GNUNET_SCHEDULER_Task * interrupt_task; 266 struct GNUNET_SCHEDULER_Task *interrupt_task;
267 267
268 /** 268 /**
269 * The event mask for the controller 269 * The event mask for the controller
@@ -620,8 +620,7 @@ interrupt (void *cls)
620 unsigned int size; 620 unsigned int size;
621 621
622 /* reschedule */ 622 /* reschedule */
623 rc->interrupt_task = GNUNET_SCHEDULER_add_delayed 623 rc->interrupt_task = GNUNET_SCHEDULER_add_shutdown (&interrupt, rc);
624 (GNUNET_TIME_UNIT_FOREVER_REL, &interrupt, rc);
625 rc_cleanup_operations (rc); 624 rc_cleanup_operations (rc);
626 if ( (GNUNET_NO == rc->shutdown) && 625 if ( (GNUNET_NO == rc->shutdown) &&
627 (NULL != c) && 626 (NULL != c) &&
@@ -988,7 +987,8 @@ host_registration_completion (void *cls, const char *emsg)
988 GNUNET_SCHEDULER_shutdown (); 987 GNUNET_SCHEDULER_shutdown ();
989 return; 988 return;
990 } 989 }
991 rc->register_hosts_task = GNUNET_SCHEDULER_add_now (&register_hosts, rc); 990 rc->register_hosts_task = GNUNET_SCHEDULER_add_now (&register_hosts,
991 rc);
992} 992}
993 993
994 994
@@ -1415,10 +1415,11 @@ GNUNET_TESTBED_run (const char *host_filename,
1415 } 1415 }
1416 rc->rcop_map = GNUNET_CONTAINER_multihashmap32_create (256); 1416 rc->rcop_map = GNUNET_CONTAINER_multihashmap32_create (256);
1417 rc->timeout_task = 1417 rc->timeout_task =
1418 GNUNET_SCHEDULER_add_delayed (timeout, &timeout_task, rc); 1418 GNUNET_SCHEDULER_add_delayed (timeout, &timeout_task, rc);
1419 GNUNET_assert (NULL == rc->interrupt_task);
1419 rc->interrupt_task = 1420 rc->interrupt_task =
1420 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &interrupt, 1421 GNUNET_SCHEDULER_add_shutdown (&interrupt,
1421 rc); 1422 rc);
1422 return; 1423 return;
1423 1424
1424error_cleanup: 1425error_cleanup: