GNUnet debian-0.24.3-29-g453fda2cf
 
Loading...
Searching...
No Matches
program.c File Reference

standard code for GNUnet startup and shutdown More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_resolver_service.h"
#include "gnunet_constants.h"
#include "speedup.h"
#include <gcrypt.h>
Include dependency graph for program.c:

Go to the source code of this file.

Data Structures

struct  CommandContext
 Context for the command. More...
 
struct  MonoContext
 
struct  DaemonHandleList
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "util-program", __VA_ARGS__)
 
#define LOG_STRERROR_FILE(kind, syscall, filename)    GNUNET_log_from_strerror_file (kind, "util-program", syscall, filename)
 

Functions

static void shutdown_task (void *cls)
 task run when the scheduler shuts down
 
static void program_main (void *cls)
 Initial task called by the scheduler for each program.
 
static int cmd_sorter (const void *a1, const void *a2)
 Compare function for 'qsort' to sort command-line arguments by the short option.
 
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run2 (const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls, int run_without_scheduler)
 Run a standard GNUnet command startup sequence (initialize loggers and configuration, parse options).
 
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run (const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
 Run a standard GNUnet command startup sequence (initialize loggers and configuration, parse options).
 
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_conf_and_options (const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, struct GNUNET_CONFIGURATION_Handle *cfg)
 Create configuration handle from options and configuration file.
 
static void monolith_main (void *cls)
 
void GNUNET_PROGRAM_monolith_main (const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, struct GNUNET_CONFIGURATION_Handle *cfg)
 Start all services and daemons in a single process.
 
static void launch_daemon (void *cls)
 
static void launch_daemons (void *cls)
 
void GNUNET_DAEMON_main (const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, struct GNUNET_CONFIGURATION_Handle *cfg, enum GNUNET_GenericReturnValue with_scheduler)
 Run the mainloop in a monolithic libgnunet.
 
enum GNUNET_GenericReturnValue GNUNET_DAEMON_register (const char *daemon_name, const char *daemon_help, GNUNET_PROGRAM_Main task)
 

Variables

static struct DaemonHandleListhll_head = NULL
 
static struct DaemonHandleListhll_tail = NULL
 

Detailed Description

standard code for GNUnet startup and shutdown

Author
Christian Grothoff

Definition in file program.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "util-program", __VA_ARGS__)

Definition at line 35 of file program.c.

◆ LOG_STRERROR_FILE

#define LOG_STRERROR_FILE (   kind,
  syscall,
  filename 
)     GNUNET_log_from_strerror_file (kind, "util-program", syscall, filename)

Definition at line 37 of file program.c.

