On Tuesday 04 November 2008 17:22:54 Bernhard Reutner-Fischer wrote:
> On Tue, Nov 04, 2008 at 04:52:42PM +0000, Roy Marples wrote:
> >On Tuesday 04 November 2008 15:46:56 Bernhard Reutner-Fischer wrote:
> >> Given these stats you should add a
> >> get_console_fd_from_name_or_die(const char *dev) instead of adding
> >> penalties for the NULL arg everywhere.
> >
> >That saves a futher 30 bytes.
> >
> >+int FAST_FUNC get_console_fd_from_name_or_die(const char *device)
> >+{
> >+    int fd;
> >+
> >+    fd = open_a_console(device);
> >+    if (fd != -1)
> >+            return fd;
>
> you don't sanity-check the KDGKBTYPE..

I didn't check the input either.

uberlaptop busybox-1.12.1 # ./sc*/blo* ../*orig/busybox ./busybox
function                                             old     new   delta
get_console_fd_from_name_or_die                        -     107    +107
.rodata                                           163385  163433     +48
packed_usage                                       24130   24151     +21
kbd_mode_main                                        223     241     +18
setfont_main                                         194     208     +14
loadfont_main                                        103     117     +14
static.KD_xxx                                          5       7      +2
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 6/0 up/down: 224/0)             Total: 224 bytes

Bit more bloaty, but more correct.
/me sighs

Thanks

Roy
diff -ur busybox-1.12.1.orig/console-tools/kbd_mode.c busybox-1.12.1/console-tools/kbd_mode.c
--- busybox-1.12.1.orig/console-tools/kbd_mode.c	2008-09-28 19:04:15.000000000 +0100
+++ busybox-1.12.1/console-tools/kbd_mode.c	2008-11-04 16:29:21.000000000 +0000
@@ -22,11 +22,14 @@
 		SCANCODE  = (1 << 0),
 		ASCII	  = (1 << 1),
 		MEDIUMRAW = (1 << 2),
-		UNICODE	  = (1 << 3)
+		UNICODE	  = (1 << 3),
+		OPT_C     = (1 << 4)
 	};
