Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1414888 > unrolled thread

[BUGFIX][PATCH v6 1/9] perf config: Fix the problem of abnormal termination at perf_parse_file()

Started byTaeung Song <treeze.taeung@gmail.com>
First post2016-06-06 13:00 +0200
Last post2016-06-08 10:50 +0200
Articles 3 — 3 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [BUGFIX][PATCH v6 1/9] perf config: Fix the problem of abnormal termination at perf_parse_file() Taeung Song <treeze.taeung@gmail.com> - 2016-06-06 13:00 +0200
    Re: [BUGFIX][PATCH v6 1/9] perf config: Fix the problem of abnormal  termination at perf_parse_file() Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-06 22:30 +0200
    [tip:perf/core] perf config: Fix abnormal termination at  perf_parse_file() tip-bot for Taeung Song <tipbot@zytor.com> - 2016-06-08 10:50 +0200

#1414888 — [BUGFIX][PATCH v6 1/9] perf config: Fix the problem of abnormal termination at perf_parse_file()

FromTaeung Song <treeze.taeung@gmail.com>
Date2016-06-06 13:00 +0200
Subject[BUGFIX][PATCH v6 1/9] perf config: Fix the problem of abnormal termination at perf_parse_file()
Message-ID<rH0qe-3MT-15@gated-at.bofh.it>
If a config file has wrong key-value pairs, perf process
will be forcibly terminated by die() at perf_parse_file()
called by perf_config() so terminal setting can be crushed
because of unusual termination.

For example,

If user config file has a wrong value 'red;default'
instead of a normal value like 'red, default' for a key 'colors.top',

    # cat ~/.perfconfig
    [colors]
        medium = red;default # wrong value

and if running sub-command 'top',

    # perf top

perf process is dead by force and terminal setting is broken
with a messge like below.

    Fatal: bad config file line 2 in /root/.perfconfig

So fix it.
If perf_config() can return on failure without calling die()
at perf_parse_file(), this problem can be solved.
And if a config file has wrong values, show the error message
and then use default config values instead of wrong config values.

Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
---
 tools/perf/util/config.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c
index dad7d82..b500737 100644
--- a/tools/perf/util/config.c
+++ b/tools/perf/util/config.c
@@ -275,7 +275,8 @@ static int perf_parse_file(config_fn_t fn, void *data)
 			break;
 		}
 	}
-	die("bad config file line %d in %s", config_linenr, config_file_name);
+	pr_err("bad config file line %d in %s\n", config_linenr, config_file_name);
+	return -1;
 }
 
 static int parse_unit_factor(const char *end, unsigned long *val)
@@ -479,16 +480,15 @@ static int perf_config_global(void)
 
 int perf_config(config_fn_t fn, void *data)
 {
-	int ret = 0, found = 0;
+	int ret = -1;
 	const char *home = NULL;
 
 	/* Setting $PERF_CONFIG makes perf read _only_ the given config file. */
 	if (config_exclusive_filename)
 		return perf_config_from_file(fn, config_exclusive_filename, data);
 	if (perf_config_system() && !access(perf_etc_perfconfig(), R_OK)) {
-		ret += perf_config_from_file(fn, perf_etc_perfconfig(),
-					    data);
-		found += 1;
+		if (perf_config_from_file(fn, perf_etc_perfconfig(), data) < 0)
+			goto out;
 	}
 
 	home = getenv("HOME");
@@ -514,14 +514,12 @@ int perf_config(config_fn_t fn, void *data)
 		if (!st.st_size)
 			goto out_free;
 
-		ret += perf_config_from_file(fn, user_config, data);
-		found += 1;
+		ret = perf_config_from_file(fn, user_config, data);
+
 out_free:
 		free(user_config);
 	}
 out:
-	if (found == 0)
-		return -1;
 	return ret;
 }
 
-- 
2.5.0

[toc] | [next] | [standalone]


