43{
48
52 char *cfgfile;
53
58
62 void *task_cls;
63
68};
69
70
74static void
76{
77 (void) cls;
79}
80
81
86static void
88{
90
93 NULL);
99}
100
101
109static int
111 const void *a2)
112{
115
116 if (toupper ((
unsigned char) c1->
shortName) >
118 return 1;
119 if (toupper ((
unsigned char) c1->
shortName) <
121 return -1;
123 return 1;
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{
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;
159 binaryHelp),
163 };
164 unsigned int deflen = sizeof(defoptions) / sizeof(defoptions[0]);
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++)
182 gargc,
185 for (char *tok = strtok (cargs, " ");
186 NULL != tok;
187 tok = strtok (NULL, " "))
189 gargc,
193 gargc,
194 NULL);
195 argv = (char *const *) gargv;
196 argc = gargc - 1;
197 }
198 memset (&cc, 0, sizeof(cc));
199 loglev = NULL;
203
204#if ENABLE_NLS
206 {
207 setlocale (LC_ALL, "");
212 if (NULL != path)
213 {
215 path);
217 }
219 }
220#endif
221 cnt = 0;
223 cnt++;
229 {
230 unsigned int xtra = 0;
231
232 for (unsigned int i = 0;
234 i++)
235 {
236 bool found = false;
237
238 for (unsigned int j = 0; j<cnt; j++)
239 {
243 (NULL != defoptions[i].
name) &&
245 defoptions[i].
name)) );
246 if (found)
247 break;
248 }
249 if (found)
250 continue;
252 &defoptions[i],
254 xtra++;
255 }
256 cnt += xtra;
257 }
258 qsort (allopts,
259 cnt,
262 loglev = NULL;
265 else
266 cfg_fn = NULL;
268 if (NULL != (spc = strstr (lpfx, " ")))
269 *spc = '\0';
271 allopts,
272 (unsigned int) argc,
273 argv);
276 loglev,
277 logfile)))
278 {
283 }
285 {
287 "Loading configuration from entry point specified as option (%s)\n",
291 {
293 _ (
"Unreadable configuration file `%s', exiting ...\n"),
299 }
303 {
305 _ (
"Malformed configuration file `%s', exiting ...\n"),
311 }
312 }
313 else
314 {
315 if ( (NULL != cfg_fn) &&
318 {
320 _ (
"Unreadable configuration file `%s', exiting ...\n"),
321 cfg_fn);
326 }
328 "Loading configuration from entry point `%s'\n",
332 cfg_fn))
333 {
335 _ (
"Malformed configuration. Exiting ...\n"));
340 }
341 }
346 "testing",
347 "skew_offset",
348 &skew_offset)) &&
351 "testing",
352 "skew_variance",
353 &skew_variance)))
354 {
355 clock_offset = skew_offset - skew_variance;
357 }
358
359
360
361
362
363
366 "arm",
367 "CONFIG"))
368 {
371 "arm",
372 "CONFIG",
374 else if (NULL != cfg_fn)
376 "arm",
377 "CONFIG",
378 cfg_fn);
379 }
380
381
382 cc.
args = &argv[iret];
383 if ((NULL == cc.
cfgfile) && (NULL != cfg_fn))
386 {
388 }
389 else
390 {
393 }
402}
403
404
407 int argc,
408 char *const *argv,
409 const char *binaryName,
410 const char *binaryHelp,
413 void *task_cls)
414{
416 argc,
417 argv,
418 binaryName,
419 binaryHelp,
421 task,
422 task_cls,
424}
425
426
429 int argc,
430 char *const *argv,
432{
434 char *opt_cfg_filename;
435 char *logfile;
436 char *loglev;
437 const char *xdg;
438 int do_daemonize;
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,
462 else
464
465 loglev = NULL;
466 logfile = NULL;
467 opt_cfg_filename = NULL;
468
470 service_options,
471 argc,
472 argv);
474 goto error;
476 {
477 goto error;
478 }
479
480
483 "DEBUG",
484 logfile))
485 {
487 goto error;
488 }
490 {
492 if (NULL != opt_cfg_filename)
493 {
498 opt_cfg_filename)) )
499 {
501 _ (
"Malformed configuration file `%s', exit ...\n"),
502 opt_cfg_filename);
503 goto error;
504 }
505 }
506 else
507 {
510 {
514 {
516 _ (
"Malformed configuration file `%s', exit ...\n"),
519 goto error;;
520 }
521 }
522 else
523 {
526 NULL))
527 {
529 _ (
"Malformed configuration, exit ...\n"));
531 goto error;
532 }
533 }
534 }
535 }
536
541
543
544error:
551
553}
554
555
557{
560};
561
562static void
564{
566
568 0,
569 NULL,
573 0,
574 NULL,
577}
578
579
580void
582 int argc,
583 char *const *argv,
585{
589 };
590
593 argc,
594 argv,
596 return;
599}
600
601
602
603
604
606{
607
609
610
612
613
615
617
619};
620
621
623
624
626
627static void
629{
631
632
633 hll->
d (NULL, NULL, NULL, hll->
cfg);
634}
635
636
637static void
639{
641
643 NULL != hll;
645 {
647 "Launching daemon %s\n",
651 hll);
652 }
653}
654
655
656void
658 int argc,
659 char *const *argv,
662{
664 "Entering GNUNET_DAEMON_main\n");
666 {
669 argc,
670 argv,
672 return;
675 }
676 else
678}
679
680
683 const char *daemon_help,
685{
687
689 "registering daemon %s\n",
696 hle);
698}
699
700
701
struct GNUNET_GETOPT_CommandLineOption options[]
#define gettext_noop(String)
#define textdomain(Domainname)
#define bindtextdomain(Domainname, Dirname)
static int ret
Final status code.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
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).
#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.
#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.
#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)
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,...
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.
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,...
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.
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.
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.
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,...
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.
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.
void GNUNET_TIME_set_offset(long long offset)
Set the timestamp offset for this instance.
static void launch_daemon(void *cls)
static struct DaemonHandleList * hll_tail
static void monolith_main(void *cls)
static struct DaemonHandleList * hll_head
static void launch_daemons(void *cls)
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.
int GNUNET_SPEEDUP_start_(const struct GNUNET_CONFIGURATION_Handle *cfg)
Start task that may speed up our system clock artificially.
void GNUNET_SPEEDUP_stop_()
Stop tasks that modify clock behavior.
void * task_cls
Closure for task.
char *const * args
Argv argument.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
GNUNET_PROGRAM_Main task
Main function to run.
char * cfgfile
Name of the configuration file used, can be NULL!
const struct GNUNET_CONFIGURATION_Handle * cfg
struct DaemonHandleList * next
struct DaemonHandleList * prev
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
struct GNUNET_CONFIGURATION_Handle * cfg