uml: const and other tidying
[deliverable/linux.git] / arch / um / os-Linux / sigio.c
index f77ce3d6f7cc9d0ac3f4d16daf8316621720cbe4..7243f5733772b47f12f5e7f4a8b21a7a15504f60 100644 (file)
@@ -26,6 +26,7 @@
  * exitcall.
  */
 static int write_sigio_pid = -1;
+static unsigned long write_sigio_stack;
 
 /* These arrays are initialized before the sigio thread is started, and
  * the descriptors closed after it is killed.  So, it can't see them change.
@@ -69,11 +70,12 @@ static int write_sigio_thread(void *unused)
                        p = &fds->poll[i];
                        if(p->revents == 0) continue;
                        if(p->fd == sigio_private[1]){
-                               n = os_read_file(sigio_private[1], &c, sizeof(c));
+                               CATCH_EINTR(n = read(sigio_private[1], &c,
+                                                    sizeof(c)));
                                if(n != sizeof(c))
                                        printk("write_sigio_thread : "
                                               "read on socket failed, "
-                                              "err = %d\n", -n);
+                                              "err = %d\n", errno);
                                tmp = current_poll;
                                current_poll = next_poll;
                                next_poll = tmp;
@@ -86,10 +88,10 @@ static int write_sigio_thread(void *unused)
                                        (fds->used - i) * sizeof(*fds->poll));
                        }
 
-                       n = os_write_file(respond_fd, &c, sizeof(c));
+                       CATCH_EINTR(n = write(respond_fd, &c, sizeof(c)));
                        if(n != sizeof(c))
                                printk("write_sigio_thread : write on socket "
-                                      "failed, err = %d\n", -n);
+                                      "failed, err = %d\n", errno);
                }
        }
 
@@ -103,7 +105,7 @@ static int need_poll(struct pollfds *polls, int n)
        if(n <= polls->size)
                return 0;
 
-       new = um_kmalloc_atomic(n * sizeof(struct pollfd));
+       new = kmalloc(n * sizeof(struct pollfd), UM_GFP_ATOMIC);
        if(new == NULL){
                printk("need_poll : failed to allocate new pollfds\n");
                return -ENOMEM;
@@ -127,15 +129,15 @@ static void update_thread(void)
        char c;
 
        flags = set_signals(0);
-       n = os_write_file(sigio_private[0], &c, sizeof(c));
+       n = write(sigio_private[0], &c, sizeof(c));
        if(n != sizeof(c)){
-               printk("update_thread : write failed, err = %d\n", -n);
+               printk("update_thread : write failed, err = %d\n", errno);
                goto fail;
        }
 
-       n = os_read_file(sigio_private[0], &c, sizeof(c));
+       CATCH_EINTR(n = read(sigio_private[0], &c, sizeof(c)));
        if(n != sizeof(c)){
-               printk("update_thread : read failed, err = %d\n", -n);
+               printk("update_thread : read failed, err = %d\n", errno);
                goto fail;
        }
 
@@ -143,8 +145,10 @@ static void update_thread(void)
        return;
  fail:
        /* Critical section start */
-       if(write_sigio_pid != -1)
+       if (write_sigio_pid != -1) {
                os_kill_process(write_sigio_pid, 1);
+               free_stack(write_sigio_stack, 0);
+       }
        write_sigio_pid = -1;
        close(sigio_private[0]);
        close(sigio_private[1]);
@@ -229,7 +233,7 @@ static struct pollfd *setup_initial_poll(int fd)
 {
        struct pollfd *p;
 
-       p = um_kmalloc(sizeof(struct pollfd));
+       p = kmalloc(sizeof(struct pollfd), UM_GFP_KERNEL);
        if (p == NULL) {
                printk("setup_initial_poll : failed to allocate poll\n");
                return NULL;
@@ -242,7 +246,6 @@ static struct pollfd *setup_initial_poll(int fd)
 
 static void write_sigio_workaround(void)
 {
-       unsigned long stack;
        struct pollfd *p;
        int err;
        int l_write_sigio_fds[2];
@@ -292,7 +295,8 @@ static void write_sigio_workaround(void)
        memcpy(sigio_private, l_sigio_private, sizeof(l_sigio_private));
 
        write_sigio_pid = run_helper_thread(write_sigio_thread, NULL,
-                                           CLONE_FILES | CLONE_VM, &stack, 0);
+                                           CLONE_FILES | CLONE_VM,
+                                           &write_sigio_stack);
 
        if (write_sigio_pid < 0)
                goto out_clear;
@@ -355,10 +359,12 @@ out:
 
 static void sigio_cleanup(void)
 {
-       if(write_sigio_pid != -1){
-               os_kill_process(write_sigio_pid, 1);
-               write_sigio_pid = -1;
-       }
+       if (write_sigio_pid == -1)
+               return;
+
+       os_kill_process(write_sigio_pid, 1);
+       free_stack(write_sigio_stack, 0);
+       write_sigio_pid = -1;
 }
 
 __uml_exitcall(sigio_cleanup);
@@ -401,7 +407,7 @@ static int async_pty(int master, int slave)
        if((fcntl(slave, F_SETFL, flags | O_NONBLOCK) < 0))
                return -errno;
 
-       return(0);
+       return 0;
 }
 
 static void __init check_one_sigio(void (*proc)(int, int))
@@ -459,17 +465,18 @@ static void tty_output(int master, int slave)
 
        memset(buf, 0, sizeof(buf));
 
-       while(os_write_file(master, buf, sizeof(buf)) > 0) ;
+       while(write(master, buf, sizeof(buf)) > 0) ;
        if(errno != EAGAIN)
-               panic("check_sigio : write failed, errno = %d\n", errno);
-       while(((n = os_read_file(slave, buf, sizeof(buf))) > 0) && !got_sigio) ;
+               panic("tty_output : write failed, errno = %d\n", errno);
+       while(((n = read(slave, buf, sizeof(buf))) > 0) && !got_sigio) ;
 
        if(got_sigio){
                printk("Yes\n");
                pty_output_sigio = 1;
        }
-       else if(n == -EAGAIN) printk("No, enabling workaround\n");
-       else panic("check_sigio : read failed, err = %d\n", n);
+       else if(n == -EAGAIN)
+               printk("No, enabling workaround\n");
+       else panic("tty_output : read failed, err = %d\n", n);
 }
 
 static void tty_close(int master, int slave)
This page took 0.040545 seconds and 5 git commands to generate.