GNUnet  0.11.x
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2012 GNUnet e.V.
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
13  Affero General Public License for more details.
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <>.
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
32 static long unsigned int exit_code = 0;
37 static struct GNUNET_OS_Process *p;
51 static void
52 maint_child_death (void *cls)
53 {
56  (void) cls;
57  if ((GNUNET_OK != GNUNET_OS_process_status (p, &type, &exit_code)) ||
61 }
72 static void
73 run (void *cls,
74  char *const *args,
75  const char *cfgfile,
76  const struct GNUNET_CONFIGURATION_Handle *cfg)
77 {
78  const char *uri;
79  const char *slash;
80  char *subsystem;
81  char *program;
82  struct GNUNET_SCHEDULER_Task *rt;
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  NULL,
120  NULL,
121  NULL,
122  program,
123  program,
124  args[0],
125  NULL);
126  GNUNET_free (program);
127  if (NULL == p)
129 }
136 static void
138 {
139  static char c;
140  int old_errno = errno; /* back-up errno */
142  GNUNET_break (
143  1 ==
146  &c,
147  sizeof(c)));
148  errno = old_errno; /* restore errno */
149 }
159 int
160 main (int argc, char *const *argv)
161 {
162  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
164  };
166  int ret;
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;
184  GNUNET_DISK_pipe_close (sigpipe);
185  sigpipe = NULL;
186  GNUNET_free_nz ((void *) argv);
187  return ((GNUNET_OK == ret) && (0 == exit_code)) ? 0 : 1;
188 }
191 /* end of gnunet-uri.c */
No special options, use non-blocking read/write operations.
static char * subsystem
Set to subsystem that we&#39;re going to get stats for (or NULL for all).
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:678
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
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:287
Definition: platform.h:42
static struct GNUNET_DISK_PipeHandle * sigpipe
Pipe used to communicate shutdown via signal.
Definition: gnunet-uri.c:42
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:946
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1458
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-uri.c:37
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
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:1667
void GNUNET_SIGNAL_handler_uninstall(struct GNUNET_SIGNAL_Context *ctx)
Uninstall a previously installed signal hander.
Definition: signal.c:77
Definition of a command line option.
static void sighandler_child_death()
Signal handler called for SIGCHLD.
Definition: gnunet-uri.c:137
#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:1672
Definition: 002.c:13
#define _(String)
GNU gettext support macro.
Definition: platform.h:184
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
No standard streams should be inherited.
Definition: gnunet_os_lib.h:73
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:820
Process status types.
Constant used to specify "forever".
The writing-end of a pipe.
The reading-end of a pipe.
The process exited with a return code.
struct GNUNET_DISK_PipeHandle * GNUNET_DISK_pipe(enum GNUNET_DISK_PipeFlags pf)
Creates an interprocess channel.
Definition: disk.c:1456
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_free_nz(ptr)
Wrapper around free.
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
int main(int argc, char *const *argv)
The main function to handle gnunet://-URIs.
Definition: gnunet-uri.c:160
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:1634
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
configuration data
Definition: configuration.c:84
Entry in list of pending tasks.
Definition: scheduler.c:134
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
static struct GNUNET_SIGNAL_Context * shc_chld
Child signal handler.
Definition: gnunet-qr.c:64
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
The termination signal.
Definition: platform.h:246
Handle used to manage a pipe.
Definition: disk.c:68
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
Definition: os_priority.c:225
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972