aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-05-05 15:10:48 +0000
committerChristian Grothoff <christian@grothoff.org>2016-05-05 15:10:48 +0000
commitae8cb91d9961899075a892a3110204bc139c2eb6 (patch)
treece1dcb5a0c2d20257c7cfe868c63dc7a08e0656f
parent0f87e6e8f440c002011d51f486e1b504da0de31e (diff)
downloadgnunet-ae8cb91d9961899075a892a3110204bc139c2eb6.tar.gz
gnunet-ae8cb91d9961899075a892a3110204bc139c2eb6.zip
add -w option to gnunet-config
-rw-r--r--doc/man/gnunet-config.14
-rw-r--r--src/util/gnunet-config.c85
2 files changed, 69 insertions, 20 deletions
diff --git a/doc/man/gnunet-config.1 b/doc/man/gnunet-config.1
index 6b4b82001..d309e7fa0 100644
--- a/doc/man/gnunet-config.1
+++ b/doc/man/gnunet-config.1
@@ -22,6 +22,9 @@ Which configuration section should be accessed or edited. Required option.
22.IP "\-S, \-\-list\-sections" 22.IP "\-S, \-\-list\-sections"
23List available configuration sections for use with \-\-section. 23List available configuration sections for use with \-\-section.
24.B 24.B
25.IP "\-W, \-\-rewrite"
26Consider differences to defaults only.
27.B
25.IP "\-o OPTION, \-\-option=OPTION" 28.IP "\-o OPTION, \-\-option=OPTION"
26Which configuration option should be accessed or edited. Required to set a value. If not given, all values of a given section will be printed in the format "OPTION = VALUE". 29Which configuration option should be accessed or edited. Required to set a value. If not given, all values of a given section will be printed in the format "OPTION = VALUE".
27.B 30.B
@@ -43,4 +46,3 @@ Print GNUnet version number.
43 46
44.SH BUGS 47.SH BUGS
45Report bugs by using Mantis <https://gnunet.org/bugs/> or by sending electronic mail to <gnunet\-developers@gnu.org> 48Report bugs by using Mantis <https://gnunet.org/bugs/> or by sending electronic mail to <gnunet\-developers@gnu.org>
46
diff --git a/src/util/gnunet-config.c b/src/util/gnunet-config.c
index 1c6205334..7ec7162f1 100644
--- a/src/util/gnunet-config.c
+++ b/src/util/gnunet-config.c
@@ -57,6 +57,11 @@ static int list_sections;
57 */ 57 */
58static int ret; 58static int ret;
59 59
60/**
61 * Should we generate a configuration file that is clean and
62 * only contains the deltas to the defaults?
63 */
64static int rewrite;
60 65
61/** 66/**
62 * Print each option in a given section. 67 * Print each option in a given section.
@@ -99,41 +104,70 @@ print_section_name (void *cls,
99 * @param cfg configuration 104 * @param cfg configuration
100 */ 105 */
101static void 106static void
102run (void *cls, char *const *args, const char *cfgfile, 107run (void *cls,
108 char *const *args,
109 const char *cfgfile,
103 const struct GNUNET_CONFIGURATION_Handle *cfg) 110 const struct GNUNET_CONFIGURATION_Handle *cfg)
104{ 111{
105 struct GNUNET_CONFIGURATION_Handle *out; 112 struct GNUNET_CONFIGURATION_Handle *out = NULL;
113 struct GNUNET_CONFIGURATION_Handle *diff = NULL;
106 114
107 if (NULL == section || list_sections) 115 if (rewrite)
116 {
117 struct GNUNET_CONFIGURATION_Handle *def;
118
119 def = GNUNET_CONFIGURATION_create ();
120 if (GNUNET_OK !=
121 GNUNET_CONFIGURATION_load (def, NULL))
122 {
123 fprintf (stderr,
124 _("failed to load configuration defaults"));
125 ret = 1;
126 return;
127 }
128 diff = GNUNET_CONFIGURATION_get_diff (def,
129 cfg);
130 cfg = diff;
131 }
132 if ( ((! rewrite) && (NULL == section)) || list_sections)
108 { 133 {
109 if (! list_sections) 134 if (! list_sections)
110 { 135 {
111 fprintf (stderr, _("--section argument is required\n")); 136 fprintf (stderr,
137 _("--section argument is required\n"));
112 } 138 }
113 fprintf (stderr, _("The following sections are available:\n")); 139 fprintf (stderr,
114 GNUNET_CONFIGURATION_iterate_sections (cfg, &print_section_name, NULL); 140 _("The following sections are available:\n"));
141 GNUNET_CONFIGURATION_iterate_sections (cfg,
142 &print_section_name,
143 NULL);
115 ret = 1; 144 ret = 1;
116 return; 145 goto cleanup;
117 } 146 }
118 147
119 if (NULL == value) 148 if ( (NULL != section) && (NULL == value) )
120 { 149 {
121 if (NULL == option) 150 if (NULL == option)
122 { 151 {
123 GNUNET_CONFIGURATION_iterate_section_values (cfg, section, 152 GNUNET_CONFIGURATION_iterate_section_values (cfg,
124 &print_option, NULL); 153 section,
154 &print_option,
155 NULL);
125 } 156 }
126 else 157 else
127 { 158 {
128 if (is_filename) 159 if (is_filename)
129 { 160 {
130 if (GNUNET_OK != 161 if (GNUNET_OK !=
131 GNUNET_CONFIGURATION_get_value_filename (cfg, section, option, &value)) 162 GNUNET_CONFIGURATION_get_value_filename (cfg,
163 section,
164 option,
165 &value))
132 { 166 {
133 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 167 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
134 section, option); 168 section, option);
135 ret = 3; 169 ret = 3;
136 return; 170 goto cleanup;
137 } 171 }
138 } 172 }
139 else 173 else
@@ -144,28 +178,38 @@ run (void *cls, char *const *args, const char *cfgfile,
144 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 178 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
145 section, option); 179 section, option);
146 ret = 3; 180 ret = 3;
147 return; 181 goto cleanup;
148 } 182 }
149 } 183 }
150 fprintf (stdout, "%s\n", value); 184 fprintf (stdout, "%s\n", value);
151 } 185 }
152 } 186 }
153 else 187 else if (NULL != section)
154 { 188 {
155 if (NULL == option) 189 if (NULL == option)
156 { 190 {
157 fprintf (stderr, _("--option argument required to set value\n")); 191 fprintf (stderr, _("--option argument required to set value\n"));
158 ret = 1; 192 ret = 1;
159 return; 193 goto cleanup;
160 } 194 }
161 out = GNUNET_CONFIGURATION_dup (cfg); 195 out = GNUNET_CONFIGURATION_dup (cfg);
162 GNUNET_CONFIGURATION_set_value_string (out, section, option, value); 196 GNUNET_CONFIGURATION_set_value_string (out,
197 section,
198 option,
199 value);
200 }
201 if ( (NULL != diff) || (NULL != out) )
202 {
163 if (GNUNET_OK != 203 if (GNUNET_OK !=
164 GNUNET_CONFIGURATION_write (out, cfgfile)) 204 GNUNET_CONFIGURATION_write ((NULL == out) ? diff : out,
205 cfgfile))
165 ret = 2; 206 ret = 2;
166 GNUNET_CONFIGURATION_destroy (out);
167 return;
168 } 207 }
208 if (NULL != out)
209 GNUNET_CONFIGURATION_destroy (out);
210 cleanup:
211 if (NULL != diff)
212 GNUNET_CONFIGURATION_destroy (diff);
169} 213}
170 214
171 215
@@ -195,6 +239,9 @@ main (int argc, char *const *argv)
195 { 'S', "list-sections", NULL, 239 { 'S', "list-sections", NULL,
196 gettext_noop ("print available configuration sections"), 240 gettext_noop ("print available configuration sections"),
197 0, &GNUNET_GETOPT_set_one, &list_sections }, 241 0, &GNUNET_GETOPT_set_one, &list_sections },
242 { 'w', "rewrite", NULL,
243 gettext_noop ("write configuration file that only contains delta to defaults"),
244 0, &GNUNET_GETOPT_set_one, &rewrite },
198 GNUNET_GETOPT_OPTION_END 245 GNUNET_GETOPT_OPTION_END
199 }; 246 };
200 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 247 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))