[git commit] mdev: do not treat non-leading '#' chars as start of comment. Closes 4676

Denys Vlasenko vda.linux at googlemail.com
Tue Jan 10 23:37:17 UTC 2012


commit: http://git.busybox.net/busybox/commit/?id=499597d6efb0de5bb6d6f52bda1f348478d7f5a9
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 include/libbb.h      |    5 +++--
 libbb/parse_config.c |    2 +-
 util-linux/mdev.c    |    3 ++-
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/include/libbb.h b/include/libbb.h
index 0c266dc..4975b97 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1195,13 +1195,14 @@ enum {
 	PARSE_MIN_DIE   = 0x00100000, // die if < min tokens found
 	// keep a copy of current line
 	PARSE_KEEP_COPY = 0x00200000 * ENABLE_FEATURE_CROND_D,
-//	PARSE_ESCAPE    = 0x00400000, // process escape sequences in tokens
+	PARSE_EOL_COMMENTS = 0x00400000, // comments are recognized even if they aren't the first char
 	// NORMAL is:
 	// * remove leading and trailing delimiters and collapse
 	//   multiple delimiters into one
 	// * warn and continue if less than mintokens delimiters found
 	// * grab everything into last token
-	PARSE_NORMAL    = PARSE_COLLAPSE | PARSE_TRIM | PARSE_GREEDY,
+	// * comments are recognized even if they aren't the first char
+	PARSE_NORMAL    = PARSE_COLLAPSE | PARSE_TRIM | PARSE_GREEDY | PARSE_EOL_COMMENTS,
 };
 typedef struct parser_t {
 	FILE *fp;
diff --git a/libbb/parse_config.c b/libbb/parse_config.c
index cf5ba4d..1590d9a 100644
--- a/libbb/parse_config.c
+++ b/libbb/parse_config.c
@@ -204,7 +204,7 @@ int FAST_FUNC config_read(parser_t *parser, char **tokens, unsigned flags, const
 			line += strcspn(line, delims[0] ? delims : delims + 1);
 		} else {
 			/* Combining, find comment char if any */
-			line = strchrnul(line, delims[0]);
+			line = strchrnul(line, PARSE_EOL_COMMENTS ? delims[0] : '\0');
 
 			/* Trim any extra delimiters from the end */
 			if (flags & PARSE_TRIM) {
diff --git a/util-linux/mdev.c b/util-linux/mdev.c
index c6be1b8..e5f0c2d 100644
--- a/util-linux/mdev.c
+++ b/util-linux/mdev.c
@@ -206,7 +206,8 @@ static void parse_next_rule(void)
 		char *tokens[4];
 		char *val;
 
-		if (!config_read(G.parser, tokens, 4, 3, "# \t", PARSE_NORMAL))
+		/* No PARSE_EOL_COMMENTS, because command may contain '#' chars */
+		if (!config_read(G.parser, tokens, 4, 3, "# \t", PARSE_NORMAL & ~PARSE_EOL_COMMENTS))
 			break;
 
 		/* Fields: [-]regex uid:gid mode [alias] [cmd] */


More information about the busybox-cvs mailing list