Re: tty session leader issue [cause now known!] (was Re: 2.6.25.3: su gets stuck for root)

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Joe Peterson
Date: Sunday, July 6, 2008 - 11:49 am

Tim Connors wrote:

I have done more investigation, and I now know the cause of the
bash/stty problem.  It appears to be a race condition in bash (well,
between two different bash shells, actually).  I saw a post from a while
back about something similar by Ingo Molnar, so I have copied him here too.

Here is the ps tree of the test case where stty has hung:

 4704 ?        S      0:00  \_ xterm
 4706 pts/3    Ss     0:00  |   \_ -bash
 4739 pts/3    S      0:00  |       \_ su
 4742 pts/3    S      0:00  |           \_ bash
 4746 pts/3    S+     0:00  |               \_ su foo
 4747 pts/3    S      0:00  |                   \_ bash
 4752 pts/3    T      0:00  |                       \_ stty -ixany

What should happen is: when "su foo" (4746) is run, it spawns a bash
shell (4747) that then makes itself the session leader when it
initializes its job control.  The stty command (in the child bash's
.bashrc) will then be able to work (and not hang).

However, the hang happens when the parent bash (4742) interferes by
reverting the tty session leader back to its child (the "su foo"
process: 4746) shortly after the child bash (4747) becomes the leader.
The parent does this when it calls
execute_command_internal()->stop_pipeline()->give_terminal_to().  This
seems to happen at a slightly random time, making the issue intermittent
- it depends which one wins the race.

In summary, when the bug does *not* occur, here is the approximate
sequence (note I am :

1) parent bash (4742) runs 'su foo' (4746)
2) parent bash sets tty leader to 'su' (4746)
3) child bash (4747) initializes and sets itself to be the leader
4) stty command in .bashrc runs successfully

When the bug occurs, here is the sequence:

1) parent bash (4742) runs 'su foo' (4746)
2) child bash (4747) initializes and sets itself to be the leader
3) parent bash sets tty leader *back* to 'su' (4746)
4) stty command runs and fails/hangs because its parent is not leader

The various calls to tcsetpgrp() that do this are interleaved from the
two bash processes, and sometimes the parent does it slightly *after*
the child bash initializes job control - that's when the problem happens.

I have not looked further to find a solution (but it's a great start to
know the cause...!).  Any further help is welcome.


I doubt that this is related.  See the following thread for more info on
this:

	http://marc.info/?l=linux-kernel&m=121528829718840&w=2


Hmm, not sure; I have not seen that behavior.


I doubt there is a connection between the bash issue and what you are
seeing with ctrl-C/ctrl-S, etc.

					-Joe
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: 2.6.25.3: su gets stuck for root, Joe Peterson, (Sun Jun 1, 6:31 pm)
Re: 2.6.25.3: su gets stuck for root, Harald Dunkel, (Sun Jun 1, 10:12 pm)
Re: 2.6.25.3: su gets stuck for root, Willy Tarreau, (Sun Jun 1, 10:32 pm)
Re: 2.6.25.3: su gets stuck for root, Joe Peterson, (Sun Jun 1, 10:42 pm)
Re: 2.6.25.3: su gets stuck for root, Joe Peterson, (Sun Jun 1, 10:55 pm)
Re: 2.6.25.3: su gets stuck for root, Alan Cox, (Mon Jun 2, 1:10 am)
Re: 2.6.25.3: su gets stuck for root, David Newall, (Mon Jun 2, 2:01 am)
Re: 2.6.25.3: su gets stuck for root, Alan Cox, (Mon Jun 2, 2:20 am)
Re: 2.6.25.3: su gets stuck for root, Vegard Nossum, (Mon Jun 2, 3:16 am)
Re: 2.6.25.3: su gets stuck for root, Vegard Nossum, (Mon Jun 2, 3:39 am)
Re: 2.6.25.3: su gets stuck for root, Alan Cox, (Mon Jun 2, 3:50 am)
Re: 2.6.25.3: su gets stuck for root, Alan Cox, (Mon Jun 2, 3:52 am)
Re: 2.6.25.3: su gets stuck for root, Vegard Nossum, (Mon Jun 2, 3:57 am)
Re: 2.6.25.3: su gets stuck for root, Alan Cox, (Mon Jun 2, 5:28 am)
Re: 2.6.25.3: su gets stuck for root, Vegard Nossum, (Mon Jun 2, 7:31 am)
Re: 2.6.25.3: su gets stuck for root, Joe Peterson, (Mon Jun 2, 8:26 am)
Re: 2.6.25.3: su gets stuck for root, Alan Cox, (Mon Jun 2, 8:51 am)
Re: 2.6.25.3: su gets stuck for root, Joe Peterson, (Mon Jun 2, 9:03 am)
Re: 2.6.25.3: su gets stuck for root, Joe Peterson, (Wed Jun 4, 7:43 am)
Re: 2.6.25.3: su gets stuck for root, Alan Cox, (Wed Jun 4, 8:16 am)
Re: 2.6.25.3: su gets stuck for root, Joe Peterson, (Wed Jun 4, 9:52 am)
Re: 2.6.25.3: su gets stuck for root, Alan Cox, (Wed Jun 4, 10:10 am)
Re: 2.6.25.3: su gets stuck for root, Joe Peterson, (Wed Jun 4, 1:32 pm)
Re: 2.6.25.3: su gets stuck for root, Joe Peterson, (Wed Jun 11, 7:04 am)
Re: 2.6.25.3: su gets stuck for root, Vegard Nossum, (Thu Jun 12, 4:52 am)
Re: 2.6.25.3: su gets stuck for root, Joe Peterson, (Fri Jun 13, 6:49 pm)
Re: 2.6.25.3: su gets stuck for root, Vegard Nossum, (Sat Jun 14, 12:45 am)
Re: 2.6.25.3: su gets stuck for root, Joe Peterson, (Sat Jun 14, 10:43 am)
Re: 2.6.25.3: su gets stuck for root, Vegard Nossum, (Sat Jun 14, 1:34 pm)
Re: 2.6.25.3: su gets stuck for root, Joe Peterson, (Sat Jun 14, 1:52 pm)
Re: 2.6.25.3: su gets stuck for root, Vegard Nossum, (Sat Jun 14, 2:26 pm)
Re: 2.6.25.3: su gets stuck for root, Joe Peterson, (Sat Jun 14, 2:34 pm)
Re: 2.6.25.3: su gets stuck for root, Joe Peterson, (Tue Jun 17, 8:32 am)
Re: tty session leader issue [cause now known!] (was Re: 2 ..., Joe Peterson, (Sun Jul 6, 11:49 am)