-	static const char KD_xxx[] ALIGN1 = "saku";
-	opt = getopt32(argv, KD_xxx);
-	fd = get_console_fd_or_die();
+	char *dev = NULL;
+	static const char KD_xxx[] ALIGN1 = "sakuC:";
+	opt = getopt32(argv, KD_xxx, &dev);
+	fd = get_console_fd_from_name_or_die(dev);
+	opt &= ~OPT_C;
 
 	if (!opt) { /* print current setting */
 		const char *mode = "unknown";
diff -ur busybox-1.12.1.orig/console-tools/loadfont.c busybox-1.12.1/console-tools/loadfont.c
--- busybox-1.12.1.orig/console-tools/loadfont.c	2008-09-28 19:04:15.000000000 +0100
+++ busybox-1.12.1/console-tools/loadfont.c	2008-11-04 16:29:21.000000000 +0000
@@ -144,10 +144,11 @@
 {
 	size_t len;
 	struct psf_header *psfhdr;
+	char *dev = NULL;
 
 	// no arguments allowed!
 	opt_complementary = "=0";
-	getopt32(argv, "");
+	getopt32(argv, "C:", &dev);
 
 	/*
 	 * We used to look at the length of the input file
@@ -159,7 +160,7 @@
 	// xmalloc_open_zipped_read_close(filename, &len);
 	if (!psfhdr)
 		bb_perror_msg_and_die("error reading input font");
-	do_load(get_console_fd_or_die(), psfhdr, len);
+	do_load(get_console_fd_from_name_or_die(dev), psfhdr, len);
 
 	return EXIT_SUCCESS;
 }
@@ -171,17 +172,17 @@
 {
 	size_t len;
 	struct psf_header *psfhdr;
-	char *mapfilename;
+	char *mapfilename, *dev = NULL;
 	int fd;
 
 	opt_complementary = "=1";
-	getopt32(argv, "m:", &mapfilename);
+	getopt32(argv, "m:C:", &mapfilename, &dev);
 	argv += optind;
 
 	// load font
 	len = 32*1024; // can't be larger
 	psfhdr = (struct psf_header *) xmalloc_open_zipped_read_close(*argv, &len);
-	fd = get_console_fd_or_die();
+	fd = get_console_fd_from_name_or_die(dev);
 	do_load(fd, psfhdr, len);
 
 	// load the screen map, if any
diff -ur busybox-1.12.1.orig/include/libbb.h busybox-1.12.1/include/libbb.h
--- busybox-1.12.1.orig/include/libbb.h	2008-09-28 19:04:26.000000000 +0100
+++ busybox-1.12.1/include/libbb.h	2008-11-04 16:29:53.000000000 +0000
@@ -287,6 +287,7 @@
 extern int device_open(const char *device, int mode) FAST_FUNC;
 enum { GETPTY_BUFSIZE = 16 }; /* more than enough for "/dev/ttyXXX" */
 extern int xgetpty(char *line) FAST_FUNC;
+extern int get_console_fd_from_name_or_die(const char *device) FAST_FUNC;
 extern int get_console_fd_or_die(void) FAST_FUNC;
 extern void console_make_active(int fd, const int vt_num) FAST_FUNC;
 extern char *find_block_device(const char *path) FAST_FUNC;
diff -ur busybox-1.12.1.orig/include/usage.h busybox-1.12.1/include/usage.h
--- busybox-1.12.1.orig/include/usage.h	2008-11-04 13:46:17.000000000 +0000
+++ busybox-1.12.1/include/usage.h	2008-11-04 16:29:21.000000000 +0000
@@ -2019,14 +2019,15 @@
        "	[ttl TTL] [tos TOS] [[no]pmtudisc] [dev PHYS_DEV]" \
 
 #define kbd_mode_trivial_usage \
-       "[-a|k|s|u]"
+       "[-C device] [-a|k|s|u]"
 #define kbd_mode_full_usage "\n\n" \
        "Report or set the keyboard mode\n" \
      "\nOptions set mode:" \
-     "\n	-a	Default (ASCII)" \
-     "\n	-k	Medium-raw (keyboard)" \
-     "\n	-s	Raw (scancode)" \
-     "\n	-u	Unicode (utf-8)" \
+     "\n	-C device	Device to use (default console)" \
+     "\n	-a		Default (ASCII)" \
+     "\n	-k		Medium-raw (keyboard)" \
+     "\n	-s		Raw (scancode)" \
+     "\n	-u		Unicode (utf-8)" \
 
 #define kill_trivial_usage \
        "[-l] [-signal] process-id..."
@@ -3520,10 +3521,11 @@
      "\n	-W	Display warnings about entries that had no matching files" \
 
 #define setfont_trivial_usage \
-       "[-m mapfile] font"
+       "[-C device] [-m mapfile] font"
 #define setfont_full_usage "\n\n" \
        "Load a console font\n" \
      "\nOptions:" \
+     "\n	-C device	Device to set font on (default console)" \
      "\n	-m mapfile	Load console screen map from mapfile"
 #define setfont_example_usage \
        "$ setfont -m koi8-r /etc/i18n/fontname\n"
diff -ur busybox-1.12.1.orig/libbb/get_console.c busybox-1.12.1/libbb/get_console.c
--- busybox-1.12.1.orig/libbb/get_console.c	2008-09-28 19:04:20.000000000 +0100
+++ busybox-1.12.1/libbb/get_console.c	2008-11-05 10:41:02.000000000 +0000
@@ -69,6 +68,26 @@
 	/*return fd; - total failure */
 }
 
+/* When setting things like fonts and keycodes we may want to operate on
+ * specific devices rather than the console we are currently attached to. */
+int FAST_FUNC get_console_fd_from_name_or_die(const char *device)
+{
+	int fd;
+	char arg;
+
+	if (!device)
+		return get_console_fd_or_die();
+
+	fd = open_a_console(device);
+	if (fd == -1)
+		bb_perror_msg_and_die("%s", device);
+
+	if (ioctl(fd, KDGKBTYPE, &arg) == -1)
+		bb_error_msg_and_die("%s: not a console", device);
+	
+	return fd;
+}
+
 /* From <linux/vt.h> */
 enum {
 	VT_ACTIVATE = 0x5606,   /* make vt active */
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox

Reply via email to