diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-06-22 11:48:40 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-06-22 11:48:53 +0200 |
commit | 4b3469ce52759581bf8833a3093cfe7ddad8aa9d (patch) | |
tree | 5f77501d550e539c346859c2c90ea6150369baa8 /src/util/gnunet-config.c | |
parent | 700b884ba5c93936122458eb7d0b417b2d7a071c (diff) | |
download | gnunet-4b3469ce52759581bf8833a3093cfe7ddad8aa9d.tar.gz gnunet-4b3469ce52759581bf8833a3093cfe7ddad8aa9d.zip |
implement #5771
Diffstat (limited to 'src/util/gnunet-config.c')
-rw-r--r-- | src/util/gnunet-config.c | 58 |
1 files changed, 43 insertions, 15 deletions
diff --git a/src/util/gnunet-config.c b/src/util/gnunet-config.c index f700428a2..9c292205a 100644 --- a/src/util/gnunet-config.c +++ b/src/util/gnunet-config.c | |||
@@ -43,6 +43,13 @@ static char *option; | |||
43 | static char *value; | 43 | static char *value; |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * Backend to check if the respective plugin is | ||
47 | * loadable. NULL if no check is to be performed. | ||
48 | * The value is the "basename" of the plugin to load. | ||
49 | */ | ||
50 | static char *backend_check; | ||
51 | |||
52 | /** | ||
46 | * Treat option as a filename. | 53 | * Treat option as a filename. |
47 | */ | 54 | */ |
48 | static int is_filename; | 55 | static int is_filename; |
@@ -55,7 +62,7 @@ static int list_sections; | |||
55 | /** | 62 | /** |
56 | * Return value from 'main'. | 63 | * Return value from 'main'. |
57 | */ | 64 | */ |
58 | static int ret; | 65 | static int global_ret; |
59 | 66 | ||
60 | /** | 67 | /** |
61 | * Should we generate a configuration file that is clean and | 68 | * Should we generate a configuration file that is clean and |
@@ -63,6 +70,7 @@ static int ret; | |||
63 | */ | 70 | */ |
64 | static int rewrite; | 71 | static int rewrite; |
65 | 72 | ||
73 | |||
66 | /** | 74 | /** |
67 | * Print each option in a given section. | 75 | * Print each option in a given section. |
68 | * | 76 | * |
@@ -149,6 +157,17 @@ run (void *cls, | |||
149 | 157 | ||
150 | (void) cls; | 158 | (void) cls; |
151 | (void) args; | 159 | (void) args; |
160 | if (NULL != backend_check) | ||
161 | { | ||
162 | char *name; | ||
163 | |||
164 | GNUNET_asprintf (&name, | ||
165 | "libgnunet_plugin_%s", | ||
166 | backend_check); | ||
167 | global_ret = (GNUNET_OK == GNUNET_PLUGIN_test (name)) ? 0 : 77; | ||
168 | GNUNET_free (name); | ||
169 | return; | ||
170 | } | ||
152 | if (rewrite) | 171 | if (rewrite) |
153 | { | 172 | { |
154 | struct GNUNET_CONFIGURATION_Handle *def; | 173 | struct GNUNET_CONFIGURATION_Handle *def; |
@@ -159,7 +178,7 @@ run (void *cls, | |||
159 | { | 178 | { |
160 | fprintf (stderr, | 179 | fprintf (stderr, |
161 | _("failed to load configuration defaults")); | 180 | _("failed to load configuration defaults")); |
162 | ret = 1; | 181 | global_ret = 1; |
163 | return; | 182 | return; |
164 | } | 183 | } |
165 | diff = GNUNET_CONFIGURATION_get_diff (def, | 184 | diff = GNUNET_CONFIGURATION_get_diff (def, |
@@ -174,7 +193,7 @@ run (void *cls, | |||
174 | _("%s or %s argument is required\n"), | 193 | _("%s or %s argument is required\n"), |
175 | "--section", | 194 | "--section", |
176 | "--list-sections"); | 195 | "--list-sections"); |
177 | ret = 1; | 196 | global_ret = 1; |
178 | } | 197 | } |
179 | else | 198 | else |
180 | { | 199 | { |
@@ -208,7 +227,7 @@ run (void *cls, | |||
208 | { | 227 | { |
209 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 228 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
210 | section, option); | 229 | section, option); |
211 | ret = 3; | 230 | global_ret = 3; |
212 | goto cleanup; | 231 | goto cleanup; |
213 | } | 232 | } |
214 | } | 233 | } |
@@ -220,7 +239,7 @@ run (void *cls, | |||
220 | { | 239 | { |
221 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 240 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
222 | section, option); | 241 | section, option); |
223 | ret = 3; | 242 | global_ret = 3; |
224 | goto cleanup; | 243 | goto cleanup; |
225 | } | 244 | } |
226 | } | 245 | } |
@@ -232,7 +251,7 @@ run (void *cls, | |||
232 | if (NULL == option) | 251 | if (NULL == option) |
233 | { | 252 | { |
234 | fprintf (stderr, _("--option argument required to set value\n")); | 253 | fprintf (stderr, _("--option argument required to set value\n")); |
235 | ret = 1; | 254 | global_ret = 1; |
236 | goto cleanup; | 255 | goto cleanup; |
237 | } | 256 | } |
238 | out = GNUNET_CONFIGURATION_dup (cfg); | 257 | out = GNUNET_CONFIGURATION_dup (cfg); |
@@ -260,7 +279,7 @@ run (void *cls, | |||
260 | if (GNUNET_OK != | 279 | if (GNUNET_OK != |
261 | GNUNET_CONFIGURATION_write ((NULL == out) ? diff : out, | 280 | GNUNET_CONFIGURATION_write ((NULL == out) ? diff : out, |
262 | cfgfile)) | 281 | cfgfile)) |
263 | ret = 2; | 282 | global_ret = 2; |
264 | } | 283 | } |
265 | GNUNET_free_non_null (cfg_fn); | 284 | GNUNET_free_non_null (cfg_fn); |
266 | if (NULL != out) | 285 | if (NULL != out) |
@@ -287,6 +306,12 @@ main (int argc, | |||
287 | "filename", | 306 | "filename", |
288 | gettext_noop ("interpret option value as a filename (with $-expansion)"), | 307 | gettext_noop ("interpret option value as a filename (with $-expansion)"), |
289 | &is_filename), | 308 | &is_filename), |
309 | //GNUNET_GETOPT_option_exclusive | ||
310 | (GNUNET_GETOPT_option_string ('b', | ||
311 | "supported-backend", | ||
312 | "BACKEND", | ||
313 | gettext_noop ("test if the current installation supports the specified BACKEND"), | ||
314 | &backend_check)), | ||
290 | GNUNET_GETOPT_option_string ('s', | 315 | GNUNET_GETOPT_option_string ('s', |
291 | "section", | 316 | "section", |
292 | "SECTION", | 317 | "SECTION", |
@@ -312,20 +337,23 @@ main (int argc, | |||
312 | &rewrite), | 337 | &rewrite), |
313 | GNUNET_GETOPT_OPTION_END | 338 | GNUNET_GETOPT_OPTION_END |
314 | }; | 339 | }; |
340 | int ret; | ||
341 | |||
315 | if (GNUNET_OK != | 342 | if (GNUNET_OK != |
316 | GNUNET_STRINGS_get_utf8_args (argc, argv, | 343 | GNUNET_STRINGS_get_utf8_args (argc, argv, |
317 | &argc, &argv)) | 344 | &argc, &argv)) |
318 | return 2; | 345 | return 2; |
319 | 346 | ||
320 | ret = (GNUNET_OK == | 347 | ret = GNUNET_PROGRAM_run (argc, |
321 | GNUNET_PROGRAM_run (argc, | 348 | argv, |
322 | argv, | 349 | "gnunet-config [OPTIONS]", |
323 | "gnunet-config [OPTIONS]", | 350 | gettext_noop ("Manipulate GNUnet configuration files"), |
324 | gettext_noop ("Manipulate GNUnet configuration files"), | 351 | options, |
325 | options, | 352 | &run, NULL); |
326 | &run, NULL)) ? 0 : ret; | ||
327 | GNUNET_free ((void*) argv); | 353 | GNUNET_free ((void*) argv); |
328 | return ret; | 354 | if (GNUNET_OK == ret) |
355 | return global_ret; | ||
356 | return 1; | ||
329 | } | 357 | } |
330 | 358 | ||
331 | /* end of gnunet-config.c */ | 359 | /* end of gnunet-config.c */ |