All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org,
	Taeung Song <treeze.taeung@gmail.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 10/11] perf config: Fix abnormal termination at perf_parse_file()
Date: Mon,  6 Jun 2016 18:04:42 -0300	[thread overview]
Message-ID: <1465247083-4763-11-git-send-email-acme@kernel.org> (raw)
In-Reply-To: <1465247083-4763-1-git-send-email-acme@kernel.org>

From: Taeung Song <treeze.taeung@gmail.com>

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 dad7d8272168..b50073741b80 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.5

  parent reply	other threads:[~2016-06-06 21:04 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-06 21:04 [GIT PULL 00/11] perf/core improvements and fixes Arnaldo Carvalho de Melo
2016-06-06 21:04 ` [PATCH 01/11] perf evsel: Provide way to extract integer value from format_field Arnaldo Carvalho de Melo
2016-06-06 21:04 ` [PATCH 02/11] perf evlist: Fix alloc_mmap() failure path Arnaldo Carvalho de Melo
2016-06-06 21:04 ` [PATCH 03/11] tools lib api: Respect CROSS_COMPILE for the linker Arnaldo Carvalho de Melo
2016-06-06 21:04 ` [PATCH 04/11] perf script: Show call graphs when 1st event doesn't have it but some other has Arnaldo Carvalho de Melo
2016-06-06 21:04 ` [PATCH 05/11] perf test: Ignore .scale and other special files Arnaldo Carvalho de Melo
2016-06-06 21:04 ` [PATCH 06/11] perf stat: Basic support for TopDown in perf stat Arnaldo Carvalho de Melo
2016-06-06 21:04 ` [PATCH 07/11] perf stat: Add computation of TopDown formulas Arnaldo Carvalho de Melo
2016-06-06 21:04 ` [PATCH 08/11] perf stat: Print topology/time headers with --metric-only Arnaldo Carvalho de Melo
2016-06-06 21:04 ` [PATCH 09/11] perf stat: Add missing aggregation headers for --metric-only CSV Arnaldo Carvalho de Melo
2016-06-06 21:04 ` Arnaldo Carvalho de Melo [this message]
2016-06-06 21:04 ` [PATCH 11/11] perf config: Handle the error when config set is NULL at collect_config() Arnaldo Carvalho de Melo
2016-06-08  7:32 ` [GIT PULL 00/11] perf/core improvements and fixes Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1465247083-4763-11-git-send-email-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=treeze.taeung@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.