Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1416569

[PATCH 10/24] perf config: Use new perf_config_set__init() to initialize config set

From Arnaldo Carvalho de Melo <acme@kernel.org>
Newsgroups linux.kernel
Subject [PATCH 10/24] perf config: Use new perf_config_set__init() to initialize config set
Date 2016-06-07 22:20 +0200
Message-ID <rHvDI-7fg-13@gated-at.bofh.it> (permalink)
References <rHvu1-7bR-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Taeung Song <treeze.taeung@gmail.com>

Instead of perf_config(), this function initializes config set by
reading various files: user config ~/.perfconfig and system config
$(sysconfdir)/perfconfig).

If there are the same config variable in both user and system config
files, user config has higher priority than system config.

Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lkml.kernel.org/r/1465291577-20973-3-git-send-email-treeze.taeung@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/config.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c
index e086f593a2aa..8749eca3055f 100644
--- a/tools/perf/util/config.c
+++ b/tools/perf/util/config.c
@@ -646,13 +646,58 @@ out_free:
 	return -1;
 }
 
+static int perf_config_set__init(struct perf_config_set *set)
+{
+	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(collect_config, config_exclusive_filename, set);
+	if (perf_config_system() && !access(perf_etc_perfconfig(), R_OK)) {
+		if (perf_config_from_file(collect_config, perf_etc_perfconfig(), set) < 0)
+			goto out;
+	}
+
+	home = getenv("HOME");
+	if (perf_config_global() && home) {
+		char *user_config = strdup(mkpath("%s/.perfconfig", home));
+		struct stat st;
+
+		if (user_config == NULL) {
+			warning("Not enough memory to process %s/.perfconfig, "
+				"ignoring it.", home);
+			goto out;
+		}
+
+		if (stat(user_config, &st) < 0)
+			goto out_free;
+
+		if (st.st_uid && (st.st_uid != geteuid())) {
+			warning("File %s not owned by current user or root, "
+				"ignoring it.", user_config);
+			goto out_free;
+		}
+
+		if (!st.st_size)
+			goto out_free;
+
+		ret = perf_config_from_file(collect_config, user_config, set);
+
+out_free:
+		free(user_config);
+	}
+out:
+	return ret;
+}
+
 struct perf_config_set *perf_config_set__new(void)
 {
 	struct perf_config_set *set = zalloc(sizeof(*set));
 
 	if (set) {
 		INIT_LIST_HEAD(&set->sections);
-		if (perf_config(collect_config, set) < 0) {
+		if (perf_config_set__init(set) < 0) {
 			perf_config_set__delete(set);
 			set = NULL;
 		}
-- 
2.5.5

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[GIT PULL 00/24] perf/core improvements and fixes Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-07 22:10 +0200
  [PATCH 08/24] perf tools: Fix crash in build_id_cache__kallsyms_path() Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-07 22:10 +0200
  [PATCH 02/24] tools lib bpf: Rename bpf_map__get_name() to bpf_map__name() Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-07 22:10 +0200
  [PATCH 20/24] perf unwind: Check the target platform before assigning unwind methods Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-07 22:10 +0200
  [PATCH 17/24] perf unwind: Rename unwind-libunwind.c to unwind-libunwind-local.c Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-07 22:10 +0200
  [PATCH 19/24] perf tools: Export normalize_arch() function Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-07 22:20 +0200
  [PATCH 22/24] perf unwind: Introduce flag to separate local/remote unwind compilation Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-07 22:20 +0200
  [PATCH 10/24] perf config: Use new perf_config_set__init() to initialize config set Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-07 22:20 +0200
  [PATCH 06/24] tools lib bpf: Make bpf_program__get_private() use IS_ERR() Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-07 22:20 +0200
  [PATCH 09/24] perf config: Constructor should free its allocated memory when failing Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-07 22:20 +0200
  [PATCH 15/24] perf unwind: Don't mix LIBUNWIND_LIBS into LIBUNWIND_LDFLAGS Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-07 22:20 +0200
  [PATCH 11/24] perf unwind: Use LIBUNWIND_DIR for remote libunwind feature check Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-07 22:20 +0200
  [PATCH 12/24] perf unwind: Decouple thread->address_space on libunwind Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-07 22:20 +0200
  [PATCH 13/24] perf unwind: Introduce 'struct unwind_libunwind_ops' for local unwind Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-07 22:20 +0200
  [PATCH 01/24] tools lib bpf: Use IS_ERR() reporting macros with bpf_map__get_private() Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-07 22:20 +0200
  Re: [GIT PULL 00/24] perf/core improvements and fixes Taeung Song <treeze.taeung@gmail.com> - 2016-06-08 01:20 +0200
    Re: [GIT PULL 00/24] perf/core improvements and fixes Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-08 15:20 +0200
  Re: [GIT PULL 00/24] perf/core improvements and fixes Ingo Molnar <mingo@kernel.org> - 2016-06-08 09:50 +0200

csiph-web