diff options
Diffstat (limited to 'arch/um/os-Linux')
-rw-r--r-- | arch/um/os-Linux/start_up.c | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/arch/um/os-Linux/start_up.c b/arch/um/os-Linux/start_up.c index 829d6b0d8b02..32753131f8d8 100644 --- a/arch/um/os-Linux/start_up.c +++ b/arch/um/os-Linux/start_up.c | |||
@@ -3,6 +3,7 @@ | |||
3 | * Licensed under the GPL | 3 | * Licensed under the GPL |
4 | */ | 4 | */ |
5 | 5 | ||
6 | #include <pty.h> | ||
6 | #include <stdio.h> | 7 | #include <stdio.h> |
7 | #include <stddef.h> | 8 | #include <stddef.h> |
8 | #include <stdarg.h> | 9 | #include <stdarg.h> |
@@ -539,3 +540,130 @@ int __init parse_iomem(char *str, int *add) | |||
539 | return(1); | 540 | return(1); |
540 | } | 541 | } |
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(); | ||
668 | } | ||
669 | |||