lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20091125093851.GA14314@sepie.suse.cz>
Date:	Wed, 25 Nov 2009 10:38:51 +0100
From:	Michal Marek <mmarek@...e.cz>
To:	Bernhard Kaindl <bernhard.kaindl@....net>
Cc:	linux-kernel@...r.kernel.org, linux-kbuild@...r.kernel.org,
	Roman Zippel <zippel@...ux-m68k.org>
Subject: [PATCH] Support loading and saving custom remarks in .config

To make it easier for users to maintain their .config over time, add
support for one-line comments (remarks) attached to config option
assignments. The format is

  # some remark
  CONFIG_FOO=y
  # another remark
  # CONFIG_BAR is not set

If a config option is removed, the respective remark is removed as well.
This patch is based on a previous patch by Bernhard Kaindl.

Signed-off-by: Michal Marek <mmarek@...e.cz>
---
 scripts/kconfig/confdata.c |   52 +++++++++++++++++++++++++++++++++++++++++++-
 scripts/kconfig/expr.h     |    1 +
 2 files changed, 52 insertions(+), 1 deletions(-)

diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index b55e72f..daa7d78 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -152,13 +152,46 @@ static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p)
 	return 0;
 }
 
+static char *extract_remark(const char *line)
+{
+	const char *p;
+	char *res, *p2;
+	static const char *alnum =
+		"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+		"abcdefghijklmnopqrstuvwxyz"
+		"0123456789_";
+
+
+	if (!line || *line != '#')
+		return NULL;
+	line++;
+	line += strspn(line, " \t");
+	if (!*line || *line == '\n')
+		return NULL;
+	if (strncmp(line, "CONFIG_", sizeof("CONFIG_") - 1) != 0)
+		goto found;
+	p = line + strspn(line, alnum);
+	if (strcmp(p, " is not set\n") == 0)
+		return NULL;
+	/* skip commented out assignments */
+	if (p[1] == '=' && !strchr(p, ' ') && !strchr(p, '\t'))
+		return NULL;
+found:
+	res = strdup(line);
+	p2 = strchr(res, '\n');
+	if (p2)
+		*p2 = '\0';
+	return res;
+}
+
 int conf_read_simple(const char *name, int def)
 {
 	FILE *in = NULL;
 	char line[1024];
 	char *p, *p2;
 	struct symbol *sym;
-	int i, def_flags;
+	char *last_remark;
+	int i, def_flags, last_remark_lineno;
 
 	if (name) {
 		in = zconf_fopen(name);
@@ -195,6 +228,8 @@ load:
 	conf_lineno = 0;
 	conf_warnings = 0;
 	conf_unsaved = 0;
+	last_remark = NULL;
+	last_remark_lineno = 0;
 
 	def_flags = SYMBOL_DEF << def;
 	for_all_symbols(i, sym) {
@@ -215,8 +250,15 @@ load:
 	}
 
 	while (fgets(line, sizeof(line), in)) {
+		char *remark;
 		conf_lineno++;
 		sym = NULL;
+		remark = extract_remark(line);
+		if (remark) {
+			free(last_remark);
+			last_remark = remark;
+			last_remark_lineno = conf_lineno;
+		}
 		switch (line[0]) {
 		case '#':
 			if (memcmp(line + 2, "CONFIG_", 7))
@@ -309,6 +351,12 @@ load:
 			}
 			cs->def[def].tri = EXPR_OR(cs->def[def].tri, sym->def[def].tri);
 		}
+		if (sym && last_remark &&
+				last_remark_lineno == conf_lineno - 1) {
+			sym->remark = last_remark;
+			/* don't free() the string in the next iteration */
+			last_remark = NULL;
+		}
 	}
 	fclose(in);
 
@@ -484,6 +532,8 @@ int conf_write(const char *name)
 				if (modules_sym->curr.tri == no)
 					type = S_BOOLEAN;
 			}
+			if (sym->remark)
+				fprintf(out, "# %s\n", sym->remark);
 			switch (type) {
 			case S_BOOLEAN:
 			case S_TRISTATE:
diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h
index 6408fef..217e8cb 100644
--- a/scripts/kconfig/expr.h
+++ b/scripts/kconfig/expr.h
@@ -77,6 +77,7 @@ enum {
 struct symbol {
 	struct symbol *next;
 	char *name;
+	char *remark;
 	enum symbol_type type;
 	struct symbol_value curr;
 	struct symbol_value def[S_DEF_COUNT];
-- 
1.6.4.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