GNUnet 0.28.0-dev.3-7-g31e20e2e6
 
Loading...
Searching...
No Matches
Program library

Start command-line programs. More...

Collaboration diagram for Program library:

Macros

#define GNUNET_DAEMON_MAIN(daemon_name, daemon_help, init_cb)
 

Typedefs

typedef void(* GNUNET_PROGRAM_Main) (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Main function that will be run.
 

Functions

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_DAEMON_register (const char *daemon_name, const char *daemon_desc, GNUNET_PROGRAM_Main task)
 
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.
 
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.
 

Detailed Description

Start command-line programs.

Macro Definition Documentation

◆ GNUNET_DAEMON_MAIN

#define GNUNET_DAEMON_MAIN (   daemon_name,
  daemon_help,
  init_cb 
)
Value:
int \
main (int argc, \
char *const *argv) \
{ \
int ret; \
}; \
argc, \
argv, \
daemon_name, \
daemon_help, \
NULL); \
return ret; \
}
struct GNUNET_GETOPT_CommandLineOption options[]
Definition 002.c:5
static int ret
Final status code.
Definition gnunet-arm.c:93
#define GNUNET_GETOPT_OPTION_END
Marker for the end of the list of options.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
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:406
Definition of a command line option.
static void init_cb(void *cls, const struct GNUNET_PeerIdentity *my_identity)

Definition at line 150 of file gnunet_program_lib.h.

154 { \
155 int ret; \
158 }; \
160 argc, \
161 argv, \
162 daemon_name, \
163 daemon_help, \
164 options, \
165 init_cb, \
166 NULL); \
167 return ret; \
168 }

Typedef Documentation

◆ GNUNET_PROGRAM_Main

typedef void(* GNUNET_PROGRAM_Main) (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)

Main function that will be run.

Parameters
clsclosure
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
cfgconfiguration

Definition at line 64 of file gnunet_program_lib.h.

Function Documentation

◆ GNUNET_PROGRAM_run2()

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).

Parameters
pdproject data for the project the program belongs to
argcnumber of command line arguments in argv
argvcommand line arguments
binaryNameour expected name
binaryHelphelp text for the program
optionscommand line options
taskmain function to run
task_clsclosure for task
run_without_schedulerGNUNET_NO start the scheduler, GNUNET_YES do not start the scheduler just run the main task
Returns
GNUNET_SYSERR on error, GNUNET_NO if successful option processing called for the program to terminate, GNUNET_OK on success (#a task was invoked)

Definition at line 131 of file program.c.

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[] = {
157 GNUNET_GETOPT_option_cfgfile (&cc.cfgfile),
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;
202 cc.cfg = cfg = GNUNET_CONFIGURATION_create (pd);
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 !=
290 GNUNET_DISK_file_test (cc.cfgfile))
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}
char * getenv()
#define textdomain(Domainname)
Definition gettext.h:61
#define bindtextdomain(Domainname, Dirname)
Definition gettext.h:62
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
static char * name
Name (label) of the records to list.
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:557
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
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_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
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
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#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/)
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:731
void GNUNET_TIME_set_offset(long long offset)
Set the timestamp offset for this instance.
Definition time.c:49
#define _(String)
GNU gettext support macro.
Definition platform.h:179
static void program_main(void *cls)
Initial task called by the scheduler for each program.
Definition program.c:87
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:110
Context for the command.
Definition program.c:43
const char * name
Long name of the option (may not be NULL)
const char shortName
Short name of the option.
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.

