GNUnet 0.22.2
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 More...
 
static void program_main (void *cls)
 Initial task called by the scheduler for each program. More...
 
static int cmd_sorter (const void *a1, const void *a2)
 Compare function for 'qsort' to sort command-line arguments by the short option. More...
 
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). More...
 
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). More...
 
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. More...
 
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. More...
 
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. More...
 
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.

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}
void GNUNET_SPEEDUP_stop_()
Stop tasks that modify clock behavior.
Definition: speedup.c:100

References GNUNET_SPEEDUP_stop_().

Referenced by program_main().

Here is the call graph for this function:
Here is the caller 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}
void GNUNET_RESOLVER_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create the connection to the resolver service.
Definition: resolver_api.c:258
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
static void shutdown_task(void *cls)
task run when the scheduler shuts down
Definition: program.c:76
int GNUNET_SPEEDUP_start_(const struct GNUNET_CONFIGURATION_Handle *cfg)
Start task that may speed up our system clock artificially.
Definition: speedup.c:60
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

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}
Definition of a command line option.
const char shortName
Short name of the option.

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}
static struct GNUNET_TESTBED_Controller * mc
Handle to the master controller.
@ GNUNET_NO
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_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:2303

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}
const struct GNUNET_CONFIGURATION_Handle * cfg
Definition: program.c:617
GNUNET_PROGRAM_Main d
Definition: program.c:615

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}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
@ GNUNET_ERROR_TYPE_DEBUG
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
static void launch_daemon(void *cls)
Definition: program.c:629
static struct DaemonHandleList * hll_head
Definition: program.c:623
#define LOG(kind,...)
Definition: program.c:35
struct DaemonHandleList * next
Definition: program.c:612

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