Skip to content

Commit

Permalink
handle exception at os.getlogin() #57
Browse files Browse the repository at this point in the history
  • Loading branch information
jotyGill committed Sep 24, 2017
1 parent ba7393e commit a199224
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions openpyn/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,12 @@ def logged_in_user_is_root(username):

def running_with_sudo():
if verify_running_as_root():
logged_in_user = print(os.environ["USER"])
if logged_in_user == "root":
return False
else:
return True
return False

'''
if logged_in_user_is_root(logged_in_user):
return False # when logged in as 'root' user notifications will work.
else:
return True # 'sudo' is used notification won't work.
try:
logged_in_user = os.getlogin()
if logged_in_user_is_root(logged_in_user):
return False # when logged in as 'root' user notifications will work.
else:
return True # 'sudo' is used notification won't work.
except FileNotFoundError:
print("os.getlogin, returned error, assuming 'openpyn' is running without 'SUDO'")
return False # regular user without 'sudo'
'''

0 comments on commit a199224

Please sign in to comment.