GNUnet 0.22.0
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  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 (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 (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 (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 (int argc, char *const *argv, struct GNUNET_CONFIGURATION_Handle *cfg)
 Start all services and daemons in a single prozess. More...
 
static void launch_daemon (void *cls)
 
static void launch_daemons (void *cls)
 
void GNUNET_DAEMON_main (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:1338
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 548 of file program.c.

549{
550 struct GNUNET_CONFIGURATION_Handle *cfg = cls;
551
553 NULL,
554 cfg,
555 GNUNET_NO);
557 NULL,
558 cfg,
559 GNUNET_NO);
560}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
@ GNUNET_NO
void GNUNET_DAEMON_main(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:633
void GNUNET_SERVICE_main(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:2296

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

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 604 of file program.c.

605{
606 struct DaemonHandleList *hll = cls;
607
608 // FIXME read from config argv argc?
609 hll->d (NULL, NULL, NULL, hll->cfg);
610}
const struct GNUNET_CONFIGURATION_Handle * cfg
Definition: program.c:592
GNUNET_PROGRAM_Main d
Definition: program.c:590

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 614 of file program.c.

615{
616 struct GNUNET_CONFIGURATION_Handle *cfg = cls;
617
618 for (struct DaemonHandleList *hll = hll_head;
619 NULL != hll;
620 hll = hll->next)
621 {
623 "Launching daemon %s\n",
624 hll->daemon_name);
625 hll->cfg = cfg;
627 hll);
628 }
629}
@ 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:1303
static void launch_daemon(void *cls)
Definition: program.c:604
static struct DaemonHandleList * hll_head
Definition: program.c:598
#define LOG(kind,...)
Definition: program.c:35
struct DaemonHandleList * next
Definition: program.c:587

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 598 of file program.c.

Referenced by GNUNET_DAEMON_register(), and launch_daemons().

◆ hll_tail

struct DaemonHandleList* hll_tail = NULL
static

Definition at line 601 of file program.c.

Referenced by GNUNET_DAEMON_register().