This commit is contained in:
brent s 2019-01-18 15:56:13 -05:00
parent 31e8c4acee
commit 623c0e3abd
1 changed files with 4 additions and 3 deletions

View File

@ -93,6 +93,7 @@ for user in psutil.users():
if login_length.total_seconds() < timeout:
continue # they haven't even been logged in for long enough yet.
idle_time = get_idle(user)
parent_pid = psutil.Process(user.pid).ppid()
try:
diff = idle_time.total_seconds() >= timeout
except AttributeError:
@ -106,17 +107,17 @@ for user in psutil.users():
'timeout': timeout}
fmtd_goodbye = goodbye_mesg.format(**fmt_vals)
if only_ssh:
if psutil.Process(user.pid).ppid() in ssh_pids:
if parent_pid in ssh_pids:
if goodbye:
subprocess.run(['write',
user.name,
user.terminal],
input = fmtd_goodbye.encode('utf-8'))
psutil.Process(user.pid).terminate()
psutil.Process(parent_pid).terminate()
else:
if goodbye:
subprocess.run(['write',
user.name,
user.terminal],
input = fmtd_goodbye.encode('utf-8'))
psutil.Process(user.pid).terminate()
psutil.Process(parent_pid).terminate()