aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-01-07 10:26:54 +0100
committerChristian Grothoff <christian@grothoff.org>2021-01-07 10:26:54 +0100
commit5b10ad755f132e849ee35516fefe27df64eb188d (patch)
tree4400517ca25353057c320b992827553b16a45200
parent90499cabec25be14fb96bb3d62b791c5bf3470c2 (diff)
downloadgnunet-5b10ad755f132e849ee35516fefe27df64eb188d.tar.gz
gnunet-5b10ad755f132e849ee35516fefe27df64eb188d.zip
properly document return value of GNUNET_PROGRAM_run
-rw-r--r--src/include/gnunet_program_lib.h14
-rw-r--r--src/util/getopt.c23
-rw-r--r--src/util/program.c87
3 files changed, 59 insertions, 65 deletions
diff --git a/src/include/gnunet_program_lib.h b/src/include/gnunet_program_lib.h
index adb159e55..4167060c0 100644
--- a/src/include/gnunet_program_lib.h
+++ b/src/include/gnunet_program_lib.h
@@ -72,9 +72,12 @@ typedef void
72 * @param task_cls closure for @a task 72 * @param task_cls closure for @a task
73 * @param run_without_scheduler #GNUNET_NO start the scheduler, 73 * @param run_without_scheduler #GNUNET_NO start the scheduler,
74 * #GNUNET_YES do not start the scheduler just run the main task 74 * #GNUNET_YES do not start the scheduler just run the main task
75 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 75 * @return #GNUNET_SYSERR on error,
76 * #GNUNET_NO if successful option processing called
77 * for the program to terminate,
78 * #GNUNET_OK on success (#a task was invoked)
76 */ 79 */
77int 80enum GNUNET_GenericReturnValue
78GNUNET_PROGRAM_run2 (int argc, 81GNUNET_PROGRAM_run2 (int argc,
79 char *const *argv, 82 char *const *argv,
80 const char *binaryName, 83 const char *binaryName,
@@ -96,9 +99,12 @@ GNUNET_PROGRAM_run2 (int argc,
96 * @param options command line options 99 * @param options command line options
97 * @param task main function to run 100 * @param task main function to run
98 * @param task_cls closure for @a task 101 * @param task_cls closure for @a task
99 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 102 * @return #GNUNET_SYSERR on error,
103 * #GNUNET_NO if successful option processing called
104 * for the program to terminate,
105 * #GNUNET_OK on success (#a task was invoked)
100 */ 106 */
101int 107enum GNUNET_GenericReturnValue
102GNUNET_PROGRAM_run (int argc, 108GNUNET_PROGRAM_run (int argc,
103 char *const *argv, 109 char *const *argv,
104 const char *binaryName, 110 const char *binaryName,
diff --git a/src/util/getopt.c b/src/util/getopt.c
index acc1b6535..6dfad96da 100644
--- a/src/util/getopt.c
+++ b/src/util/getopt.c
@@ -878,16 +878,7 @@ GNgetopt_long (int argc,
878 878
879/* ******************** now the GNUnet specific modifications... ********************* */ 879/* ******************** now the GNUnet specific modifications... ********************* */
880 880
881/** 881
882 * Parse the command line.
883 *
884 * @param binaryOptions Name of application with option summary
885 * @param allOptions defined options and handlers
886 * @param argc number of arguments
887 * @param argv actual arguments
888 * @return index into argv with first non-option
889 * argument, or #GNUNET_SYSERR on error
890 */
891int 882int
892GNUNET_GETOPT_run (const char *binaryOptions, 883GNUNET_GETOPT_run (const char *binaryOptions,
893 const struct GNUNET_GETOPT_CommandLineOption *allOptions, 884 const struct GNUNET_GETOPT_CommandLineOption *allOptions,
@@ -899,7 +890,7 @@ GNUNET_GETOPT_run (const char *binaryOptions,
899 int count; 890 int count;
900 char *shorts; 891 char *shorts;
901 int spos; 892 int spos;
902 int cont; 893 enum GNUNET_GenericReturnValue cont;
903 uint8_t *seen; 894 uint8_t *seen;
904 unsigned int optmatch = 0; 895 unsigned int optmatch = 0;
905 const char *have_exclusive = NULL; 896 const char *have_exclusive = NULL;
@@ -944,7 +935,11 @@ GNUNET_GETOPT_run (const char *binaryOptions,
944 unsigned int i; 935 unsigned int i;
945 int c; 936 int c;
946 937
947 c = GNgetopt_long (argc, argv, shorts, long_options, &option_index); 938 c = GNgetopt_long (argc,
939 argv,
940 shorts,
941 long_options,
942 &option_index);
948 if (c == GNUNET_SYSERR) 943 if (c == GNUNET_SYSERR)
949 break; /* No more flags to process */ 944 break; /* No more flags to process */
950 945
@@ -971,7 +966,9 @@ GNUNET_GETOPT_run (const char *binaryOptions,
971 } 966 }
972 if (i == count) 967 if (i == count)
973 { 968 {
974 fprintf (stderr, _ ("Use %s to get a list of options.\n"), "--help"); 969 fprintf (stderr,
970 _ ("Use %s to get a list of options.\n"),
971 "--help");
975 cont = GNUNET_SYSERR; 972 cont = GNUNET_SYSERR;
976 } 973 }
977 } 974 }
diff --git a/src/util/program.c b/src/util/program.c
index b5484855c..e34b37370 100644
--- a/src/util/program.c
+++ b/src/util/program.c
@@ -122,22 +122,7 @@ cmd_sorter (const void *a1, const void *a2)
122} 122}
123 123
124 124
125/** 125enum GNUNET_GenericReturnValue
126 * Run a standard GNUnet command startup sequence (initialize loggers
127 * and configuration, parse options).
128 *
129 * @param argc number of command line arguments in @a argv
130 * @param argv command line arguments
131 * @param binaryName our expected name
132 * @param binaryHelp help text for the program
133 * @param options command line options
134 * @param task main function to run
135 * @param task_cls closure for @a task
136 * @param run_without_scheduler #GNUNET_NO start the scheduler, #GNUNET_YES do not
137 * start the scheduler just run the main task
138 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
139 */
140int
141GNUNET_PROGRAM_run2 (int argc, 126GNUNET_PROGRAM_run2 (int argc,
142 char *const *argv, 127 char *const *argv,
143 const char *binaryName, 128 const char *binaryName,
@@ -156,7 +141,8 @@ GNUNET_PROGRAM_run2 (int argc,
156 char *logfile; 141 char *logfile;
157 char *cfg_fn; 142 char *cfg_fn;
158 const char *xdg; 143 const char *xdg;
159 int ret; 144 enum GNUNET_GenericReturnValue ret;
145 int iret;
160 unsigned int cnt; 146 unsigned int cnt;
161 unsigned long long skew_offset; 147 unsigned long long skew_offset;
162 unsigned long long skew_variance; 148 unsigned long long skew_variance;
@@ -232,7 +218,7 @@ GNUNET_PROGRAM_run2 (int argc,
232 sizeof(struct GNUNET_GETOPT_CommandLineOption), 218 sizeof(struct GNUNET_GETOPT_CommandLineOption),
233 &cmd_sorter); 219 &cmd_sorter);
234 loglev = NULL; 220 loglev = NULL;
235 if (NULL != pd->config_file && NULL != pd->user_config_file) 221 if ((NULL != pd->config_file) && (NULL != pd->user_config_file))
236 { 222 {
237 xdg = getenv ("XDG_CONFIG_HOME"); 223 xdg = getenv ("XDG_CONFIG_HOME");
238 if (NULL != xdg) 224 if (NULL != xdg)
@@ -249,12 +235,18 @@ GNUNET_PROGRAM_run2 (int argc,
249 lpfx = GNUNET_strdup (binaryName); 235 lpfx = GNUNET_strdup (binaryName);
250 if (NULL != (spc = strstr (lpfx, " "))) 236 if (NULL != (spc = strstr (lpfx, " ")))
251 *spc = '\0'; 237 *spc = '\0';
252 ret = GNUNET_GETOPT_run (binaryName, allopts, (unsigned int) argc, argv); 238 iret = GNUNET_GETOPT_run (binaryName,
253 if ((GNUNET_OK > ret) || 239 allopts,
254 (GNUNET_OK != GNUNET_log_setup (lpfx, loglev, logfile))) 240 (unsigned int) argc,
241 argv);
242 if ((GNUNET_OK > iret) ||
243 (GNUNET_OK != GNUNET_log_setup (lpfx,
244 loglev,
245 logfile)))
255 { 246 {
256 GNUNET_free (allopts); 247 GNUNET_free (allopts);
257 GNUNET_free (lpfx); 248 GNUNET_free (lpfx);
249 ret = (enum GNUNET_GenericReturnValue) iret;
258 goto cleanup; 250 goto cleanup;
259 } 251 }
260 if (NULL != cc.cfgfile) 252 if (NULL != cc.cfgfile)
@@ -274,7 +266,7 @@ GNUNET_PROGRAM_run2 (int argc,
274 } 266 }
275 else 267 else
276 { 268 {
277 if (NULL != cfg_fn && GNUNET_YES == GNUNET_DISK_file_test (cfg_fn)) 269 if ((NULL != cfg_fn) && (GNUNET_YES == GNUNET_DISK_file_test (cfg_fn)))
278 { 270 {
279 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, cfg_fn)) 271 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, cfg_fn))
280 { 272 {
@@ -306,14 +298,16 @@ GNUNET_PROGRAM_run2 (int argc,
306 } 298 }
307 GNUNET_free (allopts); 299 GNUNET_free (allopts);
308 GNUNET_free (lpfx); 300 GNUNET_free (lpfx);
309 if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cc.cfg, 301 if ((GNUNET_OK ==
310 "testing", 302 GNUNET_CONFIGURATION_get_value_number (cc.cfg,
311 "skew_offset", 303 "testing",
312 &skew_offset)) && 304 "skew_offset",
313 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cc.cfg, 305 &skew_offset)) &&
314 "testing", 306 (GNUNET_OK ==
315 "skew_variance", 307 GNUNET_CONFIGURATION_get_value_number (cc.cfg,
316 &skew_variance))) 308 "testing",
309 "skew_variance",
310 &skew_variance)))
317 { 311 {
318 clock_offset = skew_offset - skew_variance; 312 clock_offset = skew_offset - skew_variance;
319 GNUNET_TIME_set_offset (clock_offset); 313 GNUNET_TIME_set_offset (clock_offset);
@@ -323,16 +317,26 @@ GNUNET_PROGRAM_run2 (int argc,
323 specified in the configuration, remember the command-line option 317 specified in the configuration, remember the command-line option
324 in "cfg". This is typically really only having an effect if we 318 in "cfg". This is typically really only having an effect if we
325 are running code in src/arm/, as obviously the rest of the code 319 are running code in src/arm/, as obviously the rest of the code
326 has little business with ARM-specific options. */if (GNUNET_YES != GNUNET_CONFIGURATION_have_value (cfg, "arm", "CONFIG")) 320 has little business with ARM-specific options. */
321 if (GNUNET_YES !=
322 GNUNET_CONFIGURATION_have_value (cfg,
323 "arm",
324 "CONFIG"))
327 { 325 {
328 if (NULL != cc.cfgfile) 326 if (NULL != cc.cfgfile)
329 GNUNET_CONFIGURATION_set_value_string (cfg, "arm", "CONFIG", cc.cfgfile); 327 GNUNET_CONFIGURATION_set_value_string (cfg,
328 "arm",
329 "CONFIG",
330 cc.cfgfile);
330 else if (NULL != cfg_fn) 331 else if (NULL != cfg_fn)
331 GNUNET_CONFIGURATION_set_value_string (cfg, "arm", "CONFIG", cfg_fn); 332 GNUNET_CONFIGURATION_set_value_string (cfg,
333 "arm",
334 "CONFIG",
335 cfg_fn);
332 } 336 }
333 337
334 /* run */ 338 /* run */
335 cc.args = &argv[ret]; 339 cc.args = &argv[iret];
336 if ((NULL == cc.cfgfile) && (NULL != cfg_fn)) 340 if ((NULL == cc.cfgfile) && (NULL != cfg_fn))
337 cc.cfgfile = GNUNET_strdup (cfg_fn); 341 cc.cfgfile = GNUNET_strdup (cfg_fn);
338 if (GNUNET_NO == run_without_scheduler) 342 if (GNUNET_NO == run_without_scheduler)
@@ -355,20 +359,7 @@ cleanup:
355} 359}
356 360
357 361
358/** 362enum GNUNET_GenericReturnValue
359 * Run a standard GNUnet command startup sequence (initialize loggers
360 * and configuration, parse options).
361 *
362 * @param argc number of command line arguments
363 * @param argv command line arguments
364 * @param binaryName our expected name
365 * @param binaryHelp help text for the program
366 * @param options command line options
367 * @param task main function to run
368 * @param task_cls closure for @a task
369 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
370 */
371int
372GNUNET_PROGRAM_run (int argc, 363GNUNET_PROGRAM_run (int argc,
373 char *const *argv, 364 char *const *argv,
374 const char *binaryName, 365 const char *binaryName,