Adjusted running as root checks
* Suppress pylint errors when checking uid/euid/gid * Helpful when checking under Windows * Allow running wk.exe.stop_process() under Windows
This commit is contained in:
parent
d0d74b8763
commit
6c775bbba7
2 changed files with 11 additions and 11 deletions
|
|
@ -80,7 +80,8 @@ def build_cmd_kwargs(cmd, minimized=False, pipe=True, shell=False, **kwargs):
|
||||||
}
|
}
|
||||||
|
|
||||||
# Strip sudo if appropriate
|
# Strip sudo if appropriate
|
||||||
if cmd[0] == 'sudo' and os.name == 'posix' and os.geteuid() == 0:
|
if cmd[0] == 'sudo':
|
||||||
|
if os.name == 'posix' and os.geteuid() == 0: # pylint: disable=no-member
|
||||||
cmd.pop(0)
|
cmd.pop(0)
|
||||||
|
|
||||||
# Add additional kwargs if applicable
|
# Add additional kwargs if applicable
|
||||||
|
|
@ -221,21 +222,20 @@ def stop_process(proc, graceful=True):
|
||||||
NOTES: proc should be a subprocess.Popen obj.
|
NOTES: proc should be a subprocess.Popen obj.
|
||||||
If graceful is True then a SIGTERM is sent before SIGKILL.
|
If graceful is True then a SIGTERM is sent before SIGKILL.
|
||||||
"""
|
"""
|
||||||
running_as_root = os.geteuid() == 0
|
|
||||||
|
|
||||||
# Graceful exit
|
# Graceful exit
|
||||||
if graceful:
|
if graceful:
|
||||||
if running_as_root:
|
if os.name == 'posix' and os.geteuid() != 0: # pylint: disable=no-member
|
||||||
proc.terminate()
|
|
||||||
else:
|
|
||||||
run_program(['sudo', 'kill', str(proc.pid)], check=False)
|
run_program(['sudo', 'kill', str(proc.pid)], check=False)
|
||||||
|
else:
|
||||||
|
proc.terminate()
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
# Force exit
|
# Force exit
|
||||||
if running_as_root:
|
if os.name == 'posix' and os.geteuid() != 0: # pylint: disable=no-member
|
||||||
proc.kill()
|
|
||||||
else:
|
|
||||||
run_program(['sudo', 'kill', '-9', str(proc.pid)], check=False)
|
run_program(['sudo', 'kill', '-9', str(proc.pid)], check=False)
|
||||||
|
else:
|
||||||
|
proc.kill()
|
||||||
|
|
||||||
|
|
||||||
def wait_for_procs(name, exact=True, timeout=None):
|
def wait_for_procs(name, exact=True, timeout=None):
|
||||||
|
|
|
||||||
|
|
@ -122,8 +122,8 @@ def mount_network_share(details, mount_point=None, read_write=False):
|
||||||
'-t', 'cifs',
|
'-t', 'cifs',
|
||||||
'-o', (
|
'-o', (
|
||||||
f'{"rw" if read_write else "ro"}'
|
f'{"rw" if read_write else "ro"}'
|
||||||
f',uid={os.getuid()}'
|
f',uid={os.getuid()}' # pylint: disable=no-member
|
||||||
f',gid={os.getgid()}'
|
f',gid={os.getgid()}' # pylint: disable=no-member
|
||||||
f',username={username}'
|
f',username={username}'
|
||||||
f',{"password=" if password else "guest"}{password}'
|
f',{"password=" if password else "guest"}{password}'
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue