aboutsummaryrefslogtreecommitdiff
path: root/utility.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>1999-10-25 23:32:44 +0000
committerEric Andersen <andersen@codepoet.org>1999-10-25 23:32:44 +0000
commit0460ff2e5d443b485c2f6447c8c2ece1b3bec9c3 (patch)
treed761a790ee864a0a566d29c9d56173763fa04888 /utility.c
parentd143e8f2bd03470e891a5e3ccca5734edd917e73 (diff)
downloadbusybox-w32-0460ff2e5d443b485c2f6447c8c2ece1b3bec9c3.tar.gz
busybox-w32-0460ff2e5d443b485c2f6447c8c2ece1b3bec9c3.tar.bz2
busybox-w32-0460ff2e5d443b485c2f6447c8c2ece1b3bec9c3.zip
Stuf
Diffstat (limited to 'utility.c')
-rw-r--r--utility.c92
1 files changed, 92 insertions, 0 deletions
diff --git a/utility.c b/utility.c
index 124efda40..6491d834d 100644
--- a/utility.c
+++ b/utility.c
@@ -720,5 +720,97 @@ extern int find_match(char *haystack, char *needle, int ignoreCase)
720} 720}
721#endif 721#endif
722 722
723
724
725#if (defined BB_CHVT) || (defined BB_DEALLOCVT)
726
727
728#include <linux/kd.h>
729#include <sys/ioctl.h>
730
731int is_a_console(int fd)
732{
733 char arg;
734
735 arg = 0;
736 return (ioctl(fd, KDGKBTYPE, &arg) == 0
737 && ((arg == KB_101) || (arg == KB_84)));
738}
739
740static int open_a_console(char *fnam)
741{
742 int fd;
743
744 /* try read-only */
745 fd = open(fnam, O_RDWR);
746
747 /* if failed, try read-only */
748 if (fd < 0 && errno == EACCES)
749 fd = open(fnam, O_RDONLY);
750
751 /* if failed, try write-only */
752 if (fd < 0 && errno == EACCES)
753 fd = open(fnam, O_WRONLY);
754
755 /* if failed, fail */
756 if (fd < 0)
757 return -1;
758
759 /* if not a console, fail */
760 if (! is_a_console(fd))
761 {
762 close(fd);
763 return -1;
764 }
765
766 /* success */
767 return fd;
768}
769
770/*
771 * Get an fd for use with kbd/console ioctls.
772 * We try several things because opening /dev/console will fail
773 * if someone else used X (which does a chown on /dev/console).
774 *
775 * if tty_name is non-NULL, try this one instead.
776 */
777
778int get_console_fd(char* tty_name)
779{
780 int fd;
781
782 if (tty_name)
783 {
784 if (-1 == (fd = open_a_console(tty_name)))
785 return -1;
786 else
787 return fd;
788 }
789
790 fd = open_a_console("/dev/tty");
791 if (fd >= 0)
792 return fd;
793
794 fd = open_a_console("/dev/tty0");
795 if (fd >= 0)
796 return fd;
797
798 fd = open_a_console("/dev/console");
799 if (fd >= 0)
800 return fd;
801
802 for (fd = 0; fd < 3; fd++)
803 if (is_a_console(fd))
804 return fd;
805
806 fprintf(stderr,
807 "Couldnt get a file descriptor referring to the console\n");
808 return -1; /* total failure */
809}
810
811
812#endif
813
814
723/* END CODE */ 815/* END CODE */
724 816