Add support for devfs device names.
authorMatt Kraai <kraai@debian.org>
Mon, 23 Jul 2001 14:52:08 +0000 (14:52 -0000)
committerMatt Kraai <kraai@debian.org>
Mon, 23 Jul 2001 14:52:08 +0000 (14:52 -0000)
17 files changed:
Changelog
Config.h
console-tools/dumpkmap.c
console-tools/loadacm.c
console-tools/loadfont.c
console-tools/loadkmap.c
dumpkmap.c
include/libbb.h
init.c
init/init.c
libbb/get_console.c
libbb/libbb.h
loadacm.c
loadfont.c
loadkmap.c
more.c
util-linux/more.c

index eadff4d14105b6c3d8865bee1c289a4842d3a8c9..76a5e4b94328b8ca2abadd48e8c311f629646cb4 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -9,6 +9,7 @@
     Other Changes:
        * Vladimir Oleynik -- Fixed tr to support 'tr a-z A-Z' syntax,
             many ash corrections, and others optimizations, and cleanups.
+       * Matt Kraai -- Added BB_FEATURE_DEVFS to enable devfs device names.
        
 
         -Not Yet Released
index d40a959eb7ad366958a2f69e5030b05b665c81c9..da62cbfda46697a658b9674d589db32b5fe701f9 100644 (file)
--- a/Config.h
+++ b/Config.h
 // Support for TELNET to pass TERM type to remote host.  Adds 384 bytes.
 #define BB_FEATURE_TELNET_TTYPE
 //
+// Support for devfs.
+//#define BB_FEATURE_DEVFS
+//
 // End of Features List
 //
 //
index 0da01868b179cacff8210aad57e4653cb3ffbcef..22652a5e2b67167ce1ddc1cefd7da1b70e9607f2 100644 (file)
@@ -51,9 +51,9 @@ int dumpkmap_main(int argc, char **argv)
                show_usage();
        }
 
-       fd = open("/dev/tty0", O_RDWR);
+       fd = open(CURRENT_VC, O_RDWR);
        if (fd < 0) {
-               perror_msg("Error opening /dev/tty0");
+               perror_msg("Error opening " CURRENT_VC);
                return EXIT_FAILURE;
        }
 
index 5dbf03e362d65215820beb91641c1c308521f0bc..3fb4e7665121a854350edcd654a7157d6ecfe40b 100644 (file)
@@ -37,9 +37,9 @@ int loadacm_main(int argc, char **argv)
                show_usage();
        }
 
-       fd = open("/dev/tty", O_RDWR);
+       fd = open(CURRENT_VC, O_RDWR);
        if (fd < 0) {
-               perror_msg_and_die("Error opening /dev/tty1");
+               perror_msg_and_die("Error opening " CURRENT_VC);
        }
 
        if (screen_map_load(fd, stdin)) {
index 1a724ca85e17cc07356a17844af904bc365641fb..d6650019554dd59cfb99d0d7a146cafdec38c2aa 100644 (file)
@@ -46,9 +46,9 @@ extern int loadfont_main(int argc, char **argv)
        if (argc != 1)
                show_usage();
 
-       fd = open("/dev/tty0", O_RDWR);
+       fd = open(CURRENT_VC, O_RDWR);
        if (fd < 0)
-               perror_msg_and_die("Error opening /dev/tty0");
+               perror_msg_and_die("Error opening " CURRENT_VC);
        loadnewfont(fd);
 
        return EXIT_SUCCESS;
index dcb5c1caa1ef2e4b6b3772018df441d1fe948fbb..4f217d6304cc104e0743353d29bf2c0953d113f5 100644 (file)
@@ -53,9 +53,9 @@ int loadkmap_main(int argc, char **argv)
        if (argc != 1)
                show_usage();
 
-       fd = open("/dev/tty0", O_RDWR);
+       fd = open(CURRENT_VC, O_RDWR);
        if (fd < 0)
-               perror_msg_and_die("Error opening /dev/tty0");
+               perror_msg_and_die("Error opening " CURRENT_VC);
 
        read(0, buff, 7);
        if (0 != strncmp(buff, BINARY_KEYMAP_MAGIC, 7))
index 0da01868b179cacff8210aad57e4653cb3ffbcef..22652a5e2b67167ce1ddc1cefd7da1b70e9607f2 100644 (file)
@@ -51,9 +51,9 @@ int dumpkmap_main(int argc, char **argv)
                show_usage();
        }
 
