Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools/power/x86/intel_pstate_tracer: Adjust directory ownership

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@telus.net>
Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Doug Smythies and committed by
Rafael J. Wysocki
010a522c 4f7d029b

+17
+17
tools/power/x86/intel_pstate_tracer/intel_pstate_tracer.py
··· 353 353 os.system('grep -m 1 common_cpu cpu.csv > cpu{:0>3}.csv'.format(index)) 354 354 os.system('grep CPU_{:0>3} cpu.csv >> cpu{:0>3}.csv'.format(index, index)) 355 355 356 + def fix_ownership(path): 357 + """Change the owner of the file to SUDO_UID, if required""" 358 + 359 + uid = os.environ.get('SUDO_UID') 360 + gid = os.environ.get('SUDO_GID') 361 + if uid is not None: 362 + os.chown(path, int(uid), int(gid)) 363 + 356 364 def cleanup_data_files(): 357 365 """ clean up existing data files """ 358 366 ··· 526 518 527 519 if not os.path.exists('results'): 528 520 os.mkdir('results') 521 + # The regular user needs to own the directory, not root. 522 + fix_ownership('results') 529 523 530 524 os.chdir('results') 531 525 if os.path.exists(testname): 532 526 print('The test name directory already exists. Please provide a unique test name. Test re-run not supported, yet.') 533 527 sys.exit() 534 528 os.mkdir(testname) 529 + # The regular user needs to own the directory, not root. 530 + fix_ownership(testname) 535 531 os.chdir(testname) 536 532 537 533 # Temporary (or perhaps not) ··· 577 565 plot_scaled_cpu() 578 566 plot_boost_cpu() 579 567 plot_ghz_cpu() 568 + 569 + # It is preferrable, but not necessary, that the regular user owns the files, not root. 570 + for root, dirs, files in os.walk('.'): 571 + for f in files: 572 + fix_ownership(f) 580 573 581 574 os.chdir('../../')