GNUnet  0.17.6
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 = 0
 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.

53 {
55 
56  (void) cls;
61 }
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:37
static long unsigned int exit_code
Handler exit code.
Definition: gnunet-uri.c:32
@ GNUNET_OK
Definition: gnunet_common.h:99
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
int GNUNET_OS_process_status(struct GNUNET_OS_Process *proc, enum GNUNET_OS_ProcessStatusType *type, unsigned long *code)
Retrieve the status of a process.
Definition: os_priority.c:944
GNUNET_OS_ProcessStatusType
Process status types.
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
Definition: os_priority.c:280
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
Definition: os_priority.c:217
@ GNUNET_OS_PROCESS_EXITED
The process exited with a return code.
#define GNUNET_TERM_SIG
The termination signal.
Definition: platform.h:233
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model

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, p, and type.

Referenced by run().

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.

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 !=
107  {
108  fprintf (stderr, _ ("No handler known for subsystem `%s'\n"), subsystem);
110  return;
111  }
117  NULL);
119  NULL,
120  NULL,
121  NULL,
122  program,
123  program,
124  args[0],
125  NULL);
126  GNUNET_free (program);
127  if (NULL == p)
129 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
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 char * subsystem
Set to subsystem that we're going to get stats for (or NULL for all).
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
static struct GNUNET_DISK_PipeHandle * sigpipe
Pipe used to communicate shutdown via signal.
Definition: gnunet-uri.c:42
enum GNUNET_GenericReturnValue 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.
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:1616
@ GNUNET_DISK_PIPE_END_READ
The reading-end of a pipe.
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_OS_Process * GNUNET_OS_start_process(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:672
@ GNUNET_OS_INHERIT_STD_NONE
No standard streams should be inherited.
Definition: gnunet_os_lib.h:77
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:1652
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:957
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define _(String)
GNU gettext support macro.
Definition: platform.h:177
Entry in list of pending tasks.
Definition: scheduler.c:135

References _, consensus-simulation::args, cfg, GNUNET_CONFIGURATION_get_value_string(), GNUNET_DISK_PIPE_END_READ, GNUNET_DISK_pipe_handle(), GNUNET_free, GNUNET_OK, GNUNET_OS_INHERIT_STD_NONE, GNUNET_OS_start_process(), GNUNET_SCHEDULER_add_read_file(), GNUNET_SCHEDULER_cancel(), GNUNET_strndup, GNUNET_TIME_UNIT_FOREVER_REL, maint_child_death(), p, sigpipe, subsystem, and uri.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sighandler_child_death()

static void sighandler_child_death ( void  )
static

Signal handler called for SIGCHLD.

Triggers the respective handler by writing to the trigger pipe.

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

138 {
139  static char c;
140  int old_errno = errno; /* back-up errno */
141 
142  GNUNET_break (
143  1 ==
146  &c,
147  sizeof(c)));
148  errno = old_errno; /* restore errno */
149 }
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:686
@ GNUNET_DISK_PIPE_END_WRITE
The writing-end of a pipe.

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

Referenced by main().

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 160 of file gnunet-uri.c.

161 {
162  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
164  };
166  int ret;
167 
168  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
169  return 2;
171  GNUNET_assert (sigpipe != NULL);
172  shc_chld =
174  ret = GNUNET_PROGRAM_run (argc,
175  argv,
176  "gnunet-uri URI",
177  gettext_noop (
178  "Perform default-actions for GNUnet URIs"),
179  options,
180  &run,
181  NULL);
183  shc_chld = NULL;
185  sigpipe = NULL;
186  GNUNET_free_nz ((void *) argv);
187  return ((GNUNET_OK == ret) && (0 == exit_code)) ? 0 : 1;
188 }
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
static struct GNUNET_SIGNAL_Context * shc_chld
#define gettext_noop(String)
Definition: gettext.h:69
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static void sighandler_child_death()
Signal handler called for SIGCHLD.
Definition: gnunet-uri.c:137
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
enum GNUNET_GenericReturnValue GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
Definition: disk.c:1585
struct GNUNET_DISK_PipeHandle * GNUNET_DISK_pipe(enum GNUNET_DISK_PipeFlags pf)
Creates an interprocess channel.
Definition: disk.c:1442
@ GNUNET_DISK_PF_NONE
No special options, use non-blocking read/write operations.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_free_nz(ptr)
Wrapper around free.
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,...
Definition: program.c:399
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:51
void GNUNET_SIGNAL_handler_uninstall(struct GNUNET_SIGNAL_Context *ctx)
Uninstall a previously installed signal handler.
Definition: signal.c:77
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1223
#define GNUNET_SIGCHLD
Definition: platform.h:42
Definition of a command line option.

