bubblewrap
bubblewrap copied to clipboard
ctrl+c sends SIGINT to bubblwrap instead of child process
Here is a dumb python program where the issue happens:
import signal
import asyncio
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
def interrupt():
s = input("test")
print(s)
loop.stop()
loop.add_signal_handler(signal.SIGINT, interrupt)
loop.run_forever()
loop.remove_signal_handler(signal.SIGINT)
loop.close()
On host, running this program, then pressing ctrl+c, a prompt shows up, then I can type some text and enter. The text is printed again and the program exits.
Now, if I run through bwrap --ro-bind / / -- /usr/bin/python3 test.py, I get the error:
handle: <Handle interrupt() at test-interrupt.py:7>
Traceback (most recent call last):
File "/usr/lib/python3.8/asyncio/events.py", line 81, in _run
self._context.run(self._callback, *self._args)
File "test-interrupt.py", line 8, in interrupt
s = input("test")
EOFError
This is because is bwrap is part of foreground process group. Instead it should be the child process as to be the foreground process group.
Coincidentally, I just encountered this issue!
I believe bwrap could also just handle the relevant signals and redirect them to the child process?
Something like this:
void forward_signal_to_child(int signal_number) {
kill(pid, signal_number);
}
...
signal(SIGINT, forward_signal_to_child);
// And others...
Maybe just do this if a flag is passed in, in order to keep both possibilities.
I think creating a pgrp for the child process is better.
To work around this issue I have created a small wrapper for my application: https://gitlab.com/valentindavid/flatpak-buildstream/-/blob/39705ab4451a20bf4caacf061f392beafddad040/files/bst-wrapper.py
I believe bwrap could also just handle the relevant signals and redirect them to the child process?
If I understand it correctly, this would allow to reload some child processes by sending SIGHUP to bwrap. systemctl reload would work almost out of the box (with ExecReload=/usr/bin/kill -HUP $MAINPID). That would be great.
If I understand it correctly, this would allow to reload some child processes by sending SIGHUP to bwrap
Only if bwrap specifically catches and forwards SIGHUP - #402 only catches and forwards SIGINT and SIGTERM.
@smcv Can you please review either #586 or #588 for this issue? (586 is probably the worse way to go about this, but it was quick to do and solves my annoyance...)
@smcv Can you please review either #586 or #588 for this issue? (586 is probably the worse way to go about this, but it was quick to do and solves my annoyance...)
Looking into this is on my list, but my list is not short, and everyone wants their item on the list to be my top priority.
either #586 or #588
We may even want both, if I'm reading this correctly (?):
- I'm running a service in bwrap in a systemd-service: That wouldn't have any terminal emulation, right? But I'll still want the service to be able to receive
SIGHUPorSIGINTorSIGTERM - When I run a program in bwrap in a terminal, then the pgroup trickery would be "more correct" than just forwarding?
- Or would the pgroup solution also work without a terminal?