aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxrs <xrs@mail36.net>2018-01-21 19:04:28 +0100
committerxrs <xrs@mail36.net>2018-01-21 19:04:28 +0100
commit8df42fb04245ec81c0c94e2f4583dbfdc8bfc57a (patch)
treedeb9296b9818bd49bdc73563dbc9939a7c53ff9d
parenta699c651aba63c4fb0a9e9cbafd52d514848dc8e (diff)
parent64ccb23dba77c969ef70f3e27272684f6864ac0f (diff)
downloadgnunet-8df42fb04245ec81c0c94e2f4583dbfdc8bfc57a.tar.gz
gnunet-8df42fb04245ec81c0c94e2f4583dbfdc8bfc57a.zip
Merge branch 'master' of ssh://gnunet.org/gnunet
-rw-r--r--src/fs/gnunet-publish.c57
-rw-r--r--src/util/scheduler.c81
-rw-r--r--src/util/test_scheduler.c49
3 files changed, 124 insertions, 63 deletions
diff --git a/src/fs/gnunet-publish.c b/src/fs/gnunet-publish.c
index 395aad7db..c75469a24 100644
--- a/src/fs/gnunet-publish.c
+++ b/src/fs/gnunet-publish.c
@@ -895,35 +895,30 @@ main (int argc, char *const *argv)
895{ 895{
896 struct GNUNET_GETOPT_CommandLineOption options[] = { 896 struct GNUNET_GETOPT_CommandLineOption options[] = {
897 GNUNET_GETOPT_option_uint ('a', 897 GNUNET_GETOPT_option_uint ('a',
898 "anonymity", 898 "anonymity",
899 "LEVEL", 899 "LEVEL",
900 gettext_noop ("set the desired LEVEL of sender-anonymity"), 900 gettext_noop ("set the desired LEVEL of sender-anonymity"),
901 &bo.anonymity_level), 901 &bo.anonymity_level),
902
903 GNUNET_GETOPT_option_flag ('d', 902 GNUNET_GETOPT_option_flag ('d',
904 "disable-creation-time", 903 "disable-creation-time",
905 gettext_noop ("disable adding the creation time to the " 904 gettext_noop ("disable adding the creation time to the "
906 "metadata of the uploaded file"), 905 "metadata of the uploaded file"),
907 &do_disable_creation_time), 906 &do_disable_creation_time),
908
909 GNUNET_GETOPT_option_flag ('D', 907 GNUNET_GETOPT_option_flag ('D',
910 "disable-extractor", 908 "disable-extractor",
911 gettext_noop ("do not use libextractor to add keywords or metadata"), 909 gettext_noop ("do not use libextractor to add keywords or metadata"),
912 &disable_extractor), 910 &disable_extractor),
913
914 GNUNET_GETOPT_option_flag ('e', 911 GNUNET_GETOPT_option_flag ('e',
915 "extract", 912 "extract",
916 gettext_noop ("print list of extracted keywords that would " 913 gettext_noop ("print list of extracted keywords that would "
917 "be used, but do not perform upload"), 914 "be used, but do not perform upload"),
918 &extract_only), 915 &extract_only),
919
920 GNUNET_FS_GETOPT_KEYWORDS ('k', 916 GNUNET_FS_GETOPT_KEYWORDS ('k',
921 "key", 917 "key",
922 "KEYWORD", 918 "KEYWORD",
923 gettext_noop ("add an additional keyword for the top-level " 919 gettext_noop ("add an additional keyword for the top-level "
924 "file or directory (this option can be specified multiple times)"), 920 "file or directory (this option can be specified multiple times)"),
925 &topKeywords), 921 &topKeywords),
926
927 GNUNET_FS_GETOPT_METADATA ('m', 922 GNUNET_FS_GETOPT_METADATA ('m',
928 "meta", 923 "meta",
929 "TYPE:VALUE", 924 "TYPE:VALUE",
@@ -955,20 +950,16 @@ main (int argc, char *const *argv)
955 gettext_noop ("publish the files under the pseudonym " 950 gettext_noop ("publish the files under the pseudonym "
956 "NAME (place file into namespace)"), 951 "NAME (place file into namespace)"),
957 &pseudonym), 952 &pseudonym),
958
959 GNUNET_GETOPT_option_uint ('r', 953 GNUNET_GETOPT_option_uint ('r',
960 "replication", 954 "replication",
961 "LEVEL", 955 "LEVEL",
962 gettext_noop ("set the desired replication LEVEL"), 956 gettext_noop ("set the desired replication LEVEL"),
963 &bo.replication_level), 957 &bo.replication_level),
964
965
966 GNUNET_GETOPT_option_flag ('s', 958 GNUNET_GETOPT_option_flag ('s',
967 "simulate-only", 959 "simulate-only",
968 gettext_noop ("only simulate the process but do not do " 960 gettext_noop ("only simulate the process but do not do "
969 "any actual publishing (useful to compute URIs)"), 961 "any actual publishing (useful to compute URIs)"),
970 &do_simulate), 962 &do_simulate),
971
972 GNUNET_GETOPT_option_string ('t', 963 GNUNET_GETOPT_option_string ('t',
973 "this", 964 "this",
974 "ID", 965 "ID",
@@ -981,7 +972,7 @@ main (int argc, char *const *argv)
981 "URI", 972 "URI",
982 gettext_noop ("URI to be published (can be used instead of passing a " 973 gettext_noop ("URI to be published (can be used instead of passing a "
983 "file to add keywords to the file with the respective URI)"), 974 "file to add keywords to the file with the respective URI)"),
984 &uri_string), 975 &uri_string),
985 976
986 GNUNET_GETOPT_option_verbose (&verbose), 977 GNUNET_GETOPT_option_verbose (&verbose),
987 978
diff --git a/src/util/scheduler.c b/src/util/scheduler.c
index 1e52dce9f..6cf5e1168 100644
--- a/src/util/scheduler.c
+++ b/src/util/scheduler.c
@@ -330,6 +330,19 @@ static struct GNUNET_SCHEDULER_Task *ready_head[GNUNET_SCHEDULER_PRIORITY_COUNT]
330static struct GNUNET_SCHEDULER_Task *ready_tail[GNUNET_SCHEDULER_PRIORITY_COUNT]; 330static struct GNUNET_SCHEDULER_Task *ready_tail[GNUNET_SCHEDULER_PRIORITY_COUNT];
331 331
332/** 332/**
333 * Task for installing parent control handlers (it might happen that the
334 * scheduler is shutdown before this task is executed, so
335 * GNUNET_SCHEDULER_shutdown must cancel it in that case)
336 */
337static struct GNUNET_SCHEDULER_Task *install_parent_control_task;
338
339/**
340 * Task for reading from a pipe that signal handlers will use to initiate
341 * shutdown
342 */
343static struct GNUNET_SCHEDULER_Task *shutdown_pipe_task;
344
345/**
333 * Number of tasks on the ready list. 346 * Number of tasks on the ready list.
334 */ 347 */
335static unsigned int ready_count; 348static unsigned int ready_count;
@@ -476,6 +489,18 @@ GNUNET_SCHEDULER_shutdown ()
476{ 489{
477 struct GNUNET_SCHEDULER_Task *pos; 490 struct GNUNET_SCHEDULER_Task *pos;
478 491
492 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
493 "GNUNET_SCHEDULER_shutdown\n");
494 if (NULL != install_parent_control_task)
495 {
496 GNUNET_SCHEDULER_cancel (install_parent_control_task);
497 install_parent_control_task = NULL;
498 }
499 if (NULL != shutdown_pipe_task)
500 {
501 GNUNET_SCHEDULER_cancel (shutdown_pipe_task);
502 shutdown_pipe_task = NULL;
503 }
479 while (NULL != (pos = shutdown_head)) 504 while (NULL != (pos = shutdown_head))
480 { 505 {
481 GNUNET_CONTAINER_DLL_remove (shutdown_head, 506 GNUNET_CONTAINER_DLL_remove (shutdown_head,
@@ -627,14 +652,7 @@ shutdown_if_no_lifeness ()
627 for (t = pending_timeout_head; NULL != t; t = t->next) 652 for (t = pending_timeout_head; NULL != t; t = t->next)
628 if (GNUNET_YES == t->lifeness) 653 if (GNUNET_YES == t->lifeness)
629 return; 654 return;
630 /* No lifeness! Cancel all pending tasks the driver knows about and shutdown */ 655 /* No lifeness! */
631 t = pending_head;
632 while (NULL != t)
633 {
634 struct GNUNET_SCHEDULER_Task *next = t->next;
635 GNUNET_SCHEDULER_cancel (t);
636 t = next;
637 }
638 GNUNET_SCHEDULER_shutdown (); 656 GNUNET_SCHEDULER_shutdown ();
639} 657}
640 658
@@ -661,12 +679,12 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_TaskCallback task,
661 struct DriverContext context = {.scheduled_head = NULL, 679 struct DriverContext context = {.scheduled_head = NULL,
662 .scheduled_tail = NULL, 680 .scheduled_tail = NULL,
663 .timeout = GNUNET_TIME_UNIT_FOREVER_REL}; 681 .timeout = GNUNET_TIME_UNIT_FOREVER_REL};
664 682
665 driver = GNUNET_SCHEDULER_driver_select (); 683 driver = GNUNET_SCHEDULER_driver_select ();
666 driver->cls = &context; 684 driver->cls = &context;
667 685
668 GNUNET_SCHEDULER_run_with_driver (driver, task, task_cls); 686 GNUNET_SCHEDULER_run_with_driver (driver, task, task_cls);
669 687
670 GNUNET_free (driver); 688 GNUNET_free (driver);
671} 689}
672 690
@@ -842,7 +860,7 @@ driver_add_multiple (struct GNUNET_SCHEDULER_Task *t)
842 success = scheduler_driver->add (scheduler_driver->cls, 860 success = scheduler_driver->add (scheduler_driver->cls,
843 t, 861 t,
844 fdi) && success; 862 fdi) && success;
845 fdi->et = GNUNET_SCHEDULER_ET_NONE; 863 fdi->et = GNUNET_SCHEDULER_ET_NONE;
846 } 864 }
847 if (GNUNET_YES != success) 865 if (GNUNET_YES != success)
848 { 866 {
@@ -853,12 +871,20 @@ driver_add_multiple (struct GNUNET_SCHEDULER_Task *t)
853 871
854 872
855static void 873static void
856shutdown_cb (void *cls) 874install_parent_control_handler (void *cls)
875{
876 install_parent_control_task = NULL;
877 GNUNET_OS_install_parent_control_handler (NULL);
878}
879
880
881static void
882shutdown_pipe_cb (void *cls)
857{ 883{
858 char c; 884 char c;
859 const struct GNUNET_DISK_FileHandle *pr; 885 const struct GNUNET_DISK_FileHandle *pr;
860 886
861 (void) cls; 887 shutdown_pipe_task = NULL;
862 pr = GNUNET_DISK_pipe_handle (shutdown_pipe_handle, 888 pr = GNUNET_DISK_pipe_handle (shutdown_pipe_handle,
863 GNUNET_DISK_PIPE_END_READ); 889 GNUNET_DISK_PIPE_END_READ);
864 GNUNET_assert (! GNUNET_DISK_handle_invalid (pr)); 890 GNUNET_assert (! GNUNET_DISK_handle_invalid (pr));
@@ -2007,7 +2033,7 @@ GNUNET_SCHEDULER_run_from_driver (struct GNUNET_SCHEDULER_Handle *sh)
2007 return GNUNET_NO; 2033 return GNUNET_NO;
2008 } 2034 }
2009 scheduler_driver->set_wakeup (scheduler_driver->cls, 2035 scheduler_driver->set_wakeup (scheduler_driver->cls,
2010 GNUNET_TIME_absolute_get ()); 2036 GNUNET_TIME_absolute_get ());
2011 return GNUNET_OK; 2037 return GNUNET_OK;
2012} 2038}
2013 2039
@@ -2087,12 +2113,14 @@ GNUNET_SCHEDULER_run_with_driver (const struct GNUNET_SCHEDULER_Driver *driver,
2087 0, 2113 0,
2088 sizeof (tsk)); 2114 sizeof (tsk));
2089 active_task = &tsk; 2115 active_task = &tsk;
2090 GNUNET_SCHEDULER_add_now (&GNUNET_OS_install_parent_control_handler, 2116 install_parent_control_task =
2091 NULL); 2117 GNUNET_SCHEDULER_add_now (&install_parent_control_handler,
2092 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 2118 NULL);
2093 pr, 2119 shutdown_pipe_task =
2094 &shutdown_cb, 2120 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
2095 NULL); 2121 pr,
2122 &shutdown_pipe_cb,
2123 NULL);
2096 current_lifeness = GNUNET_YES; 2124 current_lifeness = GNUNET_YES;
2097 GNUNET_SCHEDULER_add_with_reason_and_priority (task, 2125 GNUNET_SCHEDULER_add_with_reason_and_priority (task,
2098 task_cls, 2126 task_cls,
@@ -2107,6 +2135,13 @@ GNUNET_SCHEDULER_run_with_driver (const struct GNUNET_SCHEDULER_Driver *driver,
2107 GNUNET_NETWORK_fdset_handle_set (sh.rs, pr); 2135 GNUNET_NETWORK_fdset_handle_set (sh.rs, pr);
2108 ret = driver->loop (driver->cls, 2136 ret = driver->loop (driver->cls,
2109 &sh); 2137 &sh);
2138 GNUNET_assert (NULL == pending_head);
2139 GNUNET_assert (NULL == pending_timeout_head);
2140 GNUNET_assert (NULL == shutdown_head);
2141 for (int i = 0; i != GNUNET_SCHEDULER_PRIORITY_COUNT; ++i)
2142 {
2143 GNUNET_assert (NULL == ready_head[i]);
2144 }
2110 GNUNET_NETWORK_fdset_destroy (sh.rs); 2145 GNUNET_NETWORK_fdset_destroy (sh.rs);
2111 GNUNET_NETWORK_fdset_destroy (sh.ws); 2146 GNUNET_NETWORK_fdset_destroy (sh.ws);
2112 2147
@@ -2197,7 +2232,7 @@ select_loop (void *cls,
2197 struct DriverContext *context; 2232 struct DriverContext *context;
2198 int select_result; 2233 int select_result;
2199 int tasks_ready; 2234 int tasks_ready;
2200 2235
2201 context = cls; 2236 context = cls;
2202 GNUNET_assert (NULL != context); 2237 GNUNET_assert (NULL != context);
2203 rs = GNUNET_NETWORK_fdset_create (); 2238 rs = GNUNET_NETWORK_fdset_create ();
@@ -2303,7 +2338,7 @@ select_loop (void *cls,
2303 } 2338 }
2304 GNUNET_NETWORK_fdset_destroy (rs); 2339 GNUNET_NETWORK_fdset_destroy (rs);
2305 GNUNET_NETWORK_fdset_destroy (ws); 2340 GNUNET_NETWORK_fdset_destroy (ws);
2306 return GNUNET_OK; 2341 return GNUNET_OK;
2307} 2342}
2308 2343
2309 2344
@@ -2313,7 +2348,7 @@ select_set_wakeup (void *cls,
2313{ 2348{
2314 struct DriverContext *context = cls; 2349 struct DriverContext *context = cls;
2315 GNUNET_assert (NULL != context); 2350 GNUNET_assert (NULL != context);
2316 2351
2317 context->timeout = GNUNET_TIME_absolute_get_remaining (dt); 2352 context->timeout = GNUNET_TIME_absolute_get_remaining (dt);
2318} 2353}
2319 2354
diff --git a/src/util/test_scheduler.c b/src/util/test_scheduler.c
index 55d4c7137..83319d2aa 100644
--- a/src/util/test_scheduler.c
+++ b/src/util/test_scheduler.c
@@ -29,6 +29,8 @@ static struct GNUNET_DISK_PipeHandle *p;
29 29
30static const struct GNUNET_DISK_FileHandle *fds[2]; 30static const struct GNUNET_DISK_FileHandle *fds[2];
31 31
32static struct GNUNET_SCHEDULER_Task *never_run_task;
33
32 34
33static void 35static void
34task2 (void *cls) 36task2 (void *cls)
@@ -76,7 +78,7 @@ taskNeverRun (void *cls)
76 78
77 79
78static void 80static void
79taskLast (void *cls) 81taskLastRd (void *cls)
80{ 82{
81 int *ok = cls; 83 int *ok = cls;
82 84
@@ -86,6 +88,27 @@ taskLast (void *cls)
86 88
87 89
88static void 90static void
91taskLastSig (void *cls)
92{
93 int *ok = cls;
94
95 GNUNET_SCHEDULER_cancel (never_run_task);
96 GNUNET_assert (9 == *ok);
97 (*ok) = 0;
98}
99
100
101static void
102taskLastShutdown (void *cls)
103{
104 int *ok = cls;
105
106 GNUNET_assert (10 == *ok);
107 (*ok) = 0;
108}
109
110
111static void
89taskRd (void *cls) 112taskRd (void *cls)
90{ 113{
91 static char c; 114 static char c;
@@ -97,7 +120,7 @@ taskRd (void *cls)
97 GNUNET_assert (GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, fds[0])); 120 GNUNET_assert (GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, fds[0]));
98 GNUNET_assert (1 == GNUNET_DISK_file_read (fds[0], &c, 1)); 121 GNUNET_assert (1 == GNUNET_DISK_file_read (fds[0], &c, 1));
99 (*ok) = 8; 122 (*ok) = 8;
100 GNUNET_SCHEDULER_add_shutdown (&taskLast, 123 GNUNET_SCHEDULER_add_shutdown (&taskLastRd,
101 cls); 124 cls);
102 GNUNET_SCHEDULER_shutdown (); 125 GNUNET_SCHEDULER_shutdown ();
103} 126}
@@ -151,6 +174,8 @@ check ()
151{ 174{
152 int ok; 175 int ok;
153 176
177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
178 "[Check scheduling]\n");
154 ok = 1; 179 ok = 1;
155 GNUNET_SCHEDULER_run (&task1, &ok); 180 GNUNET_SCHEDULER_run (&task1, &ok);
156 return ok; 181 return ok;
@@ -163,8 +188,8 @@ taskShutdown (void *cls)
163 int *ok = cls; 188 int *ok = cls;
164 189
165 GNUNET_assert (1 == *ok); 190 GNUNET_assert (1 == *ok);
166 *ok = 8; 191 *ok = 10;
167 GNUNET_SCHEDULER_add_shutdown (&taskLast, cls); 192 GNUNET_SCHEDULER_add_shutdown (&taskLastShutdown, cls);
168 GNUNET_SCHEDULER_shutdown (); 193 GNUNET_SCHEDULER_shutdown ();
169} 194}
170 195
@@ -178,6 +203,8 @@ checkShutdown ()
178{ 203{
179 int ok; 204 int ok;
180 205
206 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
207 "[Check shutdown]\n");
181 ok = 1; 208 ok = 1;
182 GNUNET_SCHEDULER_run (&taskShutdown, &ok); 209 GNUNET_SCHEDULER_run (&taskShutdown, &ok);
183 return ok; 210 return ok;
@@ -191,8 +218,12 @@ taskSig (void *cls)
191 int *ok = cls; 218 int *ok = cls;
192 219
193 GNUNET_assert (1 == *ok); 220 GNUNET_assert (1 == *ok);
194 *ok = 8; 221 *ok = 9;
195 GNUNET_SCHEDULER_add_shutdown (&taskLast, cls); 222 GNUNET_SCHEDULER_add_shutdown (&taskLastSig, cls);
223 never_run_task =
224 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5),
225 &taskNeverRun,
226 NULL);
196 GNUNET_break (0 == PLIBC_KILL (getpid (), 227 GNUNET_break (0 == PLIBC_KILL (getpid (),
197 GNUNET_TERM_SIG)); 228 GNUNET_TERM_SIG));
198} 229}
@@ -207,6 +238,8 @@ checkSignal ()
207{ 238{
208 int ok; 239 int ok;
209 240
241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
242 "[Check signal handling]\n");
210 ok = 1; 243 ok = 1;
211 GNUNET_SCHEDULER_run (&taskSig, &ok); 244 GNUNET_SCHEDULER_run (&taskSig, &ok);
212 return ok; 245 return ok;
@@ -234,6 +267,8 @@ checkCancel ()
234{ 267{
235 int ok; 268 int ok;
236 269
270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
271 "[Check task cancellation]\n");
237 ok = 1; 272 ok = 1;
238 GNUNET_SCHEDULER_run (&taskCancel, &ok); 273 GNUNET_SCHEDULER_run (&taskCancel, &ok);
239 return ok; 274 return ok;
@@ -247,11 +282,11 @@ main (int argc, char *argv[])
247 282
248 GNUNET_log_setup ("test_scheduler", "WARNING", NULL); 283 GNUNET_log_setup ("test_scheduler", "WARNING", NULL);
249 ret += check (); 284 ret += check ();
285 ret += checkCancel ();
250#ifndef MINGW 286#ifndef MINGW
251 ret += checkSignal (); 287 ret += checkSignal ();
252#endif 288#endif
253 ret += checkShutdown (); 289 ret += checkShutdown ();
254 ret += checkCancel ();
255 GNUNET_DISK_pipe_close (p); 290 GNUNET_DISK_pipe_close (p);
256 291
257 return ret; 292 return ret;