References exit_code, gettext_noop, GNUNET_assert, GNUNET_DISK_PF_NONE, GNUNET_DISK_pipe(), GNUNET_DISK_pipe_close(), GNUNET_free_nz, GNUNET_GETOPT_OPTION_END, GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_SIGCHLD, GNUNET_SIGNAL_handler_install(), GNUNET_SIGNAL_handler_uninstall(), GNUNET_STRINGS_get_utf8_args(), options, ret, run(), shc_chld, sighandler_child_death(), and sigpipe.

Here is the call graph for this function:

Variable Documentation

◆ exit_code

long unsigned int exit_code = 0
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.

Referenced by _make_continuous_arg_copy(), adjust(), age_values(), block_proc(), block_reader(), build_dns_query(), compute_scalar_product(), compute_service_response(), context_state_callback(), create_loc_uri(), CustomPeerMap_put(), CustomPeerMap_remove_peer(), display_bar(), display_request(), dns_result_parser(), do_stop_task(), download_stop_task(), dump_buffer(), encode_cont(), enforce_add_address(), enforce_del_address(), enforce_start_property(), enforce_start_request(), enforce_stop_request(), find_active_address(), find_timed_out(), for_all_records(), free_link_properties(), free_preference(), GCT_consider_path(), get_all_peers_iterator(), get_all_tunnels_iterator(), get_hello(), get_keywords_from_tokens(), get_longest_prefix(), get_path_from_GNUNET_PREFIX(), get_path_from_PATH(), get_pipeline(), get_preferences_cb(), GN_getopt_internal(), gns_resolve_name(), GNUNET_ATS_solver_generate_preferences_start(), GNUNET_CADET_close_port(), GNUNET_CADET_open_port(), GNUNET_CONFIGURATION_create(), GNUNET_CONTAINER_meta_data_insert(), GNUNET_CONTAINER_multihashmap32_remove(), GNUNET_CONTAINER_multihashmap32_remove_all(), GNUNET_CONTAINER_multihashmap_remove(), GNUNET_CONTAINER_multihashmap_remove_all(), GNUNET_CONTAINER_multipeermap_remove(), GNUNET_CONTAINER_multipeermap_remove_all(), GNUNET_CONTAINER_multishortmap_remove(), GNUNET_CONTAINER_multishortmap_remove_all(), GNUNET_CONTAINER_multiuuidmap_remove(), GNUNET_CONTAINER_multiuuidmap_remove_all(), GNUNET_CRYPTO_mpi_print_unsigned(), GNUNET_CRYPTO_paillier_create(), GNUNET_CRYPTO_zero_keys(), GNUNET_DISK_internal_file_handle_(), GNUNET_DISK_pipe_close(), GNUNET_DISK_pipe_close_end(), GNUNET_DNSPARSER_free_packet(), GNUNET_DNSPARSER_pack(), GNUNET_DNSPARSER_parse(), GNUNET_e2s(), GNUNET_e2s2(), GNUNET_FS_publish_main_(), GNUNET_FS_publish_make_status_(), GNUNET_MY_exec_prepared(), GNUNET_p2s(), GNUNET_p2s2(), GNUNET_SCHEDULER_cancel(), GNUNET_SCHEDULER_get_load(), GNUNET_SECRETSHARING_share_read(), GNUNET_SECRETSHARING_share_write(), GNUNET_SERVER_add_handlers(), GNUNET_TRANSPORT_TESTING_connect_check(), GNUNET_TRANSPORT_TESTING_done(), GNUNET_TRANSPORT_TESTING_restart_peer(), GNUNET_TRANSPORT_TESTING_start_peer(), GNUNET_TRANSPORT_TESTING_stop_peer(), GSF_cadet_query_cancel(), handle_dns_request(), handle_index_start_failed(), handle_index_start_ok(), handle_show_path(), handle_signature_response(), hash_for_index_cb(), hello_iter_cb(), ibf_hashcode_from_key(), ieee80211_get_radiotap_len(), index_mq_error_handler(), libgnunet_plugin_transport_udp_init(), main(), maint_child_death(), modify_request(), notify_connect(), notify_disconnect(), oprelease_overlay_configure_topology(), opstart_overlay_configure_topology(), parse_definitions(), parse_pattern(), peer_info_cb(), process_result(), progress_cb(), progress_proc(), publish_content(), publish_kblocks(), publish_kblocks_cont(), publish_stop_task(), queue(), queue_ready_task(), recursive_dns_resolution(), regex_add(), regex_combine(), REGEX_INTERNAL_construct_nfa(), retrieve_hello(), run(), run_process_and_wait(), schedule_transmit_on_queue(), search_stop_task(), set_feedback_task(), set_pref_task(), set_prop_task(), shutdown_task(), signal_publish_completion(), signal_publish_error(), solver_bandwidth_changed_cb(), gnunet_testing.Peer::start(), start_cb(), start_download(), start_publish(), gnunet_testing.Peer::stop(), update_network_size_estimate(), and w_check().

◆ sigpipe

struct GNUNET_DISK_PipeHandle* sigpipe
static

Pipe used to communicate shutdown via signal.

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

Referenced by main(), run(), and sighandler_child_death().