Commit 4341ec6b authored by Taeung Song's avatar Taeung Song Committed by Arnaldo Carvalho de Melo

perf config: Refactor a duplicated code for obtaining config file name

We were doing the same sequence to figure out what is the config
pathname to use, fix it by doing it before those two uses.
Signed-off-by: default avatarTaeung Song <treeze.taeung@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/1493209268-5543-2-git-send-email-treeze.taeung@gmail.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent d8040645
...@@ -159,6 +159,7 @@ int cmd_config(int argc, const char **argv) ...@@ -159,6 +159,7 @@ int cmd_config(int argc, const char **argv)
int i, ret = 0; int i, ret = 0;
struct perf_config_set *set; struct perf_config_set *set;
char *user_config = mkpath("%s/.perfconfig", getenv("HOME")); char *user_config = mkpath("%s/.perfconfig", getenv("HOME"));
const char *config_filename;
argc = parse_options(argc, argv, config_options, config_usage, argc = parse_options(argc, argv, config_options, config_usage,
PARSE_OPT_STOP_AT_NON_OPTION); PARSE_OPT_STOP_AT_NON_OPTION);
...@@ -175,6 +176,11 @@ int cmd_config(int argc, const char **argv) ...@@ -175,6 +176,11 @@ int cmd_config(int argc, const char **argv)
else if (use_user_config) else if (use_user_config)
config_exclusive_filename = user_config; config_exclusive_filename = user_config;
if (!config_exclusive_filename)
config_filename = user_config;
else
config_filename = config_exclusive_filename;
/* /*
* At only 'config' sub-command, individually use the config set * At only 'config' sub-command, individually use the config set
* because of reinitializing with options config file location. * because of reinitializing with options config file location.
...@@ -192,13 +198,9 @@ int cmd_config(int argc, const char **argv) ...@@ -192,13 +198,9 @@ int cmd_config(int argc, const char **argv)
parse_options_usage(config_usage, config_options, "l", 1); parse_options_usage(config_usage, config_options, "l", 1);
} else { } else {
ret = show_config(set); ret = show_config(set);
if (ret < 0) { if (ret < 0)
const char * config_filename = config_exclusive_filename;
if (!config_exclusive_filename)
config_filename = user_config;
pr_err("Nothing configured, " pr_err("Nothing configured, "
"please check your %s \n", config_filename); "please check your %s \n", config_filename);
}
} }
break; break;
default: default:
...@@ -221,13 +223,8 @@ int cmd_config(int argc, const char **argv) ...@@ -221,13 +223,8 @@ int cmd_config(int argc, const char **argv)
if (value == NULL) if (value == NULL)
ret = show_spec_config(set, var); ret = show_spec_config(set, var);
else { else
const char *config_filename = config_exclusive_filename;
if (!config_exclusive_filename)
config_filename = user_config;
ret = set_config(set, config_filename, var, value); ret = set_config(set, config_filename, var, value);
}
free(arg); free(arg);
} }
} else } else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment