diff options
author | Jeff Dike <jdike@addtoit.com> | 2006-03-27 04:14:32 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-03-27 11:44:38 -0500 |
commit | 8e367065eea04a6fde5cb8f3854164af99c45693 (patch) | |
tree | ed43afe11ac49b992218b83a481a9e1db87160f9 /arch/um/kernel/sigio_user.c | |
parent | 9b4f018d92dbeff9305b4cf4aa80874c3974cfcc (diff) |
[PATCH] uml: move SIGIO startup code to os-Linux/start_up.c
The serial UML OS-abstraction layer patch (um/kernel dir).
This moves all startup code from sigio_user.c file under os-Linux dir
Signed-off-by: Gennady Sharapov <Gennady.V.Sharapov@intel.com>
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'arch/um/kernel/sigio_user.c')
-rw-r--r-- | arch/um/kernel/sigio_user.c | 162 |
1 files changed, 10 insertions, 152 deletions
diff --git a/arch/um/kernel/sigio_user.c b/arch/um/kernel/sigio_user.c index f7b18e157d35..9bef9413cb5d 100644 --- a/arch/um/kernel/sigio_user.c +++ b/arch/um/kernel/sigio_user.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) | 2 | * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) |
3 | * Licensed under the GPL | 3 | * Licensed under the GPL |
4 | */ | 4 | */ |
@@ -20,127 +20,6 @@ | |||
20 | #include "sigio.h" | 20 | #include "sigio.h" |
21 | #include "os.h" | 21 | #include "os.h" |
22 | 22 | ||
23 | /* Changed during early boot */ | ||
24 | int pty_output_sigio = 0; | ||
25 | int pty_close_sigio = 0; | ||
26 | |||
27 | /* Used as a flag during SIGIO testing early in boot */ | ||
28 | static volatile int got_sigio = 0; | ||
29 | |||
30 | void __init handler(int sig) | ||
31 | { | ||
32 | got_sigio = 1; | ||
33 | } | ||
34 | |||
35 | struct openpty_arg { | ||
36 | int master; | ||
37 | int slave; | ||
38 | int err; | ||
39 | }; | ||
40 | |||
41 | static void openpty_cb(void *arg) | ||
42 | { | ||
43 | struct openpty_arg *info = arg; | ||
44 | |||
45 | info->err = 0; | ||
46 | if(openpty(&info->master, &info->slave, NULL, NULL, NULL)) | ||
47 | info->err = -errno; | ||
48 | } | ||
49 | |||
50 | void __init check_one_sigio(void (*proc)(int, int)) | ||
51 | { | ||
52 | struct sigaction old, new; | ||
53 | struct openpty_arg pty = { .master = -1, .slave = -1 }; | ||
54 | int master, slave, err; | ||
55 | |||
56 | initial_thread_cb(openpty_cb, &pty); | ||
57 | if(pty.err){ | ||
58 | printk("openpty failed, errno = %d\n", -pty.err); | ||
59 | return; | ||
60 | } | ||
61 | |||
62 | master = pty.master; | ||
63 | slave = pty.slave; | ||
64 | |||
65 | if((master == -1) || (slave == -1)){ | ||
66 | printk("openpty failed to allocate a pty\n"); | ||
67 | return; | ||
68 | } | ||
69 | |||
70 | /* Not now, but complain so we now where we failed. */ | ||
71 | err = raw(master); | ||
72 | if (err < 0) | ||
73 | panic("check_sigio : __raw failed, errno = %d\n", -err); | ||
74 | |||
75 | err = os_sigio_async(master, slave); | ||
76 | if(err < 0) | ||
77 | panic("tty_fds : sigio_async failed, err = %d\n", -err); | ||
78 | |||
79 | if(sigaction(SIGIO, NULL, &old) < 0) | ||
80 | panic("check_sigio : sigaction 1 failed, errno = %d\n", errno); | ||
81 | new = old; | ||
82 | new.sa_handler = handler; | ||
83 | if(sigaction(SIGIO, &new, NULL) < 0) | ||
84 | panic("check_sigio : sigaction 2 failed, errno = %d\n", errno); | ||
85 | |||
86 | got_sigio = 0; | ||
87 | (*proc)(master, slave); | ||
88 | |||
89 | os_close_file(master); | ||
90 | os_close_file(slave); | ||
91 | |||
92 | if(sigaction(SIGIO, &old, NULL) < 0) | ||
93 | panic("check_sigio : sigaction 3 failed, errno = %d\n", errno); | ||
94 | } | ||
95 | |||
96 | static void tty_output(int master, int slave) | ||
97 | { | ||
98 | int n; | ||
99 | char buf[512]; | ||
100 | |||
101 | printk("Checking that host ptys support output SIGIO..."); | ||
102 | |||
103 | memset(buf, 0, sizeof(buf)); | ||
104 | |||
105 | while(os_write_file(master, buf, sizeof(buf)) > 0) ; | ||
106 | if(errno != EAGAIN) | ||
107 | panic("check_sigio : write failed, errno = %d\n", errno); | ||
108 | while(((n = os_read_file(slave, buf, sizeof(buf))) > 0) && !got_sigio) ; | ||
109 | |||
110 | if (got_sigio) { | ||
111 | printk("Yes\n"); | ||
112 | pty_output_sigio = 1; | ||
113 | } else if (n == -EAGAIN) { | ||
114 | printk("No, enabling workaround\n"); | ||
115 | } else { | ||
116 | panic("check_sigio : read failed, err = %d\n", n); | ||
117 | } | ||
118 | } | ||
119 | |||
120 | static void tty_close(int master, int slave) | ||
121 | { | ||
122 | printk("Checking that host ptys support SIGIO on close..."); | ||
123 | |||
124 | os_close_file(slave); | ||
125 | if(got_sigio){ | ||
126 | printk("Yes\n"); | ||
127 | pty_close_sigio = 1; | ||
128 | } | ||
129 | else printk("No, enabling workaround\n"); | ||
130 | } | ||
131 | |||
132 | void __init check_sigio(void) | ||
133 | { | ||
134 | if((os_access("/dev/ptmx", OS_ACC_R_OK) < 0) && | ||
135 | (os_access("/dev/ptyp0", OS_ACC_R_OK) < 0)){ | ||
136 | printk("No pseudo-terminals available - skipping pty SIGIO " | ||
137 | "check\n"); | ||
138 | return; | ||
139 | } | ||
140 | check_one_sigio(tty_output); | ||
141 | check_one_sigio(tty_close); | ||
142 | } | ||
143 | |||
144 | /* Protected by sigio_lock(), also used by sigio_cleanup, which is an | 23 | /* Protected by sigio_lock(), also used by sigio_cleanup, which is an |
145 | * exitcall. | 24 | * exitcall. |
146 | */ | 25 | */ |
@@ -267,10 +146,10 @@ static void update_thread(void) | |||
267 | if(write_sigio_pid != -1) | 146 | if(write_sigio_pid != -1) |
268 | os_kill_process(write_sigio_pid, 1); | 147 | os_kill_process(write_sigio_pid, 1); |
269 | write_sigio_pid = -1; | 148 | write_sigio_pid = -1; |
270 | os_close_file(sigio_private[0]); | 149 | close(sigio_private[0]); |
271 | os_close_file(sigio_private[1]); | 150 | close(sigio_private[1]); |
272 | os_close_file(write_sigio_fds[0]); | 151 | close(write_sigio_fds[0]); |
273 | os_close_file(write_sigio_fds[1]); | 152 | close(write_sigio_fds[1]); |
274 | /* Critical section end */ | 153 | /* Critical section end */ |
275 | set_signals(flags); | 154 | set_signals(flags); |
276 | } | 155 | } |
@@ -428,39 +307,18 @@ void write_sigio_workaround(void) | |||
428 | out_free: | 307 | out_free: |
429 | kfree(p); | 308 | kfree(p); |
430 | out_close2: | 309 | out_close2: |
431 | os_close_file(l_sigio_private[0]); | 310 | close(l_sigio_private[0]); |
432 | os_close_file(l_sigio_private[1]); | 311 | close(l_sigio_private[1]); |
433 | out_close1: | 312 | out_close1: |
434 | os_close_file(l_write_sigio_fds[0]); | 313 | close(l_write_sigio_fds[0]); |
435 | os_close_file(l_write_sigio_fds[1]); | 314 | close(l_write_sigio_fds[1]); |
436 | return; | 315 | return; |
437 | } | 316 | } |
438 | 317 | ||
439 | int read_sigio_fd(int fd) | 318 | void sigio_cleanup(void) |
440 | { | ||
441 | int n; | ||
442 | char c; | ||
443 | |||
444 | n = os_read_file(fd, &c, sizeof(c)); | ||
445 | if(n != sizeof(c)){ | ||
446 | if(n < 0) { | ||
447 | printk("read_sigio_fd - read failed, err = %d\n", -n); | ||
448 | return(n); | ||
449 | } | ||
450 | else { | ||
451 | printk("read_sigio_fd - short read, bytes = %d\n", n); | ||
452 | return(-EIO); | ||
453 | } | ||
454 | } | ||
455 | return(n); | ||
456 | } | ||
457 | |||
458 | static void sigio_cleanup(void) | ||
459 | { | 319 | { |
460 | if (write_sigio_pid != -1) { | 320 | if (write_sigio_pid != -1) { |
461 | os_kill_process(write_sigio_pid, 1); | 321 | os_kill_process(write_sigio_pid, 1); |
462 | write_sigio_pid = -1; | 322 | write_sigio_pid = -1; |
463 | } | 323 | } |
464 | } | 324 | } |
465 | |||
466 | __uml_exitcall(sigio_cleanup); | ||