-       fd = open("/dev/tty0", O_RDWR);
+       fd = open(CURRENT_VC, O_RDWR);
        if (fd < 0) {
-               perror_msg("Error opening /dev/tty0");
+               perror_msg("Error opening " CURRENT_VC);
                return EXIT_FAILURE;
        }
 
index c167e10bcb19038825534555e105b3d4bdde3423..3cf932dc41ebedf5fe6e50cbd5d7871bd2f75e95 100644 (file)
@@ -288,4 +288,32 @@ extern const char * const name_longer_than_foo;
 extern const char * const unknown;
 extern const char * const can_not_create_raw_socket;
 
+#ifdef BB_FEATURE_DEVFS
+# define CURRENT_VC "/dev/vc/0"
+# define VC_1 "/dev/vc/1"
+# define VC_2 "/dev/vc/2"
+# define VC_3 "/dev/vc/3"
+# define VC_4 "/dev/vc/4"
+# define VC_5 "/dev/vc/5"
+# define SC_0 "/dev/tts/0"
+# define SC_1 "/dev/tts/1"
+# define VC_FORMAT "/dev/vc/%d"
+# define SC_FORMAT "/dev/tts/%d"
+#else
+# define CURRENT_VC "/dev/tty0"
+# define VC_1 "/dev/tty1"
+# define VC_2 "/dev/tty2"
+# define VC_3 "/dev/tty3"
+# define VC_4 "/dev/tty4"
+# define VC_5 "/dev/tty5"
+# define SC_0 "/dev/ttyS0"
+# define SC_1 "/dev/ttyS1"
+# define VC_FORMAT "/dev/tty%d"
+# define SC_FORMAT "/dev/ttyS%d"
+#endif
+
+/* The following devices are the same on devfs and non-devfs systems.  */
+#define CURRENT_TTY "/dev/tty"
+#define CONSOLE_DEV "/dev/console"
+
 #endif /* __LIBBB_H__ */
diff --git a/init.c b/init.c
index ec144ea859f34e985ecc8de8682c1772f6d14631..f397b7e0acf84de6cd721be2b9ede87daa421147 100644 (file)
--- a/init.c
+++ b/init.c
@@ -117,13 +117,6 @@ static const int RB_AUTOBOOT = 0x01234567;
 #endif
 
 
-#define VT_PRIMARY   "/dev/tty1"     /* Primary virtual console */
-#define VT_SECONDARY "/dev/tty2"     /* Virtual console */
-#define VT_THIRD     "/dev/tty3"     /* Virtual console */
-#define VT_FOURTH    "/dev/tty4"     /* Virtual console */
-#define VT_LOG       "/dev/tty5"     /* Virtual console */
-#define SERIAL_CON0  "/dev/ttyS0"    /* Primary serial console */
-#define SERIAL_CON1  "/dev/ttyS1"    /* Serial console */
 #define SHELL        "/bin/sh"      /* Default shell */
 #define LOGIN_SHELL  "-" SHELL      /* Default login shell */
 #define INITTAB      "/etc/inittab"  /* inittab file location */
