Bug 152522

Summary: Ioctl VT_ACTIVATE cause root shell in xterm to output many useless newlines
Product: [openSUSE] SUSE Linux 10.1 Reporter: Michael Gross <mgross>
Component: X.OrgAssignee: Stefan Dirsch <sndirsch>
Status: RESOLVED FIXED QA Contact: E-mail List <xorg-maintainer-bugs>
Severity: Minor    
Priority: P5 - None CC: eich, jnelson-suse, max, sndirsch, suse-beta, werner
Version: Beta 4   
Target Milestone: ---   
Hardware: i586   
OS: Other   
Whiteboard:
Found By: L3 Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---
Attachments: backtrace of the used xterm
Proposed fix.

Description Michael Gross 2006-02-21 16:29:22 UTC
Since Beta3 I (maby before) init outputs a lot of newlines when changing to runlevel 0 or 6 (at least) and I didn't notice a bugreport about that so far.

This happens both in an xterm as well as on the shell, so I suspect the bug is located in sysvinit itself. It's more like a cosmetic problem but I think we really should fix this, it does not make a good impression.

Notice: I did not change anything of relevance here, this also happens after a fresh installation, hence it should be easily reproducible. If any information besides that is required, please ask me.
Comment 1 Michael Gross 2006-02-22 12:05:20 UTC
This problem might be connected to bug #152101 although I am not certain yet.
Comment 2 Dr. Werner Fink 2006-02-23 11:17:35 UTC
init does not write to any terminal.
Comment 3 Michael Gross 2006-02-23 11:32:54 UTC
I'll try again with B5.
Comment 4 Dr. Werner Fink 2006-02-23 17:17:29 UTC
Beside this: Do you have an environment variable "CONSOLE"
in your environment?  If so try to unset CONSOLE before
running shutdown.
Comment 5 Michael Gross 2006-02-23 17:22:36 UTC
It was an standard installation without any change to the environment. Cannot check this atm, but as soon as B5 is running I will. As mentioned this happened with B3 already (when I first noted it).
Comment 6 Michael Gross 2006-03-03 16:48:31 UTC
OK I was able to reproduce this with Beta6 and there is no $CONSOLE variable in the environment.
Comment 7 Michael Gross 2006-03-06 18:12:34 UTC
OK let's rewrite the topic a little. We know now that the actual output (printing an '\n') is done by the shell, after it receives and reads some strange input from an (yet) unknown process. This does not happen at a text console and does not happen when commanding `reboot -r now'. And it does also not happen with another shell, so this seems to be a problem with bash. Updating to the latest build with some fixed line-warp issues in libreadline unfortunately did not solve the problem. I'll attached a backtrace of the xterm we tried this on.
Comment 8 Michael Gross 2006-03-06 18:14:29 UTC
Created attachment 71437 [details]
backtrace of the used xterm
Comment 9 Dr. Werner Fink 2006-03-06 18:17:54 UTC
Beside this the problem is a nasty one bbut it does _not_
crash the system nor break the reboot or halt the system.
Therefore this is IMHO a minor problem which can resolved
if I found more free time for this problem.
Comment 10 Dr. Werner Fink 2006-03-06 18:52:09 UTC
Remark: the official interface for halt/reboot/powerdown/single user mode
is the call of shutdown and not of init.  With this is works as it should.
Comment 11 Michael Gross 2006-03-07 22:18:01 UTC
This is really resistant, it's fine with me closing it with RESO->LATER. There is also a chance it vanishes with an upcoming release. I will keep track of it.
Comment 12 Dr. Werner Fink 2006-03-08 10:54:25 UTC
Hmm ... the interesstin question is: Which program or which kernel part
is flooding stdin of the bash with Carriage Return's and why does this
not happen if shutdown is calling init.
Comment 13 Dr. Werner Fink 2006-03-15 10:32:05 UTC
Just found by Max: `chvt 1' does the same as `init 6'.  To reproduce this
open an xterm or KDE konsole, become super user, do a Ctrl-l to be at the
very first line and then execute the command

           chvt 1