#1415422 — Re: [BUGFIX][PATCH v6 1/9] perf config: Fix the problem of abnormal termination at perf_parse_file()

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2016-06-06 22:30 +0200
SubjectRe: [BUGFIX][PATCH v6 1/9] perf config: Fix the problem of abnormal termination at perf_parse_file()
Message-ID<rH9jP-1cX-21@gated-at.bofh.it>
In reply to#1414888
Em Mon, Jun 06, 2016 at 07:52:52PM +0900, Taeung Song escreveu:
> For example,
> 
> If user config file has a wrong value 'red;default'
> instead of a normal value like 'red, default' for a key 'colors.top',
> 
>     # cat ~/.perfconfig
>     [colors]
>         medium = red;default # wrong value
> 
> and if running sub-command 'top',
> 
>     # perf top
> 
> perf process is dead by force and terminal setting is broken
> with a messge like below.
> 
>     Fatal: bad config file line 2 in /root/.perfconfig

Thanks, reproduced, tested, applied.

- Arnaldo

[toc] | [prev] | [next] | [standalone]


#1417085 — [tip:perf/core] perf config: Fix abnormal termination at perf_parse_file()

Fromtip-bot for Taeung Song <tipbot@zytor.com>
Date2016-06-08 10:50 +0200
Subject[tip:perf/core] perf config: Fix abnormal termination at perf_parse_file()
Message-ID<rHHlw-6ig-41@gated-at.bofh.it>
In reply to#1414888
Commit-ID:  78f71c996fb92d129ec75d572e2f5367a4f4c757
Gitweb:     http://git.kernel.org/tip/78f71c996fb92d129ec75d572e2f5367a4f4c757
Author:     Taeung Song <treeze.taeung@gmail.com>
AuthorDate: Mon, 6 Jun 2016 19:52:52 +0900
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Mon, 6 Jun 2016 17:43:17 -0300

perf config: Fix abnormal termination at perf_parse_file()

If a config file has wrong key-value pairs, the perf process will be
forcibly terminated by die() at perf_parse_file() called by
perf_config() so terminal settings can be crushed because of unusual
termination.

For example:

If user config file has a wrong value 'red;default' instead of a normal
value like 'red, default' for a key 'colors.top',

    # cat ~/.perfconfig
    [colors]
        medium = red;default # wrong value

and if running sub-command 'top',

    # perf top

perf process is dead by force and terminal setting is broken
with a messge like below.

    Fatal: bad config file line 2 in /root/.perfconfig

So fix it.
If perf_config() can return on failure without calling die()
at perf_parse_file(), this problem can be solved.
And if a config file has wrong values, show the error message
and then use default config values instead of wrong config values.

Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1465210380-26749-2-git-send-email-treeze.taeung@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/config.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c
index dad7d82..b500737 100644
--- a/tools/perf/util/config.c
+++ b/tools/perf/util/config.c
@@ -275,7 +275,8 @@ static int perf_parse_file(config_fn_t fn, void *data)
 			break;
 		}
 	}
-	die("bad config file line %d in %s", config_linenr, config_file_name);
+	pr_err("bad config file line %d in %s\n", config_linenr, config_file_name);
+	return -1;
 }
 
 static int parse_unit_factor(const char *end, unsigned long *val)
@@ -479,16 +480,15 @@ static int perf_config_global(void)
 
 int perf_config(config_fn_t fn, void *data)
 {
-	int ret = 0, found = 0;
+	int ret = -1;
 	const char *home = NULL;
 
 	/* Setting $PERF_CONFIG makes perf read _only_ the given config file. */
 	if (config_exclusive_filename)
 		return perf_config_from_file(fn, config_exclusive_filename, data);
 	if (perf_config_system() && !access(perf_etc_perfconfig(), R_OK)) {
-		ret += perf_config_from_file(fn, perf_etc_perfconfig(),
-					    data);
-		found += 1;
+		if (perf_config_from_file(fn, perf_etc_perfconfig(), data) < 0)
+			goto out;
 	}
 
 	home = getenv("HOME");
@@ -514,14 +514,12 @@ int perf_config(config_fn_t fn, void *data)
 		if (!st.st_size)
 			goto out_free;
 
-		ret += perf_config_from_file(fn, user_config, data);
-		found += 1;
+		ret = perf_config_from_file(fn, user_config, data);
+
 out_free:
 		free(user_config);
 	}
 out:
-	if (found == 0)
-		return -1;
 	return ret;
 }
 

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web