Skip to content

Commit

Permalink
better exception handling in root child harden
Browse files Browse the repository at this point in the history
  • Loading branch information
maltfield committed Jul 28, 2024
1 parent b07f753 commit 441578c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/buskill_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,11 @@ def toggle_buskill(self):
# buskill failed to arm/disarm; tell the user

msg = "Unable to toggle buskill state"
# for some reason 'e' is undefined, but we can get the exception thrown
# by the child process from its 'exception' instance field
# for some reason 'e' is sometimes undefined, but we can get the
# exception thrown by the child process from its 'exception'
# instance field
if e:
msg += "\n\nException: " +str(e)
if self.bk.usb_handler.exception[0]:
msg += "\n\nException: " +str(self.bk.usb_handler.exception[0])

Expand Down
13 changes: 11 additions & 2 deletions src/packages/buskill/root_child_mac.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,17 @@ def trigger_softshutdown_mac_halt():
# * https://github.com/BusKill/buskill-app/issues/14#issuecomment-1279975783
# * https://github.com/BusKill/buskill-app/issues/77#issuecomment-2254299923

# set owner of <this> binary to root:root
os.chown( os.path.abspath(__file__), 0, 0 )
our_filepath = os.path.abspath(__file__)

msg = "Attempting to harden ourselves " +str(our_filepath)
logging.info(msg)

try:
# set owner of <this> binary to root:root
os.chown( our_filepath, 0, 0 )
except Exception as e:
msg = "Failed to harden"
logging.warning(msg)

#############
# MAIN LOOP #
Expand Down

0 comments on commit 441578c

Please sign in to comment.