after you have been switched to the first virtual console, switch back with
(Ctrl-)Alt-F7.  Btw: even the tcsh does this but you have todo, after su and
starting a tcsh as root, the chvt command and switching back twice. This was
found by me by trail and error.  The question is: who or what is feeding the
file descriptors of the bash (fd == 0) and the tcsh (fd == 16) with CR or NL
depending on the tty settings.
Comment 14 Dr. Werner Fink 2006-03-15 10:47:29 UTC
Just to note: the final cause for the newlines is the ioctl VT_ACTIVATE.
IMHO there is a problem in the console/tty driver of the kernel as shown
by a hacked chvt.c.
Comment 15 Dr. Werner Fink 2006-03-17 14:19:08 UTC
OK just to be noted if one execute

          xset r off

in other word disable the autorepeat of the Xserver, it does not happen. 
This leads me to the assumption that we see a race condition here in
which the Xserver sees the `Enter key is pressed' but never but is missed
`Enter key is released' due to the fact that the Xserver does not get
a time slice for doing this. Therefore a `sleep 1; chvt 1' will not scroll.
Comment 16 Dr. Werner Fink 2006-03-17 15:02:23 UTC
Egbert?  Is there a way to use in the Xserver the handler for saving graphic
registers during a change virtual console to switch autorepeat temporary off?
Comment 17 Egbert Eich 2006-03-17 17:53:43 UTC
The best solution would be to reset all pressed key states. I wonder why this hasn't happend with earlier versions.
Comment 18 Stefan Dirsch 2006-03-18 23:41:07 UTC
Egbert, IIRC this bug exists since years ...
Comment 19 Dr. Werner Fink 2006-03-20 11:04:49 UTC
Yep and it was always closed with WONTFIX because no one has
an idea what was the cause of this problem.  Now we _know_ the
cause and we should fix this.  Beside this it depends on the
used Xserver and the power of the CPU and/or system in other
words a typical race condition.   If it is possible to reset
the pressed key states at a `chvt' then this should be done
within the core Xserver to avoid vendor specific problems.
Comment 20 Michael Gross 2006-04-05 13:55:38 UTC
This is a bug, not an enhancement. I'm setting this to normal.
Comment 21 Dr. Werner Fink 2006-05-15 13:43:18 UTC
Ping :)
Comment 22 Michael Gross 2006-05-22 20:06:45 UTC
Pong
Comment 23 Stefan Dirsch 2007-05-12 10:42:37 UTC
JFYI, Matthias. This is a bugreport, which is assigned to Egbert/me or with Egbert/me in CC or reported by Egbert/me.
Comment 24 Jon Nelson 2007-10-09 22:59:05 UTC
pin
Comment 25 Stefan Dirsch 2007-12-02 22:00:43 UTC
Reassigning to Egbert.
Comment 26 Stefan Dirsch 2007-12-02 22:30:03 UTC
At least minor.
Comment 27 Stefan Dirsch 2008-04-19 21:21:21 UTC
Luc, could you have a look at this? It's rather annoying.
Comment 28 Egbert Eich 2008-04-20 16:32:01 UTC
(In reply to comment #27 from Stefan Dirsch)
> Luc, could you have a look at this? It's rather annoying.
> 
???
Comment 29 Stefan Dirsch 2008-04-20 18:24:54 UTC
I thought you might appreciate help here? Am I wrong? According to the comments you didn't look at this one yet.
Comment 31 Egbert Eich 2008-04-21 16:49:33 UTC
Created attachment 209388 [details]
Proposed fix.

Eating up key events before going into the idle loop upon vt switch instead of after return should remedy this problem.
Stefan, does this do the job for you?
Comment 32 Stefan Dirsch 2008-04-21 17:36:58 UTC
Hmm. I thought I could easily reproduce this issue with

  X :1 --> Ctrl-Alt-BS
  startx -- :1 --> Ctrl-Alt-BS
  xinit -- :1 --> Ctrl-Alt-BS

but now I can't any longer. :-( Werner, can you still? Michael Gross left the company a long time ago.
Comment 33 Egbert Eich 2008-04-21 18:17:04 UTC
Stefan, start X, open a terminal, become root, type 'chvt 1' in the terminal, then enter. Once on the console switch back.
You should see a bunch of newlines without this patch.
Comment 34 Stefan Dirsch 2008-04-21 21:21:34 UTC
I could finally reproduce this issue - and Egbert's patch fixes it! Applied.
Comment 35 Matthias Hopf 2008-05-14 15:43:09 UTC
Hm, this could also fix the infamous 'F7 to apps' bug. Egbert, your patch mentions 'HACK' several times, though from a first glance this looks like a very valid change.

I'd like to see that upstream, don't you agree? Maybe there is some side effect I didn't catch yet, though.