Commit 8e367065eea04a6fde5cb8f3854164af99c45693
Committed by
Linus Torvalds
1 parent
9b4f018d92
Exists in
master
and in
7 other branches
[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>
Showing 6 changed files with 148 additions and 157 deletions Side-by-side Diff
arch/um/include/os.h
arch/um/include/sigio.h
arch/um/kernel/sigio_kern.c
1 | -/* | |
1 | +/* | |
2 | 2 | * Copyright (C) 2002 - 2003 Jeff Dike (jdike@addtoit.com) |
3 | 3 | * Licensed under the GPL |
4 | 4 | */ |
5 | 5 | |
... | ... | @@ -12,13 +12,16 @@ |
12 | 12 | #include "sigio.h" |
13 | 13 | #include "irq_user.h" |
14 | 14 | #include "irq_kern.h" |
15 | +#include "os.h" | |
15 | 16 | |
16 | 17 | /* Protected by sigio_lock() called from write_sigio_workaround */ |
17 | 18 | static int sigio_irq_fd = -1; |
18 | 19 | |
19 | 20 | static irqreturn_t sigio_interrupt(int irq, void *data, struct pt_regs *unused) |
20 | 21 | { |
21 | - read_sigio_fd(sigio_irq_fd); | |
22 | + char c; | |
23 | + | |
24 | + os_read_file(sigio_irq_fd, &c, sizeof(c)); | |
22 | 25 | reactivate_fd(sigio_irq_fd, SIGIO_WRITE_IRQ); |
23 | 26 | return(IRQ_HANDLED); |
24 | 27 | } |
... | ... | @@ -50,6 +53,9 @@ |
50 | 53 | { |
51 | 54 | spin_unlock(&sigio_spinlock); |
52 | 55 | } |
56 | + | |
57 | +extern void sigio_cleanup(void); | |
58 | +__uml_exitcall(sigio_cleanup); | |
53 | 59 | |
54 | 60 | /* |
55 | 61 | * Overrides for Emacs so that we follow Linus's tabbing style. |
arch/um/kernel/sigio_user.c
1 | -/* | |
1 | +/* | |
2 | 2 | * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) |
3 | 3 | * Licensed under the GPL |
4 | 4 | */ |
... | ... | @@ -20,127 +20,6 @@ |
20 | 20 | #include "sigio.h" |
21 | 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 | 23 | /* Protected by sigio_lock(), also used by sigio_cleanup, which is an |
145 | 24 | * exitcall. |
146 | 25 | */ |
... | ... | @@ -267,10 +146,10 @@ |
267 | 146 | if(write_sigio_pid != -1) |
268 | 147 | os_kill_process(write_sigio_pid, 1); |
269 | 148 | write_sigio_pid = -1; |
270 | - os_close_file(sigio_private[0]); | |
271 | - os_close_file(sigio_private[1]); | |
272 | - os_close_file(write_sigio_fds[0]); | |
273 | - os_close_file(write_sigio_fds[1]); | |
149 | + close(sigio_private[0]); | |
150 | + close(sigio_private[1]); | |
151 | + close(write_sigio_fds[0]); | |
152 | + close(write_sigio_fds[1]); | |
274 | 153 | /* Critical section end */ |
275 | 154 | set_signals(flags); |
276 | 155 | } |
277 | 156 | |
278 | 157 | |
279 | 158 | |
280 | 159 | |
... | ... | @@ -428,40 +307,19 @@ |
428 | 307 | out_free: |
429 | 308 | kfree(p); |
430 | 309 | out_close2: |
431 | - os_close_file(l_sigio_private[0]); | |
432 | - os_close_file(l_sigio_private[1]); | |
310 | + close(l_sigio_private[0]); | |
311 | + close(l_sigio_private[1]); | |
433 | 312 | out_close1: |
434 | - os_close_file(l_write_sigio_fds[0]); | |
435 | - os_close_file(l_write_sigio_fds[1]); | |
313 | + close(l_write_sigio_fds[0]); | |
314 | + close(l_write_sigio_fds[1]); | |
436 | 315 | return; |
437 | 316 | } |
438 | 317 | |
439 | -int read_sigio_fd(int fd) | |
318 | +void sigio_cleanup(void) | |
440 | 319 | { |
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 | -{ | |
460 | 320 | if (write_sigio_pid != -1) { |
461 | 321 | os_kill_process(write_sigio_pid, 1); |
462 | 322 | write_sigio_pid = -1; |
463 | 323 | } |
464 | 324 | } |
465 | - | |
466 | -__uml_exitcall(sigio_cleanup); |
arch/um/kernel/um_arch.c
arch/um/os-Linux/start_up.c
... | ... | @@ -3,6 +3,7 @@ |
3 | 3 | * Licensed under the GPL |
4 | 4 | */ |
5 | 5 | |
6 | +#include <pty.h> | |
6 | 7 | #include <stdio.h> |
7 | 8 | #include <stddef.h> |
8 | 9 | #include <stdarg.h> |
... | ... | @@ -537,5 +538,132 @@ |
537 | 538 | os_close_file(fd); |
538 | 539 | out: |
539 | 540 | return(1); |
541 | +} | |
542 | + | |
543 | + | |
544 | +/* Changed during early boot */ | |
545 | +int pty_output_sigio = 0; | |
546 | +int pty_close_sigio = 0; | |
547 | + | |
548 | +/* Used as a flag during SIGIO testing early in boot */ | |
549 | +static volatile int got_sigio = 0; | |
550 | + | |
551 | +static void __init handler(int sig) | |
552 | +{ | |
553 | + got_sigio = 1; | |
554 | +} | |
555 | + | |
556 | +struct openpty_arg { | |
557 | + int master; | |
558 | + int slave; | |
559 | + int err; | |
560 | +}; | |
561 | + | |
562 | +static void openpty_cb(void *arg) | |
563 | +{ | |
564 | + struct openpty_arg *info = arg; | |
565 | + | |
566 | + info->err = 0; | |
567 | + if(openpty(&info->master, &info->slave, NULL, NULL, NULL)) | |
568 | + info->err = -errno; | |
569 | +} | |
570 | + | |
571 | +static void __init check_one_sigio(void (*proc)(int, int)) | |
572 | +{ | |
573 | + struct sigaction old, new; | |
574 | + struct openpty_arg pty = { .master = -1, .slave = -1 }; | |
575 | + int master, slave, err; | |
576 | + | |
577 | + initial_thread_cb(openpty_cb, &pty); | |
578 | + if(pty.err){ | |
579 | + printk("openpty failed, errno = %d\n", -pty.err); | |
580 | + return; | |
581 | + } | |
582 | + | |
583 | + master = pty.master; | |
584 | + slave = pty.slave; | |
585 | + | |
586 | + if((master == -1) || (slave == -1)){ | |
587 | + printk("openpty failed to allocate a pty\n"); | |
588 | + return; | |
589 | + } | |
590 | + | |
591 | + /* Not now, but complain so we now where we failed. */ | |
592 | + err = raw(master); | |
593 | + if (err < 0) | |
594 | + panic("check_sigio : __raw failed, errno = %d\n", -err); | |
595 | + | |
596 | + err = os_sigio_async(master, slave); | |
597 | + if(err < 0) | |
598 | + panic("tty_fds : sigio_async failed, err = %d\n", -err); | |
599 | + | |
600 | + if(sigaction(SIGIO, NULL, &old) < 0) | |
601 | + panic("check_sigio : sigaction 1 failed, errno = %d\n", errno); | |
602 | + new = old; | |
603 | + new.sa_handler = handler; | |
604 | + if(sigaction(SIGIO, &new, NULL) < 0) | |
605 | + panic("check_sigio : sigaction 2 failed, errno = %d\n", errno); | |
606 | + | |
607 | + got_sigio = 0; | |
608 | + (*proc)(master, slave); | |
609 | + | |
610 | + close(master); | |
611 | + close(slave); | |
612 | + | |
613 | + if(sigaction(SIGIO, &old, NULL) < 0) | |
614 | + panic("check_sigio : sigaction 3 failed, errno = %d\n", errno); | |
615 | +} | |
616 | + | |
617 | +static void tty_output(int master, int slave) | |
618 | +{ | |
619 | + int n; | |
620 | + char buf[512]; | |
621 | + | |
622 | + printk("Checking that host ptys support output SIGIO..."); | |
623 | + | |
624 | + memset(buf, 0, sizeof(buf)); | |
625 | + | |
626 | + while(os_write_file(master, buf, sizeof(buf)) > 0) ; | |
627 | + if(errno != EAGAIN) | |
628 | + panic("check_sigio : write failed, errno = %d\n", errno); | |
629 | + while(((n = os_read_file(slave, buf, sizeof(buf))) > 0) && !got_sigio) ; | |
630 | + | |
631 | + if(got_sigio){ | |
632 | + printk("Yes\n"); | |
633 | + pty_output_sigio = 1; | |
634 | + } | |
635 | + else if(n == -EAGAIN) printk("No, enabling workaround\n"); | |
636 | + else panic("check_sigio : read failed, err = %d\n", n); | |
637 | +} | |
638 | + | |
639 | +static void tty_close(int master, int slave) | |
640 | +{ | |
641 | + printk("Checking that host ptys support SIGIO on close..."); | |
642 | + | |
643 | + close(slave); | |
644 | + if(got_sigio){ | |
645 | + printk("Yes\n"); | |
646 | + pty_close_sigio = 1; | |
647 | + } | |
648 | + else printk("No, enabling workaround\n"); | |
649 | +} | |
650 | + | |
651 | +void __init check_sigio(void) | |
652 | +{ | |
653 | + if((os_access("/dev/ptmx", OS_ACC_R_OK) < 0) && | |
654 | + (os_access("/dev/ptyp0", OS_ACC_R_OK) < 0)){ | |
655 | + printk("No pseudo-terminals available - skipping pty SIGIO " | |
656 | + "check\n"); | |
657 | + return; | |
658 | + } | |
659 | + check_one_sigio(tty_output); | |
660 | + check_one_sigio(tty_close); | |
661 | +} | |
662 | + | |
663 | +void os_check_bugs(void) | |
664 | +{ | |
665 | + check_ptrace(); | |
666 | + check_sigio(); | |
667 | + check_devanon(); | |
540 | 668 | } |