@@ -646,13 +646,58 @@ static int collect_config(const char *var, const char *value,
646
646
return -1 ;
647
647
}
648
648
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
+
649
694
struct perf_config_set * perf_config_set__new (void )
650
695
{
651
696
struct perf_config_set * set = zalloc (sizeof (* set ));
652
697
653
698
if (set ) {
654
699
INIT_LIST_HEAD (& set -> sections );
655
- if (perf_config ( collect_config , set ) < 0 ) {
700
+ if (perf_config_set__init ( set ) < 0 ) {
656
701
perf_config_set__delete (set );
657
702
set = NULL ;
658
703
}
0 commit comments