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