perf config: Do not die when parsing u64 or int config values
tip-bot for Arnaldo Carvalho de Melo
merge botCommit-ID: 25ce4bb8c50513e922da2709fedc9db112452fbc Gitweb: http://git.kernel.org/tip/25ce4bb8c50513e922da2709fedc9db112452fbc Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Tue, 27 Jun 2017 11:44:58 -0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 27 Jun 2017 11:44:58 -0300
perf config: Do not die when parsing u64 or int config values
Just warn the user and ignore those values.
Cc Adrian Hunter <[email protected]>
Cc David Ahern <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Wang Nan <[email protected]>
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
--- tools/perf/builtin-diff.c | 5 ++++- tools/perf/builtin-report.c | 7 +++---- tools/perf/util/config.c | 34 ++++++++++++++++++++++------------ tools/perf/util/config.h | 4 ++-- tools/perf/util/data-convert-bt.c | 6 ++---- tools/perf/util/help-unknown-cmd.c | 2 +- 6 files changed, 34 insertions(+), 24 deletions(-)
tools/perf/builtin-diff.c +4 -1
@@ -1302,7 +1302,10 @@ static int diff__config(const char *var, const char *value, void *cb __maybe_unused) {if (!strcmp (var,"diff.order" )) { - sort_compute =perf_config_int (var, value); +int ret; +if (perf_config_int (&ret, var, value) <0 ) +return -1 ; + sort_compute = ret;return 0 ; }if (!strcmp (var,"diff.compute" )) {
tools/perf/builtin-report.c +3 -4
@@ -94,10 +94,9 @@ static int report__config(const char *var, const char *value, void *cb) symbol_conf.cumulate_callchain =perf_config_bool (var, value);return 0 ; } -if (!strcmp (var,"report.queue-size" )) { - rep->queue_size =perf_config_u64 (var, value); -return 0 ; - } +if (!strcmp (var,"report.queue-size" )) +return perf_config_u64 (&rep->queue_size, var, value); +if (!strcmp (var,"report.sort_order" )) { default_sort_order =strdup (value);return 0 ;
tools/perf/util/config.c +22 -12
@@ -335,32 +335,42 @@ static int perf_parse_long(const char *value, long *ret)return 0 ; } -static void die_bad_config (const char *name) +static void bad_config (const char *name) {if (config_file_name) -die ("bad config value for '%s' in %s" , name, config_file_name); -die ("bad config value for '%s'" , name); +pr_warning ("bad config value for '%s' in %s, ignoring...\n" , name, config_file_name); +else +pr_warning ("bad config value for '%s', ignoring...\n" , name); } -u64 perf_config_u64 (const char *name,const char *value) +int perf_config_u64 (u64 *dest,const char *name,const char *value) {long long ret =0 ; -if (!perf_parse_llong (value, &ret)) -die_bad_config (name); -return (u64 ) ret; +if (!perf_parse_llong (value, &ret)) { +bad_config (name); +return -1 ; + } + + *dest = ret; +return 0 ; } -int perf_config_int (const char *name,const char *value) +int perf_config_int (int *dest,const char *name,const char *value) {long ret =0 ; -if (!perf_parse_long (value, &ret)) -die_bad_config (name); -return ret; +if (!perf_parse_long (value, &ret)) { +bad_config (name); +return -1 ; + } + *dest = ret; +return 0 ; }static int perf_config_bool_or_int (const char *name,const char *value,int *is_bool) { +int ret; + *is_bool =1 ;if (!value)return 1 ;
@@ -371,7 +381,7 @@ static int perf_config_bool_or_int(const char *name, const char *value, int *is_if (!strcasecmp (value,"false" ) || !strcasecmp (value,"no" ) || !strcasecmp (value,"off" ))return 0 ; *is_bool =0 ; -return perf_config_int (name, value); +return perf_config_int (&ret, name, value) <0 ?-1 : ret; }int perf_config_bool (const char *name,const char *value)
tools/perf/util/config.h +2 -2
@@ -27,8 +27,8 @@ extern const char *config_exclusive_filename;typedef int (*config_fn_t )(const char *,const char *,void *);int perf_default_config (const char *,const char *,void *);int perf_config (config_fn_t fn,void *); -int perf_config_int (const char *,const char *); -u64 perf_config_u64 (const char *,const char *); +int perf_config_int (int *dest,const char *,const char *); +int perf_config_u64 (u64 *dest,const char *,const char *);int perf_config_bool (const char *,const char *);int config_error_nonbool (const char *);const char *perf_etc_perfconfig (void );
tools/perf/util/data-convert-bt.c +2 -4
@@ -1444,10 +1444,8 @@ static int convert__config(const char *var, const char *value, void *cb) {struct convert *c = cb; -if (!strcmp (var,"convert.queue-size" )) { - c->queue_size =perf_config_u64 (var, value); -return 0 ; - } +if (!strcmp (var,"convert.queue-size" )) +return perf_config_u64 (&c->queue_size, var, value);return 0 ; }
tools/perf/util/help-unknown-cmd.c +1 -1
@@ -12,7 +12,7 @@ static int perf_unknown_cmd_config(const char *var, const char *value, void *cb __maybe_unused) {if (!strcmp (var,"help.autocorrect" )) - autocorrect =perf_config_int (var,value); +return perf_config_int (&autocorrect, var,value);return 0 ; }