public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Joe Peterson <joe@skyrush.com>
To: Tim Connors <tim.w.connors@gmail.com>
Cc: Vegard Nossum <vegard.nossum@gmail.com>,
	Alan Cox <alan@redhat.com>, Alan Cox <alan@lxorguk.ukuu.org.uk>,
	David Newall <davidn@davidnewall.com>, Willy Tarreau <w@1wt.eu>,
	Harald Dunkel <harald.dunkel@t-online.de>,
	linux-kernel@vger.kernel.org, Ingo Molnar <mingo@elte.hu>
Subject: Re: tty session leader issue [cause now known!] (was Re: 2.6.25.3: su gets stuck for root)
Date: Sun, 06 Jul 2008 12:49:16 -0600	[thread overview]
Message-ID: <487113AC.7000300@skyrush.com> (raw)
In-Reply-To: <alpine.DEB.1.10.0807062353450.30385@scuzzie.rather.puzzling.org>

Tim Connors wrote:
> On Wed, 2 Jul 2008, Joe Peterson wrote:
> 
>> I have done some more investigation on this problem, and I am posting
>> here my results in hope that someone can point me in the right direction
>> for further investigation...
>>
>> Summary: during the initialization of a new bash shell, the terminal
>> foreground process group often reverts back to that of the parent of the
>> bash shell (after being set *to* the bash shell pgrp by bash),
>> prohibiting commands like stty from being run by the init scripts.  The
>> result is that the execution of these commands will hang until killed,
>> causing the bash prompt to not appear.  Adding a delay in the script
>> (using sleep) increases the chance of this having time to happen.

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.

> The 6 year old inspiron 4000 gets stuck at stty erase ^? .  Randomly, but
> most of the time.
> 
> All of my machines exhibit the ctrl-C being slower than ctrl-Z discussed
> elswhere (I've almost developed a habit of typing ctrl-Z kill %1 <RET>).
> Although even ctrl-Z recently has been reluctant to always work.  I wonder
> if this is the cause of dpkg recently not responding to ctrl-Z's? (debian
> bug #486222).  dpkg does respond to kill -STOP

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

> ctrl-s doesn't always work anymore.  Again, what prompted me to write this
> email, was I couldn't pause dpkg.  It's particularly unreliable at
> stopping scrolling messages at bootup, and if I press it at the wrong time
> at bootup (not a specific place - it can be starting up any number of
> scripts), something deadlocks and won't resume upon a ctrl-q.
> alt-sysrq-k is enough to kill whatever has deadlocked.  I have a feeling,
> but don't want to test on this system right now, that pressing scroll-lock
> as opposed to ctrl-q once unlocked such a stuck display.

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

> In summary, something in tty is certainly screwed.  Does anyone see a
> connection between all of these?

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

					-Joe

  parent reply	other threads:[~2008-07-06 18:49 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-02  1:31 2.6.25.3: su gets stuck for root Joe Peterson
2008-06-02  5:12 ` Harald Dunkel
2008-06-02  5:32   ` Willy Tarreau
2008-06-02  5:55     ` Joe Peterson
2008-06-02  8:10     ` Alan Cox
2008-06-02  9:01       ` David Newall
2008-06-02  9:20         ` Alan Cox
2008-06-02 10:16           ` Vegard Nossum
2008-06-02 10:39             ` Vegard Nossum
2008-06-02 10:52               ` Alan Cox
2008-06-02 10:57                 ` Vegard Nossum
2008-06-02 12:28                   ` Alan Cox
2008-06-02 14:31                     ` Vegard Nossum
2008-06-02 10:50             ` Alan Cox
2008-06-17 15:32               ` Joe Peterson
2008-06-02 15:26           ` Joe Peterson
2008-06-02 15:51             ` Alan Cox
2008-06-02 16:03               ` Joe Peterson
2008-06-04 14:43               ` Joe Peterson
2008-06-04 15:16                 ` Alan Cox
2008-06-04 16:52                   ` Joe Peterson
2008-06-04 17:10                     ` Alan Cox
2008-06-04 20:32                       ` Joe Peterson
2008-06-11 14:04                         ` Joe Peterson
2008-06-12 11:52                           ` Vegard Nossum
2008-06-14  1:49                             ` Joe Peterson
2008-06-14  7:45                               ` Vegard Nossum
2008-06-14 17:43                                 ` Joe Peterson
2008-06-14 20:34                                   ` Vegard Nossum
2008-06-14 20:52                                     ` Joe Peterson
2008-06-14 21:26                                       ` Vegard Nossum
2008-06-14 21:34                                         ` Joe Peterson
2008-07-02 18:03                                         ` tty session leader issue (was Re: 2.6.25.3: su gets stuck for root) Joe Peterson
2008-07-02 19:21                                           ` markus reichelt
2008-07-06 14:08                                           ` Tim Connors
2008-07-06 16:44                                             ` Alan Cox
2008-07-06 18:49                                             ` Joe Peterson [this message]
2008-06-02  5:42   ` 2.6.25.3: su gets stuck for root Joe Peterson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=487113AC.7000300@skyrush.com \
    --to=joe@skyrush.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=alan@redhat.com \
    --cc=davidn@davidnewall.com \
    --cc=harald.dunkel@t-online.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=tim.w.connors@gmail.com \
    --cc=vegard.nossum@gmail.com \
    --cc=w@1wt.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox