You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"tcsetpgrp: No such process" when running in firejail #3345
# firejail --noprofile fish
Parent pid 12650, child pid 12651
Child process initialized
fish: Could not return shell to foreground
tcsetpgrp: No such process
fish: Could not return shell to foreground
tcsetpgrp: No such process
fish: Could not return shell to foreground
tcsetpgrp: No such process
fish: Could not return shell to foreground
tcsetpgrp: No such process
fish: Could not return shell to foreground
tcsetpgrp: No such process
fish: Could not return shell to foreground
tcsetpgrp: No such process
fish doesn't start up properly and goes in a suspended state in the background:
# jobs
[1] suspended (tty input) firejail --noprofile fish
An alias or umask (both autoloaded builtins? use eval) seem to trigger this, but only if they're run from config.fish during startup. Both alias and umask work fine after fish has already started.
This probably happens because firejail uses namespaces to lock down the PIDs the jail knows about. ps ux inside the jail lists:
> ps ux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
at 1 0.0 0.0 14148 2036 pts/4 S 01:39 0:00 firejail --noprofile fish
at 2 0.0 0.2 172148 5948 pts/4 S 01:39 0:00 fish
at 115 0.0 0.1 37364 3324 pts/4 R+ 01:41 0:00 ps ux
I have no idea why this only breaks during startup, though.
There is probably a better workaround, but right now I am just running alias a little later with:
set-g __fish_setup_done 0
function finish_setup
if [ $__fish_setup_done = 1 ]
returnendset __fish_setup_done 1
# [aliases and other things that break at startup]endfunctionfish_prompt
finish_setup
# [...]end
FWIW I can reproduce this. What is very odd is that leaving my normal, relatively complex, configuration in place but only removing the alias commands allows the shell to startup. Adding a single alias (the details don't matter) breaks it as reported in the original comment. Replacing the alias command with an explicit function definition also "fixes" the problem. That is, if instead of
alias ll 'ls -blF'
in my startup config I do
function ll
ls -blF $argv
end
The shell starts and the "alias" is defined and usable. Since alias is supposed to be just a shorthand for that function definition the difference in behavior is surprising. So I'm inclined to consider this a fish bug.
Looks familiar. I had thought I already reported this on our issue board, but I had not (or I can't find it): puma/puma-dev#69 (comment) on OS X.
Also went away for him when removing his aliases. I would have figured the net result of wrapping those commands was going to be to blame. Interesting.
Alias doesn't do anything all that complicated, but it executes eval.
And eval does some weird stuff.
There's this
set-l mode
ifstatus--is-interactive-job-controlset mode interactive
elseifstatus--is-full-job-controlset mode full
elseset mode none
endendifstatus--is-interactivestatus--job-control full
end# (some stuff cut to concentrate on the job control)status--job-control$mode
and this
echo"begin; $argv"\n" ;end <&3 3<&-"| source 3<&0
@ivan: Can you try these lines on their own (obviously replace $argv with some fish code)?
(We could probably replace the use of eval in alias with source, but that wouldn't solve the underlying problem - might be cleaner and faster though)
(EDIT: I overlooked some important lines for the first piece of code)
In particular, what happens here is that status --is-interactive-job-control is true (which means mode gets set to interactive), status --is-interactive also is (which means status --job-control full is executed) and then status --job-control interactive is run.
The offending call is status --job-control full - commenting that out removes the error.
<3> fish: Set status of echo"Setting job control $mode" to 0 using short circuit
<3> fish: Job is constructed
<4> fish: Continue job 2, gid 0 (echo"Setting job control $mode"), COMPLETED, NON-INTERACTIVE
<W> fish: Konnte Shell nicht wieder in Vordergrund zurückholen
tcsetpgrp: Kein passender Prozess gefunden
<4> fish: Exec job 'status --job-control $mode' with id 2
<3> fish: Skipping fork: no output for internal builtin'status'<3> fish: Set status of status--job-control$mode to 0 using short circuit
(The german messages here are "Could not return shell to foreground" and "No such process")
What's interesting here is that the job right before setting the job control mode (which is echo "Setting job control $mode") says it is "NON-INTERACTIVE". After this, sourcing config.fish is done and then fish goes interactive.
Fish starts eval something, which turns on more job control stuff (technical term) in config.fish
This causes it to start the job in its own process group and hand it control of the terminal
Then the job quits
Then fish sets up its terminal stuff (reader_interactive_init)
Fish figures it's not in control of the terminal (because tcgetpgrp still returns the finished job's pgid), and (for reasons I've yet to determine) tries determining if it is an orphan
This check involves reading outside of the foreground process group (which causes a SIGTTIN, which stops fish), and even outright sending SIGTTIN to its own process group, both of which cause fish to be stopped
Removing these checks (i.e. if (false && tcgetpgrp(STDIN_FILENO) != shell_pgid)) makes everything work^tm.
TBD is how firejail is special here - it's possible it's blocking us from blocking SIGTTIN (I haven't really looked at our signal handling).
So, the nicest thing here to do would be to figure out that the pgid we received is bogus (tcgetpgrp returns "some value larger than 1 that is not presently a process group ID" in this case) and that the terminal is hence up for grabs, and just grab it. I have no idea how to do that since I haven't found a function that does this.
Alternatively, the orphan logic could use reworking (or possibly removal - if we get SIGTTIN here anyway, we could just receive that later when we tcsetpgrp IIUC).
Or we could init the reader stuff earlier.
@ridiculousfish: Since you wrote that code: Words, possibly emojis?
I just tested this and it doesn't seem to reproduce under current fish builds. Note that we dropped the tcsetpgrp in fish startup in 3.0, which is probably why this now works.
Activity
ivan commentedon Sep 1, 2016
There is probably a better workaround, but right now I am just running
aliasa little later with:krader1961 commentedon Sep 1, 2016
FWIW I can reproduce this. What is very odd is that leaving my normal, relatively complex, configuration in place but only removing the
aliascommands allows the shell to startup. Adding a single alias (the details don't matter) breaks it as reported in the original comment. Replacing thealiascommand with an explicit function definition also "fixes" the problem. That is, if instead ofin my startup config I do
The shell starts and the "alias" is defined and usable. Since
aliasis supposed to be just a shorthand for that function definition the difference in behavior is surprising. So I'm inclined to consider this a fish bug.floam commentedon Sep 1, 2016
Looks familiar. I had thought I already reported this on our issue board, but I had not (or I can't find it): puma/puma-dev#69 (comment) on OS X.
Also went away for him when removing his aliases. I would have figured the net result of wrapping those commands was going to be to blame. Interesting.
faho commentedon Sep 1, 2016
Alias doesn't do anything all that complicated, but it executes
eval.And
evaldoes some weird stuff.There's this
and this
@ivan: Can you try these lines on their own (obviously replace $argv with some fish code)?
(We could probably replace the use of
evalin alias withsource, but that wouldn't solve the underlying problem - might be cleaner and faster though)(EDIT: I overlooked some important lines for the first piece of code)
faho commentedon Sep 1, 2016
Yes, the job control stuff does it.
In particular, what happens here is that
status --is-interactive-job-controlis true (which means mode gets set tointeractive),status --is-interactivealso is (which meansstatus --job-control fullis executed) and thenstatus --job-control interactiveis run.The offending call is
status --job-control full- commenting that out removes the error.alias: Use `source` directly
faho commentedon Sep 1, 2016
@ivan: 443fc66 should avoid triggering the error with
alias(and additonally speed up alias a bit).This should still be kept open as the underlying issue - that we try to set job control where we can't - remains.
floam commentedon Sep 1, 2016
When did job control stop working here? Did it never work in these situations? Should it not?
faho commentedon Sep 1, 2016
Okay, I've got some debug output:
(The german messages here are "Could not return shell to foreground" and "No such process")
What's interesting here is that the job right before setting the job control mode (which is
echo "Setting job control $mode") says it is "NON-INTERACTIVE". After this, sourcing config.fish is done and then fish goes interactive.Also, this is basically #1245 and #333.
faho commentedon Mar 31, 2017
Okay.... The issue here is as follows:
Fish starts
eval something, which turns on more job control stuff (technical term) in config.fishThis causes it to start the job in its own process group and hand it control of the terminal
Then the job quits
Then fish sets up its terminal stuff (
reader_interactive_init)Fish figures it's not in control of the terminal (because
tcgetpgrpstill returns the finished job's pgid), and (for reasons I've yet to determine) tries determining if it is an orphanThis check involves
reading outside of the foreground process group (which causes a SIGTTIN, which stops fish), and even outright sending SIGTTIN to its own process group, both of which cause fish to be stoppedRemoving these checks (i.e.
if (false && tcgetpgrp(STDIN_FILENO) != shell_pgid)) makes everything work^tm.TBD is how firejail is special here - it's possible it's blocking us from blocking SIGTTIN (I haven't really looked at our signal handling).
So, the nicest thing here to do would be to figure out that the pgid we received is bogus (tcgetpgrp returns "some value larger than 1 that is not presently a process group ID" in this case) and that the terminal is hence up for grabs, and just grab it. I have no idea how to do that since I haven't found a function that does this.
Alternatively, the orphan logic could use reworking (or possibly removal - if we get SIGTTIN here anyway, we could just receive that later when we
tcsetpgrpIIUC).Or we could init the reader stuff earlier.
@ridiculousfish: Since you wrote that code: Words, possibly emojis?
alias: Use `source` directly
mqudsi commentedon Mar 10, 2018
I just tested this and it doesn't seem to reproduce under current fish builds. Note that we dropped the
tcsetpgrpin fish startup in 3.0, which is probably why this now works.