42{
47
51 char *cfgfile;
52
57
61 void *task_cls;
62
67};
68
69
73static void
75{
76 (void) cls;
78}
79
80
85static void
87{
89
92 NULL);
98}
99
100
108static int
110 const void *a2)
111{
114
115 if (toupper ((
unsigned char) c1->
shortName) >
117 return 1;
118 if (toupper ((
unsigned char) c1->
shortName) <
120 return -1;
122 return 1;
124 return -1;
125 return 0;
126}
127
128
131 int argc,
132 char *const *argv,
133 const char *binaryName,
134 const char *binaryHelp,
137 void *task_cls,
138 int run_without_scheduler)
139{
141
142#if ENABLE_NLS
143 char *path;
144#endif
145 char *loglev;
146 char *logfile;
147 char *cfg_fn;
149 int iret;
150 unsigned int cnt;
151 unsigned long long skew_offset;
152 unsigned long long skew_variance;
153 long long clock_offset;
158 binaryHelp),
162 };
163 unsigned int deflen = sizeof(defoptions) / sizeof(defoptions[0]);
165 const char *gargs;
166 char *lpfx;
167 char *spc;
168
169 logfile = NULL;
170 gargs =
getenv (
"GNUNET_ARGS");
171 if (NULL != gargs)
172 {
173 char **gargv;
174 unsigned int gargc;
175 char *cargs;
176
177 gargv = NULL;
178 gargc = 0;
179 for (int i = 0; i < argc; i++)
181 gargc,
184 for (char *tok = strtok (cargs, " ");
185 NULL != tok;
186 tok = strtok (NULL, " "))
188 gargc,
192 gargc,
193 NULL);
194 argv = (char *const *) gargv;
195 argc = gargc - 1;
196 }
197 memset (&cc, 0, sizeof(cc));
198 loglev = NULL;
202
203#if ENABLE_NLS
205 {
206 setlocale (LC_ALL, "");
211 if (NULL != path)
212 {
214 path);
216 }
218 }
219#endif
220 cnt = 0;
222 cnt++;
228 {
229 unsigned int xtra = 0;
230
231 for (unsigned int i = 0;
233 i++)
234 {
235 bool found = false;
236
237 for (unsigned int j = 0; j<cnt; j++)
238 {
242 (NULL != defoptions[i].
name) &&
244 defoptions[i].
name)) );
245 if (found)
246 break;
247 }
248 if (found)
249 continue;
251 &defoptions[i],
253 xtra++;
254 }
255 cnt += xtra;
256 }
257 qsort (allopts,
258 cnt,
261 loglev = NULL;
264 else
265 cfg_fn = NULL;
267 if (NULL != (spc = strstr (lpfx, " ")))
268 *spc = '\0';
270 allopts,
271 (unsigned int) argc,
272 argv);
275 loglev,
276 logfile)))
277 {
282 }
284 {
286 "Loading configuration from entry point specified as option (%s)\n",
290 {
292 _ (
"Unreadable configuration file `%s', exiting ...\n"),
298 }
302 {
304 _ (
"Malformed configuration file `%s', exiting ...\n"),
310 }
311 }
312 else
313 {
314 if ( (NULL != cfg_fn) &&
317 {
319 _ (
"Unreadable configuration file `%s', exiting ...\n"),
320 cfg_fn);
325 }
327 "Loading configuration from entry point `%s'\n",
331 cfg_fn))
332 {
334 _ (
"Malformed configuration. Exiting ...\n"));
339 }
340 }
345 "testing",
346 "skew_offset",
347 &skew_offset)) &&
350 "testing",
351 "skew_variance",
352 &skew_variance)))
353 {
354 clock_offset = skew_offset - skew_variance;
356 }
357
358
359
360
361
362
365 "arm",
366 "CONFIG"))
367 {
370 "arm",
371 "CONFIG",
373 else if (NULL != cfg_fn)
375 "arm",
376 "CONFIG",
377 cfg_fn);
378 }
379
380
381 cc.
args = &argv[iret];
382 if ((NULL == cc.
cfgfile) && (NULL != cfg_fn))
385 {
387 }
388 else
389 {
392 }
401}
402
403
406 int argc,
407 char *const *argv,
408 const char *binaryName,
409 const char *binaryHelp,
412 void *task_cls)
413{
415 argc,
416 argv,
417 binaryName,
418 binaryHelp,
420 task,
421 task_cls,
423}
424
425
428 int argc,
429 char *const *argv,
431{
433 char *opt_cfg_filename;
434 char *logfile;
435 char *loglev;
436 const char *xdg;
437 int do_daemonize;
442 "daemonize",
444 "do daemonize (detach from terminal)"),
445 &do_daemonize),
447 NULL),
452 };
453
454 xdg =
getenv (
"XDG_CONFIG_HOME");
455 if (NULL != xdg)
457 "%s%s%s",
458 xdg,
461 else
463
464 loglev = NULL;
465 logfile = NULL;
466 opt_cfg_filename = NULL;
467
469 service_options,
470 argc,
471 argv);
473 goto error;
475 {
476 goto error;
477 }
478
479
482 "DEBUG",
483 logfile))
484 {
486 goto error;
487 }
489 {
491 if (NULL != opt_cfg_filename)
492 {
497 opt_cfg_filename)) )
498 {
500 _ (
"Malformed configuration file `%s', exit ...\n"),
501 opt_cfg_filename);
502 goto error;
503 }
504 }
505 else
506 {
509 {
513 {
515 _ (
"Malformed configuration file `%s', exit ...\n"),
518 goto error;;
519 }
520 }
521 else
522 {
525 NULL))
526 {
528 _ (
"Malformed configuration, exit ...\n"));
530 goto error;
531 }
532 }
533 }
534 }
535
540
542
543error:
550
552}
553
554
556{
559};
560
561static void
563{
565
567 0,
568 NULL,
572 0,
573 NULL,
576}
577
578
579void
581 int argc,
582 char *const *argv,
584{
588 };
589
592 argc,
593 argv,
595 return;
598}
599
600
601
602
603
605{
606
608
609
611
612
614
616
618};
619
620
622
623
625
626static void
628{
630
631
632 hll->
d (NULL, NULL, NULL, hll->
cfg);
633}
634
635
636static void
638{
640
642 NULL != hll;
644 {
646 "Launching daemon %s\n",
650 hll);
651 }
652}
653
654
655void
657 int argc,
658 char *const *argv,
661{
663 "Entering GNUNET_DAEMON_main\n");
665 {
668 argc,
669 argv,
671 return;
674 }
675 else
677}
678
679
682 const char *daemon_help,
684{
686
688 "registering daemon %s\n",
695 hle);
697}
698
699
700
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