GNUnet  0.10.x
Functions | Variables
gnunet-uri.c File Reference

tool to dispatch URIs to the appropriate GNUnet helper process More...

#include "platform.h"
#include "gnunet_util_lib.h"
Include dependency graph for gnunet-uri.c:

Go to the source code of this file.

Functions

static void maint_child_death (void *cls)
 Task triggered whenever we receive a SIGCHLD (child process died) or when user presses CTRL-C. More...
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Main function that will be run by the scheduler. More...
 
static void sighandler_child_death ()
 Signal handler called for SIGCHLD. More...
 
int main (int argc, char *const *argv)
 The main function to handle gnunet://-URIs. More...
 

Variables

static long unsigned int exit_code = 1
 Handler exit code. More...
 
static struct GNUNET_OS_Processp
 Helper process we started. More...
 
static struct GNUNET_DISK_PipeHandlesigpipe
 Pipe used to communicate shutdown via signal. More...
 

Detailed Description

tool to dispatch URIs to the appropriate GNUnet helper process

Author
Christian Grothoff

Definition in file gnunet-uri.c.

Function Documentation

◆ maint_child_death()

static void maint_child_death ( void *  cls)
static

Task triggered whenever we receive a SIGCHLD (child process died) or when user presses CTRL-C.

Parameters
clsclosure, NULL

Definition at line 52 of file gnunet-uri.c.

References exit_code, GNUNET_break, GNUNET_OK, GNUNET_OS_process_destroy(), GNUNET_OS_PROCESS_EXITED, GNUNET_OS_process_kill(), GNUNET_OS_process_status(), GNUNET_TERM_SIG, and type.

Referenced by run().

53 {
55 
56  (void)cls;
57  if ((GNUNET_OK != GNUNET_OS_process_status(p, &type, &exit_code)) ||
58  (type != GNUNET_OS_PROCESS_EXITED))
61 }
static long unsigned int exit_code
Handler exit code.
Definition: gnunet-uri.c:32
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:286
int GNUNET_OS_process_status(struct GNUNET_OS_Process *proc, enum GNUNET_OS_ProcessStatusType *type, unsigned long *code)
Retrieve the status of a process, waiting on it if dead.
Definition: os_priority.c:963
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:37
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
GNUNET_OS_ProcessStatusType
Process status types.
The process exited with a return code.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
#define GNUNET_TERM_SIG
The termination signal.
Definition: platform.h:242
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
Definition: os_priority.c:224
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle cfg 
)
static

Main function that will be run by the scheduler.

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

Definition at line 73 of file gnunet-uri.c.

References _, GNUNET_CONFIGURATION_get_value_string(), GNUNET_DISK_PIPE_END_READ, GNUNET_DISK_pipe_handle(), GNUNET_free, GNUNET_NO, GNUNET_OK, GNUNET_OS_start_process(), GNUNET_SCHEDULER_add_read_file(), GNUNET_SCHEDULER_cancel(), GNUNET_strndup, GNUNET_TIME_UNIT_FOREVER_REL, maint_child_death(), subsystem, and uri.

Referenced by main().

77 {
78  const char *uri;
79  const char *slash;
80  char *subsystem;
81  char *program;
82  struct GNUNET_SCHEDULER_Task *rt;
83 
84  (void)cls;
85  (void)cfgfile;
86  if (NULL == (uri = args[0]))
87  {
88  fprintf(stderr, _("No URI specified on command line\n"));
89  return;
90  }
91  if (0 != strncasecmp("gnunet://", uri, strlen("gnunet://")))
92  {
93  fprintf(stderr,
94  _("Invalid URI: does not start with `%s'\n"),
95  "gnunet://");
96  return;
97  }
98  uri += strlen("gnunet://");
99  if (NULL == (slash = strchr(uri, '/')))
100  {
101  fprintf(stderr, _("Invalid URI: fails to specify subsystem\n"));
102  return;
103  }
104  subsystem = GNUNET_strndup(uri, slash - uri);
105  if (GNUNET_OK !=
106  GNUNET_CONFIGURATION_get_value_string(cfg, "uri", subsystem, &program))
107  {
108  fprintf(stderr, _("No handler known for subsystem `%s'\n"), subsystem);
109  GNUNET_free(subsystem);
110  return;
111  }
112  GNUNET_free(subsystem);
117  NULL);
119  0,
120  NULL,
121  NULL,
122  NULL,
123  program,
124  program,
125  args[0],
126  NULL);
127  GNUNET_free(program);
128  if (NULL == p)
130 }
static char * subsystem
Set to subsystem that we're going to get stats for (or NULL for all).
static struct GNUNET_DISK_PipeHandle * sigpipe
Pipe used to communicate shutdown via signal.
Definition: gnunet-uri.c:42
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:37
struct GNUNET_OS_Process * GNUNET_OS_start_process(int pipe_control, enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, struct GNUNET_DISK_PipeHandle *pipe_stderr, const char *filename,...)
Start a process.
Definition: os_priority.c:687
#define GNUNET_NO
Definition: gnunet_common.h:78
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_file(struct GNUNET_TIME_Relative delay, const struct GNUNET_DISK_FileHandle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1615
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
const struct GNUNET_DISK_FileHandle * GNUNET_DISK_pipe_handle(const struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd n)
Get the handle to a particular pipe end.
Definition: disk.c:1744
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static struct GNUNET_FS_Uri * uri
Value of URI provided on command-line (when not publishing a file but just creating UBlocks to refer ...
static void maint_child_death(void *cls)
Task triggered whenever we receive a SIGCHLD (child process died) or when user presses CTRL-C...
Definition: gnunet-uri.c:52
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
The reading-end of a pipe.
int GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
Entry in list of pending tasks.
Definition: scheduler.c:131
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sighandler_child_death()

static void sighandler_child_death ( )
static

Signal handler called for SIGCHLD.

Triggers the respective handler by writing to the trigger pipe.

Definition at line 138 of file gnunet-uri.c.

References GNUNET_break, GNUNET_DISK_file_write(), GNUNET_DISK_PIPE_END_WRITE, and GNUNET_DISK_pipe_handle().

Referenced by main().

139 {
140  static char c;
141  int old_errno = errno; /* back-up errno */
142 
143  GNUNET_break(
144  1 ==
147  &c,
148  sizeof(c)));
149  errno = old_errno; /* restore errno */
150 }
static struct GNUNET_DISK_PipeHandle * sigpipe
Pipe used to communicate shutdown via signal.
Definition: gnunet-uri.c:42
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
const struct GNUNET_DISK_FileHandle * GNUNET_DISK_pipe_handle(const struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd n)
Get the handle to a particular pipe end.
Definition: disk.c:1744
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:817
The writing-end of a pipe.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 
)

