blob: 6443809cfdfbc1e8b4ecd695ffe51bc35dbfbdfa [file] [log] [blame]
Jeff Dike8e367062006-03-27 01:14:32 -08001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#include <unistd.h>
7#include <stdlib.h>
8#include <termios.h>
9#include <pty.h>
10#include <signal.h>
Jeff Dikec65badb2007-05-06 14:51:06 -070011#include <fcntl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <errno.h>
13#include <string.h>
14#include <sched.h>
15#include <sys/socket.h>
16#include <sys/poll.h>
17#include "init.h"
18#include "user.h"
19#include "kern_util.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include "sigio.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include "os.h"
Paolo 'Blaisorblade' Giarrussoc13e5692006-10-19 23:28:20 -070022#include "um_malloc.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Jeff Dikef206aab2006-03-27 01:14:33 -080024/* Protected by sigio_lock(), also used by sigio_cleanup, which is an
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 * exitcall.
26 */
27static int write_sigio_pid = -1;
Jeff Dikec4399012007-07-15 23:38:56 -070028static unsigned long write_sigio_stack;
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30/* These arrays are initialized before the sigio thread is started, and
31 * the descriptors closed after it is killed. So, it can't see them change.
32 * On the UML side, they are changed under the sigio_lock.
33 */
Jeff Dike5f4e8fd2006-03-27 01:14:40 -080034#define SIGIO_FDS_INIT {-1, -1}
35
36static int write_sigio_fds[2] = SIGIO_FDS_INIT;
37static int sigio_private[2] = SIGIO_FDS_INIT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39struct pollfds {
40 struct pollfd *poll;
41 int size;
42 int used;
43};
44
45/* Protected by sigio_lock(). Used by the sigio thread, but the UML thread
46 * synchronizes with it.
47 */
Jeff Dike19bdf042006-09-25 23:33:04 -070048static struct pollfds current_poll;
49static struct pollfds next_poll;
50static struct pollfds all_sigio_fds;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52static int write_sigio_thread(void *unused)
53{
54 struct pollfds *fds, tmp;
55 struct pollfd *p;
56 int i, n, respond_fd;
57 char c;
58
Jeff Dikecd2ee4a2005-05-05 16:15:32 -070059 signal(SIGWINCH, SIG_IGN);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 fds = &current_poll;
61 while(1){
62 n = poll(fds->poll, fds->used, -1);
63 if(n < 0){
64 if(errno == EINTR) continue;
65 printk("write_sigio_thread : poll returned %d, "
66 "errno = %d\n", n, errno);
67 }
68 for(i = 0; i < fds->used; i++){
69 p = &fds->poll[i];
70 if(p->revents == 0) continue;
71 if(p->fd == sigio_private[1]){
Jeff Dikea61f3342007-05-06 14:51:35 -070072 CATCH_EINTR(n = read(sigio_private[1], &c,
73 sizeof(c)));
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 if(n != sizeof(c))
75 printk("write_sigio_thread : "
Jeff Dike19bdf042006-09-25 23:33:04 -070076 "read on socket failed, "
Jeff Dikea61f3342007-05-06 14:51:35 -070077 "err = %d\n", errno);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 tmp = current_poll;
79 current_poll = next_poll;
80 next_poll = tmp;
81 respond_fd = sigio_private[1];
82 }
83 else {
84 respond_fd = write_sigio_fds[1];
85 fds->used--;
86 memmove(&fds->poll[i], &fds->poll[i + 1],
87 (fds->used - i) * sizeof(*fds->poll));
88 }
89
Jeff Dikea61f3342007-05-06 14:51:35 -070090 CATCH_EINTR(n = write(respond_fd, &c, sizeof(c)));
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 if(n != sizeof(c))
Jeff Dike19bdf042006-09-25 23:33:04 -070092 printk("write_sigio_thread : write on socket "
Jeff Dikea61f3342007-05-06 14:51:35 -070093 "failed, err = %d\n", errno);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 }
95 }
Jeff Dike1b57e9c2006-01-06 00:18:49 -080096
97 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098}
99
Jeff Dike19bdf042006-09-25 23:33:04 -0700100static int need_poll(struct pollfds *polls, int n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101{
Jeff Dike838e56a2007-02-16 01:27:21 -0800102 struct pollfd *new;
103
104 if(n <= polls->size)
Jeff Dike19bdf042006-09-25 23:33:04 -0700105 return 0;
Jeff Dike838e56a2007-02-16 01:27:21 -0800106
Jeff Dikee4c4bf92007-07-15 23:38:56 -0700107 new = kmalloc(n * sizeof(struct pollfd), UM_GFP_ATOMIC);
Jeff Dike838e56a2007-02-16 01:27:21 -0800108 if(new == NULL){
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 printk("need_poll : failed to allocate new pollfds\n");
Jeff Dike19bdf042006-09-25 23:33:04 -0700110 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 }
Jeff Dike838e56a2007-02-16 01:27:21 -0800112
113 memcpy(new, polls->poll, polls->used * sizeof(struct pollfd));
114 kfree(polls->poll);
115
116 polls->poll = new;
Jeff Dike19bdf042006-09-25 23:33:04 -0700117 polls->size = n;
Jeff Dike19bdf042006-09-25 23:33:04 -0700118 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119}
120
121/* Must be called with sigio_lock held, because it's needed by the marked
Jeff Dike19bdf042006-09-25 23:33:04 -0700122 * critical section.
123 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124static void update_thread(void)
125{
126 unsigned long flags;
127 int n;
128 char c;
129
130 flags = set_signals(0);
Jeff Dikea61f3342007-05-06 14:51:35 -0700131 n = write(sigio_private[0], &c, sizeof(c));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 if(n != sizeof(c)){
Jeff Dikea61f3342007-05-06 14:51:35 -0700133 printk("update_thread : write failed, err = %d\n", errno);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 goto fail;
135 }
136
Jeff Dikea61f3342007-05-06 14:51:35 -0700137 CATCH_EINTR(n = read(sigio_private[0], &c, sizeof(c)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 if(n != sizeof(c)){
Jeff Dikea61f3342007-05-06 14:51:35 -0700139 printk("update_thread : read failed, err = %d\n", errno);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 goto fail;
141 }
142
143 set_signals(flags);
144 return;
145 fail:
146 /* Critical section start */
Jeff Dikec4399012007-07-15 23:38:56 -0700147 if (write_sigio_pid != -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 os_kill_process(write_sigio_pid, 1);
Jeff Dikec4399012007-07-15 23:38:56 -0700149 free_stack(write_sigio_stack, 0);
150 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 write_sigio_pid = -1;
Jeff Dike8e367062006-03-27 01:14:32 -0800152 close(sigio_private[0]);
153 close(sigio_private[1]);
154 close(write_sigio_fds[0]);
155 close(write_sigio_fds[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 /* Critical section end */
157 set_signals(flags);
158}
159
Jeff Dike19bdf042006-09-25 23:33:04 -0700160int add_sigio_fd(int fd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161{
Jeff Dike19bdf042006-09-25 23:33:04 -0700162 struct pollfd *p;
163 int err = 0, i, n;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
165 sigio_lock();
Jeff Dike19bdf042006-09-25 23:33:04 -0700166 for(i = 0; i < all_sigio_fds.used; i++){
167 if(all_sigio_fds.poll[i].fd == fd)
168 break;
169 }
170 if(i == all_sigio_fds.used)
171 goto out;
172
173 p = &all_sigio_fds.poll[i];
174
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 for(i = 0; i < current_poll.used; i++){
Jeff Dikef206aab2006-03-27 01:14:33 -0800176 if(current_poll.poll[i].fd == fd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 goto out;
178 }
179
Jeff Dike838e56a2007-02-16 01:27:21 -0800180 n = current_poll.used;
181 err = need_poll(&next_poll, n + 1);
Jeff Dikef206aab2006-03-27 01:14:33 -0800182 if(err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 goto out;
184
Jeff Dike838e56a2007-02-16 01:27:21 -0800185 memcpy(next_poll.poll, current_poll.poll,
186 current_poll.used * sizeof(struct pollfd));
187 next_poll.poll[n] = *p;
188 next_poll.used = n + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 update_thread();
190 out:
191 sigio_unlock();
Jeff Dike19bdf042006-09-25 23:33:04 -0700192 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193}
194
195int ignore_sigio_fd(int fd)
196{
197 struct pollfd *p;
198 int err = 0, i, n = 0;
199
Jeff Dike61232f22006-07-10 04:45:11 -0700200 /* This is called from exitcalls elsewhere in UML - if
201 * sigio_cleanup has already run, then update_thread will hang
202 * or fail because the thread is no longer running.
203 */
204 if(write_sigio_pid == -1)
205 return -EIO;
206
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 sigio_lock();
208 for(i = 0; i < current_poll.used; i++){
209 if(current_poll.poll[i].fd == fd) break;
210 }
211 if(i == current_poll.used)
212 goto out;
Jeff Dikef206aab2006-03-27 01:14:33 -0800213
Jeff Dike19bdf042006-09-25 23:33:04 -0700214 err = need_poll(&next_poll, current_poll.used - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 if(err)
216 goto out;
217
218 for(i = 0; i < current_poll.used; i++){
219 p = &current_poll.poll[i];
Jeff Dike19bdf042006-09-25 23:33:04 -0700220 if(p->fd != fd)
221 next_poll.poll[n++] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 }
Jeff Dike838e56a2007-02-16 01:27:21 -0800223 next_poll.used = current_poll.used - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
225 update_thread();
226 out:
227 sigio_unlock();
Jeff Dike61232f22006-07-10 04:45:11 -0700228 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229}
230
Jeff Dikef206aab2006-03-27 01:14:33 -0800231static struct pollfd *setup_initial_poll(int fd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232{
233 struct pollfd *p;
234
Jeff Dikee4c4bf92007-07-15 23:38:56 -0700235 p = kmalloc(sizeof(struct pollfd), UM_GFP_KERNEL);
Paolo 'Blaisorblade' Giarrussob6a2b132006-01-18 17:42:57 -0800236 if (p == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 printk("setup_initial_poll : failed to allocate poll\n");
Paolo 'Blaisorblade' Giarrussob6a2b132006-01-18 17:42:57 -0800238 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 }
Jeff Dike19bdf042006-09-25 23:33:04 -0700240 *p = ((struct pollfd) { .fd = fd,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 .events = POLLIN,
242 .revents = 0 });
Paolo 'Blaisorblade' Giarrussob6a2b132006-01-18 17:42:57 -0800243 return p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244}
245
Jeff Dike8e64d96a2006-07-10 04:45:11 -0700246static void write_sigio_workaround(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247{
Paolo 'Blaisorblade' Giarrussob6a2b132006-01-18 17:42:57 -0800248 struct pollfd *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 int err;
Paolo 'Blaisorblade' Giarrussob6a2b132006-01-18 17:42:57 -0800250 int l_write_sigio_fds[2];
251 int l_sigio_private[2];
252 int l_write_sigio_pid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
Paolo 'Blaisorblade' Giarrussob6a2b132006-01-18 17:42:57 -0800254 /* We call this *tons* of times - and most ones we must just fail. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 sigio_lock();
Paolo 'Blaisorblade' Giarrussob6a2b132006-01-18 17:42:57 -0800256 l_write_sigio_pid = write_sigio_pid;
257 sigio_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
Paolo 'Blaisorblade' Giarrussob6a2b132006-01-18 17:42:57 -0800259 if (l_write_sigio_pid != -1)
260 return;
261
262 err = os_pipe(l_write_sigio_fds, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 if(err < 0){
264 printk("write_sigio_workaround - os_pipe 1 failed, "
265 "err = %d\n", -err);
Paolo 'Blaisorblade' Giarrussob6a2b132006-01-18 17:42:57 -0800266 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 }
Paolo 'Blaisorblade' Giarrussob6a2b132006-01-18 17:42:57 -0800268 err = os_pipe(l_sigio_private, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 if(err < 0){
Jeff Dikef206aab2006-03-27 01:14:33 -0800270 printk("write_sigio_workaround - os_pipe 2 failed, "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 "err = %d\n", -err);
272 goto out_close1;
273 }
Paolo 'Blaisorblade' Giarrussob6a2b132006-01-18 17:42:57 -0800274
275 p = setup_initial_poll(l_sigio_private[1]);
276 if(!p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 goto out_close2;
278
Paolo 'Blaisorblade' Giarrussob6a2b132006-01-18 17:42:57 -0800279 sigio_lock();
280
281 /* Did we race? Don't try to optimize this, please, it's not so likely
282 * to happen, and no more than once at the boot. */
283 if(write_sigio_pid != -1)
Jeff Dike5f4e8fd2006-03-27 01:14:40 -0800284 goto out_free;
285
286 current_poll = ((struct pollfds) { .poll = p,
287 .used = 1,
288 .size = 1 });
289
290 if (write_sigio_irq(l_write_sigio_fds[0]))
291 goto out_clear_poll;
292
293 memcpy(write_sigio_fds, l_write_sigio_fds, sizeof(l_write_sigio_fds));
294 memcpy(sigio_private, l_sigio_private, sizeof(l_sigio_private));
Paolo 'Blaisorblade' Giarrussob6a2b132006-01-18 17:42:57 -0800295
296 write_sigio_pid = run_helper_thread(write_sigio_thread, NULL,
Jeff Dikec4399012007-07-15 23:38:56 -0700297 CLONE_FILES | CLONE_VM,
298 &write_sigio_stack);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
Paolo 'Blaisorblade' Giarrussob6a2b132006-01-18 17:42:57 -0800300 if (write_sigio_pid < 0)
301 goto out_clear;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 sigio_unlock();
304 return;
305
Jeff Dike5f4e8fd2006-03-27 01:14:40 -0800306out_clear:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 write_sigio_pid = -1;
Jeff Dike5f4e8fd2006-03-27 01:14:40 -0800308 write_sigio_fds[0] = -1;
309 write_sigio_fds[1] = -1;
310 sigio_private[0] = -1;
311 sigio_private[1] = -1;
312out_clear_poll:
313 current_poll = ((struct pollfds) { .poll = NULL,
314 .size = 0,
315 .used = 0 });
316out_free:
Jeff Dike5f4e8fd2006-03-27 01:14:40 -0800317 sigio_unlock();
Paolo 'Blaisorblade' Giarrussoe6fb54a2006-04-10 22:53:36 -0700318 kfree(p);
Jeff Dike5f4e8fd2006-03-27 01:14:40 -0800319out_close2:
Jeff Dike8e367062006-03-27 01:14:32 -0800320 close(l_sigio_private[0]);
321 close(l_sigio_private[1]);
Jeff Dike5f4e8fd2006-03-27 01:14:40 -0800322out_close1:
Jeff Dike8e367062006-03-27 01:14:32 -0800323 close(l_write_sigio_fds[0]);
324 close(l_write_sigio_fds[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325}
326
Jeff Dikec65badb2007-05-06 14:51:06 -0700327/* Changed during early boot */
328static int pty_output_sigio = 0;
329static int pty_close_sigio = 0;
330
Jeff Dike8e64d96a2006-07-10 04:45:11 -0700331void maybe_sigio_broken(int fd, int read)
332{
Jeff Dike19bdf042006-09-25 23:33:04 -0700333 int err;
334
Jeff Dike8e64d96a2006-07-10 04:45:11 -0700335 if(!isatty(fd))
336 return;
337
338 if((read || pty_output_sigio) && (!read || pty_close_sigio))
339 return;
340
341 write_sigio_workaround();
Jeff Dike19bdf042006-09-25 23:33:04 -0700342
343 sigio_lock();
344 err = need_poll(&all_sigio_fds, all_sigio_fds.used + 1);
Jeff Dike04a51e62007-02-28 20:13:11 -0800345 if(err){
346 printk("maybe_sigio_broken - failed to add pollfd for "
347 "descriptor %d\n", fd);
Jeff Dike19bdf042006-09-25 23:33:04 -0700348 goto out;
Jeff Dike04a51e62007-02-28 20:13:11 -0800349 }
Jeff Dike838e56a2007-02-16 01:27:21 -0800350
Jeff Dike19bdf042006-09-25 23:33:04 -0700351 all_sigio_fds.poll[all_sigio_fds.used++] =
352 ((struct pollfd) { .fd = fd,
353 .events = read ? POLLIN : POLLOUT,
354 .revents = 0 });
355out:
356 sigio_unlock();
Jeff Dike8e64d96a2006-07-10 04:45:11 -0700357}
358
Jeff Dike29ac1c22006-07-10 04:45:12 -0700359static void sigio_cleanup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360{
Jeff Dikec4399012007-07-15 23:38:56 -0700361 if (write_sigio_pid == -1)
362 return;
363
364 os_kill_process(write_sigio_pid, 1);
365 free_stack(write_sigio_stack, 0);
366 write_sigio_pid = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367}
Jeff Dike29ac1c22006-07-10 04:45:12 -0700368
369__uml_exitcall(sigio_cleanup);
Jeff Dikec65badb2007-05-06 14:51:06 -0700370
371/* Used as a flag during SIGIO testing early in boot */
372static volatile int got_sigio = 0;
373
374static void __init handler(int sig)
375{
376 got_sigio = 1;
377}
378
379struct openpty_arg {
380 int master;
381 int slave;
382 int err;
383};
384
385static void openpty_cb(void *arg)
386{
387 struct openpty_arg *info = arg;
388
389 info->err = 0;
390 if(openpty(&info->master, &info->slave, NULL, NULL, NULL))
391 info->err = -errno;
392}
393
394static int async_pty(int master, int slave)
395{
396 int flags;
397
398 flags = fcntl(master, F_GETFL);
399 if(flags < 0)
400 return -errno;
401
402 if((fcntl(master, F_SETFL, flags | O_NONBLOCK | O_ASYNC) < 0) ||
403 (fcntl(master, F_SETOWN, os_getpid()) < 0))
404 return -errno;
405
406 if((fcntl(slave, F_SETFL, flags | O_NONBLOCK) < 0))
407 return -errno;
408
WANG Congc0a92902008-02-04 22:30:41 -0800409 return 0;
Jeff Dikec65badb2007-05-06 14:51:06 -0700410}
411
412static void __init check_one_sigio(void (*proc)(int, int))
413{
414 struct sigaction old, new;
415 struct openpty_arg pty = { .master = -1, .slave = -1 };
416 int master, slave, err;
417
418 initial_thread_cb(openpty_cb, &pty);
419 if(pty.err){
420 printk("openpty failed, errno = %d\n", -pty.err);
421 return;
422 }
423
424 master = pty.master;
425 slave = pty.slave;
426
427 if((master == -1) || (slave == -1)){
428 printk("openpty failed to allocate a pty\n");
429 return;
430 }
431
432 /* Not now, but complain so we now where we failed. */
433 err = raw(master);
434 if (err < 0)
435 panic("check_sigio : __raw failed, errno = %d\n", -err);
436
437 err = async_pty(master, slave);
438 if(err < 0)
439 panic("tty_fds : sigio_async failed, err = %d\n", -err);
440
441 if(sigaction(SIGIO, NULL, &old) < 0)
442 panic("check_sigio : sigaction 1 failed, errno = %d\n", errno);
443 new = old;
444 new.sa_handler = handler;
445 if(sigaction(SIGIO, &new, NULL) < 0)
446 panic("check_sigio : sigaction 2 failed, errno = %d\n", errno);
447
448 got_sigio = 0;
449 (*proc)(master, slave);
450
451 close(master);
452 close(slave);
453
454 if(sigaction(SIGIO, &old, NULL) < 0)
455 panic("check_sigio : sigaction 3 failed, errno = %d\n", errno);
456}
457
458static void tty_output(int master, int slave)
459{
460 int n;
461 char buf[512];
462
463 printk("Checking that host ptys support output SIGIO...");
464
465 memset(buf, 0, sizeof(buf));
466
Jeff Dikea61f3342007-05-06 14:51:35 -0700467 while(write(master, buf, sizeof(buf)) > 0) ;
Jeff Dikec65badb2007-05-06 14:51:06 -0700468 if(errno != EAGAIN)
Jeff Dikeef0470c2007-05-06 14:51:33 -0700469 panic("tty_output : write failed, errno = %d\n", errno);
Jeff Dikea61f3342007-05-06 14:51:35 -0700470 while(((n = read(slave, buf, sizeof(buf))) > 0) && !got_sigio) ;
Jeff Dikec65badb2007-05-06 14:51:06 -0700471
472 if(got_sigio){
473 printk("Yes\n");
474 pty_output_sigio = 1;
475 }
Jeff Dikeef0470c2007-05-06 14:51:33 -0700476 else if(n == -EAGAIN)
477 printk("No, enabling workaround\n");
478 else panic("tty_output : read failed, err = %d\n", n);
Jeff Dikec65badb2007-05-06 14:51:06 -0700479}
480
481static void tty_close(int master, int slave)
482{
483 printk("Checking that host ptys support SIGIO on close...");
484
485 close(slave);
486 if(got_sigio){
487 printk("Yes\n");
488 pty_close_sigio = 1;
489 }
490 else printk("No, enabling workaround\n");
491}
492
493void __init check_sigio(void)
494{
495 if((os_access("/dev/ptmx", OS_ACC_R_OK) < 0) &&
496 (os_access("/dev/ptyp0", OS_ACC_R_OK) < 0)){
497 printk("No pseudo-terminals available - skipping pty SIGIO "
498 "check\n");
499 return;
500 }
501 check_one_sigio(tty_output);
502 check_one_sigio(tty_close);
503}
504
505/* Here because it only does the SIGIO testing for now */
506void __init os_check_bugs(void)
507{
508 check_sigio();
509}