All of lore.kernel.org
 help / color / mirror / Atom feed
* [uml-devel] tcsetattr returning -1, errno = EINTR
@ 2004-08-04  8:17 Matt Clay
  2004-08-24 15:35 ` BlaisorBlade
  0 siblings, 1 reply; 2+ messages in thread
From: Matt Clay @ 2004-08-04  8:17 UTC (permalink / raw)
  To: UML Devel

[-- Attachment #1: Type: text/plain, Size: 4077 bytes --]

While booting UML in skas mode, I've noticed occasional glitches in the 
console output during the boot process.  At first I thought this was related 
to bug #260111, but now that Allen Chan has found the cause, I'm still 
having this problem after using the move_console_write patch.

Sometimes the console output shows up like this:

<snip>
NET4: Linux TCP/IP 1.0 for NET4.0
                                  IP Protocols: ICMP, UDP, TCP
IP: routing cache hash table of 512 buckets, 4Kbytes
<snip>

I've tracked this back to calls to tcsetattr failing in 
generic_console_write.  It returns -1, and sets errno to 4 (EINTR).  I don't 
know if failed calls should be restarted or not, but I'm pretty sure 
ignoring the errors isn't a good idea.

Since the problem is intermittent, I created a GDB command file to automate 
my testing.  I've attached the command file, should you want to try this 
yourself.

Here's output from one of my sessions (yes, running it without a root image 
is the intent, the problem is visible before you get that far):

GNU gdb 6.1.1
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i486-slackware-linux"...Using host libthread_db 
library "/lib/libthread_db.so.1".

(gdb) source watch-tcsetattr.txt
0xa01130f0 <tcsetattr>: 0x83e58955
Breakpoint 1 at 0xa0113134: file string.h, line 486.
Breakpoint 2 at 0xa000b707: file panic.c, line 60.
Checking for the skas3 patch in the host...found
Checking for /proc/mm...found
Checking for /dev/anon on the host...Not available (open failed with errno 2)
Linux version 2.4.26-2um (matt@aida) (gcc version 3.3.4) #8 Wed Aug 4 
00:09:08 PDT 2004
On node 0 totalpages: 8192
zone(0): 8192 pages.
zone(1): 0 pages.
zone(2): 0 pages.
Kernel command line: con=xterm root=/dev/ubd0
Calibrating delay loop... 3322.67 BogoMIPS
Memory: 30152k available
Dentry cache hash table entries: 4096 (order: 3, 32768 bytes)
Inode cache hash table entries: 2048 (order: 2, 16384 bytes)
Mount cache hash table entries: 512 (order: 0, 4096 bytes)
Buffer cache hash table entries: 1024 (order: 0, 4096 bytes)
Page-cache hash table entries: 8192 (order: 3, 32768 bytes)
Checking for host processor cmov support...Yes
Checking for host processor xmm support...No
Checking that ptrace can change system call numbers...OK
Checking that host ptys support output SIGIO...Yes
Checking that host ptys support SIGIO on close...No, enabling workaround
POSIX conformance testing by UNIFIX
Linux NET4.0 for Linux 2.4
Based upon Swansea University Computer Society NET3.039
Initializing RT netlink socket
Starting kswapd
pty: 256 Unix98 ptys configured
SLIP: version 0.8.4-NET3.019-NEWTTY (dynamic channels, max=256).
loop: loaded (max 8 devices)
PPP generic driver version 2.4.2
Universal TUN/TAP device driver 1.5 (C)1999-2002 Maxim Krasnyansky
Initializing software serial port version 1
mconsole (version 2) initialized on /home/matt/.uml/kdiP2e/mconsole
unable to open root_fs for validation
ubd : Synchronous mode
Initializing stdio console driver
  *** tcsetattr failed, returned = -1, errno = 4 ***
  *** tcsetattr failed, returned = -1, errno = 4 ***
  *** tcsetattr failed, returned = -1, errno = 4 ***
  *** tcsetattr failed, returned = -1, errno = 4 ***
  *** tcsetattr failed, returned = -1, errno = 4 ***
  *** tcsetattr failed, returned = -1, errno = 4 ***
  *** tcsetattr failed, returned = -1, errno = 4 ***

Breakpoint 2, panic (fmt=0xa0162440 "VFS: Unable to mount root fs on %s") at 
panic.c:60
60              bust_spinlocks(1);
(gdb) c
Continuing.
  *** tcsetattr failed, returned = -1, errno = 4 ***
  *** tcsetattr failed, returned = -1, errno = 4 ***

Breakpoint 2, panic (fmt=0xa015e8ea "Segfault with no mm") at panic.c:60
60              bust_spinlocks(1);
(gdb) c
Continuing.


Program exited with code 01.
(gdb) q

[-- Attachment #2: watch-tcsetattr.txt --]
[-- Type: text/plain, Size: 1165 bytes --]

# These GDB commands should make watching tcsetattr failures much easier.  
# You can use them with UML in skas mode just by doing "gdb linux".  No 
# arguments are needed to demonstrate the problem.
#
# Pass signals through that UML uses.
handle SIGSEGV pass nostop noprint
handle SIGUSR1 pass nostop noprint
# Find out where tcsetattr is and try to guess where the breakpoint should 
# go.  We want the breakpoint just before tcsetattr returns.  You can always
# set it manually if this doesn't work.
x tcsetattr
set $tcsetattr_start = $_
set $tcsetattr_ret = $tcsetattr_start+17
# Set our breakpoint to run after a failed call to tcsetattr.  This should
# trigger just before tcsetattr returns with a non-zero return value.
break *$tcsetattr_ret
condition 1 $eax != 0
commands 1
silent
printf " *** tcsetattr failed, returned = %d, errno = %d *** \n", $eax, errno
c
end
# Break on panic so we don't lose our xterm when the kernel panics, which it
# should do as long as you run it without any arguments.
break panic
# Ok, time to run our test.  You don't have to use an xterm, but it will
# keep the error messages from printing out on your console.
r con=xterm

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [uml-devel] tcsetattr returning -1, errno = EINTR
  2004-08-04  8:17 [uml-devel] tcsetattr returning -1, errno = EINTR Matt Clay
@ 2004-08-24 15:35 ` BlaisorBlade
  0 siblings, 0 replies; 2+ messages in thread
