Skip to content

Commit 8beeb00

Browse files
Taeungacmel
authored andcommitted
perf config: Use new perf_config_set__init() to initialize config set
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 <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 25d8f48 commit 8beeb00

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

tools/perf/util/config.c

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,13 +646,58 @@ static int collect_config(const char *var, const char *value,
646646
return -1;
647647
}
648648

649+
static int perf_config_set__init(struct perf_config_set *set)
650+
{
651+
int ret = -1;
652+
const char *home = NULL;
653+
654+
/* Setting $PERF_CONFIG makes perf read _only_ the given config file. */
655+
if (config_exclusive_filename)
656+
return perf_config_from_file(collect_config, config_exclusive_filename, set);
657+
if (perf_config_system() && !access(perf_etc_perfconfig(), R_OK)) {
658+
if (perf_config_from_file(collect_config, perf_etc_perfconfig(), set) < 0)
659+
goto out;
660+
}
661+
662+
home = getenv("HOME");
663+
if (perf_config_global() && home) {
664+
char *user_config = strdup(mkpath("%s/.perfconfig", home));
665+
struct stat st;
666+
667+
if (user_config == NULL) {
668+
warning("Not enough memory to process %s/.perfconfig, "
669+
"ignoring it.", home);
670+
goto out;
671+
}
672+
673+
if (stat(user_config, &st) < 0)
674+
goto out_free;
675+
676+
if (st.st_uid && (st.st_uid != geteuid())) {
677+
warning("File %s not owned by current user or root, "
678+
"ignoring it.", user_config);
679+
goto out_free;
680+
}
681+
682+
if (!st.st_size)
683+
goto out_free;
684+
685+
ret = perf_config_from_file(collect_config, user_config, set);
686+
687+
out_free:
688+
free(user_config);
689+
}
690+
out:
691+
return ret;
692+
}
693+
649694
struct perf_config_set *perf_config_set__new(void)
650695
{
651696
struct perf_config_set *set = zalloc(sizeof(*set));
652697

653698
if (set) {
654699
INIT_LIST_HEAD(&set->sections);
655-
if (perf_config(collect_config, set) < 0) {
700+
if (perf_config_set__init(set) < 0) {
656701
perf_config_set__delete(set);
657702
set = NULL;
658703
}

0 commit comments

Comments
 (0)