aboutsummaryrefslogtreecommitdiff
path: root/src/util/program.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-04-10 13:02:28 +0200
committerChristian Grothoff <christian@grothoff.org>2018-04-10 13:02:51 +0200
commit0cd0e3a5287af73bb81219ebc9548395a8945ce8 (patch)
treeb5bb24d78a4eed519b37e6fb8f9291a6282d06d4 /src/util/program.c
parent3eae3e43d6f94449cb89998a676e6696438cc604 (diff)
downloadgnunet-0cd0e3a5287af73bb81219ebc9548395a8945ce8.tar.gz
gnunet-0cd0e3a5287af73bb81219ebc9548395a8945ce8.zip
more work on gnunet-zoneimport, some bugfix in flat namestore, misc. style fixes
Diffstat (limited to 'src/util/program.c')
-rw-r--r--src/util/program.c89
1 files changed, 62 insertions, 27 deletions
diff --git a/src/util/program.c b/src/util/program.c
index 9e3037b8b..a02bff77c 100644
--- a/src/util/program.c
+++ b/src/util/program.c
@@ -138,10 +138,13 @@ cmd_sorter (const void *a1, const void *a2)
138 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 138 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
139 */ 139 */
140int 140int
141GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName, 141GNUNET_PROGRAM_run2 (int argc,
142 char *const *argv,
143 const char *binaryName,
142 const char *binaryHelp, 144 const char *binaryHelp,
143 const struct GNUNET_GETOPT_CommandLineOption *options, 145 const struct GNUNET_GETOPT_CommandLineOption *options,
144 GNUNET_PROGRAM_Main task, void *task_cls, 146 GNUNET_PROGRAM_Main task,
147 void *task_cls,
145 int run_without_scheduler) 148 int run_without_scheduler)
146{ 149{
147 struct CommandContext cc; 150 struct CommandContext cc;
@@ -158,7 +161,6 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName,
158 unsigned long long skew_variance; 161 unsigned long long skew_variance;
159 long long clock_offset; 162 long long clock_offset;
160 struct GNUNET_CONFIGURATION_Handle *cfg; 163 struct GNUNET_CONFIGURATION_Handle *cfg;
161
162 struct GNUNET_GETOPT_CommandLineOption defoptions[] = { 164 struct GNUNET_GETOPT_CommandLineOption defoptions[] = {
163 GNUNET_GETOPT_option_cfgfile (&cc.cfgfile), 165 GNUNET_GETOPT_option_cfgfile (&cc.cfgfile),
164 GNUNET_GETOPT_option_help (binaryHelp), 166 GNUNET_GETOPT_option_help (binaryHelp),
@@ -177,23 +179,31 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName,
177 { 179 {
178 char **gargv; 180 char **gargv;
179 unsigned int gargc; 181 unsigned int gargc;
180 int i;
181 char *tok;
182 char *cargs; 182 char *cargs;
183 183
184 gargv = NULL; 184 gargv = NULL;
185 gargc = 0; 185 gargc = 0;
186 for (i = 0; i < argc; i++) 186 for (int i = 0; i < argc; i++)
187 GNUNET_array_append (gargv, gargc, GNUNET_strdup (argv[i])); 187 GNUNET_array_append (gargv,
188 gargc,
189 GNUNET_strdup (argv[i]));
188 cargs = GNUNET_strdup (gargs); 190 cargs = GNUNET_strdup (gargs);
189 for (tok = strtok (cargs, " "); NULL != tok; tok = strtok (NULL, " ")) 191 for (char *tok = strtok (cargs, " ");
190 GNUNET_array_append (gargv, gargc, GNUNET_strdup (tok)); 192 NULL != tok;
193 tok = strtok (NULL, " "))
194 GNUNET_array_append (gargv,
195 gargc,
196 GNUNET_strdup (tok));
191 GNUNET_free (cargs); 197 GNUNET_free (cargs);
192 GNUNET_array_append (gargv, gargc, NULL); 198 GNUNET_array_append (gargv,
199 gargc,
200 NULL);
193 argv = (char *const *) gargv; 201 argv = (char *const *) gargv;
194 argc = gargc - 1; 202 argc = gargc - 1;
195 } 203 }
196 memset (&cc, 0, sizeof (cc)); 204 memset (&cc,
205 0,
206 sizeof (cc));
197 loglev = NULL; 207 loglev = NULL;
198 cc.task = task; 208 cc.task = task;
199 cc.task_cls = task_cls; 209 cc.task_cls = task_cls;
@@ -204,7 +214,8 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName,
204 path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR); 214 path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR);
205 if (NULL != path) 215 if (NULL != path)
206 { 216 {
207 BINDTEXTDOMAIN ("GNUnet", path); 217 BINDTEXTDOMAIN ("GNUnet",
218 path);
208 GNUNET_free (path); 219 GNUNET_free (path);
209 } 220 }
210 textdomain ("GNUnet"); 221 textdomain ("GNUnet");
@@ -216,13 +227,17 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName,
216 GNUNET_malloc ((cnt + 227 GNUNET_malloc ((cnt +
217 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption) + 228 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption) +
218 sizeof (defoptions)); 229 sizeof (defoptions));
219 GNUNET_memcpy (allopts, defoptions, sizeof (defoptions)); 230 GNUNET_memcpy (allopts,
231 defoptions,
232 sizeof (defoptions));
220 GNUNET_memcpy (&allopts 233 GNUNET_memcpy (&allopts
221 [sizeof (defoptions) / 234 [sizeof (defoptions) /
222 sizeof (struct GNUNET_GETOPT_CommandLineOption)], options, 235 sizeof (struct GNUNET_GETOPT_CommandLineOption)], options,
223 (cnt + 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption)); 236 (cnt + 1) * sizeof (struct GNUNET_GETOPT_CommandLineOption));
224 cnt += sizeof (defoptions) / sizeof (struct GNUNET_GETOPT_CommandLineOption); 237 cnt += sizeof (defoptions) / sizeof (struct GNUNET_GETOPT_CommandLineOption);
225 qsort (allopts, cnt, sizeof (struct GNUNET_GETOPT_CommandLineOption), 238 qsort (allopts,
239 cnt,
240 sizeof (struct GNUNET_GETOPT_CommandLineOption),
226 &cmd_sorter); 241 &cmd_sorter);
227 loglev = NULL; 242 loglev = NULL;
228 xdg = getenv ("XDG_CONFIG_HOME"); 243 xdg = getenv ("XDG_CONFIG_HOME");
@@ -237,9 +252,15 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName,
237 lpfx = GNUNET_strdup (binaryName); 252 lpfx = GNUNET_strdup (binaryName);
238 if (NULL != (spc = strstr (lpfx, " "))) 253 if (NULL != (spc = strstr (lpfx, " ")))
239 *spc = '\0'; 254 *spc = '\0';
240 ret = GNUNET_GETOPT_run (binaryName, allopts, (unsigned int) argc, argv); 255 ret = GNUNET_GETOPT_run (binaryName,
256 allopts,
257 (unsigned int) argc,
258 argv);
241 if ((GNUNET_OK > ret) || 259 if ((GNUNET_OK > ret) ||
242 (GNUNET_OK != GNUNET_log_setup (lpfx, loglev, logfile))) 260 (GNUNET_OK !=
261 GNUNET_log_setup (lpfx,
262 loglev,
263 logfile)))
243 { 264 {
244 GNUNET_free (allopts); 265 GNUNET_free (allopts);
245 GNUNET_free (lpfx); 266 GNUNET_free (lpfx);
@@ -250,7 +271,9 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName,
250 if (GNUNET_YES == 271 if (GNUNET_YES ==
251 GNUNET_DISK_file_test (cc.cfgfile)) 272 GNUNET_DISK_file_test (cc.cfgfile))
252 { 273 {
253 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, cc.cfgfile)) 274 if (GNUNET_SYSERR ==
275 GNUNET_CONFIGURATION_load (cfg,
276 cc.cfgfile))
254 { 277 {
255 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 278 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
256 _("Malformed configuration file `%s', exit ...\n"), 279 _("Malformed configuration file `%s', exit ...\n"),
@@ -263,11 +286,14 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName,
263 } 286 }
264 else 287 else
265 { 288 {
266 if (0 != strcmp (cc.cfgfile, cfg_fn)) 289 if (0 != strcmp (cc.cfgfile,
290 cfg_fn))
267 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 291 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
268 _("Could not access configuration file `%s'\n"), 292 _("Could not access configuration file `%s'\n"),
269 cc.cfgfile); 293 cc.cfgfile);
270 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, NULL)) 294 if (GNUNET_SYSERR ==
295 GNUNET_CONFIGURATION_load (cfg,
296 NULL))
271 { 297 {
272 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 298 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
273 _("Malformed configuration, exit ...\n")); 299 _("Malformed configuration, exit ...\n"));
@@ -280,11 +306,15 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName,
280 GNUNET_free (allopts); 306 GNUNET_free (allopts);
281 GNUNET_free (lpfx); 307 GNUNET_free (lpfx);
282 if (GNUNET_OK == 308 if (GNUNET_OK ==
283 GNUNET_CONFIGURATION_get_value_number (cc.cfg, "testing", "skew_offset", 309 GNUNET_CONFIGURATION_get_value_number (cc.cfg,
310 "testing",
311 "skew_offset",
284 &skew_offset) && 312 &skew_offset) &&
285 (GNUNET_OK == 313 (GNUNET_OK ==
286 GNUNET_CONFIGURATION_get_value_number (cc.cfg, "testing", 314 GNUNET_CONFIGURATION_get_value_number (cc.cfg,
287 "skew_variance", &skew_variance))) 315 "testing",
316 "skew_variance",
317 &skew_variance)))
288 { 318 {
289 clock_offset = skew_offset - skew_variance; 319 clock_offset = skew_offset - skew_variance;
290 GNUNET_TIME_set_offset (clock_offset); 320 GNUNET_TIME_set_offset (clock_offset);
@@ -301,7 +331,8 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName,
301 "CONFIG")) 331 "CONFIG"))
302 { 332 {
303 GNUNET_CONFIGURATION_set_value_string (cfg, 333 GNUNET_CONFIGURATION_set_value_string (cfg,
304 "arm", "CONFIG", 334 "arm",
335 "CONFIG",
305 cc.cfgfile); 336 cc.cfgfile);
306 } 337 }
307 338
@@ -314,7 +345,10 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName,
314 else 345 else
315 { 346 {
316 GNUNET_RESOLVER_connect (cc.cfg); 347 GNUNET_RESOLVER_connect (cc.cfg);
317 cc.task (cc.task_cls, cc.args, cc.cfgfile, cc.cfg); 348 cc.task (cc.task_cls,
349 cc.args,
350 cc.cfgfile,
351 cc.cfg);
318 } 352 }
319 ret = GNUNET_OK; 353 ret = GNUNET_OK;
320 cleanup: 354 cleanup:
@@ -326,6 +360,7 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName,
326 return ret; 360 return ret;
327} 361}
328 362
363
329/** 364/**
330 * Run a standard GNUnet command startup sequence (initialize loggers 365 * Run a standard GNUnet command startup sequence (initialize loggers
331 * and configuration, parse options). 366 * and configuration, parse options).