Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2097805pxb; Mon, 18 Jan 2021 08:10:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJwkuvNsPHjUtwsHQWgFyiFNFaI3eQtbSvdPapy/f20rLoJ03UfxecXJqnIDWz+8/Lsytkhm X-Received: by 2002:a50:b944:: with SMTP id m62mr167056ede.182.1610986250180; Mon, 18 Jan 2021 08:10:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610986250; cv=none; d=google.com; s=arc-20160816; b=wISTaGbHZfOiYEP6HRqcxCo/xiwb8gS/pzUBhklnUioH1TvLHJ7Fb7Oj13bAHxhX7f 0f8AjiC/aun7T7Peg5FHNp5BEWS+f5j0lursnXyj8FoxKCvf8ZTRjkq0Mznjx86zGYor kHbT+w5YzfSihyP399TgWV0K2fKwjs5+eP2EGJLrRJEG7Nuqzbr90xrdtLnHrgosHTBO bk4M2ZwQirUuoxyPTAMJiIfsoVnTiL0lQyA6ZyLzE7dT9PvNpLUWHvtK5vWscggMydF/ +BxeY2+1eRfsTknmsRgkm4pJoU/LIBP1EV34QNlhGEsE5qX7eRzvatn7lbiJrhayvvpU 97MQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=FkI2cz38HKyrrokH9OEJNkHav8AjS0k9f+QcbNxnv7Y=; b=ootHZhk63+jFidMuBF/DHEUKgT3F/TE/AERH+gkl34vfQx7c4PLPVI5ObdStWKTgRx UlpLuOO2O6adp/YAkU/TjwsUCRBP7X5Tfj9u2fJPZJGwyH0954OZXsnbMsU0CuVVLL2d 3w69T+wtLsut9Y+MNWIDCgJpMJNMpwFAcJ8XYkg+BdGAlyT/q7fGbKfMHiyXHqIGi/qu HsaF1D59a5PwRWYyyxysnOCmzOZe/C+WE1Tc8cdslmvrv7Ctqpj7+CNueWj0Z/RojpYi /fWmg6KVw54EPRsGZR3HmrSBWjm388Y0AhmqJdAtAkjyRWssXEY0ey7sBpvfnPRMdSE+ xsrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VsdIePPE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dm28si356122edb.528.2021.01.18.08.10.27; Mon, 18 Jan 2021 08:10:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VsdIePPE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406422AbhARQGo (ORCPT + 99 others); Mon, 18 Jan 2021 11:06:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:35500 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406314AbhARQFv (ORCPT ); Mon, 18 Jan 2021 11:05:51 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 339B820E65; Mon, 18 Jan 2021 16:05:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1610985910; bh=RaFc/KU/UqPArIcxvNLD5/A8Ei7pqUtAnaVAu+7Z3pk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=VsdIePPEC7Xzr8TIb+V9aZi3eNY1JaPPNf8M61pMNwO6qyIi9VT8TiKewTuMGRz7v VI+g1BW9W5uIhBrF0ikaWhw5xdKMfSHZYr+cgZb2nzLg53JqpCgBdNnVHnGMJXVNXe g9QYlmhTIZ+69p1BsB4VPKqx6rpMY1w9JZ4MTb+8/W17ig0OtymuTwi2cOfRwO3gO2 C2smGToBbbWfeRCjPX1eWRTF4u6KleYS7yFlCfB+FZFnrFknKbb6zVnpGvaUI1PflR 1ELFLTHLlBs7sK61Pw8u3yjwKIZ2qyfIoWNb/N7p0HscmNr9Hjej+xbxoB5uAihmc3 nv+UgXhIHG9Aw== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 433B040CE2; Mon, 18 Jan 2021 13:05:08 -0300 (-03) Date: Mon, 18 Jan 2021 13:05:08 -0300 From: Arnaldo Carvalho de Melo To: Jiri Olsa Cc: lkml , Peter Zijlstra , Ingo Molnar , Mark Rutland , Namhyung Kim , Alexander Shishkin , Michael Petlan , Ian Rogers , Stephane Eranian , Alexei Budankov Subject: Re: [PATCH 04/22] perf tools: Add perf_home_perfconfig function Message-ID: <20210118160508.GE12699@kernel.org> References: <20210102220441.794923-1-jolsa@kernel.org> <20210102220441.794923-5-jolsa@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210102220441.794923-5-jolsa@kernel.org> X-Url: http://acmel.wordpress.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Sat, Jan 02, 2021 at 11:04:23PM +0100, Jiri Olsa escreveu: > Factor out the perf_home_perfconfig, that looks for > .perfconfig in home directory including check for > PERF_CONFIG_NOGLOBAL and for proper permission. Thanks, applied. - Arnaldo > Signed-off-by: Jiri Olsa > --- > tools/perf/util/config.c | 89 ++++++++++++++++++++++++---------------- > tools/perf/util/config.h | 1 + > 2 files changed, 54 insertions(+), 36 deletions(-) > > diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c > index 222cb2e2de25..34fe80ccdad1 100644 > --- a/tools/perf/util/config.c > +++ b/tools/perf/util/config.c > @@ -531,6 +531,56 @@ static int perf_config_global(void) > return !perf_env_bool("PERF_CONFIG_NOGLOBAL", 0); > } > > +static char *home_perfconfig(void) > +{ > + const char *home = NULL; > + char *config; > + struct stat st; > + > + home = getenv("HOME"); > + > + /* > + * Skip reading user config if: > + * - there is no place to read it from (HOME) > + * - we are asked not to (PERF_CONFIG_NOGLOBAL=1) > + */ > + if (!home || !*home || !perf_config_global()) > + return NULL; > + > + config = strdup(mkpath("%s/.perfconfig", home)); > + if (config == NULL) { > + pr_warning("Not enough memory to process %s/.perfconfig, ignoring it.", home); > + return NULL; > + } > + > + if (stat(config, &st) < 0) > + goto out_free; > + > + if (st.st_uid && (st.st_uid != geteuid())) { > + pr_warning("File %s not owned by current user or root, ignoring it.", config); > + goto out_free; > + } > + > + if (st.st_size) > + return config; > + > +out_free: > + free(config); > + return NULL; > +} > + > +const char *perf_home_perfconfig(void) > +{ > + static const char *config; > + static bool failed; > + > + config = failed ? NULL : home_perfconfig(); > + if (!config) > + failed = true; > + > + return config; > +} > + > static struct perf_config_section *find_section(struct list_head *sections, > const char *section_name) > { > @@ -676,9 +726,6 @@ int perf_config_set__collect(struct perf_config_set *set, const char *file_name, > static int perf_config_set__init(struct perf_config_set *set) > { > int ret = -1; > - const char *home = NULL; > - char *user_config; > - struct stat st; > > /* Setting $PERF_CONFIG makes perf read _only_ the given config file. */ > if (config_exclusive_filename) > @@ -687,41 +734,11 @@ static int perf_config_set__init(struct perf_config_set *set) > if (perf_config_from_file(collect_config, perf_etc_perfconfig(), set) < 0) > goto out; > } > - > - home = getenv("HOME"); > - > - /* > - * Skip reading user config if: > - * - there is no place to read it from (HOME) > - * - we are asked not to (PERF_CONFIG_NOGLOBAL=1) > - */ > - if (!home || !*home || !perf_config_global()) > - return 0; > - > - user_config = strdup(mkpath("%s/.perfconfig", home)); > - if (user_config == NULL) { > - pr_warning("Not enough memory to process %s/.perfconfig, ignoring it.", home); > - goto out; > - } > - > - if (stat(user_config, &st) < 0) { > - if (errno == ENOENT) > - ret = 0; > - goto out_free; > - } > - > - ret = 0; > - > - if (st.st_uid && (st.st_uid != geteuid())) { > - pr_warning("File %s not owned by current user or root, ignoring it.", user_config); > - goto out_free; > + if (perf_config_global() && perf_home_perfconfig()) { > + if (perf_config_from_file(collect_config, perf_home_perfconfig(), set) < 0) > + goto out; > } > > - if (st.st_size) > - ret = perf_config_from_file(collect_config, user_config, set); > - > -out_free: > - free(user_config); > out: > return ret; > } > diff --git a/tools/perf/util/config.h b/tools/perf/util/config.h > index ee5a242446e9..d6c4f80f367c 100644 > --- a/tools/perf/util/config.h > +++ b/tools/perf/util/config.h > @@ -37,6 +37,7 @@ int perf_config_u64(u64 *dest, const char *, const char *); > int perf_config_bool(const char *, const char *); > int config_error_nonbool(const char *); > const char *perf_etc_perfconfig(void); > +const char *perf_home_perfconfig(void); > > struct perf_config_set *perf_config_set__new(void); > struct perf_config_set *perf_config_set__load_file(const char *file); > -- > 2.26.2 > -- - Arnaldo