GNUnet  0.10.x
Data Structures | Macros | Functions
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...
 

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

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 34 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 36 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 75 of file program.c.

References GNUNET_SPEEDUP_stop_().

Referenced by program_main().

76 {
77  (void) cls;
79 }
void GNUNET_SPEEDUP_stop_()
Stop tasks that modify clock behavior.
Definition: speedup.c:105
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 87 of file program.c.

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

88 {
89  struct CommandContext *cc = cls;
90 
94  cc->task (cc->task_cls, cc->args, cc->cfgfile, cc->cfg);
95 }
Context for the command.
Definition: program.c:42
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, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1293
char *const * args
Argv argument.
Definition: program.c:47
static void shutdown_task(void *cls)
task run when the scheduler shuts down
Definition: program.c:75
char * cfgfile
Name of the configuration file used, can be NULL!
Definition: program.c:52
void * task_cls
Closure for task.
Definition: program.c:62
GNUNET_PROGRAM_Main task
Main function to run.
Definition: program.c:57
int GNUNET_SPEEDUP_start_(const struct GNUNET_CONFIGURATION_Handle *cfg)
Start task that may speed up our system clock artificially.
Definition: speedup.c:65
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: program.c:67
void GNUNET_RESOLVER_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create the connection to the resolver service.
Definition: resolver_api.c:254
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 106 of file program.c.

References GNUNET_GETOPT_CommandLineOption::shortName.

Referenced by GNUNET_PROGRAM_run2().

107 {
108  const struct GNUNET_GETOPT_CommandLineOption *c1 = a1;
109  const struct GNUNET_GETOPT_CommandLineOption *c2 = a2;
110 
111  if (toupper ((unsigned char) c1->shortName) >
112  toupper ((unsigned char) c2->shortName))
113  return 1;
114  if (toupper ((unsigned char) c1->shortName) <
115  toupper ((unsigned char) c2->shortName))
116  return -1;
117  if (c1->shortName > c2->shortName)
118  return 1;
119  if (c1->shortName < c2->shortName)
120  return -1;
121  return 0;
122 }
Definition of a command line option.
const char shortName
Short name of the option.
Here is the caller graph for this function: