Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions dojjail/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def setup_ns(self):
socket.sethostname(self.name)
if self.ns_flags & NS.PID:
pid = fork_clean(parent_death_signal=None if self.persist else 9)
host_target_pids[self.id] = pid
host_target_pids[self.id].value = pid
if pid:
with DelayedKeyboardInterrupt():
os.waitid(os.P_PID, pid, os.WEXITED)
Expand Down Expand Up @@ -140,13 +140,20 @@ def wait(self):
return result

def kill(self, *, signal=signal.SIGTERM):
try:
# This SIGTERM goes to the "waiting python process"
os.kill(self.pid, signal)
# Target being executed in namespaces does not exit gracefully /w SIGTERM
os.kill(host_target_pids[self.id].value, 9)
except ProcessLookupError:
pass
# This SIGTERM goes to the "waiting python process".
if self.pid > 0:
try:
os.kill(self.pid, signal)
except ProcessLookupError:
pass

# Only kill the target PID when we actually created one.
target_pid = host_target_pids[self.id].value
if self.ns_flags & NS.PID and target_pid > 0:
try:
os.kill(target_pid, 9)
except ProcessLookupError:
pass

def enter(self, *, uid=PRIVILEGED_UID):
assert self.pid
Expand Down