Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 1 | /* |
Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 2 | * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{linux.intel,addtoit}.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Licensed under the GPL |
| 4 | */ |
| 5 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <stdlib.h> |
Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 7 | #include <unistd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <errno.h> |
Jeff Dike | 1d2ddcf | 2006-02-07 12:58:41 -0800 | [diff] [blame] | 9 | #include <sched.h> |
Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 10 | #include <signal.h> |
| 11 | #include <termios.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <sys/ioctl.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include "chan_user.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include "os.h" |
Jeff Dike | 89fe647 | 2007-10-16 01:26:39 -0700 | [diff] [blame] | 15 | #include "um_malloc.h" |
| 16 | |
| 17 | void generic_close(int fd, void *unused) |
| 18 | { |
Jeff Dike | 8e2d10e | 2007-10-16 01:26:40 -0700 | [diff] [blame] | 19 | close(fd); |
Jeff Dike | 89fe647 | 2007-10-16 01:26:39 -0700 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | int generic_read(int fd, char *c_out, void *unused) |
| 23 | { |
| 24 | int n; |
| 25 | |
Jeff Dike | 8e2d10e | 2007-10-16 01:26:40 -0700 | [diff] [blame] | 26 | n = read(fd, c_out, sizeof(*c_out)); |
| 27 | if (n > 0) |
| 28 | return n; |
| 29 | else if (errno == EAGAIN) |
Jeff Dike | 89fe647 | 2007-10-16 01:26:39 -0700 | [diff] [blame] | 30 | return 0; |
Jeff Dike | 8e2d10e | 2007-10-16 01:26:40 -0700 | [diff] [blame] | 31 | else if (n == 0) |
Jeff Dike | 89fe647 | 2007-10-16 01:26:39 -0700 | [diff] [blame] | 32 | return -EIO; |
Jeff Dike | 8e2d10e | 2007-10-16 01:26:40 -0700 | [diff] [blame] | 33 | return -errno; |
Jeff Dike | 89fe647 | 2007-10-16 01:26:39 -0700 | [diff] [blame] | 34 | } |
| 35 | |
Jeff Dike | 8e2d10e | 2007-10-16 01:26:40 -0700 | [diff] [blame] | 36 | /* XXX Trivial wrapper around write */ |
Jeff Dike | 89fe647 | 2007-10-16 01:26:39 -0700 | [diff] [blame] | 37 | |
| 38 | int generic_write(int fd, const char *buf, int n, void *unused) |
| 39 | { |
Jeff Dike | c59dbca | 2007-10-16 01:26:42 -0700 | [diff] [blame] | 40 | int err; |
| 41 | |
| 42 | err = write(fd, buf, n); |
| 43 | if (err > 0) |
| 44 | return err; |
| 45 | else if (errno == EAGAIN) |
| 46 | return 0; |
| 47 | else if (err == 0) |
| 48 | return -EIO; |
| 49 | return -errno; |
Jeff Dike | 89fe647 | 2007-10-16 01:26:39 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | int generic_window_size(int fd, void *unused, unsigned short *rows_out, |
| 53 | unsigned short *cols_out) |
| 54 | { |
Jeff Dike | 8e2d10e | 2007-10-16 01:26:40 -0700 | [diff] [blame] | 55 | struct winsize size; |
Jeff Dike | 89fe647 | 2007-10-16 01:26:39 -0700 | [diff] [blame] | 56 | int ret; |
| 57 | |
Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 58 | if (ioctl(fd, TIOCGWINSZ, &size) < 0) |
Jeff Dike | 8e2d10e | 2007-10-16 01:26:40 -0700 | [diff] [blame] | 59 | return -errno; |
Jeff Dike | 89fe647 | 2007-10-16 01:26:39 -0700 | [diff] [blame] | 60 | |
Jeff Dike | 8e2d10e | 2007-10-16 01:26:40 -0700 | [diff] [blame] | 61 | ret = ((*rows_out != size.ws_row) || (*cols_out != size.ws_col)); |
Jeff Dike | 89fe647 | 2007-10-16 01:26:39 -0700 | [diff] [blame] | 62 | |
Jeff Dike | 8e2d10e | 2007-10-16 01:26:40 -0700 | [diff] [blame] | 63 | *rows_out = size.ws_row; |
| 64 | *cols_out = size.ws_col; |
Jeff Dike | 89fe647 | 2007-10-16 01:26:39 -0700 | [diff] [blame] | 65 | |
| 66 | return ret; |
| 67 | } |
| 68 | |
| 69 | void generic_free(void *data) |
| 70 | { |
| 71 | kfree(data); |
| 72 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
Paolo 'Blaisorblade' Giarrusso | 55c033c | 2005-11-13 16:07:11 -0800 | [diff] [blame] | 74 | int generic_console_write(int fd, const char *buf, int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | { |
Jeff Dike | ce3b642 | 2007-12-01 12:16:30 -0800 | [diff] [blame] | 76 | sigset_t old, no_sigio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | struct termios save, new; |
| 78 | int err; |
| 79 | |
Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 80 | if (isatty(fd)) { |
Jeff Dike | ce3b642 | 2007-12-01 12:16:30 -0800 | [diff] [blame] | 81 | sigemptyset(&no_sigio); |
| 82 | sigaddset(&no_sigio, SIGIO); |
| 83 | if (sigprocmask(SIG_BLOCK, &no_sigio, &old)) |
| 84 | goto error; |
| 85 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | CATCH_EINTR(err = tcgetattr(fd, &save)); |
| 87 | if (err) |
| 88 | goto error; |
| 89 | new = save; |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 90 | /* |
| 91 | * The terminal becomes a bit less raw, to handle \n also as |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | * "Carriage Return", not only as "New Line". Otherwise, the new |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 93 | * line won't start at the first column. |
| 94 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | new.c_oflag |= OPOST; |
| 96 | CATCH_EINTR(err = tcsetattr(fd, TCSAFLUSH, &new)); |
| 97 | if (err) |
| 98 | goto error; |
| 99 | } |
| 100 | err = generic_write(fd, buf, n, NULL); |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 101 | /* |
| 102 | * Restore raw mode, in any case; we *must* ignore any error apart |
| 103 | * EINTR, except for debug. |
| 104 | */ |
Jeff Dike | ce3b642 | 2007-12-01 12:16:30 -0800 | [diff] [blame] | 105 | if (isatty(fd)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | CATCH_EINTR(tcsetattr(fd, TCSAFLUSH, &save)); |
Jeff Dike | ce3b642 | 2007-12-01 12:16:30 -0800 | [diff] [blame] | 107 | sigprocmask(SIG_SETMASK, &old, NULL); |
| 108 | } |
| 109 | |
Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 110 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | error: |
Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 112 | return -errno; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | /* |
| 116 | * UML SIGWINCH handling |
| 117 | * |
Jeff Dike | 42a359e | 2007-07-15 23:38:55 -0700 | [diff] [blame] | 118 | * The point of this is to handle SIGWINCH on consoles which have host |
| 119 | * ttys and relay them inside UML to whatever might be running on the |
| 120 | * console and cares about the window size (since SIGWINCH notifies |
| 121 | * about terminal size changes). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | * |
Jeff Dike | 42a359e | 2007-07-15 23:38:55 -0700 | [diff] [blame] | 123 | * So, we have a separate thread for each host tty attached to a UML |
| 124 | * device (side-issue - I'm annoyed that one thread can't have |
| 125 | * multiple controlling ttys for the purpose of handling SIGWINCH, but |
| 126 | * I imagine there are other reasons that doesn't make any sense). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | * |
Jeff Dike | 42a359e | 2007-07-15 23:38:55 -0700 | [diff] [blame] | 128 | * SIGWINCH can't be received synchronously, so you have to set up to |
| 129 | * receive it as a signal. That being the case, if you are going to |
| 130 | * wait for it, it is convenient to sit in sigsuspend() and wait for |
| 131 | * the signal to bounce you out of it (see below for how we make sure |
| 132 | * to exit only on SIGWINCH). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | */ |
| 134 | |
| 135 | static void winch_handler(int sig) |
| 136 | { |
| 137 | } |
| 138 | |
| 139 | struct winch_data { |
| 140 | int pty_fd; |
| 141 | int pipe_fd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | static int winch_thread(void *arg) |
| 145 | { |
| 146 | struct winch_data *data = arg; |
| 147 | sigset_t sigs; |
| 148 | int pty_fd, pipe_fd; |
Jeff Dike | 8ca842c | 2007-10-16 01:27:08 -0700 | [diff] [blame] | 149 | int count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | char c = 1; |
| 151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | pty_fd = data->pty_fd; |
| 153 | pipe_fd = data->pipe_fd; |
Jeff Dike | 8ca842c | 2007-10-16 01:27:08 -0700 | [diff] [blame] | 154 | count = write(pipe_fd, &c, sizeof(c)); |
Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 155 | if (count != sizeof(c)) |
| 156 | printk(UM_KERN_ERR "winch_thread : failed to write " |
| 157 | "synchronization byte, err = %d\n", -count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 159 | /* |
| 160 | * We are not using SIG_IGN on purpose, so don't fix it as I thought to |
Bodo Stroesser | ed1b58d | 2005-09-03 15:57:24 -0700 | [diff] [blame] | 161 | * do! If using SIG_IGN, the sigsuspend() call below would not stop on |
Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 162 | * SIGWINCH. |
| 163 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
| 165 | signal(SIGWINCH, winch_handler); |
| 166 | sigfillset(&sigs); |
Bodo Stroesser | ed1b58d | 2005-09-03 15:57:24 -0700 | [diff] [blame] | 167 | /* Block all signals possible. */ |
Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 168 | if (sigprocmask(SIG_SETMASK, &sigs, NULL) < 0) { |
| 169 | printk(UM_KERN_ERR "winch_thread : sigprocmask failed, " |
| 170 | "errno = %d\n", errno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | exit(1); |
| 172 | } |
Bodo Stroesser | ed1b58d | 2005-09-03 15:57:24 -0700 | [diff] [blame] | 173 | /* In sigsuspend(), block anything else than SIGWINCH. */ |
| 174 | sigdelset(&sigs, SIGWINCH); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 176 | if (setsid() < 0) { |
| 177 | printk(UM_KERN_ERR "winch_thread : setsid failed, errno = %d\n", |
| 178 | errno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | exit(1); |
| 180 | } |
| 181 | |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 182 | if (ioctl(pty_fd, TIOCSCTTY, 0) < 0) { |
Jeff Dike | 8ca842c | 2007-10-16 01:27:08 -0700 | [diff] [blame] | 183 | printk(UM_KERN_ERR "winch_thread : TIOCSCTTY failed on " |
| 184 | "fd %d err = %d\n", pty_fd, errno); |
| 185 | exit(1); |
| 186 | } |
| 187 | |
Jeff Dike | cb8fa61 | 2007-10-16 01:27:34 -0700 | [diff] [blame] | 188 | if (tcsetpgrp(pty_fd, os_getpid()) < 0) { |
Jeff Dike | 8ca842c | 2007-10-16 01:27:08 -0700 | [diff] [blame] | 189 | printk(UM_KERN_ERR "winch_thread : tcsetpgrp failed on " |
| 190 | "fd %d err = %d\n", pty_fd, errno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | exit(1); |
| 192 | } |
| 193 | |
Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 194 | /* |
| 195 | * These are synchronization calls between various UML threads on the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | * host - since they are not different kernel threads, we cannot use |
| 197 | * kernel semaphores. We don't use SysV semaphores because they are |
Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 198 | * persistent. |
| 199 | */ |
Jeff Dike | 8ca842c | 2007-10-16 01:27:08 -0700 | [diff] [blame] | 200 | count = read(pipe_fd, &c, sizeof(c)); |
Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 201 | if (count != sizeof(c)) |
| 202 | printk(UM_KERN_ERR "winch_thread : failed to read " |
Jeff Dike | 8ca842c | 2007-10-16 01:27:08 -0700 | [diff] [blame] | 203 | "synchronization byte, err = %d\n", errno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 205 | while(1) { |
| 206 | /* |
| 207 | * This will be interrupted by SIGWINCH only, since |
Jeff Dike | 42a359e | 2007-07-15 23:38:55 -0700 | [diff] [blame] | 208 | * other signals are blocked. |
| 209 | */ |
Bodo Stroesser | ed1b58d | 2005-09-03 15:57:24 -0700 | [diff] [blame] | 210 | sigsuspend(&sigs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
Jeff Dike | 8ca842c | 2007-10-16 01:27:08 -0700 | [diff] [blame] | 212 | count = write(pipe_fd, &c, sizeof(c)); |
Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 213 | if (count != sizeof(c)) |
| 214 | printk(UM_KERN_ERR "winch_thread : write failed, " |
Jeff Dike | 8ca842c | 2007-10-16 01:27:08 -0700 | [diff] [blame] | 215 | "err = %d\n", errno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | |
Jeff Dike | 42a359e | 2007-07-15 23:38:55 -0700 | [diff] [blame] | 219 | static int winch_tramp(int fd, struct tty_struct *tty, int *fd_out, |
| 220 | unsigned long *stack_out) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | { |
| 222 | struct winch_data data; |
Jeff Dike | 1f96ddb | 2005-06-08 15:48:27 -0700 | [diff] [blame] | 223 | int fds[2], n, err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | char c; |
| 225 | |
| 226 | err = os_pipe(fds, 1, 1); |
Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 227 | if (err < 0) { |
| 228 | printk(UM_KERN_ERR "winch_tramp : os_pipe failed, err = %d\n", |
| 229 | -err); |
Jeff Dike | 1f96ddb | 2005-06-08 15:48:27 -0700 | [diff] [blame] | 230 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | data = ((struct winch_data) { .pty_fd = fd, |
Jeff Dike | 1d2ddcf | 2006-02-07 12:58:41 -0800 | [diff] [blame] | 234 | .pipe_fd = fds[1] } ); |
Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 235 | /* |
| 236 | * CLONE_FILES so this thread doesn't hold open files which are open |
Jeff Dike | 42a359e | 2007-07-15 23:38:55 -0700 | [diff] [blame] | 237 | * now, but later closed in a different thread. This is a |
| 238 | * problem with /dev/net/tun, which if held open by this |
| 239 | * thread, prevents the TUN/TAP device from being reused. |
Jeff Dike | 1d2ddcf | 2006-02-07 12:58:41 -0800 | [diff] [blame] | 240 | */ |
Jeff Dike | c439901 | 2007-07-15 23:38:56 -0700 | [diff] [blame] | 241 | err = run_helper_thread(winch_thread, &data, CLONE_FILES, stack_out); |
Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 242 | if (err < 0) { |
| 243 | printk(UM_KERN_ERR "fork of winch_thread failed - errno = %d\n", |
| 244 | -err); |
Jeff Dike | 1f96ddb | 2005-06-08 15:48:27 -0700 | [diff] [blame] | 245 | goto out_close; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | *fd_out = fds[0]; |
Jeff Dike | 8ca842c | 2007-10-16 01:27:08 -0700 | [diff] [blame] | 249 | n = read(fds[0], &c, sizeof(c)); |
Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 250 | if (n != sizeof(c)) { |
| 251 | printk(UM_KERN_ERR "winch_tramp : failed to read " |
| 252 | "synchronization byte\n"); |
Jeff Dike | 8ca842c | 2007-10-16 01:27:08 -0700 | [diff] [blame] | 253 | printk(UM_KERN_ERR "read failed, err = %d\n", errno); |
Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 254 | printk(UM_KERN_ERR "fd %d will not support SIGWINCH\n", fd); |
| 255 | err = -EINVAL; |
Jeff Dike | 1d2ddcf | 2006-02-07 12:58:41 -0800 | [diff] [blame] | 256 | goto out_close; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | } |
Eduard-Gabriel Munteanu | 89df6bf | 2007-07-15 23:38:51 -0700 | [diff] [blame] | 258 | |
| 259 | if (os_set_fd_block(*fd_out, 0)) { |
Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 260 | printk(UM_KERN_ERR "winch_tramp: failed to set thread_fd " |
| 261 | "non-blocking.\n"); |
Eduard-Gabriel Munteanu | 89df6bf | 2007-07-15 23:38:51 -0700 | [diff] [blame] | 262 | goto out_close; |
| 263 | } |
| 264 | |
| 265 | return err; |
Jeff Dike | 1f96ddb | 2005-06-08 15:48:27 -0700 | [diff] [blame] | 266 | |
| 267 | out_close: |
Jeff Dike | 8ca842c | 2007-10-16 01:27:08 -0700 | [diff] [blame] | 268 | close(fds[1]); |
| 269 | close(fds[0]); |
Jeff Dike | 1f96ddb | 2005-06-08 15:48:27 -0700 | [diff] [blame] | 270 | out: |
| 271 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | void register_winch(int fd, struct tty_struct *tty) |
| 275 | { |
Jeff Dike | 42a359e | 2007-07-15 23:38:55 -0700 | [diff] [blame] | 276 | unsigned long stack; |
| 277 | int pid, thread, count, thread_fd = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | char c = 1; |
| 279 | |
Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 280 | if (!isatty(fd)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | return; |
| 282 | |
| 283 | pid = tcgetpgrp(fd); |
Al Viro | 17e0520 | 2011-08-18 20:08:19 +0100 | [diff] [blame] | 284 | if (is_skas_winch(pid, fd, tty)) { |
| 285 | register_winch_irq(-1, fd, -1, tty, 0); |
| 286 | return; |
| 287 | } |
| 288 | |
| 289 | if (pid == -1) { |
Jeff Dike | 42a359e | 2007-07-15 23:38:55 -0700 | [diff] [blame] | 290 | thread = winch_tramp(fd, tty, &thread_fd, &stack); |
| 291 | if (thread < 0) |
| 292 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | |
Jeff Dike | 42a359e | 2007-07-15 23:38:55 -0700 | [diff] [blame] | 294 | register_winch_irq(thread_fd, fd, thread, tty, stack); |
| 295 | |
Jeff Dike | 8ca842c | 2007-10-16 01:27:08 -0700 | [diff] [blame] | 296 | count = write(thread_fd, &c, sizeof(c)); |
Jeff Dike | e99525f | 2007-10-16 01:26:41 -0700 | [diff] [blame] | 297 | if (count != sizeof(c)) |
| 298 | printk(UM_KERN_ERR "register_winch : failed to write " |
Jeff Dike | 8ca842c | 2007-10-16 01:27:08 -0700 | [diff] [blame] | 299 | "synchronization byte, err = %d\n", errno); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | } |
| 301 | } |