]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - arch/um/drivers/chan_user.c
Merge branch 'x86-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[mv-sheeva.git] / arch / um / drivers / chan_user.c
index d29e56d8ced462764ecf721dbaf97af9d399908c..cfeb3f4a44afc0ef9cb6a5edf5e08d0d81ec32a1 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
  * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com)
  * Licensed under the GPL
  */
@@ -11,6 +11,7 @@
 #include <termios.h>
 #include <sys/ioctl.h>
 #include "chan_user.h"
+#include "kern_constants.h"
 #include "os.h"
 #include "um_malloc.h"
 #include "user.h"
@@ -74,27 +75,40 @@ void generic_free(void *data)
 
 int generic_console_write(int fd, const char *buf, int n)
 {
+       sigset_t old, no_sigio;
        struct termios save, new;
        int err;
 
        if (isatty(fd)) {
+               sigemptyset(&no_sigio);
+               sigaddset(&no_sigio, SIGIO);
+               if (sigprocmask(SIG_BLOCK, &no_sigio, &old))
+                       goto error;
+
                CATCH_EINTR(err = tcgetattr(fd, &save));
                if (err)
                        goto error;
                new = save;
-               /* The terminal becomes a bit less raw, to handle \n also as
+               /*
+                * The terminal becomes a bit less raw, to handle \n also as
                 * "Carriage Return", not only as "New Line". Otherwise, the new
-                * line won't start at the first column.*/
+                * line won't start at the first column.
+                */
                new.c_oflag |= OPOST;
                CATCH_EINTR(err = tcsetattr(fd, TCSAFLUSH, &new));
                if (err)
                        goto error;
        }
        err = generic_write(fd, buf, n, NULL);
-       /* Restore raw mode, in any case; we *must* ignore any error apart
-        * EINTR, except for debug.*/
-       if (isatty(fd))
+       /*
+        * 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));
+               sigprocmask(SIG_SETMASK, &old, NULL);
+       }
+
        return err;
 error:
        return -errno;
@@ -134,12 +148,12 @@ static int winch_thread(void *arg)
        struct winch_data *data = arg;
        sigset_t sigs;
        int pty_fd, pipe_fd;
-       int count, err;
+       int count;
        char c = 1;
 
        pty_fd = data->pty_fd;
        pipe_fd = data->pipe_fd;
-       count = os_write_file(pipe_fd, &c, sizeof(c));
+       count = write(pipe_fd, &c, sizeof(c));
        if (count != sizeof(c))
                printk(UM_KERN_ERR "winch_thread : failed to write "
                       "synchronization byte, err = %d\n", -count);
@@ -167,10 +181,15 @@ static int winch_thread(void *arg)
                exit(1);
        }
 
-       err = os_new_tty_pgrp(pty_fd, os_getpid());
-       if (err < 0) {
-               printk(UM_KERN_ERR "winch_thread : new_tty_pgrp failed on "
-                      "fd %d err = %d\n", pty_fd, -err);
+       if (ioctl(pty_fd, TIOCSCTTY, 0) < 0) {
+               printk(UM_KERN_ERR "winch_thread : TIOCSCTTY failed on "
+                      "fd %d err = %d\n", pty_fd, errno);
+               exit(1);
+       }
+
+       if (tcsetpgrp(pty_fd, os_getpid()) < 0) {
+               printk(UM_KERN_ERR "winch_thread : tcsetpgrp failed on "
+                      "fd %d err = %d\n", pty_fd, errno);
                exit(1);
        }
 
@@ -180,10 +199,10 @@ static int winch_thread(void *arg)
         * kernel semaphores. We don't use SysV semaphores because they are
         * persistent.
         */
-       count = os_read_file(pipe_fd, &c, sizeof(c));
+       count = read(pipe_fd, &c, sizeof(c));
        if (count != sizeof(c))
                printk(UM_KERN_ERR "winch_thread : failed to read "
-                      "synchronization byte, err = %d\n", -count);
+                      "synchronization byte, err = %d\n", errno);
 
        while(1) {
                /*
@@ -192,10 +211,10 @@ static int winch_thread(void *arg)
                 */
                sigsuspend(&sigs);
 
-               count = os_write_file(pipe_fd, &c, sizeof(c));
+               count = write(pipe_fd, &c, sizeof(c));
                if (count != sizeof(c))
                        printk(UM_KERN_ERR "winch_thread : write failed, "
-                              "err = %d\n", -count);
+                              "err = %d\n", errno);
        }
 }
 
@@ -229,11 +248,11 @@ static int winch_tramp(int fd, struct tty_struct *tty, int *fd_out,
        }
 
        *fd_out = fds[0];
-       n = os_read_file(fds[0], &c, sizeof(c));
+       n = read(fds[0], &c, sizeof(c));
        if (n != sizeof(c)) {
                printk(UM_KERN_ERR "winch_tramp : failed to read "
                       "synchronization byte\n");
-               printk(UM_KERN_ERR "read failed, err = %d\n", -n);
+               printk(UM_KERN_ERR "read failed, err = %d\n", errno);
                printk(UM_KERN_ERR "fd %d will not support SIGWINCH\n", fd);
                err = -EINVAL;
                goto out_close;
@@ -248,8 +267,8 @@ static int winch_tramp(int fd, struct tty_struct *tty, int *fd_out,
        return err;
 
  out_close:
-       os_close_file(fds[1]);
-       os_close_file(fds[0]);
+       close(fds[1]);
+       close(fds[0]);
  out:
        return err;
 }
@@ -264,17 +283,16 @@ void register_winch(int fd, struct tty_struct *tty)
                return;
 
        pid = tcgetpgrp(fd);
-       if (!CHOOSE_MODE_PROC(is_tracer_winch, is_skas_winch, pid, fd, tty) &&
-           (pid == -1)) {
+       if (!is_skas_winch(pid, fd, tty) && (pid == -1)) {
                thread = winch_tramp(fd, tty, &thread_fd, &stack);
                if (thread < 0)
                        return;
 
                register_winch_irq(thread_fd, fd, thread, tty, stack);
 
-               count = os_write_file(thread_fd, &c, sizeof(c));
+               count = write(thread_fd, &c, sizeof(c));
                if (count != sizeof(c))
                        printk(UM_KERN_ERR "register_winch : failed to write "
-                              "synchronization byte, err = %d\n", -count);
+                              "synchronization byte, err = %d\n", errno);
        }
 }