From patchwork Tue Apr 18 00:12:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Smythies X-Patchwork-Id: 9684757 X-Patchwork-Delegate: rjw@sisk.pl Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EBD60602C2 for ; Tue, 18 Apr 2017 00:12:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD5E32097A for ; Tue, 18 Apr 2017 00:12:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D0A7D25404; Tue, 18 Apr 2017 00:12:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 76BD72097A for ; Tue, 18 Apr 2017 00:12:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753961AbdDRAM1 (ORCPT ); Mon, 17 Apr 2017 20:12:27 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:33539 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753649AbdDRAM0 (ORCPT ); Mon, 17 Apr 2017 20:12:26 -0400 Received: by mail-pf0-f195.google.com with SMTP id c198so27625176pfc.0; Mon, 17 Apr 2017 17:12:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=S5msDQi/l/485CBoilB4s/u7HIZjHuy2nFXOj+U7R8c=; b=mtrrpOfTffN3fEjGQiP5YgNZYYLa6jaNs3LmEl+2ua76gJaEm/emEulpbmRoXYIKXG nDl2/Hrl2LoGMx5/zw/FMYNTHfbufavosXF379CYA6i1wTdsi5cdub6A0xoe9z16zaFA uNV2r9zHN/bJQF5jBfj7bACJf8uHq0Y8NcV99e3+8ryuTfsbnCMxTY4fUmNNNCK1MBPB ukPhO+rlaWu13OqSrkb0lBkIMCFnWpt0NqAk7MYsvMsswCgKgI6jqjNFyiItUa+q8Y2G NG2rMs2FIa+qaG5g9f2yyrDx5bekNUpYR5P4g6PJs+y/3Nlfd4lvv2nz8i4+336cg8rI 4q2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=S5msDQi/l/485CBoilB4s/u7HIZjHuy2nFXOj+U7R8c=; b=d36UjnXhslIZ3CAGpoDrGCgQCFCz4QvlhDCE20miVEudFk1pPJaDrZ3GeMFAHUMR/t Wj8SlTVl5L/zkyPlFfxeqEY/S/v1PX+doGWtONrgMEVifQ9NyiftjS454IOCqxeP0geG zZQj+Gp1JtGEwlQiRLhgn4ntUsO+SIHl5QyEz7ufvhsS9N0aevcWsyWC0a5JbdAlivPv 0vIzdFlLaLpegKKNxADjKvyhoHyPNyvKWxFO93arsRO3v4XYYnl52OM0ZgcclqS84n9U cY2iK3DMVyyqjzz86EILUER3uLwTzWSC5RzMjHCz8iNEFcX8oCWVt/kYD4bREyI4cgxc R9fg== X-Gm-Message-State: AN3rC/4mTNhDH8+LoBgvgE9X1nZZf2nfT7e2n4xPgHSAZKWF/vkY+Wsw ItGkz8rIyg4+jw== X-Received: by 10.84.241.129 with SMTP id b1mr19316960pll.107.1492474345315; Mon, 17 Apr 2017 17:12:25 -0700 (PDT) Received: from s15.smythies.com (mail.smythies.com. [173.180.45.4]) by smtp.gmail.com with ESMTPSA id s10sm20132787pfe.28.2017.04.17.17.12.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Apr 2017 17:12:24 -0700 (PDT) From: Doug Smythies X-Google-Original-From: Doug Smythies To: srinivas.pandruvada@linux.intel.com, rjw@rjwysocki.net, len.brown@intel.com Cc: dsmythies@telus.net, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: [PATCH v2] tools/power/x86/intel_pstate_tracer: Adjust directory ownership Date: Mon, 17 Apr 2017 17:12:13 -0700 Message-Id: <1492474333-8356-1-git-send-email-dsmythies@telus.net> X-Mailer: git-send-email 2.7.4 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The intel_pstate_tracer.py script only needs to be run as root when it is also used to actually acquire the trace data that it will post process. Otherwise it is generally preferable that it be run as a regular user. If run the first time as root the results directory will be incorrect for any subsequent run as a regular user. For any run as root the specific testname subdirectory will not allow any subsequent file saves by a regular user. Typically, and for example, the regular user might be attempting to save a .csv file converted to a spreadsheet with added calculations or graphs. Set the directories and files owner and groups IDs to be the regular user, if required. Signed-off-by: Doug Smythies --- .../x86/intel_pstate_tracer/intel_pstate_tracer.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tools/power/x86/intel_pstate_tracer/intel_pstate_tracer.py b/tools/power/x86/intel_pstate_tracer/intel_pstate_tracer.py index fd706ac..0b24dd9 100755 --- a/tools/power/x86/intel_pstate_tracer/intel_pstate_tracer.py +++ b/tools/power/x86/intel_pstate_tracer/intel_pstate_tracer.py @@ -353,6 +353,14 @@ def split_csv(): os.system('grep -m 1 common_cpu cpu.csv > cpu{:0>3}.csv'.format(index)) os.system('grep CPU_{:0>3} cpu.csv >> cpu{:0>3}.csv'.format(index, index)) +def fix_ownership(path): + """Change the owner of the file to SUDO_UID, if required""" + + uid = os.environ.get('SUDO_UID') + gid = os.environ.get('SUDO_GID') + if uid is not None: + os.chown(path, int(uid), int(gid)) + def cleanup_data_files(): """ clean up existing data files """ @@ -518,12 +526,16 @@ else: if not os.path.exists('results'): os.mkdir('results') + # The regular user needs to own the directory, not root. + fix_ownership('results') os.chdir('results') if os.path.exists(testname): print('The test name directory already exists. Please provide a unique test name. Test re-run not supported, yet.') sys.exit() os.mkdir(testname) +# The regular user needs to own the directory, not root. +fix_ownership(testname) os.chdir(testname) # Temporary (or perhaps not) @@ -566,4 +578,9 @@ plot_scaled_cpu() plot_boost_cpu() plot_ghz_cpu() +# It is preferrable, but not necessary, that the regular user owns the files, not root. +for root, dirs, files in os.walk('.'): + for f in files: + fix_ownership(f) + os.chdir('../../')