[PATCH v2 4/4] perf config: Automatically create config file if not exists when setting config

From: Taeung Song
Date: Mon May 08 2017 - 07:08:13 EST


When setting config key-value pairs,
if user or system config files are nonexistent,
currently perf-config's setting didn't work right.
So automatically create a config file on the situation.

Before:

$ rm -f ~/.perfconfig && perf config --user report.children=false

$ cat ~/.perfconfig
cat: /root/.perfconfig: No such file or directory

After:

$ rm -f ~/.perfconfig && perf config --user report.children=false

$ cat ~/.perfconfig
# this file is auto-generated.
[report]
children = false

NOTE:
Even if not free config_set after perf_config_set__init() failed,
it'll be freed at the tail end (i.e. by perf_config_set__delete()
at the end of cmd_config()).

Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Signed-off-by: Taeung Song <treeze.taeung@xxxxxxxxx>
---
tools/perf/util/config.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c
index 8d724f0..1cc5d80 100644
--- a/tools/perf/util/config.c
+++ b/tools/perf/util/config.c
@@ -691,10 +691,7 @@ struct perf_config_set *perf_config_set__new(void)

if (set) {
INIT_LIST_HEAD(&set->sections);
- if (perf_config_set__init(set) < 0) {
- perf_config_set__delete(set);
- set = NULL;
- }
+ perf_config_set__init(set);
}

return set;
--
2.7.4