# This patch cleans up the uses of raw since I was playing with that code # anyway. All uses of raw and the associated uses of tcgetattr have their # return values checked. # raw now prints an error is something went wrong instead of relying on a # flag passed in from the caller. # The now argument was dropped, and all callers get TCSADRAIN rather than # possibly TCSANOW. Index: um/arch/um/drivers/fd.c =================================================================== --- um.orig/arch/um/drivers/fd.c 2004-08-10 11:32:43.000000000 -0400 +++ um/arch/um/drivers/fd.c 2004-08-10 11:45:14.000000000 -0400 @@ -7,6 +7,7 @@ #include #include #include +#include #include "user.h" #include "user_util.h" #include "chan_user.h" @@ -45,10 +46,16 @@ int fd_open(int input, int output, int primary, void *d, char **dev_out) { struct fd_chan *data = d; + int err; if(data->raw && isatty(data->fd)){ - tcgetattr(data->fd, &data->tt); - raw(data->fd, 0); + CATCH_EINTR(err = tcgetattr(data->fd, &data->tt)); + if(err) + return(err); + + err = raw(data->fd); + if(err) + return(err); } sprintf(data->str, "%d", data->fd); *dev_out = data->str; @@ -58,9 +65,13 @@ void fd_close(int fd, void *d) { struct fd_chan *data = d; + int err; if(data->raw && isatty(fd)){ - tcsetattr(fd, TCSAFLUSH, &data->tt); + CATCH_EINTR(err = tcsetattr(fd, TCSAFLUSH, &data->tt)); + if(err) + printk("Failed to restore terminal state - " + "errno = %d\n", -err); data->raw = 0; } } Index: um/arch/um/drivers/port_user.c =================================================================== --- um.orig/arch/um/drivers/port_user.c 2004-08-10 11:32:43.000000000 -0400 +++ um/arch/um/drivers/port_user.c 2004-08-10 11:45:14.000000000 -0400 @@ -76,12 +76,17 @@ int port_open(int input, int output, int primary, void *d, char **dev_out) { struct port_chan *data = d; - int fd; + int fd, err; fd = port_wait(data->kernel_data); if((fd >= 0) && data->raw){ - tcgetattr(fd, &data->tt); - raw(fd, 0); + CATCH_EINTR(err = tcgetattr(fd, &data->tt)); + if(err) + return(err); + + err = raw(fd); + if(err) + return(err); } *dev_out = data->dev; return(fd); Index: um/arch/um/drivers/pty.c =================================================================== --- um.orig/arch/um/drivers/pty.c 2004-08-10 11:32:43.000000000 -0400 +++ um/arch/um/drivers/pty.c 2004-08-10 11:45:14.000000000 -0400 @@ -38,7 +38,7 @@ { struct pty_chan *data = d; char *dev; - int fd; + int fd, err; fd = get_pty(); if(fd < 0){ @@ -46,8 +46,13 @@ return(-errno); } if(data->raw){ - tcgetattr(fd, &data->tt); - raw(fd, 0); + CATCH_EINTR(err = tcgetattr(fd, &data->tt)); + if(err) + return(err); + + err = raw(fd); + if(err) + return(err); } dev = ptsname(fd); @@ -89,13 +94,19 @@ int pty_open(int input, int output, int primary, void *d, char **dev_out) { struct pty_chan *data = d; - int fd; + int fd, err; char dev[sizeof("/dev/ptyxx\0")] = "/dev/ptyxx"; fd = getmaster(dev); - if(fd < 0) return(-errno); + if(fd < 0) + return(-errno); + + if(data->raw){ + err = raw(fd); + if(err) + return(err); + } - if(data->raw) raw(fd, 0); if(data->announce) (*data->announce)(dev, data->dev); sprintf(data->dev_name, "%s", dev); Index: um/arch/um/drivers/tty.c =================================================================== --- um.orig/arch/um/drivers/tty.c 2004-08-10 11:32:43.000000000 -0400 +++ um/arch/um/drivers/tty.c 2004-08-10 11:45:14.000000000 -0400 @@ -41,13 +41,18 @@ int tty_open(int input, int output, int primary, void *d, char **dev_out) { struct tty_chan *data = d; - int fd; + int fd, err; fd = os_open_file(data->dev, of_set_rw(OPENFLAGS(), input, output), 0); if(fd < 0) return(fd); if(data->raw){ - tcgetattr(fd, &data->tt); - raw(fd, 0); + CATCH_EINTR(err = tcgetattr(fd, &data->tt)); + if(err) + return(err); + + err = raw(fd); + if(err) + return(err); } *dev_out = data->dev; Index: um/arch/um/drivers/xterm.c =================================================================== --- um.orig/arch/um/drivers/xterm.c 2004-08-10 11:32:43.000000000 -0400 +++ um/arch/um/drivers/xterm.c 2004-08-10 11:45:14.000000000 -0400 @@ -83,6 +83,7 @@ " are 'xterm=gnome-terminal,-t,-x'.\n\n" ); +/* XXX This badly needs some cleaning up in the error paths */ int xterm_open(int input, int output, int primary, void *d, char **dev_out) { struct xterm_chan *data = d; @@ -141,8 +142,19 @@ goto out; } - tcgetattr(new, &data->tt); - if(data->raw) raw(new, 0); + CATCH_EINTR(err = tcgetattr(new, &data->tt)); + if(err){ + new = err; + goto out; + } + + if(data->raw){ + err = raw(new); + if(err){ + new = err; + goto out; + } + } data->pid = pid; *dev_out = NULL; Index: um/arch/um/include/user_util.h =================================================================== --- um.orig/arch/um/include/user_util.h 2004-08-10 11:45:13.000000000 -0400 +++ um/arch/um/include/user_util.h 2004-08-10 11:45:14.000000000 -0400 @@ -89,9 +89,7 @@ extern int can_do_skas(void); extern void arch_init_thread(void); extern int setjmp_wrapper(void (*proc)(void *, void *), ...); - -extern int __raw(int fd, int complain, int now); -#define raw(fd, complain) __raw((fd), (complain), 1) +extern int raw(int fd); #endif Index: um/arch/um/kernel/sigio_user.c =================================================================== --- um.orig/arch/um/kernel/sigio_user.c 2004-08-10 11:45:13.000000000 -0400 +++ um/arch/um/kernel/sigio_user.c 2004-08-10 11:45:14.000000000 -0400 @@ -69,7 +69,7 @@ } /* Not now, but complain so we now where we failed. */ - err = __raw(master, 1, 0); + err = raw(master); if (err < 0) panic("check_sigio : __raw failed, errno = %d\n", -err); Index: um/arch/um/kernel/user_util.c =================================================================== --- um.orig/arch/um/kernel/user_util.c 2004-08-10 11:45:13.000000000 -0400 +++ um/arch/um/kernel/user_util.c 2004-08-10 11:45:14.000000000 -0400 @@ -118,25 +118,23 @@ } } -int __raw(int fd, int complain, int now) +int raw(int fd) { struct termios tt; - int err, when; + int err; CATCH_EINTR(err = tcgetattr(fd, &tt)); if (err < 0) { - if (complain) - printk("tcgetattr failed, errno = %d\n", errno); + printk("tcgetattr failed, errno = %d\n", errno); return(-errno); } cfmakeraw(&tt); - when = (now ? TCSANOW : TCSADRAIN); - CATCH_EINTR(err = tcsetattr(fd, when, &tt)); + CATCH_EINTR(err = tcsetattr(fd, TCSADRAIN, &tt)); if (err < 0) { - if (complain) - printk("tcsetattr failed, errno = %d\n", errno); + printk("tcsetattr failed, errno = %d\n", errno); + return(-errno); } /* XXX tcsetattr could have applied only some changes