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] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 27 Apr 2015 15:34:26 +0900
From:	Taeung Song <treeze.taeung@...il.com>
To:	Arnaldo Carvalho de Melo <acme@...nel.org>
Cc:	linux-kernel@...r.kernel.org, jolsa@...hat.com,
	namhyung@...nel.org, Taeung Song <treeze.taeung@...il.com>
Subject: [PATCH 4/4] perf tools: Add a option 'remove' to perf-config.

A option 'remove' is to remove specific config variables.
For the syntax examples,

    # perf config -r | --remove [section.subkey ...]

Signed-off-by: Taeung Song <treeze.taeung@...il.com>
---
 tools/perf/Documentation/perf-config.txt |  6 ++++
 tools/perf/builtin-config.c              | 48 +++++++++++++++++++++++---------
 2 files changed, 41 insertions(+), 13 deletions(-)

diff --git a/tools/perf/Documentation/perf-config.txt b/tools/perf/Documentation/perf-config.txt
index 1c9027e..fb8ca74 100644
--- a/tools/perf/Documentation/perf-config.txt
+++ b/tools/perf/Documentation/perf-config.txt
@@ -13,6 +13,8 @@ or
 'perf config' -l | --list
 or
 'perf config' -a | --all
+or
+'perf config' -r | --remove [section.subkey ...]
 
 DESCRIPTION
 -----------
@@ -29,6 +31,10 @@ OPTIONS
 --all::
 	Show current and all possible config variables with default values.
 
+-r::
+--remove::
+	Remove specific config variables.
+
 CONFIGURATION FILE
 ------------------
 
diff --git a/tools/perf/builtin-config.c b/tools/perf/builtin-config.c
index a67aea3..ff49c22 100644
--- a/tools/perf/builtin-config.c
+++ b/tools/perf/builtin-config.c
@@ -18,6 +18,7 @@ static struct {
 	bool get_action;
 	bool set_action;
 	bool all_action;
+	bool remove_action;
 } params;
 
 struct list_head *sections;
@@ -31,6 +32,7 @@ static const struct option config_options[] = {
 	OPT_BOOLEAN('l', "list", &params.list_action, "show current config variables"),
 	OPT_BOOLEAN('a', "all", &params.all_action,
 		    "show current and all possible config variables with default values"),
+	OPT_BOOLEAN('r', "remove", &params.remove_action, "remove specific variables: [section.subkey ...]"),
 	OPT_END()
 };
 
@@ -150,19 +152,26 @@ static int set_config(const char *section_name, const char *subkey,
 
 	find_config(&section_node, &element_node, section_name, subkey);
 
-	/* if there isn't existent section, add a new section */
-	if (!section_node) {
-		section_node = init_config_section(section_name);
-		if (!section_node)
-			return -1;
-		list_add_tail(&section_node->list, sections);
+	if (!value) {
+		/* value == NULL means remove the variable */
+		if (section_node && element_node)
+			element_node->value = NULL;
+		else
+			pr_err("Error: Failed to find the variable.\n");
+	} else {
+		/* if there isn't existent section, add a new section */
+		if (!section_node) {
+			section_node = init_config_section(section_name);
+			if (!section_node)
+				return -1;
+			list_add_tail(&section_node->list, sections);
+		}
+		/* if nothing to replace, add a new element which contains key-value pair. */
+		if (!element_node)
+			return add_config_element(&section_node->element_head, subkey, value);
+		else
+			element_node->value = (char *)value;;
 	}
-	/* if nothing to replace, add a new element which contains key-value pair. */
-	if (!element_node)
-		return add_config_element(&section_node->element_head, subkey, value);
-	else
-		element_node->value = (char *)value;
-
 	return 0;
 }
 
@@ -367,7 +376,20 @@ int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused)
 		ret = perf_config(show_config, NULL);
 	else if (params.all_action && argc == 0)
 		ret = show_all_config();
-	else {
+	else if (params.remove_action) {
+		for (i = 0; argv[i]; i++) {
+			value = strrchr(argv[i], '=');
+			if (value == NULL || value == argv[0])
+				ret = perf_configset_with_option(set_spec_config, argv[i]);
+			else {
+				pr_err("invalid key: %s", argv[i]);
+				return -1;
+			}
+			if (ret < 0)
+				goto out;
+		}
+	} else {
+
 		pr_warning("Error: Unknown argument.\n");
 		usage_with_options(config_usage, config_options);
 	}
-- 
1.9.1

--
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