Skip to content

Commit

Permalink
fix Bug with GUI notifications #86
Browse files Browse the repository at this point in the history
  • Loading branch information
hakavlad committed Feb 16, 2020
1 parent cda2c95 commit 122233a
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions nohang/nohang
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,11 @@ def re_pid_environ(pid):
returns None if these vars is not in /proc/[pid]/environ
"""
try:
with open('/proc/' + pid + '/environ') as f:
env = f.read()
with open('/proc/' + pid + '/environ', 'rb') as f:
env = f.read().decode('utf-8', 'ignore')
except FileNotFoundError:
log('notify helper: FileNotFoundError')
return None
except ProcessLookupError:
log('notify helper: ProcessLookupError')
return None

if display_env in env and dbus_env in env and user_env in env:
Expand Down Expand Up @@ -929,10 +927,13 @@ def pid_to_cmdline(pid):
returns string cmdline
"""
try:
with open('/proc/' + pid + '/cmdline') as f:
return f.read().replace('\x00', ' ').rstrip()
with open('/proc/' + pid + '/cmdline', 'rb') as f:
return f.read().decode('utf-8', 'ignore').replace(
'\x00', ' ').rstrip()
except FileNotFoundError:
return ''
except ProcessLookupError:
return ''


def pid_to_environ(pid):
Expand All @@ -943,10 +944,13 @@ def pid_to_environ(pid):
returns string environ
"""
try:
with open('/proc/' + pid + '/environ') as f:
return f.read().replace('\x00', ' ').rstrip()
with open('/proc/' + pid + '/environ', 'rb') as f:
return f.read().decode('utf-8', 'ignore').replace(
'\x00', ' ').rstrip()
except FileNotFoundError:
return ''
except ProcessLookupError:
return ''


def pid_to_realpath(pid):
Expand All @@ -956,6 +960,8 @@ def pid_to_realpath(pid):
return os.path.realpath('/proc/' + pid + '/exe')
except FileNotFoundError:
return ''
except ProcessLookupError:
return ''


def pid_to_cwd(pid):
Expand All @@ -965,6 +971,8 @@ def pid_to_cwd(pid):
return os.path.realpath('/proc/' + pid + '/cwd')
except FileNotFoundError:
return ''
except ProcessLookupError:
return ''


def pid_to_uid(pid):
Expand Down

0 comments on commit 122233a

Please sign in to comment.