Re: [PATCH v2] tools/power/x86/intel_pstate_tracer: Adjust directory ownership

From: Srinivas Pandruvada
Date: Tue Apr 18 2017 - 14:38:22 EST


On Tue, 2017-04-18 at 15:58 +0200, Rafael J. Wysocki wrote:
> On Monday, April 17, 2017 05:12:13 PM Doug Smythies wrote:
> >
> > 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 <dsmythies@xxxxxxxxx>
ÂAcked-by: Srinivas Pandruvada <srinivas.pandruvada@xxxxxxxxxxxxxxx>

>
> Srinivas, any concerns?
No, I am fine with the change.

Thanks,
Srinivas

>
> >
> > ---
> > Â.../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('../../')
> >
>