aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-08-05 18:20:34 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-08-05 18:20:34 +0200
commit50db1f29bf96c2ae4dbb96763793a9592d99cf02 (patch)
tree9f99e1eab5aa1fb22d8656ab42a2d048bc7fcc2c
parent20077c1429915b2c223e4d179a033f2b1806872c (diff)
downloadbusybox-w32-50db1f29bf96c2ae4dbb96763793a9592d99cf02.tar.gz
busybox-w32-50db1f29bf96c2ae4dbb96763793a9592d99cf02.tar.bz2
busybox-w32-50db1f29bf96c2ae4dbb96763793a9592d99cf02.zip
sysctl: recognize ";comment" and "<whitespace>#comment" lines
function old new delta config_read 639 699 +60 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--include/libbb.h5
-rw-r--r--libbb/parse_config.c12
-rw-r--r--procps/sysctl.c7
3 files changed, 19 insertions, 5 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 6077f64c9..51e8f27a5 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1403,6 +1403,11 @@ enum {
1403 // keep a copy of current line 1403 // keep a copy of current line
1404 PARSE_KEEP_COPY = 0x00200000 * ENABLE_FEATURE_CROND_D, 1404 PARSE_KEEP_COPY = 0x00200000 * ENABLE_FEATURE_CROND_D,
1405 PARSE_EOL_COMMENTS = 0x00400000, // comments are recognized even if they aren't the first char 1405 PARSE_EOL_COMMENTS = 0x00400000, // comments are recognized even if they aren't the first char
1406 PARSE_ALT_COMMENTS = 0x00800000, // delim[0] and delim[1] are two different allowed comment chars
1407 // (so far, delim[0] will only work as comment char for full-line comment)
1408 // (IOW: it works as if PARSE_EOL_COMMENTS is not set. sysctl applet is okay with this)
1409 PARSE_WS_COMMENTS = 0x01000000, // comments are recognized even if there is whitespace before
1410 // ("line start><space><tab><space>#comment" is also comment, not only "line start>#comment")
1406 // NORMAL is: 1411 // NORMAL is:
1407 // * remove leading and trailing delimiters and collapse 1412 // * remove leading and trailing delimiters and collapse
1408 // multiple delimiters into one 1413 // multiple delimiters into one
diff --git a/libbb/parse_config.c b/libbb/parse_config.c
index da7482c6d..eaf69d97f 100644
--- a/libbb/parse_config.c
+++ b/libbb/parse_config.c
@@ -161,13 +161,18 @@ mintokens > 0 make config_read() print error message if less than mintokens
161#undef config_read 161#undef config_read
162int FAST_FUNC config_read(parser_t *parser, char **tokens, unsigned flags, const char *delims) 162int FAST_FUNC config_read(parser_t *parser, char **tokens, unsigned flags, const char *delims)
163{ 163{
164 char *line; 164 char *line, *p;
165 int ntokens, mintokens; 165 int ntokens, mintokens;
166 int t; 166 int t;
167 char alt_comment_ch;
167 168
168 if (!parser) 169 if (!parser)
169 return 0; 170 return 0;
170 171
172 alt_comment_ch = '\0';
173 if (flags & PARSE_ALT_COMMENTS)
174 alt_comment_ch = *delims++;
175
171 ntokens = (uint8_t)flags; 176 ntokens = (uint8_t)flags;
172 mintokens = (uint8_t)(flags >> 8); 177 mintokens = (uint8_t)(flags >> 8);
173 178
@@ -184,7 +189,10 @@ int FAST_FUNC config_read(parser_t *parser, char **tokens, unsigned flags, const
184 if (flags & PARSE_TRIM) 189 if (flags & PARSE_TRIM)
185 line += strspn(line, delims + 1); 190 line += strspn(line, delims + 1);
186 191
187 if (line[0] == '\0' || line[0] == delims[0]) 192 p = line;
193 if (flags & PARSE_WS_COMMENTS)
194 p = skip_whitespace(p);
195 if (p[0] == '\0' || p[0] == delims[0] || p[0] == alt_comment_ch)
188 goto again; 196 goto again;
189 197
190 if (flags & PARSE_KEEP_COPY) { 198 if (flags & PARSE_KEEP_COPY) {
diff --git a/procps/sysctl.c b/procps/sysctl.c
index ef1a1b99f..a42a91247 100644
--- a/procps/sysctl.c
+++ b/procps/sysctl.c
@@ -247,15 +247,16 @@ static int sysctl_handle_preload_file(const char *filename)
247 /* Must do it _after_ config_open(): */ 247 /* Must do it _after_ config_open(): */
248 xchdir("/proc/sys"); 248 xchdir("/proc/sys");
249 249
250//TODO: ';' is comment char too
251//TODO: <space><tab><space>#comment is also comment, not strictly 1st char only
252 parse_flags = 0; 250 parse_flags = 0;
253 parse_flags &= ~PARSE_COLLAPSE; // NO (var==val is not var=val) - treat consecutive delimiters as one 251 parse_flags &= ~PARSE_COLLAPSE; // NO (var==val is not var=val) - treat consecutive delimiters as one
254 parse_flags &= ~PARSE_TRIM; // NO - trim leading and trailing delimiters 252 parse_flags &= ~PARSE_TRIM; // NO - trim leading and trailing delimiters
255 parse_flags |= PARSE_GREEDY; // YES - last token takes entire remainder of the line 253 parse_flags |= PARSE_GREEDY; // YES - last token takes entire remainder of the line
256 parse_flags &= ~PARSE_MIN_DIE; // NO - die if < min tokens found 254 parse_flags &= ~PARSE_MIN_DIE; // NO - die if < min tokens found
257 parse_flags &= ~PARSE_EOL_COMMENTS; // NO (only first char) - comments are recognized even if not first char 255 parse_flags &= ~PARSE_EOL_COMMENTS; // NO (only first char) - comments are recognized even if not first char
258 while (config_read(parser, token, 2, 2, "#=", parse_flags)) { 256 parse_flags |= PARSE_ALT_COMMENTS;// YES - two comment chars: ';' and '#'
257 /* <space><tab><space>#comment is also comment, not strictly 1st char only */
258 parse_flags |= PARSE_WS_COMMENTS; // YES - comments are recognized even if there is whitespace before
259 while (config_read(parser, token, 2, 2, ";#=", parse_flags)) {
259 char *tp; 260 char *tp;
260 261
261 trim(token[1]); 262 trim(token[1]);