43{
47 char *const *args;
48
52 char *cfgfile;
53
58
62 void *task_cls;
63
67 const struct GNUNET_CONFIGURATION_Handle *cfg;
68};
69
70
74static void
75shutdown_task (void *cls)
76{
77 (void) cls;
79}
80
81
86static void
87program_main (void *cls)
88{
89 struct CommandContext *cc = cls;
90
93 NULL);
95 cc->task (cc->task_cls,
96 cc->args,
97 cc->cfgfile,
98 cc->cfg);
99}
100
101
109static int
110cmd_sorter (const void *a1,
111 const void *a2)
112{
113 const struct GNUNET_GETOPT_CommandLineOption *c1 = a1;
114 const struct GNUNET_GETOPT_CommandLineOption *c2 = a2;
115
116 if (toupper ((unsigned char) c1->shortName) >
117 toupper ((unsigned char) c2->shortName))
118 return 1;
119 if (toupper ((unsigned char) c1->shortName) <
120 toupper ((unsigned char) c2->shortName))
121 return -1;
122 if (c1->shortName > c2->shortName)
123 return 1;
124 if (c1->shortName < c2->shortName)
125 return -1;
126 return 0;
127}
128
129
132 int argc,
133 char *const *argv,
134 const char *binaryName,
135 const char *binaryHelp,
138 void *task_cls,
139 int run_without_scheduler)
140{
141 struct CommandContext cc;
142
143#if ENABLE_NLS
144 char *path;
145#endif
146 char *loglev;
147 char *logfile;
148 char *cfg_fn;
150 int iret;
151 unsigned int cnt;
152 unsigned long long skew_offset;
153 unsigned long long skew_variance;
154 long long clock_offset;
156 const struct GNUNET_GETOPT_CommandLineOption defoptions[] = {
159 binaryHelp),
163 };
164 unsigned int deflen = sizeof(defoptions) / sizeof(defoptions[0]);
165 struct GNUNET_GETOPT_CommandLineOption *allopts;
166 const char *gargs;
167 char *lpfx;
168 char *spc;
169
170 logfile = NULL;
171 gargs = getenv ("GNUNET_ARGS");
172 if (NULL != gargs)
173 {
174 char **gargv;
175 unsigned int gargc;
176 char *cargs;
177
178 gargv = NULL;
179 gargc = 0;
180 for (int i = 0; i < argc; i++)
181 GNUNET_array_append (gargv,
182 gargc,
183 GNUNET_strdup (argv[i]));
184 cargs = GNUNET_strdup (gargs);
185 for (char *tok = strtok (cargs, " ");
186 NULL != tok;
187 tok = strtok (NULL, " "))
188 GNUNET_array_append (gargv,
189 gargc,
190 GNUNET_strdup (tok));
191 GNUNET_free (cargs);
192 GNUNET_array_append (gargv,
193 gargc,
194 NULL);
195 argv = (char *const *) gargv;
196 argc = gargc - 1;
197 }
198 memset (&cc, 0, sizeof(cc));
199 loglev = NULL;
200 cc.task = task;
201 cc.task_cls = task_cls;
203 /* prepare */
204#if ENABLE_NLS
205 if (NULL != pd->gettext_domain)
206 {
207 setlocale (LC_ALL, "");
208 path = (NULL == pd->gettext_path)
212 if (NULL != path)
213 {
215 path);
216 GNUNET_free (path);
217 }
219 }
220#endif
221 cnt = 0;
222 while (NULL != options[cnt].name)
223 cnt++;
224 allopts = GNUNET_new_array (cnt + deflen + 1,
226 GNUNET_memcpy (allopts,
227 options,
228 cnt * sizeof(struct GNUNET_GETOPT_CommandLineOption));
229 {
230 unsigned int xtra = 0;
231
232 for (unsigned int i = 0;
233 i<sizeof (defoptions) / sizeof(struct GNUNET_GETOPT_CommandLineOption);
234 i++)
235 {
236 bool found = false;
237
238 for (unsigned int j = 0; j<cnt; j++)
239 {
240 found |= ( (options[j].shortName == defoptions[i].shortName) &&
241 (0 != options[j].shortName) );
242 found |= ( (NULL != options[j].name) &&
243 (NULL != defoptions[i].name) &&
244 (0 == strcmp (options[j].name,
245 defoptions[i].name)) );
246 if (found)
247 break;
248 }
249 if (found)
250 continue;
251 GNUNET_memcpy (&allopts[cnt + xtra],
252 &defoptions[i],
253 sizeof (struct GNUNET_GETOPT_CommandLineOption));
254 xtra++;
255 }
256 cnt += xtra;
257 }
258 qsort (allopts,
259 cnt,
260 sizeof(struct GNUNET_GETOPT_CommandLineOption),
261 &cmd_sorter);
262 loglev = NULL;
263 if ((NULL != pd->config_file) && (NULL != pd->user_config_file))
265 else
266 cfg_fn = NULL;
267 lpfx = GNUNET_strdup (binaryName);
268 if (NULL != (spc = strstr (lpfx, " ")))
269 *spc = '\0';
270 iret = GNUNET_GETOPT_run (binaryName,
271 allopts,
272 (unsigned int) argc,
273 argv);
274 if ((GNUNET_OK > iret) ||
275 (GNUNET_OK != GNUNET_log_setup (lpfx,
276 loglev,
277 logfile)))
278 {
279 GNUNET_free (allopts);
280 GNUNET_free (lpfx);
281 ret = (enum GNUNET_GenericReturnValue) iret;
282 goto cleanup;
283 }
284 if (NULL != cc.cfgfile)
285 {
287 "Loading configuration from entry point specified as option (%s)\n",
288 cc.cfgfile);
289 if (GNUNET_YES !=
291 {
293 _ ("Unreadable configuration file `%s', exiting ...\n"),
294 cc.cfgfile);
296 GNUNET_free (allopts);
297 GNUNET_free (lpfx);
298 goto cleanup;
299 }
300 if (GNUNET_SYSERR ==
302 cc.cfgfile))
303 {
305 _ ("Malformed configuration file `%s', exiting ...\n"),
306 cc.cfgfile);
308 GNUNET_free (allopts);
309 GNUNET_free (lpfx);
310 goto cleanup;
311 }
312 }
313 else
314 {
315 if ( (NULL != cfg_fn) &&
316 (GNUNET_YES !=
317 GNUNET_DISK_file_test (cfg_fn)) )
318 {
320 _ ("Unreadable configuration file `%s', exiting ...\n"),
321 cfg_fn);
323 GNUNET_free (allopts);
324 GNUNET_free (lpfx);
325 goto cleanup;
326 }
328 "Loading configuration from entry point `%s'\n",
329 cc.cfgfile);
330 if (GNUNET_SYSERR ==
332 cfg_fn))
333 {
335 _ ("Malformed configuration. Exiting ...\n"));
337 GNUNET_free (allopts);
338 GNUNET_free (lpfx);
339 goto cleanup;
340 }
341 }
342 GNUNET_free (allopts);
343 GNUNET_free (lpfx);
344 if ((GNUNET_OK ==
346 "testing",
347 "skew_offset",
348 &skew_offset)) &&
349 (GNUNET_OK ==
351 "testing",
352 "skew_variance",
353 &skew_variance)))
354 {
355 clock_offset = skew_offset - skew_variance;
356 GNUNET_TIME_set_offset (clock_offset);
357 }
358 /* ARM needs to know which configuration file to use when starting
359 services. If we got a command-line option *and* if nothing is
360 specified in the configuration, remember the command-line option
361 in "cfg". This is typically really only having an effect if we
362 are running code in src/arm/, as obviously the rest of the code
363 has little business with ARM-specific options. */
364 if (GNUNET_YES !=
366 "arm",
367 "CONFIG"))
368 {
369 if (NULL != cc.cfgfile)
371 "arm",
372 "CONFIG",
373 cc.cfgfile);
374 else if (NULL != cfg_fn)
376 "arm",
377 "CONFIG",
378 cfg_fn);
379 }
380
381 /* run */
382 cc.args = &argv[iret];
383 if ((NULL == cc.cfgfile) && (NULL != cfg_fn))
384 cc.cfgfile = GNUNET_strdup (cfg_fn);
385 if (GNUNET_NO == run_without_scheduler)
386 {
388 }
389 else
390 {
392 cc.task (cc.task_cls, cc.args, cc.cfgfile, cc.cfg);
393 }
394 ret = GNUNET_OK;
395cleanup:
397 GNUNET_free (cc.cfgfile);
398 GNUNET_free (cfg_fn);
399 GNUNET_free (loglev);
400 GNUNET_free (logfile);
401 return ret;
402}
403
404
407 int argc,
408 char *const *argv,
409 const char *binaryName,
410 const char *binaryHelp,
413 void *task_cls)
414{
415 return GNUNET_PROGRAM_run2 (pd,
416 argc,
417 argv,
418 binaryName,
419 binaryHelp,
420 options,
421 task,
422 task_cls,
423 GNUNET_NO);
424}
425
426
429 int argc,
430 char *const *argv,
432{
433 char *cfg_filename;
434 char *opt_cfg_filename;
435 char *logfile;
436 char *loglev;
437 const char *xdg;
438 int do_daemonize;
439 int ret;
440 struct GNUNET_GETOPT_CommandLineOption service_options[] = {
441 GNUNET_GETOPT_option_cfgfile (&opt_cfg_filename),
443 "daemonize",
445 "do daemonize (detach from terminal)"),
446 &do_daemonize),
448 NULL),
453 };
454
455 xdg = getenv ("XDG_CONFIG_HOME");
456 if (NULL != xdg)
458 "%s%s%s",
459 xdg,
461 pd->config_file);
462 else
464
465 loglev = NULL;
466 logfile = NULL;
467 opt_cfg_filename = NULL;
468 // FIXME we need to set this up for each service!
469 ret = GNUNET_GETOPT_run ("libgnunet",
470 service_options,
471 argc,
472 argv);
473 if (GNUNET_SYSERR == ret)
474 goto error;
475 if (GNUNET_NO == ret)
476 {
477 goto error;
478 }
479 // FIXME we need to set this up for each service!
480 // NOTE: that was not the idea. What are you proposing? -CG
481 if (GNUNET_OK !=
482 GNUNET_log_setup ("libgnunet",
483 "DEBUG",// loglev,
484 logfile))
485 {
486 GNUNET_break (0);
487 goto error;
488 }
489 if (NULL == cfg)
490 {
492 if (NULL != opt_cfg_filename)
493 {
494 if ( (GNUNET_YES !=
495 GNUNET_DISK_file_test (opt_cfg_filename)) ||
496 (GNUNET_SYSERR ==
498 opt_cfg_filename)) )
499 {
501 _ ("Malformed configuration file `%s', exit ...\n"),
502 opt_cfg_filename);
503 goto error;
504 }
505 }
506 else
507 {
508 if (GNUNET_YES ==
510 {
511 if (GNUNET_SYSERR ==
514 {
516 _ ("Malformed configuration file `%s', exit ...\n"),
519 goto error;;
520 }
521 }
522 else
523 {
524 if (GNUNET_SYSERR ==
526 NULL))
527 {
529 _ ("Malformed configuration, exit ...\n"));
531 goto error;
532 }
533 }
534 }
535 }
536
537 GNUNET_free (logfile);
538 GNUNET_free (loglev);
540 GNUNET_free (opt_cfg_filename);
541
542 return GNUNET_OK;
543
544error:
547 GNUNET_free (logfile);
548 GNUNET_free (loglev);
550 GNUNET_free (opt_cfg_filename);
551
552 return GNUNET_SYSERR;
553}
554
555
556struct MonoContext
557{
558 const struct GNUNET_OS_ProjectData *pd;
560};
561
562static void
563monolith_main (void *cls)
564{
565 struct MonoContext *mc = cls;
566
568 0,
569 NULL,
570 mc->cfg,
571 GNUNET_NO);
573 0,
574 NULL,
575 mc->cfg,
576 GNUNET_NO);
577}
578
579
580void
582 int argc,
583 char *const *argv,
585{
586 struct MonoContext mc = {
587 .cfg = cfg,
588 .pd = pd
589 };
590
591 if (GNUNET_YES !=
593 argc,
594 argv,
595 cfg))
596 return;
598 &mc);
599}
600
601
602/* A list of daemons to be launched when GNUNET_main()
603 * is called
604 */
605struct DaemonHandleList
606{
607 /* DLL */
608 struct DaemonHandleList *prev;
609
610 /* DLL */
611 struct DaemonHandleList *next;
612
613 /* Program to launch */
615
616 const struct GNUNET_CONFIGURATION_Handle *cfg;
617
618 const char *daemon_name;
619};
620
621/* The daemon list */
622static struct DaemonHandleList *hll_head = NULL;
623
624/* The daemon list */
625static struct DaemonHandleList *hll_tail = NULL;
626
627static void
628launch_daemon (void *cls)
629{
630 struct DaemonHandleList *hll = cls;
631
632 // FIXME read from config argv argc?
633 hll->d (NULL, NULL, NULL, hll->cfg);
634}
635
636
637static void
638launch_daemons (void *cls)
639{
640 struct GNUNET_CONFIGURATION_Handle *cfg = cls;
641
642 for (struct DaemonHandleList *hll = hll_head;
643 NULL != hll;
644 hll = hll->next)
645 {
647 "Launching daemon %s\n",
648 hll->daemon_name);
649 hll->cfg = cfg;
651 hll);
652 }
653}
654
655
656void
658 int argc,
659 char *const *argv,
661 enum GNUNET_GenericReturnValue with_scheduler)
662{
664 "Entering GNUNET_DAEMON_main\n");
665 if (GNUNET_YES == with_scheduler)
666 {
667 if (GNUNET_YES !=
669 argc,
670 argv,
671 cfg))
672 return;
674 cfg);
675 }
676 else
678}
679
680
682GNUNET_DAEMON_register (const char *daemon_name,
683 const char *daemon_help,
685{
686 struct DaemonHandleList *hle;
687
689 "registering daemon %s\n",
691 hle = GNUNET_new (struct DaemonHandleList);
692 hle->d = task;
695 hll_tail,
696 hle);
697 return GNUNET_OK;
698}
699
700
701/* end of program.c */
struct GNUNET_GETOPT_CommandLineOption options[]
Definition 002.c:5
char * getenv()
#define gettext_noop(String)
Definition gettext.h:74
#define textdomain(Domainname)
Definition gettext.h:61
#define bindtextdomain(Domainname, Dirname)
Definition gettext.h:62
static int ret
Final status code.
Definition gnunet-arm.c:93
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
static char * cfg_filename
Name of the configuration file.
struct GNUNET_SCHEDULER_Task * shutdown_task
static char * name
Name (label) of the records to list.
static struct GNUNET_TESTBED_Controller * mc
Handle to the master controller.
static void cleanup()
Cleanup task.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(const struct GNUNET_OS_ProjectData *pd)
Create a new configuration object.
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
char * GNUNET_CONFIGURATION_default_filename(const struct GNUNET_OS_ProjectData *pd)
Return the filename of the default configuration filename that is used when no explicit configuration...
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_have_value(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Test if we have a value for a particular option.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
Definition disk.c:533
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_cfgfile(char **fn)
Allow user to specify configuration file name (-c option)
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_logfile(char **logfn)
Allow user to specify log file name (-l option)
int GNUNET_GETOPT_run(const char *binaryOptions, const struct GNUNET_GETOPT_CommandLineOption *allOptions, unsigned int argc, char *const *argv)
Parse the command line.
Definition getopt.c:884
#define GNUNET_GETOPT_OPTION_END
Marker for the end of the list of options.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_help(const struct GNUNET_OS_ProjectData *pd, const char *about)
Defining the option to print the command line help text (-h option).
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_loglevel(char **level)
Define the '-L' log level option.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag(char shortName, const char *name, const char *description, int *val)
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_version(const char *version)
Define the option to print the version of the application (-v option)
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
#define GNUNET_free(ptr)
Wrapper around free.
char * GNUNET_OS_installation_get_path(const struct GNUNET_OS_ProjectData *pd, enum GNUNET_OS_InstallationPathKind dirkind)
Get the path to a specific GNUnet installation directory or, with GNUNET_OS_IPK_SELF_PREFIX,...
@ GNUNET_OS_IPK_LOCALEDIR
Return the directory where translations are installed (share/locale/)
enum GNUNET_GenericReturnValue GNUNET_DAEMON_register(const char *daemon_name, const char *daemon_help, GNUNET_PROGRAM_Main task)
Definition program.c:683
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run2(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls, int run_without_scheduler)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition program.c:132
void GNUNET_PROGRAM_monolith_main(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, struct GNUNET_CONFIGURATION_Handle *cfg)
Start all services and daemons in a single process.
Definition program.c:582
void(* GNUNET_PROGRAM_Main)(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition program.c:407
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_conf_and_options(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, struct GNUNET_CONFIGURATION_Handle *cfg)
Create configuration handle from options and configuration file.
Definition program.c:429
void GNUNET_DAEMON_main(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, struct GNUNET_CONFIGURATION_Handle *cfg, enum GNUNET_GenericReturnValue with_scheduler)
Run the mainloop in a monolithic libgnunet.
Definition program.c:658
void GNUNET_RESOLVER_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create the connection to the resolver service.
void GNUNET_SCHEDULER_run(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Initialize and run scheduler.
Definition scheduler.c:725
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition scheduler.c:1339
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition scheduler.c:1304
void GNUNET_SERVICE_main(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, struct GNUNET_CONFIGURATION_Handle *cfg, enum GNUNET_GenericReturnValue with_scheduler)
Run the mainloop in a monolithic libgnunet.
Definition service.c:2347
void GNUNET_TIME_set_offset(long long offset)
Set the timestamp offset for this instance.
Definition time.c:49
#define DIR_SEPARATOR_STR
Definition platform.h:167
#define _(String)
GNU gettext support macro.
Definition platform.h:179
static void launch_daemon(void *cls)
Definition program.c:629
static struct DaemonHandleList * hll_tail
Definition program.c:626
static void monolith_main(void *cls)
Definition program.c:564
static struct DaemonHandleList * hll_head
Definition program.c:623
static void launch_daemons(void *cls)
Definition program.c:639
static void program_main(void *cls)
Initial task called by the scheduler for each program.
Definition program.c:88
static int cmd_sorter(const void *a1, const void *a2)
Compare function for 'qsort' to sort command-line arguments by the short option.
Definition program.c:111
#define LOG(kind,...)
Definition program.c:35
int GNUNET_SPEEDUP_start_(const struct GNUNET_CONFIGURATION_Handle *cfg)
Start task that may speed up our system clock artificially.
Definition speedup.c:60
void GNUNET_SPEEDUP_stop_()
Stop tasks that modify clock behavior.
Definition speedup.c:100
Context for the command.
Definition program.c:44
void * task_cls
Closure for task.
Definition program.c:63
char *const * args
Argv argument.
Definition program.c:48
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition program.c:68
GNUNET_PROGRAM_Main task
Main function to run.
Definition program.c:58
char * cfgfile
Name of the configuration file used, can be NULL!
Definition program.c:53
const struct GNUNET_CONFIGURATION_Handle * cfg
Definition program.c:617
GNUNET_PROGRAM_Main d
Definition program.c:615
struct DaemonHandleList * next
Definition program.c:612
struct DaemonHandleList * prev
Definition program.c:609
const char * daemon_name
Definition program.c:619
const struct GNUNET_OS_ProjectData * pd
Project data for this configuration object.
Definition of a command line option.
const char * name
Long name of the option (may not be NULL)
const char shortName
Short name of the option.
Project-specific data used to help the OS subsystem find installation paths.
const char * gettext_path
Gettext directory, e.g.
const char * gettext_domain
Gettext domain for localisation, e.g.
const char * user_config_file
Configuration file name to use (if $XDG_CONFIG_HOME is not set).
const char * config_file
Configuration file name (in $XDG_CONFIG_HOME) to use.
const char * version
String identifying the current project version.
const struct GNUNET_OS_ProjectData * pd
Definition program.c:559
struct GNUNET_CONFIGURATION_Handle * cfg
Definition program.c:560

Function Documentation

◆ shutdown_task()

static void shutdown_task ( void *  cls)
static

task run when the scheduler shuts down

Definition at line 76 of file program.c.

77{
78 (void) cls;
80}

References GNUNET_SPEEDUP_stop_().

Here is the call graph for this function:

◆ program_main()

static void program_main ( void *  cls)
static

Initial task called by the scheduler for each program.

Runs the program-specific main task.

Definition at line 88 of file program.c.

89{
90 struct CommandContext *cc = cls;
91
94 NULL);
96 cc->task (cc->task_cls,
97 cc->args,
98 cc->cfgfile,
99 cc->cfg);
100}

References CommandContext::args, CommandContext::cfg, CommandContext::cfgfile, GNUNET_RESOLVER_connect(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SPEEDUP_start_(), shutdown_task, CommandContext::task, and CommandContext::task_cls.

Referenced by GNUNET_PROGRAM_run2().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cmd_sorter()

static int cmd_sorter ( const void *  a1,
const void *  a2 
)
static

Compare function for 'qsort' to sort command-line arguments by the short option.

Parameters
a1first command line option
a2second command line option

Definition at line 111 of file program.c.

113{
114 const struct GNUNET_GETOPT_CommandLineOption *c1 = a1;
115 const struct GNUNET_GETOPT_CommandLineOption *c2 = a2;
116
117 if (toupper ((unsigned char) c1->shortName) >
118 toupper ((unsigned char) c2->shortName))
119 return 1;
120 if (toupper ((unsigned char) c1->shortName) <
121 toupper ((unsigned char) c2->shortName))
122 return -1;
123 if (c1->shortName > c2->shortName)
124 return 1;
125 if (c1->shortName < c2->shortName)
126 return -1;
127 return 0;
128}

References GNUNET_GETOPT_CommandLineOption::shortName.

Referenced by GNUNET_PROGRAM_run2().

Here is the caller graph for this function:

◆ monolith_main()

static void monolith_main ( void *  cls)
static

Definition at line 564 of file program.c.

565{
566 struct MonoContext *mc = cls;
567
569 0,
570 NULL,
571 mc->cfg,
572 GNUNET_NO);
574 0,
575 NULL,
576 mc->cfg,
577 GNUNET_NO);
578}

References GNUNET_DAEMON_main(), GNUNET_NO, GNUNET_SERVICE_main(), and mc.

Referenced by GNUNET_PROGRAM_monolith_main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ launch_daemon()

static void launch_daemon ( void *  cls)
static

Definition at line 629 of file program.c.

630{
631 struct DaemonHandleList *hll = cls;
632
633 // FIXME read from config argv argc?
634 hll->d (NULL, NULL, NULL, hll->cfg);
635}

References DaemonHandleList::cfg, and DaemonHandleList::d.

Referenced by launch_daemons().

Here is the caller graph for this function:

◆ launch_daemons()

static void launch_daemons ( void *  cls)
static

Definition at line 639 of file program.c.

640{
641 struct GNUNET_CONFIGURATION_Handle *cfg = cls;
642
643 for (struct DaemonHandleList *hll = hll_head;
644 NULL != hll;
645 hll = hll->next)
646 {
648 "Launching daemon %s\n",
649 hll->daemon_name);
650 hll->cfg = cfg;
652 hll);
653 }
654}

References cfg, GNUNET_ERROR_TYPE_DEBUG, GNUNET_SCHEDULER_add_now(), hll_head, launch_daemon(), LOG, and DaemonHandleList::next.

Referenced by GNUNET_DAEMON_main().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ hll_head

struct DaemonHandleList* hll_head = NULL
static

Definition at line 623 of file program.c.

Referenced by GNUNET_DAEMON_register(), and launch_daemons().

◆ hll_tail

struct DaemonHandleList* hll_tail = NULL
static

Definition at line 626 of file program.c.

Referenced by GNUNET_DAEMON_register().