# There are a number of calls to os_* functions from code that's already # inside os-Linux, and thus can call libc directly. In most cases, the # wrappers added no value, and existed only to separate libc and kernel # headers. When the calls are under os-Linux, this is pointless. # # os_{read,write}_file do add some value, unlike the other wrappers, # namely that it retries if the corresponding read() or write() returns # -EINTR and that it handles userspace addresses properly by making sure # they are mapped, avoiding the read() or write() returning -EFAULT. # So, we need to be sure that when these calls are replaced, there is a # CATCH_EINTR added and that the buffer is kernel memory. # # In addition, the wrappers returned -errno, rather than {-1,0}, so the # replacement code needs to look at errno for the error. # # This patch also makes a number of whitespace and formatting cleanups, # plus some error path fixes around the affected code. # # os_print_error just goes away since it's replaced by perror and printk. # # os_getpid is preserved for the moment because it takes care to make # sure that the system call is executed, avoiding an old libc bug which # cached the pid of a different thread. # # etap_open needs to undo tap_open_common if a socketpair fails # Also maybe undo etap_tramp if an error came back # Split out os_set_exec_close interface change # tuntap_open needs to undo tap_open_common # clean up os_set_fd_async # Remove helper_hup and helper_pause from helper_child # Add NOCLDWAIT support # os_get_exec_close can just return the flag # ptrace_child should kill itself rather than calling _exit Index: linux-2.6.17/arch/um/os-Linux/irq.c =================================================================== --- linux-2.6.17.orig/arch/um/os-Linux/irq.c 2007-10-24 10:04:50.000000000 -0400 +++ linux-2.6.17/arch/um/os-Linux/irq.c 2007-11-19 11:56:18.000000000 -0500 @@ -36,8 +36,8 @@ int os_waiting_for_events(struct irq_fd if (n < 0) { err = -errno; if (errno != EINTR) - printk("sigio_handler: os_waiting_for_events:" - " poll returned %d, errno = %d\n", n, errno); + printk("os_waiting_for_events: poll returned %d, " + "errno = %d\n", n, errno); return err; } Index: linux-2.6.17/arch/um/os-Linux/tty.c =================================================================== --- linux-2.6.17.orig/arch/um/os-Linux/tty.c 2007-10-17 12:11:50.000000000 -0400 +++ linux-2.6.17/arch/um/os-Linux/tty.c 2007-11-19 11:56:18.000000000 -0500 @@ -1,10 +1,11 @@ -/* +/* * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) * Licensed under the GPL */ #include #include +#include #include "os.h" #include "user.h" #include "kern_util.h" @@ -26,36 +27,29 @@ static void grantpt_cb(void *arg) int get_pty(void) { struct grantpt_info info; - int fd; + int fd, err; - fd = os_open_file("/dev/ptmx", of_rdwr(OPENFLAGS()), 0); + fd = open("/dev/ptmx", O_RDWR, 0); if(fd < 0){ - printk("get_pty : Couldn't open /dev/ptmx - err = %d\n", -fd); - return(fd); + err = -errno; + printk("get_pty : Couldn't open /dev/ptmx - errno = %d\n", + errno); + return -err; } info.fd = fd; initial_thread_cb(grantpt_cb, &info); if(info.res < 0){ - printk("get_pty : Couldn't grant pty - errno = %d\n", + printk("get_pty : Couldn't grant pty - errno = %d\n", -info.err); - return(-1); + return -info.err; } if(unlockpt(fd) < 0){ + err = -errno; printk("get_pty : Couldn't unlock pty - errno = %d\n", errno); - return(-1); + return err; } - return(fd); -} -/* - * Overrides for Emacs so that we follow Linus's tabbing style. - * Emacs will notice this stuff at the end of the file and automatically - * adjust the settings for this buffer only. This must remain at the end - * of the file. - * --------------------------------------------------------------------------- - * Local variables: - * c-file-style: "linux" - * End: - */ + return fd; +} Index: linux-2.6.17/arch/um/os-Linux/tty_log.c =================================================================== --- linux-2.6.17.orig/arch/um/os-Linux/tty_log.c 2007-10-17 12:11:50.000000000 -0400 +++ linux-2.6.17/arch/um/os-Linux/tty_log.c 2007-11-19 11:56:18.000000000 -0500 @@ -59,13 +59,19 @@ int open_tty_log(void *tty, void *curren } sprintf(buf, "%s/%0u-%0u", tty_log_dir, (unsigned int) tv.tv_sec, - (unsigned int) tv.tv_usec); + (unsigned int) tv.tv_usec); - fd = os_open_file(buf, of_append(of_create(of_rdwr(OPENFLAGS()))), + /* + * O_TRUNC and O_CREAT are both specified in order to get an + * empty file regardless of whether it was already present or + * not. + */ + fd = open(buf, O_RDWR | O_TRUNC | O_CREAT, 0644); 0644); if(fd < 0){ + fd = -errno; printk("open_tty_log : couldn't open '%s', errno = %d\n", - buf, -fd); + buf, errno); } return fd; } @@ -86,7 +92,7 @@ void close_tty_log(int fd, void *tty) write(tty_log_fd, &data, sizeof(data)); return; } - os_close_file(fd); + close(fd); } static int log_chunk(int fd, const char *buf, int len)