References _, CommandContext::args, bindtextdomain, cfg, CommandContext::cfg, CommandContext::cfgfile, cleanup(), cmd_sorter(), GNUNET_OS_ProjectData::config_file, getenv(), GNUNET_OS_ProjectData::gettext_domain, GNUNET_OS_ProjectData::gettext_path, GNUNET_array_append, GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_default_filename(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_have_value(), GNUNET_CONFIGURATION_load(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_DISK_file_test(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_GETOPT_option_cfgfile(), GNUNET_GETOPT_option_help(), GNUNET_GETOPT_option_logfile(), GNUNET_GETOPT_option_loglevel(), GNUNET_GETOPT_option_version(), GNUNET_GETOPT_run(), GNUNET_log, GNUNET_log_setup(), GNUNET_memcpy, GNUNET_new_array, GNUNET_NO, GNUNET_OK, GNUNET_OS_installation_get_path(), GNUNET_OS_IPK_LOCALEDIR, GNUNET_RESOLVER_connect(), GNUNET_SCHEDULER_run(), GNUNET_strdup, GNUNET_SYSERR, GNUNET_TIME_set_offset(), GNUNET_YES, name, GNUNET_GETOPT_CommandLineOption::name, options, program_main(), ret, GNUNET_GETOPT_CommandLineOption::shortName, CommandContext::task, CommandContext::task_cls, textdomain, GNUNET_OS_ProjectData::user_config_file, and GNUNET_OS_ProjectData::version.

Referenced by GNUNET_PROGRAM_run(), main(), and main().

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

◆ GNUNET_PROGRAM_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, parse options).

Parameters
pdproject data for the project the program belongs to
argcnumber of command line arguments
argvcommand line arguments
binaryNameour expected name
binaryHelphelptext for "-h" option (about the app)
optionscommand line options
taskmain function to run
task_clsclosure for task
Returns
GNUNET_SYSERR on error, GNUNET_NO if successful option processing called for the program to terminate, GNUNET_OK on success (#a task was invoked)

Definition at line 406 of file program.c.

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}
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:131

References GNUNET_NO, GNUNET_PROGRAM_run2(), and options.

Referenced by GNUNET_TRANSPORT_TESTING_connect_check(), main(), main(), and main().

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

◆ GNUNET_DAEMON_register()

enum GNUNET_GenericReturnValue GNUNET_DAEMON_register ( const char *  daemon_name,
const char *  daemon_desc,
GNUNET_PROGRAM_Main  task 
)

Definition at line 682 of file program.c.

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}
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct DaemonHandleList * hll_tail
Definition program.c:625
static struct DaemonHandleList * hll_head
Definition program.c:622
#define LOG(kind,...)
Definition program.c:34
GNUNET_PROGRAM_Main d
Definition program.c:614
const char * daemon_name
Definition program.c:618

References DaemonHandleList::d, DaemonHandleList::daemon_name, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_new, GNUNET_OK, hll_head, hll_tail, and LOG.

◆ GNUNET_PROGRAM_monolith_main()

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.

Parameters
pdproject data for the project the program belongs to
argcnumber of command line arguments
argvcommand line arguments

Definition at line 581 of file program.c.

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}
static struct GNUNET_TESTBED_Controller * mc
Handle to the master controller.
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:428
static void monolith_main(void *cls)
Definition program.c:563
const struct GNUNET_OS_ProjectData * pd
Project data for this configuration object.
const struct GNUNET_OS_ProjectData * pd
Definition program.c:558
struct GNUNET_CONFIGURATION_Handle * cfg
Definition program.c:559

References cfg, MonoContext::cfg, GNUNET_PROGRAM_conf_and_options(), GNUNET_SCHEDULER_run(), GNUNET_YES, mc, monolith_main(), GNUNET_CONFIGURATION_Handle::pd, and MonoContext::pd.

Here is the call graph for this function:

◆ GNUNET_PROGRAM_conf_and_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.

Parameters
pdproject data for the project the program belongs to
argcnumber of command line arguments
argvcommand line arguments

Definition at line 428 of file program.c.

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}
#define gettext_noop(String)
Definition gettext.h:74
static char * cfg_filename
Name of the configuration file.
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.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define DIR_SEPARATOR_STR
Definition platform.h:167
void GNUNET_SPEEDUP_stop_()
Stop tasks that modify clock behavior.
Definition speedup.c:100

References _, cfg, cfg_filename, GNUNET_OS_ProjectData::config_file, DIR_SEPARATOR_STR, getenv(), gettext_noop, GNUNET_asprintf(), GNUNET_break, GNUNET_CONFIGURATION_create(), GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_load(), GNUNET_DISK_file_test(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_GETOPT_option_cfgfile(), GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_flag(), GNUNET_GETOPT_option_help(), GNUNET_GETOPT_option_logfile(), GNUNET_GETOPT_option_loglevel(), GNUNET_GETOPT_option_version(), GNUNET_GETOPT_run(), GNUNET_log, GNUNET_log_setup(), GNUNET_NO, GNUNET_OK, GNUNET_SPEEDUP_stop_(), GNUNET_strdup, GNUNET_SYSERR, GNUNET_YES, ret, GNUNET_OS_ProjectData::user_config_file, and GNUNET_OS_ProjectData::version.

Referenced by GNUNET_DAEMON_main(), GNUNET_PROGRAM_monolith_main(), and GNUNET_SERVICE_main().

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

◆ GNUNET_DAEMON_main()

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.

Must be called such that services are actually launched.

Parameters
pdproject data for the project the program belongs to
argcnumber of command line arguments
argvcommand line arguments

Definition at line 657 of file program.c.

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}
static void launch_daemons(void *cls)
Definition program.c:638

References cfg, GNUNET_ERROR_TYPE_DEBUG, GNUNET_PROGRAM_conf_and_options(), GNUNET_SCHEDULER_run(), GNUNET_YES, launch_daemons(), LOG, and GNUNET_CONFIGURATION_Handle::pd.

Referenced by monolith_main().

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