diff options
Diffstat (limited to 'src/util/gnunet-uri.c')
-rw-r--r-- | src/util/gnunet-uri.c | 84 |
1 files changed, 47 insertions, 37 deletions
diff --git a/src/util/gnunet-uri.c b/src/util/gnunet-uri.c index 58f9e331c..33ff7b1e6 100644 --- a/src/util/gnunet-uri.c +++ b/src/util/gnunet-uri.c | |||
@@ -53,9 +53,9 @@ maint_child_death (void *cls) | |||
53 | { | 53 | { |
54 | enum GNUNET_OS_ProcessStatusType type; | 54 | enum GNUNET_OS_ProcessStatusType type; |
55 | 55 | ||
56 | if ( (GNUNET_OK != | 56 | (void) cls; |
57 | GNUNET_OS_process_status (p, &type, &exit_code)) || | 57 | if ((GNUNET_OK != GNUNET_OS_process_status (p, &type, &exit_code)) || |
58 | (type != GNUNET_OS_PROCESS_EXITED) ) | 58 | (type != GNUNET_OS_PROCESS_EXITED)) |
59 | GNUNET_break (0 == GNUNET_OS_process_kill (p, GNUNET_TERM_SIG)); | 59 | GNUNET_break (0 == GNUNET_OS_process_kill (p, GNUNET_TERM_SIG)); |
60 | GNUNET_OS_process_destroy (p); | 60 | GNUNET_OS_process_destroy (p); |
61 | } | 61 | } |
@@ -70,56 +70,60 @@ maint_child_death (void *cls) | |||
70 | * @param cfg configuration | 70 | * @param cfg configuration |
71 | */ | 71 | */ |
72 | static void | 72 | static void |
73 | run (void *cls, char *const *args, const char *cfgfile, | 73 | run (void *cls, |
74 | char *const *args, | ||
75 | const char *cfgfile, | ||
74 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 76 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
75 | { | 77 | { |
76 | const char *uri; | 78 | const char *uri; |
77 | const char *slash; | 79 | const char *slash; |
78 | char *subsystem; | 80 | char *subsystem; |
79 | char *program; | 81 | char *program; |
80 | struct GNUNET_SCHEDULER_Task * rt; | 82 | struct GNUNET_SCHEDULER_Task *rt; |
81 | 83 | ||
84 | (void) cls; | ||
85 | (void) cfgfile; | ||
82 | if (NULL == (uri = args[0])) | 86 | if (NULL == (uri = args[0])) |
83 | { | 87 | { |
84 | fprintf (stderr, | 88 | fprintf (stderr, _ ("No URI specified on command line\n")); |
85 | _("No URI specified on command line\n")); | ||
86 | return; | 89 | return; |
87 | } | 90 | } |
88 | if (0 != strncasecmp ("gnunet://", uri, strlen ("gnunet://"))) | 91 | if (0 != strncasecmp ("gnunet://", uri, strlen ("gnunet://"))) |
89 | { | 92 | { |
90 | fprintf (stderr, | 93 | fprintf (stderr, |
91 | _("Invalid URI: does not start with `%s'\n"), | 94 | _ ("Invalid URI: does not start with `%s'\n"), |
92 | "gnunet://"); | 95 | "gnunet://"); |
93 | return; | 96 | return; |
94 | } | 97 | } |
95 | uri += strlen ("gnunet://"); | 98 | uri += strlen ("gnunet://"); |
96 | if (NULL == (slash = strchr (uri, '/'))) | 99 | if (NULL == (slash = strchr (uri, '/'))) |
97 | { | 100 | { |
98 | fprintf (stderr, _("Invalid URI: fails to specify subsystem\n")); | 101 | fprintf (stderr, _ ("Invalid URI: fails to specify subsystem\n")); |
99 | return; | 102 | return; |
100 | } | 103 | } |
101 | subsystem = GNUNET_strndup (uri, slash - uri); | 104 | subsystem = GNUNET_strndup (uri, slash - uri); |
102 | if (GNUNET_OK != | 105 | if (GNUNET_OK != |
103 | GNUNET_CONFIGURATION_get_value_string (cfg, | 106 | GNUNET_CONFIGURATION_get_value_string (cfg, "uri", subsystem, &program)) |
104 | "uri", | ||
105 | subsystem, | ||
106 | &program)) | ||
107 | { | 107 | { |
108 | fprintf (stderr, _("No handler known for subsystem `%s'\n"), subsystem); | 108 | fprintf (stderr, _ ("No handler known for subsystem `%s'\n"), subsystem); |
109 | GNUNET_free (subsystem); | 109 | GNUNET_free (subsystem); |
110 | return; | 110 | return; |
111 | } | 111 | } |
112 | GNUNET_free (subsystem); | 112 | GNUNET_free (subsystem); |
113 | rt = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | 113 | rt = GNUNET_SCHEDULER_add_read_file ( |
114 | GNUNET_DISK_pipe_handle (sigpipe, | 114 | GNUNET_TIME_UNIT_FOREVER_REL, |
115 | GNUNET_DISK_PIPE_END_READ), | 115 | GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ), |
116 | &maint_child_death, NULL); | 116 | &maint_child_death, |
117 | p = GNUNET_OS_start_process (GNUNET_NO, 0, | 117 | NULL); |
118 | NULL, NULL, NULL, | 118 | p = GNUNET_OS_start_process (GNUNET_NO, |
119 | program, | 119 | 0, |
120 | program, | 120 | NULL, |
121 | args[0], | 121 | NULL, |
122 | NULL); | 122 | NULL, |
123 | program, | ||
124 | program, | ||
125 | args[0], | ||
126 | NULL); | ||
123 | GNUNET_free (program); | 127 | GNUNET_free (program); |
124 | if (NULL == p) | 128 | if (NULL == p) |
125 | GNUNET_SCHEDULER_cancel (rt); | 129 | GNUNET_SCHEDULER_cancel (rt); |
@@ -134,13 +138,15 @@ static void | |||
134 | sighandler_child_death () | 138 | sighandler_child_death () |
135 | { | 139 | { |
136 | static char c; | 140 | static char c; |
137 | int old_errno = errno; /* back-up errno */ | 141 | int old_errno = errno; /* back-up errno */ |
138 | 142 | ||
139 | GNUNET_break (1 == | 143 | GNUNET_break ( |
140 | GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle | 144 | 1 == |
141 | (sigpipe, GNUNET_DISK_PIPE_END_WRITE), | 145 | GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle (sigpipe, |
142 | &c, sizeof (c))); | 146 | GNUNET_DISK_PIPE_END_WRITE), |
143 | errno = old_errno; /* restore errno */ | 147 | &c, |
148 | sizeof (c))); | ||
149 | errno = old_errno; /* restore errno */ | ||
144 | } | 150 | } |
145 | 151 | ||
146 | 152 | ||
@@ -155,8 +161,7 @@ int | |||
155 | main (int argc, char *const *argv) | 161 | main (int argc, char *const *argv) |
156 | { | 162 | { |
157 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 163 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
158 | GNUNET_GETOPT_OPTION_END | 164 | GNUNET_GETOPT_OPTION_END}; |
159 | }; | ||
160 | struct GNUNET_SIGNAL_Context *shc_chld; | 165 | struct GNUNET_SIGNAL_Context *shc_chld; |
161 | int ret; | 166 | int ret; |
162 | 167 | ||
@@ -166,9 +171,14 @@ main (int argc, char *const *argv) | |||
166 | GNUNET_assert (sigpipe != NULL); | 171 | GNUNET_assert (sigpipe != NULL); |
167 | shc_chld = | 172 | shc_chld = |
168 | GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death); | 173 | GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death); |
169 | ret = GNUNET_PROGRAM_run (argc, argv, "gnunet-uri URI", | 174 | ret = GNUNET_PROGRAM_run (argc, |
170 | gettext_noop ("Perform default-actions for GNUnet URIs"), | 175 | argv, |
171 | options, &run, NULL); | 176 | "gnunet-uri URI", |
177 | gettext_noop ( | ||
178 | "Perform default-actions for GNUnet URIs"), | ||
179 | options, | ||
180 | &run, | ||
181 | NULL); | ||
172 | GNUNET_SIGNAL_handler_uninstall (shc_chld); | 182 | GNUNET_SIGNAL_handler_uninstall (shc_chld); |
173 | shc_chld = NULL; | 183 | shc_chld = NULL; |
174 | GNUNET_DISK_pipe_close (sigpipe); | 184 | GNUNET_DISK_pipe_close (sigpipe); |