@@ -176,10 +169,10 @@ struct initActionTag {
 static initAction *initActionList = NULL;
 
 
-static char *secondConsole = VT_SECONDARY;
-static char *thirdConsole  = VT_THIRD;
-static char *fourthConsole = VT_FOURTH;
-static char *log           = VT_LOG;
+static char *secondConsole = VC_2;
+static char *thirdConsole  = VC_3;
+static char *fourthConsole = VC_4;
+static char *log           = VC_5;
 static int  kernelVersion  = 0;
 static char termType[32]   = "TERM=linux";
 static char console[32]    = _PATH_CONSOLE;
@@ -341,20 +334,19 @@ static void console_init()
        else if ((s = getenv("console")) != NULL) {
                /* remap tty[ab] to /dev/ttyS[01] */
                if (strcmp(s, "ttya") == 0)
-                       safe_strncpy(console, SERIAL_CON0, sizeof(console));
+                       safe_strncpy(console, SC_0, sizeof(console));
                else if (strcmp(s, "ttyb") == 0)
-                       safe_strncpy(console, SERIAL_CON1, sizeof(console));
+                       safe_strncpy(console, SC_1, sizeof(console));
        }
 #endif
        else {
                /* 2.2 kernels: identify the real console backend and try to use it */
                if (ioctl(0, TIOCGSERIAL, &sr) == 0) {
                        /* this is a serial console */
-                       snprintf(console, sizeof(console) - 1, "/dev/ttyS%d", sr.line);
+                       snprintf(console, sizeof(console) - 1, SC_FORMAT, sr.line);
                } else if (ioctl(0, VT_GETSTATE, &vt) == 0) {
                        /* this is linux virtual tty */
-                       snprintf(console, sizeof(console) - 1, "/dev/tty%d",
-                                        vt.v_active);
+                       snprintf(console, sizeof(console) - 1, VC_FORMAT, vt.v_active);
                } else {
                        safe_strncpy(console, _PATH_CONSOLE, sizeof(console));
                        tried_devcons++;
@@ -371,7 +363,7 @@ static void console_init()
                /* Can't open selected console -- try vt1 */
                if (!tried_vtprimary) {
                        tried_vtprimary++;
-                       safe_strncpy(console, VT_PRIMARY, sizeof(console));
+                       safe_strncpy(console, VC_1, sizeof(console));
                        continue;
                }
                break;
index ec144ea859f34e985ecc8de8682c1772f6d14631..f397b7e0acf84de6cd721be2b9ede87daa421147 100644 (file)
@@ -117,13 +117,6 @@ static const int RB_AUTOBOOT = 0x01234567;
 #endif
 
 
-#define VT_PRIMARY   "/dev/tty1"     /* Primary virtual console */
-#define VT_SECONDARY "/dev/tty2"     /* Virtual console */
-#define VT_THIRD     "/dev/tty3"     /* Virtual console */
-#define VT_FOURTH    "/dev/tty4"     /* Virtual console */
-#define VT_LOG       "/dev/tty5"     /* Virtual console */
-#define SERIAL_CON0  "/dev/ttyS0"    /* Primary serial console */
-#define SERIAL_CON1  "/dev/ttyS1"    /* Serial console */
 #define SHELL        "/bin/sh"      /* Default shell */
 #define LOGIN_SHELL  "-" SHELL      /* Default login shell */
 #define INITTAB      "/etc/inittab"  /* inittab file location */
@@ -176,10 +169,10 @@ struct initActionTag {
 static initAction *initActionList = NULL;
 
 
-static char *secondConsole = VT_SECONDARY;
-static char *thirdConsole  = VT_THIRD;
-static char *fourthConsole = VT_FOURTH;
-static char *log           = VT_LOG;
+static char *secondConsole = VC_2;
+static char *thirdConsole  = VC_3;
+static char *fourthConsole = VC_4;
+static char *log           = VC_5;
 static int  kernelVersion  = 0;
 static char termType[32]   = "TERM=linux";
 static char console[32]    = _PATH_CONSOLE;
@@ -341,20 +334,19 @@ static void console_init()
        else if ((s = getenv("console")) != NULL) {
                /* remap tty[ab] to /dev/ttyS[01] */
                if (strcmp(s, "ttya") == 0)
-                       safe_strncpy(console, SERIAL_CON0, sizeof(console));
+                       safe_strncpy(console, SC_0, sizeof(console));
                else if (strcmp(s, "ttyb") == 0)
-                       safe_strncpy(console, SERIAL_CON1, sizeof(console));
+                       safe_strncpy(console, SC_1, sizeof(console));
        }
 #endif
        else {
                /* 2.2 kernels: identify the real console backend and try to use it */
                if (ioctl(0, TIOCGSERIAL, &sr) == 0) {
                        /* this is a serial console */
-                       snprintf(console, sizeof(console) - 1, "/dev/ttyS%d", sr.line);
+                       snprintf(console, sizeof(console) - 1, SC_FORMAT, sr.line);
                } else if (ioctl(0, VT_GETSTATE, &vt) == 0) {
                        /* this is linux virtual tty */
-                       snprintf(console, sizeof(console) - 1, "/dev/tty%d",
-                                        vt.v_active);
+                       snprintf(console, sizeof(console) - 1, VC_FORMAT, vt.v_active);
                } else {
                        safe_strncpy(console, _PATH_CONSOLE, sizeof(console));
                        tried_devcons++;
@@ -371,7 +363,7 @@ static void console_init()
                /* Can't open selected console -- try vt1 */
                if (!tried_vtprimary) {
                        tried_vtprimary++;
-                       safe_strncpy(console, VT_PRIMARY, sizeof(console));
+                       safe_strncpy(console, VC_1, sizeof(console));
                        continue;
                }
                break;
index 4be9adc84166ef1688099e64891e7c515f30d157..3b36a59e79cd4af44923a5a42922e14e6bfe35aa 100644 (file)
@@ -98,15 +98,15 @@ int get_console_fd(char *tty_name)
                        return fd;
        }
 
-       fd = open_a_console("/dev/tty");
+       fd = open_a_console(CURRENT_TTY);
        if (fd >= 0)
                return fd;
 
-       fd = open_a_console("/dev/tty0");
+       fd = open_a_console(CURRENT_VC);
        if (fd >= 0)
                return fd;
 
-       fd = open_a_console("/dev/console");
+       fd = open_a_console(CONSOLE_DEV);
        if (fd >= 0)
                return fd;
 
@@ -114,7 +114,7 @@ int get_console_fd(char *tty_name)
                if (is_a_console(fd))
                        return fd;
 
-       error_msg("Couldnt get a file descriptor referring to the console");
+       error_msg("Couldn't get a file descriptor referring to the console");
        return -1;                                      /* total failure */
 }
 
index c167e10bcb19038825534555e105b3d4bdde3423..3cf932dc41ebedf5fe6e50cbd5d7871bd2f75e95 100644 (file)
@@ -288,4 +288,32 @@ extern const char * const name_longer_than_foo;
 extern const char * const unknown;
 extern const char * const can_not_create_raw_socket;
 
+#ifdef BB_FEATURE_DEVFS
+# define CURRENT_VC "/dev/vc/0"
+# define VC_1 "/dev/vc/1"
+# define VC_2 "/dev/vc/2"
+# define VC_3 "/dev/vc/3"
+# define VC_4 "/dev/vc/4"
+# define VC_5 "/dev/vc/5"
+# define SC_0 "/dev/tts/0"
+# define SC_1 "/dev/tts/1"
+# define VC_FORMAT "/dev/vc/%d"
+# define SC_FORMAT "/dev/tts/%d"
+#else
+# define CURRENT_VC "/dev/tty0"
+# define VC_1 "/dev/tty1"
+# define VC_2 "/dev/tty2"
+# define VC_3 "/dev/tty3"
+# define VC_4 "/dev/tty4"
+# define VC_5 "/dev/tty5"
+# define SC_0 "/dev/ttyS0"
+# define SC_1 "/dev/ttyS1"
+# define VC_FORMAT "/dev/tty%d"
+# define SC_FORMAT "/dev/ttyS%d"
+#endif
+
+/* The following devices are the same on devfs and non-devfs systems.  */
+#define CURRENT_TTY "/dev/tty"
+#define CONSOLE_DEV "/dev/console"
+
 #endif /* __LIBBB_H__ */
index 5dbf03e362d65215820beb91641c1c308521f0bc..3fb4e7665121a854350edcd654a7157d6ecfe40b 100644 (file)
--- a/loadacm.c
+++ b/loadacm.c
@@ -37,9 +37,9 @@ int loadacm_main(int argc, char **argv)
                show_usage();
        }
 
-       fd = open("/dev/tty", O_RDWR);
+       fd = open(CURRENT_VC, O_RDWR);
        if (fd < 0) {
-               perror_msg_and_die("Error opening /dev/tty1");
+               perror_msg_and_die("Error opening " CURRENT_VC);
        }
 
        if (screen_map_load(fd, stdin)) {
index 1a724ca85e17cc07356a17844af904bc365641fb..d6650019554dd59cfb99d0d7a146cafdec38c2aa 100644 (file)
@@ -46,9 +46,9 @@ extern int loadfont_main(int argc, char **argv)
        if (argc != 1)
                show_usage();
 
-       fd = open("/dev/tty0", O_RDWR);
+       fd = open(CURRENT_VC, O_RDWR);
        if (fd < 0)
-               perror_msg_and_die("Error opening /dev/tty0");
+               perror_msg_and_die("Error opening " CURRENT_VC);
        loadnewfont(fd);
 
        return EXIT_SUCCESS;
index dcb5c1caa1ef2e4b6b3772018df441d1fe948fbb..4f217d6304cc104e0743353d29bf2c0953d113f5 100644 (file)
@@ -53,9 +53,9 @@ int loadkmap_main(int argc, char **argv)
        if (argc != 1)
                show_usage();
 
-       fd = open("/dev/tty0", O_RDWR);
+       fd = open(CURRENT_VC, O_RDWR);
        if (fd < 0)
-               perror_msg_and_die("Error opening /dev/tty0");
+               perror_msg_and_die("Error opening " CURRENT_VC);
 
        read(0, buff, 7);
        if (0 != strncmp(buff, BINARY_KEYMAP_MAGIC, 7))
diff --git a/more.c b/more.c
index 6cdec729be153762e895636bd73c172530feae2a..780cddf665e1b75dfb105047a5dd65b5f46c2ba3 100644 (file)
--- a/more.c
+++ b/more.c
@@ -79,9 +79,9 @@ extern int more_main(int argc, char **argv)
 
        /* not use inputing from terminal if usage: more > outfile */
        if(isatty(fileno(stdout))) {
-               cin = fopen("/dev/tty", "r");
+               cin = fopen(CURRENT_TTY, "r");
                if (!cin)
-                       cin = xfopen("/dev/console", "r");
+                       cin = xfopen(CONSOLE_DEV, "r");
                please_display_more_prompt = 0;
 #ifdef BB_FEATURE_USE_TERMIOS
                getTermSettings(fileno(cin), &initial_settings);
index 6cdec729be153762e895636bd73c172530feae2a..780cddf665e1b75dfb105047a5dd65b5f46c2ba3 100644 (file)
@@ -79,9 +79,9 @@ extern int more_main(int argc, char **argv)
 
        /* not use inputing from terminal if usage: more > outfile */
        if(isatty(fileno(stdout))) {
-               cin = fopen("/dev/tty", "r");
+               cin = fopen(CURRENT_TTY, "r");
                if (!cin)
-                       cin = xfopen("/dev/console", "r");
+                       cin = xfopen(CONSOLE_DEV, "r");
                please_display_more_prompt = 0;
 #ifdef BB_FEATURE_USE_TERMIOS
                getTermSettings(fileno(cin), &initial_settings);