perf config: Do not die when parsing u64 or int config values

Just warn the user and ignore those values.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-tbf60nj3ierm6hrkhpothymx@git.kernel.orgSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
上级 62d94b00
...@@ -1302,7 +1302,10 @@ static int diff__config(const char *var, const char *value, ...@@ -1302,7 +1302,10 @@ static int diff__config(const char *var, const char *value,
void *cb __maybe_unused) void *cb __maybe_unused)
{ {
if (!strcmp(var, "diff.order")) { 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; return 0;
} }
if (!strcmp(var, "diff.compute")) { if (!strcmp(var, "diff.compute")) {
......
...@@ -94,10 +94,9 @@ static int report__config(const char *var, const char *value, void *cb) ...@@ -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); symbol_conf.cumulate_callchain = perf_config_bool(var, value);
return 0; return 0;
} }
if (!strcmp(var, "report.queue-size")) { if (!strcmp(var, "report.queue-size"))
rep->queue_size = perf_config_u64(var, value); return perf_config_u64(&rep->queue_size, var, value);
return 0;
}
if (!strcmp(var, "report.sort_order")) { if (!strcmp(var, "report.sort_order")) {
default_sort_order = strdup(value); default_sort_order = strdup(value);
return 0; return 0;
......
...@@ -335,32 +335,42 @@ static int perf_parse_long(const char *value, long *ret) ...@@ -335,32 +335,42 @@ static int perf_parse_long(const char *value, long *ret)
return 0; return 0;
} }
static void die_bad_config(const char *name) static void bad_config(const char *name)
{ {
if (config_file_name) if (config_file_name)
die("bad config value for '%s' in %s", name, config_file_name); pr_warning("bad config value for '%s' in %s, ignoring...\n", name, config_file_name);
die("bad config value for '%s'", 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; long long ret = 0;
if (!perf_parse_llong(value, &ret)) if (!perf_parse_llong(value, &ret)) {
die_bad_config(name); bad_config(name);
return (u64) ret; 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; long ret = 0;
if (!perf_parse_long(value, &ret)) if (!perf_parse_long(value, &ret)) {
die_bad_config(name); bad_config(name);
return ret; return -1;
}
*dest = ret;
return 0;
} }
static int perf_config_bool_or_int(const char *name, const char *value, int *is_bool) static int perf_config_bool_or_int(const char *name, const char *value, int *is_bool)
{ {
int ret;
*is_bool = 1; *is_bool = 1;
if (!value) if (!value)
return 1; return 1;
...@@ -371,7 +381,7 @@ static int perf_config_bool_or_int(const char *name, const char *value, int *is_ ...@@ -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")) if (!strcasecmp(value, "false") || !strcasecmp(value, "no") || !strcasecmp(value, "off"))
return 0; return 0;
*is_bool = 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) int perf_config_bool(const char *name, const char *value)
......
...@@ -27,8 +27,8 @@ extern const char *config_exclusive_filename; ...@@ -27,8 +27,8 @@ extern const char *config_exclusive_filename;
typedef int (*config_fn_t)(const char *, const char *, void *); typedef int (*config_fn_t)(const char *, const char *, void *);
int perf_default_config(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(config_fn_t fn, void *);
int perf_config_int(const char *, const char *); int perf_config_int(int *dest, const char *, const char *);
u64 perf_config_u64(const char *, const char *); int perf_config_u64(u64 *dest, const char *, const char *);
int perf_config_bool(const char *, const char *); int perf_config_bool(const char *, const char *);
int config_error_nonbool(const char *); int config_error_nonbool(const char *);
const char *perf_etc_perfconfig(void); const char *perf_etc_perfconfig(void);
......
...@@ -1444,10 +1444,8 @@ static int convert__config(const char *var, const char *value, void *cb) ...@@ -1444,10 +1444,8 @@ static int convert__config(const char *var, const char *value, void *cb)
{ {
struct convert *c = cb; struct convert *c = cb;
if (!strcmp(var, "convert.queue-size")) { if (!strcmp(var, "convert.queue-size"))
c->queue_size = perf_config_u64(var, value); return perf_config_u64(&c->queue_size, var, value);
return 0;
}
return 0; return 0;
} }
......
...@@ -12,7 +12,7 @@ static int perf_unknown_cmd_config(const char *var, const char *value, ...@@ -12,7 +12,7 @@ static int perf_unknown_cmd_config(const char *var, const char *value,
void *cb __maybe_unused) void *cb __maybe_unused)
{ {
if (!strcmp(var, "help.autocorrect")) if (!strcmp(var, "help.autocorrect"))
autocorrect = perf_config_int(var,value); return perf_config_int(&autocorrect, var,value);
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册