diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/testbed/gnunet-helper-testbed.c | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/testbed/gnunet-helper-testbed.c')
-rw-r--r-- | src/testbed/gnunet-helper-testbed.c | 556 |
1 files changed, 279 insertions, 277 deletions
diff --git a/src/testbed/gnunet-helper-testbed.c b/src/testbed/gnunet-helper-testbed.c index a45f8de03..979d6c38f 100644 --- a/src/testbed/gnunet-helper-testbed.c +++ b/src/testbed/gnunet-helper-testbed.c | |||
@@ -49,12 +49,12 @@ | |||
49 | /** | 49 | /** |
50 | * Generic logging shortcut | 50 | * Generic logging shortcut |
51 | */ | 51 | */ |
52 | #define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) | 52 | #define LOG(kind, ...) GNUNET_log(kind, __VA_ARGS__) |
53 | 53 | ||
54 | /** | 54 | /** |
55 | * Debug logging shorthand | 55 | * Debug logging shorthand |
56 | */ | 56 | */ |
57 | #define LOG_DEBUG(...) LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | 57 | #define LOG_DEBUG(...) LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) |
58 | 58 | ||
59 | 59 | ||
60 | /** | 60 | /** |
@@ -70,8 +70,7 @@ | |||
70 | /** | 70 | /** |
71 | * Context for a single write on a chunk of memory | 71 | * Context for a single write on a chunk of memory |
72 | */ | 72 | */ |
73 | struct WriteContext | 73 | struct WriteContext { |
74 | { | ||
75 | /** | 74 | /** |
76 | * The data to write | 75 | * The data to write |
77 | */ | 76 | */ |
@@ -151,50 +150,50 @@ static int status; | |||
151 | * @param cls NULL | 150 | * @param cls NULL |
152 | */ | 151 | */ |
153 | static void | 152 | static void |
154 | shutdown_task (void *cls) | 153 | shutdown_task(void *cls) |
155 | { | 154 | { |
156 | LOG_DEBUG ("Shutting down\n"); | 155 | LOG_DEBUG("Shutting down\n"); |
157 | if (NULL != testbed) | 156 | if (NULL != testbed) |
158 | { | 157 | { |
159 | LOG_DEBUG ("Killing testbed\n"); | 158 | LOG_DEBUG("Killing testbed\n"); |
160 | GNUNET_break (0 == GNUNET_OS_process_kill (testbed, GNUNET_TERM_SIG)); | 159 | GNUNET_break(0 == GNUNET_OS_process_kill(testbed, GNUNET_TERM_SIG)); |
161 | } | 160 | } |
162 | if (NULL != read_task_id) | 161 | if (NULL != read_task_id) |
163 | { | 162 | { |
164 | GNUNET_SCHEDULER_cancel (read_task_id); | 163 | GNUNET_SCHEDULER_cancel(read_task_id); |
165 | read_task_id = NULL; | 164 | read_task_id = NULL; |
166 | } | 165 | } |
167 | if (NULL != write_task_id) | 166 | if (NULL != write_task_id) |
168 | { | 167 | { |
169 | struct WriteContext *wc; | 168 | struct WriteContext *wc; |
170 | 169 | ||
171 | wc = GNUNET_SCHEDULER_cancel (write_task_id); | 170 | wc = GNUNET_SCHEDULER_cancel(write_task_id); |
172 | write_task_id = NULL; | 171 | write_task_id = NULL; |
173 | GNUNET_free (wc->data); | 172 | GNUNET_free(wc->data); |
174 | GNUNET_free (wc); | 173 | GNUNET_free(wc); |
175 | } | 174 | } |
176 | if (NULL != child_death_task_id) | 175 | if (NULL != child_death_task_id) |
177 | { | 176 | { |
178 | GNUNET_SCHEDULER_cancel (child_death_task_id); | 177 | GNUNET_SCHEDULER_cancel(child_death_task_id); |
179 | child_death_task_id = NULL; | 178 | child_death_task_id = NULL; |
180 | } | 179 | } |
181 | if (NULL != stdin_fd) | 180 | if (NULL != stdin_fd) |
182 | (void) GNUNET_DISK_file_close (stdin_fd); | 181 | (void)GNUNET_DISK_file_close(stdin_fd); |
183 | if (NULL != stdout_fd) | 182 | if (NULL != stdout_fd) |
184 | (void) GNUNET_DISK_file_close (stdout_fd); | 183 | (void)GNUNET_DISK_file_close(stdout_fd); |
185 | GNUNET_MST_destroy (tokenizer); | 184 | GNUNET_MST_destroy(tokenizer); |
186 | tokenizer = NULL; | 185 | tokenizer = NULL; |
187 | if (NULL != testbed) | 186 | if (NULL != testbed) |
188 | { | 187 | { |
189 | GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (testbed)); | 188 | GNUNET_break(GNUNET_OK == GNUNET_OS_process_wait(testbed)); |
190 | GNUNET_OS_process_destroy (testbed); | 189 | GNUNET_OS_process_destroy(testbed); |
191 | testbed = NULL; | 190 | testbed = NULL; |
192 | } | 191 | } |
193 | if (NULL != test_system) | 192 | if (NULL != test_system) |
194 | { | 193 | { |
195 | GNUNET_TESTING_system_destroy (test_system, GNUNET_YES); | 194 | GNUNET_TESTING_system_destroy(test_system, GNUNET_YES); |
196 | test_system = NULL; | 195 | test_system = NULL; |
197 | } | 196 | } |
198 | } | 197 | } |
199 | 198 | ||
200 | 199 | ||
@@ -204,34 +203,34 @@ shutdown_task (void *cls) | |||
204 | * @param cls the WriteContext | 203 | * @param cls the WriteContext |
205 | */ | 204 | */ |
206 | static void | 205 | static void |
207 | write_task (void *cls) | 206 | write_task(void *cls) |
208 | { | 207 | { |
209 | struct WriteContext *wc = cls; | 208 | struct WriteContext *wc = cls; |
210 | ssize_t bytes_wrote; | 209 | ssize_t bytes_wrote; |
211 | 210 | ||
212 | GNUNET_assert (NULL != wc); | 211 | GNUNET_assert(NULL != wc); |
213 | write_task_id = NULL; | 212 | write_task_id = NULL; |
214 | bytes_wrote = GNUNET_DISK_file_write (stdout_fd, | 213 | bytes_wrote = GNUNET_DISK_file_write(stdout_fd, |
215 | wc->data + wc->pos, | 214 | wc->data + wc->pos, |
216 | wc->length - wc->pos); | 215 | wc->length - wc->pos); |
217 | if (GNUNET_SYSERR == bytes_wrote) | 216 | if (GNUNET_SYSERR == bytes_wrote) |
218 | { | 217 | { |
219 | LOG (GNUNET_ERROR_TYPE_WARNING, "Cannot reply back configuration\n"); | 218 | LOG(GNUNET_ERROR_TYPE_WARNING, "Cannot reply back configuration\n"); |
220 | GNUNET_free (wc->data); | 219 | GNUNET_free(wc->data); |
221 | GNUNET_free (wc); | 220 | GNUNET_free(wc); |
222 | return; | 221 | return; |
223 | } | 222 | } |
224 | wc->pos += bytes_wrote; | 223 | wc->pos += bytes_wrote; |
225 | if (wc->pos == wc->length) | 224 | if (wc->pos == wc->length) |
226 | { | 225 | { |
227 | GNUNET_free (wc->data); | 226 | GNUNET_free(wc->data); |
228 | GNUNET_free (wc); | 227 | GNUNET_free(wc); |
229 | return; | 228 | return; |
230 | } | 229 | } |
231 | write_task_id = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, | 230 | write_task_id = GNUNET_SCHEDULER_add_write_file(GNUNET_TIME_UNIT_FOREVER_REL, |
232 | stdout_fd, | 231 | stdout_fd, |
233 | &write_task, | 232 | &write_task, |
234 | wc); | 233 | wc); |
235 | } | 234 | } |
236 | 235 | ||
237 | 236 | ||
@@ -242,7 +241,7 @@ write_task (void *cls) | |||
242 | * @param cls closure, NULL if we need to self-restart | 241 | * @param cls closure, NULL if we need to self-restart |
243 | */ | 242 | */ |
244 | static void | 243 | static void |
245 | child_death_task (void *cls) | 244 | child_death_task(void *cls) |
246 | { | 245 | { |
247 | const struct GNUNET_DISK_FileHandle *pr; | 246 | const struct GNUNET_DISK_FileHandle *pr; |
248 | char c[16]; | 247 | char c[16]; |
@@ -250,36 +249,36 @@ child_death_task (void *cls) | |||
250 | unsigned long code; | 249 | unsigned long code; |
251 | int ret; | 250 | int ret; |
252 | 251 | ||
253 | pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ); | 252 | pr = GNUNET_DISK_pipe_handle(sigpipe, GNUNET_DISK_PIPE_END_READ); |
254 | child_death_task_id = NULL; | 253 | child_death_task_id = NULL; |
255 | /* consume the signal */ | 254 | /* consume the signal */ |
256 | GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof (c))); | 255 | GNUNET_break(0 < GNUNET_DISK_file_read(pr, &c, sizeof(c))); |
257 | LOG_DEBUG ("Got SIGCHLD\n"); | 256 | LOG_DEBUG("Got SIGCHLD\n"); |
258 | if (NULL == testbed) | 257 | if (NULL == testbed) |
259 | { | 258 | { |
260 | GNUNET_break (0); | 259 | GNUNET_break(0); |
261 | return; | 260 | return; |
262 | } | 261 | } |
263 | GNUNET_break (GNUNET_SYSERR != | 262 | GNUNET_break(GNUNET_SYSERR != |
264 | (ret = GNUNET_OS_process_status (testbed, &type, &code))); | 263 | (ret = GNUNET_OS_process_status(testbed, &type, &code))); |
265 | if (GNUNET_NO != ret) | 264 | if (GNUNET_NO != ret) |
266 | { | ||
267 | GNUNET_OS_process_destroy (testbed); | ||
268 | testbed = NULL; | ||
269 | /* Send SIGTERM to our process group */ | ||
270 | if (0 != kill (0, GNUNET_TERM_SIG)) | ||
271 | { | 265 | { |
272 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "signal"); | 266 | GNUNET_OS_process_destroy(testbed); |
273 | GNUNET_SCHEDULER_shutdown (); /* Couldn't send the signal, we shutdown frowning */ | 267 | testbed = NULL; |
268 | /* Send SIGTERM to our process group */ | ||
269 | if (0 != kill(0, GNUNET_TERM_SIG)) | ||
270 | { | ||
271 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "signal"); | ||
272 | GNUNET_SCHEDULER_shutdown(); /* Couldn't send the signal, we shutdown frowning */ | ||
273 | } | ||
274 | return; | ||
274 | } | 275 | } |
275 | return; | 276 | LOG_DEBUG("Child hasn't died. Resuming to monitor its status\n"); |
276 | } | ||
277 | LOG_DEBUG ("Child hasn't died. Resuming to monitor its status\n"); | ||
278 | child_death_task_id = | 277 | child_death_task_id = |
279 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 278 | GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, |
280 | pr, | 279 | pr, |
281 | &child_death_task, | 280 | &child_death_task, |
282 | NULL); | 281 | NULL); |
283 | } | 282 | } |
284 | 283 | ||
285 | 284 | ||
@@ -296,7 +295,7 @@ child_death_task (void *cls) | |||
296 | * #GNUNET_SYSERR to stop further processing with error | 295 | * #GNUNET_SYSERR to stop further processing with error |
297 | */ | 296 | */ |
298 | static int | 297 | static int |
299 | tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message) | 298 | tokenizer_cb(void *cls, const struct GNUNET_MessageHeader *message) |
300 | { | 299 | { |
301 | const struct GNUNET_TESTBED_HelperInit *msg; | 300 | const struct GNUNET_TESTBED_HelperInit *msg; |
302 | struct GNUNET_TESTBED_HelperReply *reply; | 301 | struct GNUNET_TESTBED_HelperReply *reply; |
@@ -316,182 +315,185 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message) | |||
316 | uint16_t hostname_size; | 315 | uint16_t hostname_size; |
317 | uint16_t msize; | 316 | uint16_t msize; |
318 | 317 | ||
319 | msize = ntohs (message->size); | 318 | msize = ntohs(message->size); |
320 | if ((sizeof (struct GNUNET_TESTBED_HelperInit) >= msize) || | 319 | if ((sizeof(struct GNUNET_TESTBED_HelperInit) >= msize) || |
321 | (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT != ntohs (message->type))) | 320 | (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT != ntohs(message->type))) |
322 | { | 321 | { |
323 | LOG (GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n"); | 322 | LOG(GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n"); |
324 | goto error; | 323 | goto error; |
325 | } | 324 | } |
326 | msg = (const struct GNUNET_TESTBED_HelperInit *) message; | 325 | msg = (const struct GNUNET_TESTBED_HelperInit *)message; |
327 | trusted_ip_size = ntohs (msg->trusted_ip_size); | 326 | trusted_ip_size = ntohs(msg->trusted_ip_size); |
328 | trusted_ip = (char *) &msg[1]; | 327 | trusted_ip = (char *)&msg[1]; |
329 | if ('\0' != trusted_ip[trusted_ip_size]) | 328 | if ('\0' != trusted_ip[trusted_ip_size]) |
330 | { | 329 | { |
331 | LOG (GNUNET_ERROR_TYPE_WARNING, "Trusted IP cannot be empty -- exiting\n"); | 330 | LOG(GNUNET_ERROR_TYPE_WARNING, "Trusted IP cannot be empty -- exiting\n"); |
332 | goto error; | 331 | goto error; |
333 | } | 332 | } |
334 | hostname_size = ntohs (msg->hostname_size); | 333 | hostname_size = ntohs(msg->hostname_size); |
335 | if ((sizeof (struct GNUNET_TESTBED_HelperInit) + trusted_ip_size + 1 + | 334 | if ((sizeof(struct GNUNET_TESTBED_HelperInit) + trusted_ip_size + 1 + |
336 | hostname_size) >= msize) | 335 | hostname_size) >= msize) |
337 | { | 336 | { |
338 | GNUNET_break (0); | 337 | GNUNET_break(0); |
339 | LOG (GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n"); | 338 | LOG(GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n"); |
340 | goto error; | 339 | goto error; |
341 | } | 340 | } |
342 | ul_config_size = (uLongf) ntohs (msg->config_size); | 341 | ul_config_size = (uLongf)ntohs(msg->config_size); |
343 | config = GNUNET_malloc (ul_config_size); | 342 | config = GNUNET_malloc(ul_config_size); |
344 | xconfig_size = msize - (trusted_ip_size + 1 + hostname_size + | 343 | xconfig_size = msize - (trusted_ip_size + 1 + hostname_size + |
345 | sizeof (struct GNUNET_TESTBED_HelperInit)); | 344 | sizeof(struct GNUNET_TESTBED_HelperInit)); |
346 | int ret = uncompress ((Bytef *) config, | 345 | int ret = uncompress((Bytef *)config, |
347 | &ul_config_size, | 346 | &ul_config_size, |
348 | (const Bytef *) (trusted_ip + trusted_ip_size + 1 + | 347 | (const Bytef *)(trusted_ip + trusted_ip_size + 1 + |
349 | hostname_size), | 348 | hostname_size), |
350 | (uLongf) xconfig_size); | 349 | (uLongf)xconfig_size); |
351 | if (Z_OK != ret) | 350 | if (Z_OK != ret) |
352 | { | ||
353 | switch (ret) | ||
354 | { | 351 | { |
355 | case Z_MEM_ERROR: | 352 | switch (ret) |
356 | LOG (GNUNET_ERROR_TYPE_ERROR, "Not enough memory for decompression\n"); | 353 | { |
357 | break; | 354 | case Z_MEM_ERROR: |
358 | case Z_BUF_ERROR: | 355 | LOG(GNUNET_ERROR_TYPE_ERROR, "Not enough memory for decompression\n"); |
359 | LOG (GNUNET_ERROR_TYPE_ERROR, "Output buffer too small\n"); | 356 | break; |
360 | break; | 357 | |
361 | case Z_DATA_ERROR: | 358 | case Z_BUF_ERROR: |
362 | LOG (GNUNET_ERROR_TYPE_ERROR, "Data corrupted/incomplete\n"); | 359 | LOG(GNUNET_ERROR_TYPE_ERROR, "Output buffer too small\n"); |
363 | break; | 360 | break; |
364 | default: | 361 | |
365 | GNUNET_break (0); | 362 | case Z_DATA_ERROR: |
363 | LOG(GNUNET_ERROR_TYPE_ERROR, "Data corrupted/incomplete\n"); | ||
364 | break; | ||
365 | |||
366 | default: | ||
367 | GNUNET_break(0); | ||
368 | } | ||
369 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
370 | "Error while uncompressing config -- exiting\n"); | ||
371 | GNUNET_free(config); | ||
372 | goto error; | ||
366 | } | 373 | } |
367 | LOG (GNUNET_ERROR_TYPE_ERROR, | 374 | cfg = GNUNET_CONFIGURATION_create(); |
368 | "Error while uncompressing config -- exiting\n"); | ||
369 | GNUNET_free (config); | ||
370 | goto error; | ||
371 | } | ||
372 | cfg = GNUNET_CONFIGURATION_create (); | ||
373 | if (GNUNET_OK != | 375 | if (GNUNET_OK != |
374 | GNUNET_CONFIGURATION_deserialize (cfg, config, ul_config_size, NULL)) | 376 | GNUNET_CONFIGURATION_deserialize(cfg, config, ul_config_size, NULL)) |
375 | { | 377 | { |
376 | LOG (GNUNET_ERROR_TYPE_ERROR, "Unable to deserialize config -- exiting\n"); | 378 | LOG(GNUNET_ERROR_TYPE_ERROR, "Unable to deserialize config -- exiting\n"); |
377 | GNUNET_free (config); | 379 | GNUNET_free(config); |
378 | goto error; | 380 | goto error; |
379 | } | 381 | } |
380 | GNUNET_free (config); | 382 | GNUNET_free(config); |
381 | hostname = NULL; | 383 | hostname = NULL; |
382 | if (0 != hostname_size) | 384 | if (0 != hostname_size) |
383 | { | 385 | { |
384 | hostname = GNUNET_malloc (hostname_size + 1); | 386 | hostname = GNUNET_malloc(hostname_size + 1); |
385 | GNUNET_strlcpy (hostname, | 387 | GNUNET_strlcpy(hostname, |
386 | ((char *) &msg[1]) + trusted_ip_size + 1, | 388 | ((char *)&msg[1]) + trusted_ip_size + 1, |
387 | hostname_size + 1); | 389 | hostname_size + 1); |
388 | } | 390 | } |
389 | /* unset GNUNET_TESTING_PREFIX if present as it is more relevant for testbed */ | 391 | /* unset GNUNET_TESTING_PREFIX if present as it is more relevant for testbed */ |
390 | evstr = getenv (GNUNET_TESTING_PREFIX); | 392 | evstr = getenv(GNUNET_TESTING_PREFIX); |
391 | if (NULL != evstr) | 393 | if (NULL != evstr) |
392 | { | 394 | { |
393 | /* unsetting the variable will invalidate the pointer! */ | 395 | /* unsetting the variable will invalidate the pointer! */ |
394 | evstr = GNUNET_strdup (evstr); | 396 | evstr = GNUNET_strdup(evstr); |
395 | #ifdef WINDOWS | 397 | #ifdef WINDOWS |
396 | GNUNET_break (0 != SetEnvironmentVariable (GNUNET_TESTING_PREFIX, NULL)); | 398 | GNUNET_break(0 != SetEnvironmentVariable(GNUNET_TESTING_PREFIX, NULL)); |
397 | #else | 399 | #else |
398 | GNUNET_break (0 == unsetenv (GNUNET_TESTING_PREFIX)); | 400 | GNUNET_break(0 == unsetenv(GNUNET_TESTING_PREFIX)); |
399 | #endif | 401 | #endif |
400 | } | 402 | } |
401 | test_system = | 403 | test_system = |
402 | GNUNET_TESTING_system_create ("testbed-helper", trusted_ip, hostname, NULL); | 404 | GNUNET_TESTING_system_create("testbed-helper", trusted_ip, hostname, NULL); |
403 | if (NULL != evstr) | 405 | if (NULL != evstr) |
404 | { | 406 | { |
405 | #ifdef WINDOWS | 407 | #ifdef WINDOWS |
406 | GNUNET_assert (0 != SetEnvironmentVariable (GNUNET_TESTING_PREFIX, evstr)); | 408 | GNUNET_assert(0 != SetEnvironmentVariable(GNUNET_TESTING_PREFIX, evstr)); |
407 | #else | 409 | #else |
408 | char *evar; | 410 | char *evar; |
409 | 411 | ||
410 | GNUNET_asprintf (&evar, GNUNET_TESTING_PREFIX "=%s", evstr); | 412 | GNUNET_asprintf(&evar, GNUNET_TESTING_PREFIX "=%s", evstr); |
411 | GNUNET_assert (0 == putenv (evar)); /* consumes 'evar', | 413 | GNUNET_assert(0 == putenv(evar)); /* consumes 'evar', |
412 | see putenv(): becomes part of envrionment! */ | 414 | see putenv(): becomes part of envrionment! */ |
413 | #endif | 415 | #endif |
414 | GNUNET_free (evstr); | 416 | GNUNET_free(evstr); |
415 | evstr = NULL; | 417 | evstr = NULL; |
416 | } | 418 | } |
417 | GNUNET_free_non_null (hostname); | 419 | GNUNET_free_non_null(hostname); |
418 | hostname = NULL; | 420 | hostname = NULL; |
419 | GNUNET_assert (NULL != test_system); | 421 | GNUNET_assert(NULL != test_system); |
420 | GNUNET_assert (GNUNET_OK == | 422 | GNUNET_assert(GNUNET_OK == |
421 | GNUNET_TESTING_configuration_create (test_system, cfg)); | 423 | GNUNET_TESTING_configuration_create(test_system, cfg)); |
422 | GNUNET_assert (GNUNET_OK == | 424 | GNUNET_assert(GNUNET_OK == |
423 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 425 | GNUNET_CONFIGURATION_get_value_filename(cfg, |
424 | "PATHS", | 426 | "PATHS", |
425 | "DEFAULTCONFIG", | 427 | "DEFAULTCONFIG", |
426 | &config)); | 428 | &config)); |
427 | if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, config)) | 429 | if (GNUNET_OK != GNUNET_CONFIGURATION_write(cfg, config)) |
428 | { | 430 | { |
429 | LOG (GNUNET_ERROR_TYPE_WARNING, | 431 | LOG(GNUNET_ERROR_TYPE_WARNING, |
430 | "Unable to write config file: %s -- exiting\n", | 432 | "Unable to write config file: %s -- exiting\n", |
431 | config); | 433 | config); |
432 | GNUNET_CONFIGURATION_destroy (cfg); | 434 | GNUNET_CONFIGURATION_destroy(cfg); |
433 | GNUNET_free (config); | 435 | GNUNET_free(config); |
434 | goto error; | 436 | goto error; |
435 | } | 437 | } |
436 | LOG_DEBUG ("Staring testbed with config: %s\n", config); | 438 | LOG_DEBUG("Staring testbed with config: %s\n", config); |
437 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-testbed"); | 439 | binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-testbed"); |
438 | { | 440 | { |
439 | char *evar; | 441 | char *evar; |
440 | 442 | ||
441 | /* expose testbed configuration through env variable */ | 443 | /* expose testbed configuration through env variable */ |
442 | GNUNET_asprintf (&evar, "%s=%s", ENV_TESTBED_CONFIG, config); | 444 | GNUNET_asprintf(&evar, "%s=%s", ENV_TESTBED_CONFIG, config); |
443 | GNUNET_assert (0 == putenv (evar)); /* consumes 'evar', | 445 | GNUNET_assert(0 == putenv(evar)); /* consumes 'evar', |
444 | see putenv(): becomes part of envrionment! */ | 446 | see putenv(): becomes part of envrionment! */ |
445 | evstr = NULL; | 447 | evstr = NULL; |
446 | } | 448 | } |
447 | testbed = GNUNET_OS_start_process (PIPE_CONTROL, | 449 | testbed = GNUNET_OS_start_process(PIPE_CONTROL, |
448 | GNUNET_OS_INHERIT_STD_ERR /*verbose? */, | 450 | GNUNET_OS_INHERIT_STD_ERR /*verbose? */, |
449 | NULL, | 451 | NULL, |
450 | NULL, | 452 | NULL, |
451 | NULL, | 453 | NULL, |
452 | binary, | 454 | binary, |
453 | "gnunet-service-testbed", | 455 | "gnunet-service-testbed", |
454 | "-c", | 456 | "-c", |
455 | config, | 457 | config, |
456 | NULL); | 458 | NULL); |
457 | GNUNET_free (binary); | 459 | GNUNET_free(binary); |
458 | GNUNET_free (config); | 460 | GNUNET_free(config); |
459 | if (NULL == testbed) | 461 | if (NULL == testbed) |
460 | { | 462 | { |
461 | LOG (GNUNET_ERROR_TYPE_WARNING, | 463 | LOG(GNUNET_ERROR_TYPE_WARNING, |
462 | "Error starting gnunet-service-testbed -- exiting\n"); | 464 | "Error starting gnunet-service-testbed -- exiting\n"); |
463 | GNUNET_CONFIGURATION_destroy (cfg); | 465 | GNUNET_CONFIGURATION_destroy(cfg); |
464 | goto error; | 466 | goto error; |
465 | } | 467 | } |
466 | done_reading = GNUNET_YES; | 468 | done_reading = GNUNET_YES; |
467 | config = GNUNET_CONFIGURATION_serialize (cfg, &config_size); | 469 | config = GNUNET_CONFIGURATION_serialize(cfg, &config_size); |
468 | GNUNET_CONFIGURATION_destroy (cfg); | 470 | GNUNET_CONFIGURATION_destroy(cfg); |
469 | cfg = NULL; | 471 | cfg = NULL; |
470 | xconfig_size = | 472 | xconfig_size = |
471 | GNUNET_TESTBED_compress_config_ (config, config_size, &xconfig); | 473 | GNUNET_TESTBED_compress_config_(config, config_size, &xconfig); |
472 | GNUNET_free (config); | 474 | GNUNET_free(config); |
473 | wc = GNUNET_new (struct WriteContext); | 475 | wc = GNUNET_new(struct WriteContext); |
474 | wc->length = xconfig_size + sizeof (struct GNUNET_TESTBED_HelperReply); | 476 | wc->length = xconfig_size + sizeof(struct GNUNET_TESTBED_HelperReply); |
475 | reply = GNUNET_realloc (xconfig, wc->length); | 477 | reply = GNUNET_realloc(xconfig, wc->length); |
476 | memmove (&reply[1], reply, xconfig_size); | 478 | memmove(&reply[1], reply, xconfig_size); |
477 | reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY); | 479 | reply->header.type = htons(GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY); |
478 | reply->header.size = htons ((uint16_t) wc->length); | 480 | reply->header.size = htons((uint16_t)wc->length); |
479 | reply->config_size = htons ((uint16_t) config_size); | 481 | reply->config_size = htons((uint16_t)config_size); |
480 | wc->data = reply; | 482 | wc->data = reply; |
481 | write_task_id = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, | 483 | write_task_id = GNUNET_SCHEDULER_add_write_file(GNUNET_TIME_UNIT_FOREVER_REL, |
482 | stdout_fd, | 484 | stdout_fd, |
483 | &write_task, | 485 | &write_task, |
484 | wc); | 486 | wc); |
485 | child_death_task_id = GNUNET_SCHEDULER_add_read_file ( | 487 | child_death_task_id = GNUNET_SCHEDULER_add_read_file( |
486 | GNUNET_TIME_UNIT_FOREVER_REL, | 488 | GNUNET_TIME_UNIT_FOREVER_REL, |
487 | GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ), | 489 | GNUNET_DISK_pipe_handle(sigpipe, GNUNET_DISK_PIPE_END_READ), |
488 | &child_death_task, | 490 | &child_death_task, |
489 | NULL); | 491 | NULL); |
490 | return GNUNET_OK; | 492 | return GNUNET_OK; |
491 | 493 | ||
492 | error: | 494 | error: |
493 | status = GNUNET_SYSERR; | 495 | status = GNUNET_SYSERR; |
494 | GNUNET_SCHEDULER_shutdown (); | 496 | GNUNET_SCHEDULER_shutdown(); |
495 | return GNUNET_SYSERR; | 497 | return GNUNET_SYSERR; |
496 | } | 498 | } |
497 | 499 | ||
@@ -502,41 +504,41 @@ error: | |||
502 | * @param cls NULL | 504 | * @param cls NULL |
503 | */ | 505 | */ |
504 | static void | 506 | static void |
505 | read_task (void *cls) | 507 | read_task(void *cls) |
506 | { | 508 | { |
507 | char buf[GNUNET_MAX_MESSAGE_SIZE]; | 509 | char buf[GNUNET_MAX_MESSAGE_SIZE]; |
508 | ssize_t sread; | 510 | ssize_t sread; |
509 | 511 | ||
510 | read_task_id = NULL; | 512 | read_task_id = NULL; |
511 | sread = GNUNET_DISK_file_read (stdin_fd, buf, sizeof (buf)); | 513 | sread = GNUNET_DISK_file_read(stdin_fd, buf, sizeof(buf)); |
512 | if ((GNUNET_SYSERR == sread) || (0 == sread)) | 514 | if ((GNUNET_SYSERR == sread) || (0 == sread)) |
513 | { | 515 | { |
514 | LOG_DEBUG ("STDIN closed\n"); | 516 | LOG_DEBUG("STDIN closed\n"); |
515 | GNUNET_SCHEDULER_shutdown (); | 517 | GNUNET_SCHEDULER_shutdown(); |
516 | return; | 518 | return; |
517 | } | 519 | } |
518 | if (GNUNET_YES == done_reading) | 520 | if (GNUNET_YES == done_reading) |
519 | { | 521 | { |
520 | /* didn't expect any more data! */ | 522 | /* didn't expect any more data! */ |
521 | GNUNET_break_op (0); | 523 | GNUNET_break_op(0); |
522 | GNUNET_SCHEDULER_shutdown (); | 524 | GNUNET_SCHEDULER_shutdown(); |
523 | return; | 525 | return; |
524 | } | 526 | } |
525 | LOG_DEBUG ("Read %u bytes\n", (unsigned int) sread); | 527 | LOG_DEBUG("Read %u bytes\n", (unsigned int)sread); |
526 | /* FIXME: could introduce a GNUNET_MST_read2 to read | 528 | /* FIXME: could introduce a GNUNET_MST_read2 to read |
527 | directly from 'stdin_fd' and save a memcpy() here */ | 529 | directly from 'stdin_fd' and save a memcpy() here */ |
528 | if (GNUNET_OK != | 530 | if (GNUNET_OK != |
529 | GNUNET_MST_from_buffer (tokenizer, buf, sread, GNUNET_NO, GNUNET_NO)) | 531 | GNUNET_MST_from_buffer(tokenizer, buf, sread, GNUNET_NO, GNUNET_NO)) |
530 | { | 532 | { |
531 | GNUNET_break (0); | 533 | GNUNET_break(0); |
532 | GNUNET_SCHEDULER_shutdown (); | 534 | GNUNET_SCHEDULER_shutdown(); |
533 | return; | 535 | return; |
534 | } | 536 | } |
535 | read_task_id /* No timeout while reading */ | 537 | read_task_id /* No timeout while reading */ |
536 | = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 538 | = GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, |
537 | stdin_fd, | 539 | stdin_fd, |
538 | &read_task, | 540 | &read_task, |
539 | NULL); | 541 | NULL); |
540 | } | 542 | } |
541 | 543 | ||
542 | 544 | ||
@@ -549,20 +551,20 @@ read_task (void *cls) | |||
549 | * @param cfg configuration | 551 | * @param cfg configuration |
550 | */ | 552 | */ |
551 | static void | 553 | static void |
552 | run (void *cls, | 554 | run(void *cls, |
553 | char *const *args, | 555 | char *const *args, |
554 | const char *cfgfile, | 556 | const char *cfgfile, |
555 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 557 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
556 | { | 558 | { |
557 | LOG_DEBUG ("Starting testbed helper...\n"); | 559 | LOG_DEBUG("Starting testbed helper...\n"); |
558 | tokenizer = GNUNET_MST_create (&tokenizer_cb, NULL); | 560 | tokenizer = GNUNET_MST_create(&tokenizer_cb, NULL); |
559 | stdin_fd = GNUNET_DISK_get_handle_from_native (stdin); | 561 | stdin_fd = GNUNET_DISK_get_handle_from_native(stdin); |
560 | stdout_fd = GNUNET_DISK_get_handle_from_native (stdout); | 562 | stdout_fd = GNUNET_DISK_get_handle_from_native(stdout); |
561 | read_task_id = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 563 | read_task_id = GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL, |
562 | stdin_fd, | 564 | stdin_fd, |
563 | &read_task, | 565 | &read_task, |
564 | NULL); | 566 | NULL); |
565 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 567 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); |
566 | } | 568 | } |
567 | 569 | ||
568 | 570 | ||
@@ -570,18 +572,18 @@ run (void *cls, | |||
570 | * Signal handler called for SIGCHLD. | 572 | * Signal handler called for SIGCHLD. |
571 | */ | 573 | */ |
572 | static void | 574 | static void |
573 | sighandler_child_death () | 575 | sighandler_child_death() |
574 | { | 576 | { |
575 | static char c; | 577 | static char c; |
576 | int old_errno; /* back-up errno */ | 578 | int old_errno; /* back-up errno */ |
577 | 579 | ||
578 | old_errno = errno; | 580 | old_errno = errno; |
579 | GNUNET_break ( | 581 | GNUNET_break( |
580 | 1 == | 582 | 1 == |
581 | GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle (sigpipe, | 583 | GNUNET_DISK_file_write(GNUNET_DISK_pipe_handle(sigpipe, |
582 | GNUNET_DISK_PIPE_END_WRITE), | 584 | GNUNET_DISK_PIPE_END_WRITE), |
583 | &c, | 585 | &c, |
584 | sizeof (c))); | 586 | sizeof(c))); |
585 | errno = old_errno; | 587 | errno = old_errno; |
586 | } | 588 | } |
587 | 589 | ||
@@ -594,31 +596,31 @@ sighandler_child_death () | |||
594 | * @return return code | 596 | * @return return code |
595 | */ | 597 | */ |
596 | int | 598 | int |
597 | main (int argc, char **argv) | 599 | main(int argc, char **argv) |
598 | { | 600 | { |
599 | struct GNUNET_SIGNAL_Context *shc_chld; | 601 | struct GNUNET_SIGNAL_Context *shc_chld; |
600 | struct GNUNET_GETOPT_CommandLineOption options[] = {GNUNET_GETOPT_OPTION_END}; | 602 | struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END }; |
601 | int ret; | 603 | int ret; |
602 | 604 | ||
603 | status = GNUNET_OK; | 605 | status = GNUNET_OK; |
604 | if (NULL == | 606 | if (NULL == |
605 | (sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO))) | 607 | (sigpipe = GNUNET_DISK_pipe(GNUNET_NO, GNUNET_NO, GNUNET_NO, GNUNET_NO))) |
606 | { | 608 | { |
607 | GNUNET_break (0); | 609 | GNUNET_break(0); |
608 | return 1; | 610 | return 1; |
609 | } | 611 | } |
610 | shc_chld = | 612 | shc_chld = |
611 | GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death); | 613 | GNUNET_SIGNAL_handler_install(GNUNET_SIGCHLD, &sighandler_child_death); |
612 | ret = GNUNET_PROGRAM_run (argc, | 614 | ret = GNUNET_PROGRAM_run(argc, |
613 | argv, | 615 | argv, |
614 | "gnunet-helper-testbed", | 616 | "gnunet-helper-testbed", |
615 | "Helper for starting gnunet-service-testbed", | 617 | "Helper for starting gnunet-service-testbed", |
616 | options, | 618 | options, |
617 | &run, | 619 | &run, |
618 | NULL); | 620 | NULL); |
619 | GNUNET_SIGNAL_handler_uninstall (shc_chld); | 621 | GNUNET_SIGNAL_handler_uninstall(shc_chld); |
620 | shc_chld = NULL; | 622 | shc_chld = NULL; |
621 | GNUNET_DISK_pipe_close (sigpipe); | 623 | GNUNET_DISK_pipe_close(sigpipe); |
622 | if (GNUNET_OK != ret) | 624 | if (GNUNET_OK != ret) |
623 | return 1; | 625 | return 1; |
624 | return (GNUNET_OK == status) ? 0 : 1; | 626 | return (GNUNET_OK == status) ? 0 : 1; |