add debug_gui_notifications; use encode instead of cache
This commit is contained in:
parent
1ade5ca49f
commit
f70a65c8f0
40
nohang
40
nohang
@ -16,6 +16,15 @@ from signal import signal, SIGKILL, SIGTERM, SIGINT, SIGQUIT, SIGHUP
|
|||||||
# define functions
|
# define functions
|
||||||
|
|
||||||
|
|
||||||
|
def encoder(string):
|
||||||
|
"""
|
||||||
|
"""
|
||||||
|
encoded = ''
|
||||||
|
for i in string:
|
||||||
|
encoded += str(ord(i)) + ':'
|
||||||
|
return encoded[:-1]
|
||||||
|
|
||||||
|
|
||||||
def get_swap_threshold_tuple(string):
|
def get_swap_threshold_tuple(string):
|
||||||
# re (Num %, True) or (Num KiB, False)
|
# re (Num %, True) or (Num KiB, False)
|
||||||
"""Returns KiB value if abs val was set in config, or tuple with %"""
|
"""Returns KiB value if abs val was set in config, or tuple with %"""
|
||||||
@ -867,26 +876,13 @@ def send_notify_etc(pid, name, command):
|
|||||||
def send_notification(title, body):
|
def send_notification(title, body):
|
||||||
"""
|
"""
|
||||||
"""
|
"""
|
||||||
split_by = '#' * 16
|
cmd = '{} "--euid={}" "--debug={}" "--title={}" "--body={}" &'.format(
|
||||||
|
notify_helper_path,
|
||||||
|
self_uid,
|
||||||
|
debug_gui_notifications,
|
||||||
|
title,
|
||||||
|
encoder(body))
|
||||||
|
|
||||||
t000 = time()
|
|
||||||
|
|
||||||
path_to_cache = '/dev/shm/nohang_notify_cache_uid{}_time{}'.format(
|
|
||||||
str(self_uid), t000
|
|
||||||
)
|
|
||||||
|
|
||||||
text = '{}{}{}'.format(title, split_by, body)
|
|
||||||
|
|
||||||
try:
|
|
||||||
with open(path_to_cache, 'w') as f:
|
|
||||||
f.write(text)
|
|
||||||
os.chmod(path_to_cache, 0o600)
|
|
||||||
except OSError:
|
|
||||||
log('OSError while send notification '
|
|
||||||
'(No space left on device: /dev/shm)')
|
|
||||||
return None
|
|
||||||
|
|
||||||
cmd = '{} --uid {} --time {} &'.format(notify_helper_path, self_uid, t000)
|
|
||||||
exe(cmd)
|
exe(cmd)
|
||||||
|
|
||||||
|
|
||||||
@ -2414,6 +2410,7 @@ gui_notifications = conf_parse_bool('gui_notifications')
|
|||||||
decrease_oom_score_adj = conf_parse_bool('decrease_oom_score_adj')
|
decrease_oom_score_adj = conf_parse_bool('decrease_oom_score_adj')
|
||||||
ignore_psi = conf_parse_bool('ignore_psi')
|
ignore_psi = conf_parse_bool('ignore_psi')
|
||||||
ignore_zram = conf_parse_bool('ignore_zram')
|
ignore_zram = conf_parse_bool('ignore_zram')
|
||||||
|
debug_gui_notifications = conf_parse_bool('debug_gui_notifications')
|
||||||
|
|
||||||
|
|
||||||
(mem_min_sigterm_kb, mem_min_sigterm_mb, mem_min_sigterm_percent
|
(mem_min_sigterm_kb, mem_min_sigterm_mb, mem_min_sigterm_percent
|
||||||
@ -2937,6 +2934,8 @@ if print_config:
|
|||||||
|
|
||||||
log(' min_badness: {}'.format(min_badness))
|
log(' min_badness: {}'.format(min_badness))
|
||||||
log(' min_delay_after_sigterm: {} sec'.format(min_delay_after_sigterm))
|
log(' min_delay_after_sigterm: {} sec'.format(min_delay_after_sigterm))
|
||||||
|
log(' post_zombie_delay: {} sec'.format(post_zombie_delay))
|
||||||
|
log(' victim_cache_time: {} sec'.format(victim_cache_time))
|
||||||
log(' decrease_oom_score_adj: {}'.format(decrease_oom_score_adj))
|
log(' decrease_oom_score_adj: {}'.format(decrease_oom_score_adj))
|
||||||
log(' oom_score_adj_max: {}'.format(oom_score_adj_max))
|
log(' oom_score_adj_max: {}'.format(oom_score_adj_max))
|
||||||
|
|
||||||
@ -2998,7 +2997,7 @@ if print_config:
|
|||||||
else:
|
else:
|
||||||
log(' (not set)')
|
log(' (not set)')
|
||||||
|
|
||||||
log('6. Customize corrective actions.')
|
log('6. Customize corrective actions')
|
||||||
|
|
||||||
if len(soft_actions_list) > 0:
|
if len(soft_actions_list) > 0:
|
||||||
log(' Match by: regexp: command: ')
|
log(' Match by: regexp: command: ')
|
||||||
@ -3033,6 +3032,7 @@ if print_config:
|
|||||||
log(' print_victim_info: {}'.format(print_victim_info))
|
log(' print_victim_info: {}'.format(print_victim_info))
|
||||||
log(' print_victim_cmdline: {}'.format(print_victim_cmdline))
|
log(' print_victim_cmdline: {}'.format(print_victim_cmdline))
|
||||||
log(' max_ancestry_depth: {}'.format(max_ancestry_depth))
|
log(' max_ancestry_depth: {}'.format(max_ancestry_depth))
|
||||||
|
log(' debug_gui_notifications: {}'.format(debug_gui_notifications))
|
||||||
log(' separate_log: {}'.format(separate_log))
|
log(' separate_log: {}'.format(separate_log))
|
||||||
log(' psi_debug: {}'.format(psi_debug))
|
log(' psi_debug: {}'.format(psi_debug))
|
||||||
|
|
||||||
|
10
nohang.conf
10
nohang.conf
@ -267,12 +267,12 @@ oom_score_adj_max = 0
|
|||||||
- OOM prevention results and
|
- OOM prevention results and
|
||||||
- low memory warnings
|
- low memory warnings
|
||||||
|
|
||||||
gui_notifications = False
|
gui_notifications = True
|
||||||
|
|
||||||
Enable GUI notifications about the low level of available memory.
|
Enable GUI notifications about the low level of available memory.
|
||||||
Valid values are True and False.
|
Valid values are True and False.
|
||||||
|
|
||||||
gui_low_memory_warnings = False
|
gui_low_memory_warnings = True
|
||||||
|
|
||||||
Execute the command instead of sending GUI notifications if the value is
|
Execute the command instead of sending GUI notifications if the value is
|
||||||
not empty line. For example:
|
not empty line. For example:
|
||||||
@ -305,7 +305,7 @@ min_time_between_warnings = 20
|
|||||||
Display the configuration when the program starts.
|
Display the configuration when the program starts.
|
||||||
Valid values are True and False.
|
Valid values are True and False.
|
||||||
|
|
||||||
print_config = False
|
print_config = True
|
||||||
|
|
||||||
Print memory check results.
|
Print memory check results.
|
||||||
Valid values are True and False.
|
Valid values are True and False.
|
||||||
@ -337,7 +337,9 @@ print_victim_info = True
|
|||||||
|
|
||||||
print_victim_cmdline = False
|
print_victim_cmdline = False
|
||||||
|
|
||||||
max_ancestry_depth = 5
|
max_ancestry_depth = 4
|
||||||
|
|
||||||
|
debug_gui_notifications = False
|
||||||
|
|
||||||
separate_log = False
|
separate_log = False
|
||||||
|
|
||||||
|
@ -2,7 +2,15 @@
|
|||||||
|
|
||||||
# print('Starting nohang_notify_helper')
|
# print('Starting nohang_notify_helper')
|
||||||
|
|
||||||
debug = True
|
|
||||||
|
def decoder(string):
|
||||||
|
"""
|
||||||
|
"""
|
||||||
|
decoded = ''
|
||||||
|
for i in string.split(':'):
|
||||||
|
decoded += chr(int(i))
|
||||||
|
return decoded
|
||||||
|
|
||||||
|
|
||||||
def write(path, string):
|
def write(path, string):
|
||||||
"""
|
"""
|
||||||
@ -118,9 +126,24 @@ except OSError:
|
|||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
_, uid, debug, title, body = argv
|
||||||
|
|
||||||
|
uid = uid.partition('--euid=')[2]
|
||||||
|
|
||||||
|
debug = debug.partition('--debug=')[2]
|
||||||
|
|
||||||
|
if debug == 'True':
|
||||||
|
debug = True
|
||||||
|
else:
|
||||||
|
debug = False
|
||||||
|
|
||||||
|
title = title.partition('--title=')[2]
|
||||||
|
|
||||||
|
body = decoder(body.partition('--body=')[2])
|
||||||
|
|
||||||
if len(argv) != 5:
|
if len(argv) != 5:
|
||||||
print('nohang_notify_helper: invalid input')
|
print('nohang_notify_helper: invalid input')
|
||||||
exit()
|
exit(1)
|
||||||
|
|
||||||
|
|
||||||
with open('/proc/meminfo') as f:
|
with open('/proc/meminfo') as f:
|
||||||
@ -132,29 +155,10 @@ with open('/proc/meminfo') as f:
|
|||||||
else:
|
else:
|
||||||
wait_time = 2
|
wait_time = 2
|
||||||
|
|
||||||
|
|
||||||
if debug:
|
if debug:
|
||||||
print('nohang_notify_helper: wait_time:', wait_time)
|
print('nohang_notify_helper: wait_time:', wait_time, 'sec')
|
||||||
|
|
||||||
split_by = '#' * 16
|
|
||||||
|
|
||||||
|
|
||||||
uid = argv[2]
|
|
||||||
|
|
||||||
timestamp = argv[4]
|
|
||||||
|
|
||||||
|
|
||||||
path_to_cache = '/dev/shm/nohang_notify_cache_uid{}_time{}'.format(
|
|
||||||
uid, timestamp
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
title, body = rfile(path_to_cache).split(split_by)
|
|
||||||
except FileNotFoundError:
|
|
||||||
print('nohang_notify_helper: FileNotFoundError')
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
remove(path_to_cache)
|
|
||||||
|
|
||||||
if uid != '0':
|
if uid != '0':
|
||||||
cmd = ['notify-send', '--icon=dialog-warning', title, body]
|
cmd = ['notify-send', '--icon=dialog-warning', title, body]
|
||||||
@ -182,10 +186,10 @@ if list_len > 0:
|
|||||||
for i in list_with_envs:
|
for i in list_with_envs:
|
||||||
if debug:
|
if debug:
|
||||||
print('Send a GUI notification:\n ',
|
print('Send a GUI notification:\n ',
|
||||||
'title: ', [title],
|
'title: ', [title],
|
||||||
'\n body: ', [body],
|
'\n body: ', [body],
|
||||||
'\n user/env:', i
|
'\n user/env:', i
|
||||||
)
|
)
|
||||||
|
|
||||||
# iterating over logged-in users
|
# iterating over logged-in users
|
||||||
for i in list_with_envs:
|
for i in list_with_envs:
|
||||||
|
Loading…
Reference in New Issue
Block a user