diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-04-09 23:14:03 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-04-09 23:14:03 +0000 |
commit | 29e6158507a0758192075ac6ece7ba8e75ddc49a (patch) | |
tree | b91ded48da322f8ba4c9bb0f5504228aa036c2d1 /src/fs/gnunet-auto-share.c | |
parent | 5dfcb058ab5db9ae0c4b147d8a99c64ca0980028 (diff) | |
download | gnunet-29e6158507a0758192075ac6ece7ba8e75ddc49a.tar.gz gnunet-29e6158507a0758192075ac6ece7ba8e75ddc49a.zip |
small API change: do no longer pass rarely needed GNUNET_SCHEDULER_TaskContext to all scheduler tasks; instead, allow the relatively few tasks that need it to obtain the context via GNUNET_SCHEDULER_get_task_context()
Diffstat (limited to 'src/fs/gnunet-auto-share.c')
-rw-r--r-- | src/fs/gnunet-auto-share.c | 64 |
1 files changed, 29 insertions, 35 deletions
diff --git a/src/fs/gnunet-auto-share.c b/src/fs/gnunet-auto-share.c index 3e5c8777c..aef66614c 100644 --- a/src/fs/gnunet-auto-share.c +++ b/src/fs/gnunet-auto-share.c | |||
@@ -317,17 +317,15 @@ save_state () | |||
317 | * Task run on shutdown. Serializes our current state to disk. | 317 | * Task run on shutdown. Serializes our current state to disk. |
318 | * | 318 | * |
319 | * @param cls closure, unused | 319 | * @param cls closure, unused |
320 | * @param tc scheduler context, unused | ||
321 | */ | 320 | */ |
322 | static void | 321 | static void |
323 | do_stop_task (void *cls, | 322 | do_stop_task (void *cls) |
324 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
325 | { | 323 | { |
326 | kill_task = NULL; | 324 | kill_task = NULL; |
327 | do_shutdown = GNUNET_YES; | 325 | do_shutdown = GNUNET_YES; |
328 | if (NULL != publish_proc) | 326 | if (NULL != publish_proc) |
329 | { | 327 | { |
330 | GNUNET_OS_process_kill (publish_proc, | 328 | GNUNET_OS_process_kill (publish_proc, |
331 | SIGKILL); | 329 | SIGKILL); |
332 | return; | 330 | return; |
333 | } | 331 | } |
@@ -351,11 +349,9 @@ schedule_next_task (void); | |||
351 | * process died). | 349 | * process died). |
352 | * | 350 | * |
353 | * @param cls the `struct WorkItem` we were working on | 351 | * @param cls the `struct WorkItem` we were working on |
354 | * @param tc context | ||
355 | */ | 352 | */ |
356 | static void | 353 | static void |
357 | maint_child_death (void *cls, | 354 | maint_child_death (void *cls) |
358 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
359 | { | 355 | { |
360 | struct WorkItem *wi = cls; | 356 | struct WorkItem *wi = cls; |
361 | struct GNUNET_HashCode key; | 357 | struct GNUNET_HashCode key; |
@@ -364,10 +360,12 @@ maint_child_death (void *cls, | |||
364 | int ret; | 360 | int ret; |
365 | char c; | 361 | char c; |
366 | const struct GNUNET_DISK_FileHandle *pr; | 362 | const struct GNUNET_DISK_FileHandle *pr; |
363 | const struct GNUNET_SCHEDULER_TaskContext *tc; | ||
367 | 364 | ||
368 | run_task = NULL; | 365 | run_task = NULL; |
369 | pr = GNUNET_DISK_pipe_handle (sigpipe, | 366 | pr = GNUNET_DISK_pipe_handle (sigpipe, |
370 | GNUNET_DISK_PIPE_END_READ); | 367 | GNUNET_DISK_PIPE_END_READ); |
368 | tc = GNUNET_SCHEDULER_get_task_context (); | ||
371 | if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) | 369 | if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) |
372 | { | 370 | { |
373 | /* shutdown scheduled us, someone else will kill child, | 371 | /* shutdown scheduled us, someone else will kill child, |
@@ -389,7 +387,7 @@ maint_child_death (void *cls, | |||
389 | { | 387 | { |
390 | /* process still running? Then where did the SIGCHLD come from? | 388 | /* process still running? Then where did the SIGCHLD come from? |
391 | Well, let's declare it spurious (kernel bug?) and keep rolling. | 389 | Well, let's declare it spurious (kernel bug?) and keep rolling. |
392 | */ | 390 | */ |
393 | GNUNET_break (0); | 391 | GNUNET_break (0); |
394 | run_task = | 392 | run_task = |
395 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 393 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
@@ -398,7 +396,7 @@ maint_child_death (void *cls, | |||
398 | return; | 396 | return; |
399 | } | 397 | } |
400 | GNUNET_assert (GNUNET_OK == ret); | 398 | GNUNET_assert (GNUNET_OK == ret); |
401 | 399 | ||
402 | GNUNET_OS_process_destroy (publish_proc); | 400 | GNUNET_OS_process_destroy (publish_proc); |
403 | publish_proc = NULL; | 401 | publish_proc = NULL; |
404 | 402 | ||
@@ -457,11 +455,9 @@ sighandler_child_death () | |||
457 | * Function called to process work items. | 455 | * Function called to process work items. |
458 | * | 456 | * |
459 | * @param cls closure, NULL | 457 | * @param cls closure, NULL |
460 | * @param tc scheduler context (unused) | ||
461 | */ | 458 | */ |
462 | static void | 459 | static void |
463 | work (void *cls, | 460 | work (void *cls) |
464 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
465 | { | 461 | { |
466 | static char *argv[14]; | 462 | static char *argv[14]; |
467 | static char anon_level[20]; | 463 | static char anon_level[20]; |
@@ -521,7 +517,7 @@ work (void *cls, | |||
521 | NULL); | 517 | NULL); |
522 | return; | 518 | return; |
523 | } | 519 | } |
524 | pr = GNUNET_DISK_pipe_handle (sigpipe, | 520 | pr = GNUNET_DISK_pipe_handle (sigpipe, |
525 | GNUNET_DISK_PIPE_END_READ); | 521 | GNUNET_DISK_PIPE_END_READ); |
526 | run_task = | 522 | run_task = |
527 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 523 | GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, |
@@ -549,13 +545,13 @@ determine_id (void *cls, | |||
549 | 545 | ||
550 | if (0 != STAT (filename, &sbuf)) | 546 | if (0 != STAT (filename, &sbuf)) |
551 | { | 547 | { |
552 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 548 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
553 | "stat", | 549 | "stat", |
554 | filename); | 550 | filename); |
555 | return GNUNET_OK; | 551 | return GNUNET_OK; |
556 | } | 552 | } |
557 | GNUNET_CRYPTO_hash (filename, | 553 | GNUNET_CRYPTO_hash (filename, |
558 | strlen (filename), | 554 | strlen (filename), |
559 | &fx[0]); | 555 | &fx[0]); |
560 | if (!S_ISDIR (sbuf.st_mode)) | 556 | if (!S_ISDIR (sbuf.st_mode)) |
561 | { | 557 | { |
@@ -564,8 +560,8 @@ determine_id (void *cls, | |||
564 | fattr[0] = GNUNET_htonll (sbuf.st_size); | 560 | fattr[0] = GNUNET_htonll (sbuf.st_size); |
565 | fattr[0] = GNUNET_htonll (sbuf.st_mtime); | 561 | fattr[0] = GNUNET_htonll (sbuf.st_mtime); |
566 | 562 | ||
567 | GNUNET_CRYPTO_hash (fattr, | 563 | GNUNET_CRYPTO_hash (fattr, |
568 | sizeof (fattr), | 564 | sizeof (fattr), |
569 | &fx[1]); | 565 | &fx[1]); |
570 | } | 566 | } |
571 | else | 567 | else |
@@ -579,7 +575,7 @@ determine_id (void *cls, | |||
579 | } | 575 | } |
580 | /* use hash here to make hierarchical structure distinct from | 576 | /* use hash here to make hierarchical structure distinct from |
581 | all files on the same level */ | 577 | all files on the same level */ |
582 | GNUNET_CRYPTO_hash (fx, | 578 | GNUNET_CRYPTO_hash (fx, |
583 | sizeof (fx), | 579 | sizeof (fx), |
584 | &ft); | 580 | &ft); |
585 | /* use XOR here so that order of the files in the directory | 581 | /* use XOR here so that order of the files in the directory |
@@ -653,11 +649,9 @@ add_file (void *cls, | |||
653 | * Periodically run task to update our view of the directory to share. | 649 | * Periodically run task to update our view of the directory to share. |
654 | * | 650 | * |
655 | * @param cls NULL | 651 | * @param cls NULL |
656 | * @param tc scheduler context, unused | ||
657 | */ | 652 | */ |
658 | static void | 653 | static void |
659 | scan (void *cls, | 654 | scan (void *cls) |
660 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
661 | { | 655 | { |
662 | run_task = NULL; | 656 | run_task = NULL; |
663 | start_time = GNUNET_TIME_absolute_get (); | 657 | start_time = GNUNET_TIME_absolute_get (); |
@@ -695,7 +689,7 @@ schedule_next_task () | |||
695 | } | 689 | } |
696 | else | 690 | else |
697 | { | 691 | { |
698 | run_task = GNUNET_SCHEDULER_add_now (&work, | 692 | run_task = GNUNET_SCHEDULER_add_now (&work, |
699 | NULL); | 693 | NULL); |
700 | } | 694 | } |
701 | } | 695 | } |
@@ -710,15 +704,15 @@ schedule_next_task () | |||
710 | * @param c configuration | 704 | * @param c configuration |
711 | */ | 705 | */ |
712 | static void | 706 | static void |
713 | run (void *cls, | 707 | run (void *cls, |
714 | char *const *args, | 708 | char *const *args, |
715 | const char *cfgfile, | 709 | const char *cfgfile, |
716 | const struct GNUNET_CONFIGURATION_Handle *c) | 710 | const struct GNUNET_CONFIGURATION_Handle *c) |
717 | { | 711 | { |
718 | /* check arguments */ | 712 | /* check arguments */ |
719 | if ( (NULL == args[0]) || | 713 | if ( (NULL == args[0]) || |
720 | (NULL != args[1]) || | 714 | (NULL != args[1]) || |
721 | (GNUNET_YES != | 715 | (GNUNET_YES != |
722 | GNUNET_DISK_directory_test (args[0], | 716 | GNUNET_DISK_directory_test (args[0], |
723 | GNUNET_YES)) ) | 717 | GNUNET_YES)) ) |
724 | { | 718 | { |
@@ -729,14 +723,14 @@ run (void *cls, | |||
729 | cfg_filename = GNUNET_strdup (cfgfile); | 723 | cfg_filename = GNUNET_strdup (cfgfile); |
730 | cfg = c; | 724 | cfg = c; |
731 | dir_name = args[0]; | 725 | dir_name = args[0]; |
732 | work_finished = GNUNET_CONTAINER_multihashmap_create (1024, | 726 | work_finished = GNUNET_CONTAINER_multihashmap_create (1024, |
733 | GNUNET_NO); | 727 | GNUNET_NO); |
734 | load_state (); | 728 | load_state (); |
735 | run_task = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, | 729 | run_task = GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, |
736 | &scan, | 730 | &scan, |
737 | NULL); | 731 | NULL); |
738 | kill_task = | 732 | kill_task = |
739 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 733 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
740 | &do_stop_task, | 734 | &do_stop_task, |
741 | NULL); | 735 | NULL); |
742 | } | 736 | } |
@@ -799,17 +793,17 @@ main (int argc, char *const *argv) | |||
799 | int ok; | 793 | int ok; |
800 | struct GNUNET_SIGNAL_Context *shc_chld; | 794 | struct GNUNET_SIGNAL_Context *shc_chld; |
801 | 795 | ||
802 | if (GNUNET_OK != | 796 | if (GNUNET_OK != |
803 | GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 797 | GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
804 | return 2; | 798 | return 2; |
805 | sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, | 799 | sigpipe = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, |
806 | GNUNET_NO, GNUNET_NO); | 800 | GNUNET_NO, GNUNET_NO); |
807 | GNUNET_assert (NULL != sigpipe); | 801 | GNUNET_assert (NULL != sigpipe); |
808 | shc_chld = | 802 | shc_chld = |
809 | GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, | 803 | GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, |
810 | &sighandler_child_death); | 804 | &sighandler_child_death); |
811 | ok = (GNUNET_OK == | 805 | ok = (GNUNET_OK == |
812 | GNUNET_PROGRAM_run (argc, argv, | 806 | GNUNET_PROGRAM_run (argc, argv, |
813 | "gnunet-auto-share [OPTIONS] FILENAME", | 807 | "gnunet-auto-share [OPTIONS] FILENAME", |
814 | gettext_noop | 808 | gettext_noop |
815 | ("Automatically publish files from a directory on GNUnet"), | 809 | ("Automatically publish files from a directory on GNUnet"), |
@@ -823,7 +817,7 @@ main (int argc, char *const *argv) | |||
823 | } | 817 | } |
824 | while (NULL != (wi = work_head)) | 818 | while (NULL != (wi = work_head)) |
825 | { | 819 | { |
826 | GNUNET_CONTAINER_DLL_remove (work_head, | 820 | GNUNET_CONTAINER_DLL_remove (work_head, |
827 | work_tail, | 821 | work_tail, |
828 | wi); | 822 | wi); |
829 | GNUNET_free (wi->filename); | 823 | GNUNET_free (wi->filename); |