fix GUI notifications
This commit is contained in:
parent
38ceaecc59
commit
86c9c10355
58
nohang
58
nohang
@ -9,6 +9,9 @@ from time import sleep, time
|
|||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
from sys import stdout
|
from sys import stdout
|
||||||
|
|
||||||
|
from subprocess import Popen, PIPE
|
||||||
|
|
||||||
|
|
||||||
sig_dict = {signal.SIGKILL: 'SIGKILL',
|
sig_dict = {signal.SIGKILL: 'SIGKILL',
|
||||||
signal.SIGTERM: 'SIGTERM'}
|
signal.SIGTERM: 'SIGTERM'}
|
||||||
|
|
||||||
@ -43,6 +46,46 @@ name_strip_string = '\'"`\\!-$'
|
|||||||
# function definition section
|
# function definition section
|
||||||
|
|
||||||
|
|
||||||
|
# return list of tuples with
|
||||||
|
# username, DISPLAY and DBUS_SESSION_BUS_ADDRESS
|
||||||
|
def root_notify_env():
|
||||||
|
|
||||||
|
ps_output_list = Popen(['ps', 'aue'], stdout=PIPE
|
||||||
|
).communicate()[0].decode().split('\n')
|
||||||
|
|
||||||
|
di = 'DISPLAY='
|
||||||
|
db = 'DBUS_SESSION_BUS_ADDRESS='
|
||||||
|
us = 'USER='
|
||||||
|
ro = 'root '
|
||||||
|
|
||||||
|
lines_with_displays = []
|
||||||
|
for line in ps_output_list:
|
||||||
|
if di in line and db in line and us in line and not line.startswith(ro):
|
||||||
|
lines_with_displays.append(line)
|
||||||
|
|
||||||
|
# list of tuples with all necessary
|
||||||
|
deus = []
|
||||||
|
for i in lines_with_displays:
|
||||||
|
for i in i.split(' '):
|
||||||
|
if i.startswith(us):
|
||||||
|
user = i.strip('\n').split('=')[1]
|
||||||
|
continue
|
||||||
|
if i.startswith(di):
|
||||||
|
disp_value = i.strip('\n').split('=')[1][0:2]
|
||||||
|
disp = di + disp_value
|
||||||
|
continue
|
||||||
|
if i.startswith(db):
|
||||||
|
dbus = i.strip('\n')
|
||||||
|
deus.append(tuple([user, disp, dbus]))
|
||||||
|
|
||||||
|
# unique list of tuples
|
||||||
|
vult = []
|
||||||
|
for user_env_tuple in set(deus):
|
||||||
|
vult.append(user_env_tuple)
|
||||||
|
|
||||||
|
return vult
|
||||||
|
|
||||||
|
|
||||||
def string_to_float_convert_test(string):
|
def string_to_float_convert_test(string):
|
||||||
try:
|
try:
|
||||||
return float(string)
|
return float(string)
|
||||||
@ -204,13 +247,20 @@ def send_notify(signal, name, pid, oom_score, vm_rss, vm_swap):
|
|||||||
'id:</i> <b>{}</b> \n<i>Badness:</i> <b>{}</b> \n<i>VmRSS:</i> <b' \
|
'id:</i> <b>{}</b> \n<i>Badness:</i> <b>{}</b> \n<i>VmRSS:</i> <b' \
|
||||||
'>{} MiB</b> \n<i>VmSwap:</i> <b>{} MiB</b>" &'.format(
|
'>{} MiB</b> \n<i>VmSwap:</i> <b>{} MiB</b>" &'.format(
|
||||||
sig_dict[signal], name.strip(name_strip_string), pid, oom_score, vm_rss, vm_swap)
|
sig_dict[signal], name.strip(name_strip_string), pid, oom_score, vm_rss, vm_swap)
|
||||||
|
|
||||||
if root:
|
if root:
|
||||||
# отправляем уведомление всем залогиненным пользователям
|
# отправляем уведомление всем залогиненным пользователям
|
||||||
for uid in os.listdir('/run/user'):
|
b = root_notify_env()
|
||||||
root_notify_command = 'sudo -u {} DISPLAY={} notify-send {} "Pr' \
|
if len(b) > 0:
|
||||||
'eventing OOM" '.format(
|
for i in b:
|
||||||
users_dict[uid], root_display, notify_options)
|
username = i[0]
|
||||||
|
display_env = i[1]
|
||||||
|
dbus_env = i[2]
|
||||||
|
# su username - -c "env DISPLAY=... DBUS_SESSION_BUS_ADDRESS=... notify-send 'head' 'body'"
|
||||||
|
root_notify_command = 'sudo -u {} {} {} notify-send "Preventing OOM" '.format(
|
||||||
|
username, display_env, dbus_env)
|
||||||
os.system(root_notify_command + info)
|
os.system(root_notify_command + info)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# отправляем уведомление пользователю, который запустил nohang
|
# отправляем уведомление пользователю, который запустил nohang
|
||||||
user_notify_command = 'notify-send {} "Preventing OOM" '.format(
|
user_notify_command = 'notify-send {} "Preventing OOM" '.format(
|
||||||
|
Loading…
Reference in New Issue
Block a user