[GH-ISSUE #3491] Firejail breaks daemonizing processes #2196

Open
opened 2026-05-05 08:52:32 -06:00 by gitea-mirror · 6 comments
Owner

Originally created by @NetSysFire on GitHub (Jul 4, 2020).
Original GitHub issue: https://github.com/netblue30/firejail/issues/3491

The following snippet works without problems when executed without firejail. However, when run with firejail (firejail bash snippet.sh), it keeps this process in the foreground.
This causes problems with the SSH connection multiplexing feature and causes ansible and even git over SSH to hang, because SSH can not daemonize and lingers indefinitely.

#!/bin/bash

some_loop(){
  while true; do
    echo "looped"
    sleep 3
  done
}

echo "some interactive stuff"
echo -n "enter something: "
read -r spam
echo "you entered $spam"
echo "forking loop and exiting"
(some_loop&)

Related: https://github.com/netblue30/firejail/issues/1518

Originally created by @NetSysFire on GitHub (Jul 4, 2020). Original GitHub issue: https://github.com/netblue30/firejail/issues/3491 The following snippet works without problems when executed without firejail. However, when run with firejail (`firejail bash snippet.sh`), it keeps this process in the foreground. This causes problems with the SSH connection multiplexing feature and causes ansible and even git over SSH to hang, because SSH can not daemonize and lingers indefinitely. ```bash #!/bin/bash some_loop(){ while true; do echo "looped" sleep 3 done } echo "some interactive stuff" echo -n "enter something: " read -r spam echo "you entered $spam" echo "forking loop and exiting" (some_loop&) ``` Related: https://github.com/netblue30/firejail/issues/1518
gitea-mirror added the
bug
label 2026-05-05 08:52:32 -06:00
Author
Owner

@rusty-snake commented on GitHub (Jul 4, 2020):

Duplicate of #2433?

<!-- gh-comment-id:653800270 --> @rusty-snake commented on GitHub (Jul 4, 2020): Duplicate of #2433?
Author
Owner

@ghost commented on GitHub (Jul 4, 2020):

@rusty-snake I was talking with the OP on IRC about this for quite a while. I think there are a few other potentially related issues. The fact there's seemingly something keeping firejail from backgrounding processes might be the root cause or the common-denominator for issues that go beyond SSH and git. I'll add proper links to those i could find as soon as i can track them down again.

<!-- gh-comment-id:653801991 --> @ghost commented on GitHub (Jul 4, 2020): @rusty-snake I was talking with the OP on IRC about this for quite a while. I think there are a few other potentially related issues. The fact there's seemingly something keeping firejail from backgrounding processes might be the root cause or the common-denominator for issues that go beyond SSH and git. I'll add proper links to those i could find as soon as i can track them down again.
Author
Owner

@ghost commented on GitHub (Apr 27, 2021):

Might be not the right issues here? I have problems with ansible. Might be a similar problem to the other issues.

Unlink /usr/local/bin/ssh works but if I'm using firejail then I can't use Ansible. The Gathering Facts already can't reach the hosts:
{"changed": false, "msg": "Failed to connect to the host via ssh: ", "unreachable": true}.

But I can connect just fine with ssh.

Edit:
It fits better with this issue https://github.com/netblue30/firejail/issues/1518

<!-- gh-comment-id:827488976 --> @ghost commented on GitHub (Apr 27, 2021): Might be not the right issues here? I have problems with ansible. Might be a similar problem to the other issues. Unlink `/usr/local/bin/ssh` works but if I'm using firejail then I can't use Ansible. The `Gathering Facts` already can't reach the hosts: `{"changed": false, "msg": "Failed to connect to the host via ssh: ", "unreachable": true}`. But I can connect just fine with ssh. Edit: It fits better with this issue https://github.com/netblue30/firejail/issues/1518
Author
Owner

@ndorf commented on GitHub (Sep 21, 2021):

To daemonize, a process must sever its relationship with its parent (e.g, the shell). This is done by forking and exiting; the new, orphaned process is usually assigned PID 1 (init) as a parent.

Under firejail, it seems that orphaned processes are instead inherited by the same firejail process that spawned their parents, so it's not possible to "fork away" from your parent -- you'll just inherit the same one again.

Could this possibly be solved by having a second firejail process, that itself is daemonized (detached from both its original parent process and the tty), and inherits orphaned processes instead of the main one?

<!-- gh-comment-id:923638494 --> @ndorf commented on GitHub (Sep 21, 2021): To daemonize, a process must sever its relationship with its parent (e.g, the shell). This is done by forking and exiting; the new, orphaned process is usually assigned PID 1 (init) as a parent. Under firejail, it seems that orphaned processes are instead inherited by the same firejail process that spawned their parents, so it's not possible to "fork away" from your parent -- you'll just inherit the same one again. Could this possibly be solved by having a second firejail process, that itself is daemonized (detached from both its original parent process and the tty), and inherits orphaned processes instead of the main one?
Author
Owner

@itoffshore commented on GitHub (Oct 31, 2021):

I came across this issue with ansible - I did notice that connections to localhost worked & it was only remote ssh connections that failed.

Mentioning here in case helpful as the other issue is closed.

<!-- gh-comment-id:955732403 --> @itoffshore commented on GitHub (Oct 31, 2021): I came across this issue with `ansible` - I did notice that connections to `localhost` worked & it was only remote `ssh` connections that failed. Mentioning here in case helpful as the [other issue](https://github.com/netblue30/firejail/issues/1518#issuecomment-955721870) is closed.
Author
Owner

@kmk3 commented on GitHub (Apr 6, 2023):

See the following thread for a potential workaround:

<!-- gh-comment-id:1499655982 --> @kmk3 commented on GitHub (Apr 6, 2023): See the following thread for a potential workaround: * <https://github.com/netblue30/firejail/issues/5751#issuecomment-1497839796>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/firejail#2196
No description provided.