Skip to content

Commit

Permalink
fix: always terminate host component when browser is terminated
Browse files Browse the repository at this point in the history
On chrome and chromium, the native part is not reliably terminated when
the browser is terminated. As we also cannot reliably send a message to
the host part on termination of the browser, there is no direct way to
let the host script known. In theory, the script should terminate once
stdio is closed, but in practice this is not always the case, leading to
orphaned processes.

To fix this, we use prctl to register a PDEATHSIG handler.

Signed-off-by: Felix Moessbauer <[email protected]>
  • Loading branch information
fmoessbauer committed Jul 2, 2024
1 parent f021a77 commit 7b60438
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions linux-entra-sso.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import json
import struct
import uuid
import ctypes
from signal import SIGINT
from threading import Thread, Lock
from gi.repository import GLib
from pydbus import SessionBus
Expand All @@ -25,6 +27,8 @@
# dbus start service reply codes
START_REPLY_SUCCESS = 1
START_REPLY_ALREADY_RUNNING = 2
# prctl constants
PR_SET_PDEATHSIG = 1


class NativeMessaging:
Expand Down Expand Up @@ -186,8 +190,17 @@ def run_dbus_monitor():
loop = GLib.MainLoop()
loop.run()

def register_terminate_with_parent():
libc = ctypes.CDLL("libc.so.6")
libc.prctl(PR_SET_PDEATHSIG, SIGINT, 0, 0, 0)

print("Running as browser plugin.", file=sys.stderr)
print("For interactive mode, start with --interactive", file=sys.stderr)

# on chrome and chromium, the parent process does not reliably
# terminate the plugin process when the parent process is killed.
register_terminate_with_parent()

ssomib = SsoMib(daemon=True)
ssomib.on_broker_state_changed(notify_state_change)
monitor = Thread(target=run_dbus_monitor)
Expand Down

0 comments on commit 7b60438

Please sign in to comment.