The main function to handle gnunet://-URIs.

Parameters
argcnumber of arguments from the command line
argvcommand line arguments
Returns
0 ok, 1 on error

Definition at line 161 of file gnunet-uri.c.

References exit_code, gettext_noop, GNUNET_assert, GNUNET_DISK_pipe(), GNUNET_DISK_pipe_close(), GNUNET_free, GNUNET_GETOPT_OPTION_END, GNUNET_NO, GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_SIGCHLD, GNUNET_SIGNAL_handler_install(), GNUNET_SIGNAL_handler_uninstall(), GNUNET_STRINGS_get_utf8_args(), ret, run(), and sighandler_child_death().

162 {
163  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
165  };
166  struct GNUNET_SIGNAL_Context *shc_chld;
167  int ret;
168 
169  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
170  return 2;
172  GNUNET_assert(sigpipe != NULL);
173  shc_chld =
175  ret = GNUNET_PROGRAM_run(argc,
176  argv,
177  "gnunet-uri URI",
178  gettext_noop(
179  "Perform default-actions for GNUnet URIs"),
180  options,
181  &run,
182  NULL);
184  shc_chld = NULL;
186  sigpipe = NULL;
187  GNUNET_free((void *)argv);
188  return ((GNUNET_OK == ret) && (0 == exit_code)) ? 0 : 1;
189 }
static long unsigned int exit_code
Handler exit code.
Definition: gnunet-uri.c:32
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define GNUNET_SIGCHLD
Definition: platform.h:42
static struct GNUNET_DISK_PipeHandle * sigpipe
Pipe used to communicate shutdown via signal.
Definition: gnunet-uri.c:42
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1439
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
void GNUNET_SIGNAL_handler_uninstall(struct GNUNET_SIGNAL_Context *ctx)
Uninstall a previously installed signal hander.
Definition: signal.c:75
Definition of a command line option.
static int ret
Final status code.
Definition: gnunet-arm.c:89
static void sighandler_child_death()
Signal handler called for SIGCHLD.
Definition: gnunet-uri.c:138
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_DISK_PipeHandle * GNUNET_DISK_pipe(int blocking_read, int blocking_write, int inherit_read, int inherit_write)
Creates an interprocess channel.
Definition: disk.c:1518
struct GNUNET_SIGNAL_Context * GNUNET_SIGNAL_handler_install(int signal, GNUNET_SIGNAL_Handler handler)
Install a signal handler that will be run if the given signal is received.
Definition: signal.c:50
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run by the scheduler.
Definition: gnunet-uri.c:73
int GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
Definition: disk.c:1706
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).
Definition: program.c:367
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:

Variable Documentation

◆ exit_code

long unsigned int exit_code = 1
static

Handler exit code.

Definition at line 32 of file gnunet-uri.c.

Referenced by main(), and maint_child_death().

◆ p

struct GNUNET_OS_Process* p
static

Helper process we started.

Definition at line 37 of file gnunet-uri.c.

◆ sigpipe

struct GNUNET_DISK_PipeHandle* sigpipe
static

Pipe used to communicate shutdown via signal.

Definition at line 42 of file gnunet-uri.c.