From: BlaisorBlade @ 2004-08-24 15:35 UTC (permalink / raw)
  To: user-mode-linux-devel; +Cc: Matt Clay

[-- Attachment #1: Type: text/plain, Size: 1224 bytes --]

Alle 10:17, mercoledì 4 agosto 2004, Matt Clay ha scritto:
> While booting UML in skas mode, I've noticed occasional glitches in the
> console output during the boot process.  At first I thought this was
> related to bug #260111, but now that Allen Chan has found the cause, I'm
> still having this problem after using the move_console_write patch.
>
> Sometimes the console output shows up like this:
>
> <snip>
> NET4: Linux TCP/IP 1.0 for NET4.0
>                                   IP Protocols: ICMP, UDP, TCP
> IP: routing cache hash table of 512 buckets, 4Kbytes
> <snip>
>
> I've tracked this back to calls to tcsetattr failing in
> generic_console_write.  It returns -1, and sets errno to 4 (EINTR).  I
> don't know if failed calls should be restarted or not, but I'm pretty sure
> ignoring the errors isn't a good idea.
Yes, it should be restarted.

For avoiding too much boilerplate in such cases, see the CATCH_EINTR macro 
added in the catch-eintr patch (included in the late 2.4 and 2.6 -um trees, 
see the changelogs for the links). See the attached code, and give an opinion 
- I'm not sure it is the exact one.
-- 
Paolo Giarrusso, aka Blaisorblade
Linux registered user n. 292729

[-- Attachment #2: uml-catch_eintr_generic_console_write.patch --]
[-- Type: text/x-diff, Size: 1542 bytes --]



Signed-off-by: Paolo 'Blaisorblade' Giarrusso <blaisorblade_spam@yahoo.it>
---

 uml-linux-2.6.7-paolo/arch/um/drivers/chan_user.c |   21 +++++++++++++++------
 1 files changed, 15 insertions(+), 6 deletions(-)

diff -puN arch/um/drivers/chan_user.c~catch_eintr_generic_console_write arch/um/drivers/chan_user.c
--- uml-linux-2.6.7/arch/um/drivers/chan_user.c~catch_eintr_generic_console_write	2004-08-24 17:13:31.000000000 +0200
+++ uml-linux-2.6.7-paolo/arch/um/drivers/chan_user.c	2004-08-24 17:30:22.000000000 +0200
@@ -31,23 +31,32 @@ struct winch_data {
 	int close_me;
 };
 
-/* XXX This breaks horribly (by hanging UML) when moved to chan_kern.c - 
- * needs investigation
- */
 int generic_console_write(int fd, const char *buf, int n, void *unused)
 {
 	struct termios save, new;
 	int err;
 
 	if(isatty(fd)){
-		tcgetattr(fd, &save);
+		CATCH_EINTR(err = tcgetattr(fd, &save));
+		if (err)
+			goto error;
 		new = save;
+		/*The terminal becomes a bit less raw, to handle \n
+		 * also as "Carriage Return", not only as "New Line".*/
 		new.c_oflag |= OPOST;
-		tcsetattr(fd, TCSAFLUSH, &new);
+		CATCH_EINTR(err = tcsetattr(fd, TCSAFLUSH, &new));
+		if (err)
+			goto error;
 	}
 	err = generic_write(fd, buf, n, NULL);
-	if(isatty(fd)) tcsetattr(fd, TCSAFLUSH, &save);
+	/*Restore raw mode, in any case; we *must* ignore any error
+	 * apart EINTR, except for debug.*/
+	if(isatty(fd))
+		CATCH_EINTR(tcsetattr(fd, TCSAFLUSH, &save));
+out:
 	return(err);
+error:
+	return(-errno);
 }
 
 static int winch_thread(void *arg)
_

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-08-29 21:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-08-04  8:17 [uml-devel] tcsetattr returning -1, errno = EINTR Matt Clay
2004-08-24 15:35 ` BlaisorBlade

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.