From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1423078AbcFHIlV (ORCPT ); Wed, 8 Jun 2016 04:41:21 -0400 Received: from terminus.zytor.com ([198.137.202.10]:53862 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161213AbcFHIlQ (ORCPT ); Wed, 8 Jun 2016 04:41:16 -0400 Date: Wed, 8 Jun 2016 01:40:38 -0700 From: tip-bot for Taeung Song Message-ID: Cc: acme@redhat.com, linux-kernel@vger.kernel.org, hpa@zytor.com, mhiramat@kernel.org, treeze.taeung@gmail.com, jolsa@kernel.org, mingo@kernel.org, namhyung@kernel.org, peterz@infradead.org, tglx@linutronix.de, alexander.shishkin@linux.intel.com Reply-To: namhyung@kernel.org, alexander.shishkin@linux.intel.com, tglx@linutronix.de, peterz@infradead.org, hpa@zytor.com, mhiramat@kernel.org, acme@redhat.com, linux-kernel@vger.kernel.org, treeze.taeung@gmail.com, jolsa@kernel.org, mingo@kernel.org In-Reply-To: <1465210380-26749-2-git-send-email-treeze.taeung@gmail.com> References: <1465210380-26749-2-git-send-email-treeze.taeung@gmail.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf config: Fix abnormal termination at perf_parse_file() Git-Commit-ID: 78f71c996fb92d129ec75d572e2f5367a4f4c757 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 78f71c996fb92d129ec75d572e2f5367a4f4c757 Gitweb: http://git.kernel.org/tip/78f71c996fb92d129ec75d572e2f5367a4f4c757 Author: Taeung Song AuthorDate: Mon, 6 Jun 2016 19:52:52 +0900 Committer: Arnaldo Carvalho de Melo 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 Tested-by: Arnaldo Carvalho de Melo Cc: Alexander Shishkin Cc: Jiri Olsa Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1465210380-26749-2-git-send-email-treeze.taeung@gmail.com Signed-off-by: Arnaldo Carvalho de Melo --- 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; }