GNUnet 0.21.1
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_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:1340
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:

Variable Documentation

◆ hll_head

struct DaemonHandleList* hll_head = NULL
static

Definition at line 435 of file program.c.

Referenced by GNUNET_DAEMON_register().

◆ hll_tail

struct DaemonHandleList* hll_tail = NULL
static

Definition at line 438 of file program.c.

Referenced by GNUNET_DAEMON_register().