[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [BusyBox] get_console_fd patch
From:       "Evin Robertson" <nitfol () my-deja ! com>
Date:       2001-02-24 21:11:42
[Download RAW message or body]

I'm using devfs which doesn't by default create /dev/tty0, so
loadkmap wasn't working as it tries to open("/dev/tty0", O_RDWR);

Here's a patch which makes dumpkmap, loadkmap, and loadfont
use get_console_fd.  It now works fine.

None of the applets which call get_console_fd appear to work
if get_console_fd returns -1, so I've renamed it to
get_console_fd_or_die, and made it error_msg_and_die.

I couldn't see any reason why all applets were calling
get_console_fd with an argument of "/dev/console" instead of
letting it try various devices, so this patch also makes it
take type void, which saves a few bytes.


------------------------------------------------------------
--== Sent via Deja.com ==--
http://www.deja.com/



["get_console_fd.patch" (application/octet-stream)]

Only in busybox-foo/: busybox
diff -ur busybox-cvs/busybox.h busybox-foo/busybox.h
--- busybox-cvs/busybox.h	Thu Feb 22 18:38:48 2001
+++ busybox-foo/busybox.h	Sat Feb 24 14:55:05 2001
@@ -130,7 +130,7 @@
 
 extern int get_kernel_revision(void);
 
-extern int get_console_fd(char* tty_name);
+extern int get_console_fd_or_die(void);
 extern struct mntent *find_mount_point(const char *name, const char *table);
 extern void write_mtab(char* blockDevice, char* directory, 
 	char* filesystemType, long flags, char* string_flags);
diff -ur busybox-cvs/chvt.c busybox-foo/chvt.c
--- busybox-cvs/chvt.c	Tue Feb 20 01:14:07 2001
+++ busybox-foo/chvt.c	Sat Feb 24 14:55:39 2001
@@ -21,7 +21,7 @@
 
 	if ((argc != 2) || (**(argv + 1) == '-'))
 		show_usage();
-	fd = get_console_fd("/dev/console");
+	fd = get_console_fd_or_die();
 	num = atoi(argv[1]);
 	if (ioctl(fd, VT_ACTIVATE, num))
 		perror_msg_and_die("VT_ACTIVATE");
diff -ur busybox-cvs/deallocvt.c busybox-foo/deallocvt.c
--- busybox-cvs/deallocvt.c	Tue Feb 20 01:14:07 2001
+++ busybox-foo/deallocvt.c	Sat Feb 24 14:55:43 2001
@@ -21,7 +21,7 @@
 	if (argc > 2)
 		show_usage();
 
-	fd = get_console_fd("/dev/console");
+	fd = get_console_fd_or_die();
 
 	if (argc == 1) {
 		/* deallocate all unused consoles */
diff -ur busybox-cvs/dumpkmap.c busybox-foo/dumpkmap.c
--- busybox-cvs/dumpkmap.c	Tue Feb 20 01:14:07 2001
+++ busybox-foo/dumpkmap.c	Sat Feb 24 14:55:47 2001
@@ -51,11 +51,7 @@
 		show_usage();
 	}
 
-	fd = open("/dev/tty0", O_RDWR);
-	if (fd < 0) {
-		perror_msg("Error opening /dev/tty0");
-		return EXIT_FAILURE;
-	}
+	fd = get_console_fd_or_die();
 
 	write(1, magic, 7);
 
diff -ur busybox-cvs/loadfont.c busybox-foo/loadfont.c
--- busybox-cvs/loadfont.c	Tue Feb 20 01:14:07 2001
+++ busybox-foo/loadfont.c	Sat Feb 24 14:55:50 2001
@@ -46,9 +46,8 @@
 	if (argc != 1)
 		show_usage();
 
-	fd = open("/dev/tty0", O_RDWR);
-	if (fd < 0)
-		perror_msg_and_die("Error opening /dev/tty0");
+	fd = get_console_fd_or_die();
+
 	loadnewfont(fd);
 
 	return EXIT_SUCCESS;
diff -ur busybox-cvs/loadkmap.c busybox-foo/loadkmap.c
--- busybox-cvs/loadkmap.c	Tue Feb 20 01:14:07 2001
+++ busybox-foo/loadkmap.c	Sat Feb 24 14:55:55 2001
@@ -53,9 +53,7 @@
 	if (argc != 1)
 		show_usage();
 
-	fd = open("/dev/tty0", O_RDWR);
-	if (fd < 0)
-		perror_msg_and_die("Error opening /dev/tty0");
+	fd = get_console_fd_or_die();
 
 	read(0, buff, 7);
 	if (0 != strncmp(buff, BINARY_KEYMAP_MAGIC, 7))
diff -ur busybox-cvs/setkeycodes.c busybox-foo/setkeycodes.c
--- busybox-cvs/setkeycodes.c	Tue Feb 20 01:14:08 2001
+++ busybox-foo/setkeycodes.c	Sat Feb 24 14:55:59 2001
@@ -46,7 +46,7 @@
       show_usage();
 	}
 	 
-	fd = get_console_fd("/dev/console");
+	fd = get_console_fd_or_die();
 
     while (argc > 2) {
 	a.keycode = atoi(argv[2]);
diff -ur busybox-cvs/utility.c busybox-foo/utility.c
--- busybox-cvs/utility.c	Thu Feb 22 22:55:24 2001
+++ busybox-foo/utility.c	Sat Feb 24 14:54:44 2001
@@ -948,7 +948,8 @@
  || BB_ID || BB_LOGGER || BB_LOGNAME || BB_WHOAMI */
 
 
-#if (defined BB_CHVT) || (defined BB_DEALLOCVT) || (defined BB_SETKEYCODES)
+#if (defined BB_CHVT) || (defined BB_DEALLOCVT) || (defined BB_SETKEYCODES) \
+ || (defined BB_DUMPKMAP) || (defined BB_LOADKMAP) || (defined BB_LOADFONT)
 
 /* From <linux/kd.h> */ 
 static const int KDGKBTYPE = 0x4B33;  /* get keyboard type */
@@ -998,20 +999,12 @@
  * We try several things because opening /dev/console will fail
  * if someone else used X (which does a chown on /dev/console).
  *
- * if tty_name is non-NULL, try this one instead.
  */
 
-int get_console_fd(char *tty_name)
+int get_console_fd_or_die(void)
 {
 	int fd;
 
-	if (tty_name) {
-		if (-1 == (fd = open_a_console(tty_name)))
-			return -1;
-		else
-			return fd;
-	}
-
 	fd = open_a_console("/dev/tty");
 	if (fd >= 0)
 		return fd;
@@ -1028,8 +1021,7 @@
 		if (is_a_console(fd))
 			return fd;
 
-	error_msg("Couldnt get a file descriptor referring to the console");
-	return -1;					/* total failure */
+	error_msg_and_die("Couldnt get a file descriptor referring to the console");
 }
 
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic