Hi everyone,

I believe I've come across bug. I find that if I have a config.fish consisting
of the following two lines

status --job-control full
. empty.fish

where empty.fish is just an empty file in ~/.config/fish, Fish will hang when I
attempt to log in on a virtual console (e.g. tty1). If I run Fish within X11 or
with either of those lines commented out, everything's fine. I think the second
line can be any command that cause Fish to perform a fork().

The fix is pretty simple and just involves replacing getpid() with getpgrp() in
terminal_return_from_job in proc.c. See below for the detailed explanation. I'm
certainly no expert so I would appreciate it if anyone else can confirm that my
fix looks ok.

Best,
Adam Cozzette

diff --git a/proc.c b/proc.c
index b98de61..edcc7c6 100644
--- a/proc.c
+++ b/proc.c
@@ -931,7 +931,7 @@ static int terminal_give_to_job( job_t *j, int cont )
 static int terminal_return_from_job( job_t *j)
 {
 
-       if( tcsetpgrp (0, getpid()) )
+       if( tcsetpgrp (0, getpgrp()) )
        {
                debug( 1, _( L"Could not return shell to foreground" ) );
                wperror( L"tcsetpgrp" );

Here's what causes the bug as far as I can tell:

1. When I login on a virtual console, /bin/login calls Fish. When Fish begins
executing its process group and the process group controlling the terminal are
both the pid of the /bin/login process.

2. The ". empty.fish" line causes Fish to fork a new process. The new process
creates a new process group and takes control of the terminal under the name of
that process group.

3. When the child process finishes, the parent prcoess attempts to take back
control of the terminal by setting its controlling process group id to be its
pid.

4. Now there is a mismatch between the process group id of the Fish shell (= the
pid of the /bin/login process) and the process group id controlling the terminal
(= the pid of the Fish shell). reader_interactive_init detects the mismatch and
it thinks that it doesn't have control of the terminal, so it hangs as it waits
for control.

My fix just solves the problem in step 3 by having the parent process correctly
reassign control of the terminal to its process group.

$ uname -a
Linux anconia 2.6.39-ARCH #1 SMP PREEMPT Sat Jul 9 15:31:04 CEST 2011 i686 
Intel(R) Atom(TM) CPU N280 @ 1.66GHz GenuineIntel GNU/Linux

-- 
Adam Cozzette
Harvey Mudd College Class of 2012

------------------------------------------------------------------------------
Magic Quadrant for Content-Aware Data Loss Prevention
Research study explores the data loss prevention market. Includes in-depth
analysis on the changes within the DLP market, and the criteria used to
evaluate the strengths and weaknesses of these DLP solutions.
http://www.accelacomm.com/jaw/sfnl/114/51385063/
_______________________________________________
Fish-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to