On Tuesday 04 November 2008 14:58:30 Roy Marples wrote:
> So, in an attempt yet again to get OpenRC to boot cleanly using busybox
> here's a patch that enables -C device for kbd_mode and setfont. The patch
> is done so extending similar support for other console tools is fairly
> trivial.

I forgot to attach the patch! How embarrasing :)
Anyway, attached

uberlaptop busybox-1.12.1 # ./scripts/bloat-o-meter ../*orig/busybox busybox
function                                             old     new   delta
get_console_fd_or_die                                141     193     +52
.rodata                                           163385  163419     +34
packed_usage                                       24130   24158     +28
kbd_mode_main                                        223     241     +18
setfont_main                                         194     208     +14
loadfont_main                                        103     117     +14
setkeycodes_main                                     186     191      +5
loadkmap_main                                        246     251      +5
dumpkmap_main                                        280     285      +5
deallocvt_main                                       102     107      +5
chvt_main                                             61      66      +5
static.KD_xxx                                          5       7      +2
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 12/0 up/down: 187/0)            Total: 187 bytes


Thanks

Roy
diff -ur busybox-1.12.1.orig/console-tools/chvt.c busybox-1.12.1/console-tools/chvt.c
--- busybox-1.12.1.orig/console-tools/chvt.c	2008-09-28 19:04:15.000000000 +0100
+++ busybox-1.12.1/console-tools/chvt.c	2008-11-04 14:14:04.000000000 +0000
@@ -19,6 +19,6 @@
 	}
 
 	num = xatou_range(argv[1], 1, 63);
-	console_make_active(get_console_fd_or_die(), num);
+	console_make_active(get_console_fd_or_die(NULL), num);
 	return EXIT_SUCCESS;
 }
diff -ur busybox-1.12.1.orig/console-tools/deallocvt.c busybox-1.12.1/console-tools/deallocvt.c
--- busybox-1.12.1.orig/console-tools/deallocvt.c	2008-09-28 19:04:15.000000000 +0100
+++ busybox-1.12.1/console-tools/deallocvt.c	2008-11-04 14:14:25.000000000 +0000
@@ -28,6 +28,6 @@
 	}
 
 	/* double cast suppresses "cast to ptr from int of different size" */
-	xioctl(get_console_fd_or_die(), VT_DISALLOCATE, (void *)(ptrdiff_t)num);
+	xioctl(get_console_fd_or_die(NULL), VT_DISALLOCATE, (void *)(ptrdiff_t)num);
 	return EXIT_SUCCESS;
 }
diff -ur busybox-1.12.1.orig/console-tools/dumpkmap.c busybox-1.12.1/console-tools/dumpkmap.c
--- busybox-1.12.1.orig/console-tools/dumpkmap.c	2008-09-28 19:04:15.000000000 +0100
+++ busybox-1.12.1/console-tools/dumpkmap.c	2008-11-04 14:15:07.000000000 +0000
@@ -32,7 +32,7 @@
 
 /*	bb_warn_ignoring_args(argc>=2);*/
 
-	fd = get_console_fd_or_die();
+	fd = get_console_fd_or_die(NULL);
 
 	write(STDOUT_FILENO, "bkeymap", 7);
 
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 14:36:15.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();
+	const char *dev = NULL;
+	static const char KD_xxx[] ALIGN1 = "sakuC:";
+	opt = getopt32(argv, KD_xxx, &dev);
+	fd = get_console_fd_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 14:18:42.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_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_or_die(dev);
 	do_load(fd, psfhdr, len);
 
 	// load the screen map, if any
diff -ur busybox-1.12.1.orig/console-tools/loadkmap.c busybox-1.12.1/console-tools/loadkmap.c
--- busybox-1.12.1.orig/console-tools/loadkmap.c	2008-09-28 19:04:15.000000000 +0100
+++ busybox-1.12.1/console-tools/loadkmap.c	2008-11-04 14:19:10.000000000 +0000
@@ -35,7 +35,7 @@
 
 /*  bb_warn_ignoring_args(argc>=2);*/
 
-	fd = get_console_fd_or_die();
+	fd = get_console_fd_or_die(NULL);
 
 	xread(STDIN_FILENO, flags, 7);
 	if (strncmp(flags, BINARY_KEYMAP_MAGIC, 7))
diff -ur busybox-1.12.1.orig/console-tools/setkeycodes.c busybox-1.12.1/console-tools/setkeycodes.c
--- busybox-1.12.1.orig/console-tools/setkeycodes.c	2008-09-28 19:04:15.000000000 +0100
+++ busybox-1.12.1/console-tools/setkeycodes.c	2008-11-04 14:19:39.000000000 +0000
@@ -30,7 +30,7 @@
 		bb_show_usage();
 	}
 
-	fd = get_console_fd_or_die();
+	fd = get_console_fd_or_die(NULL);
 
 	while (argc > 2) {
 		a.keycode = xatou_range(argv[2], 0, 127);
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 14:11:26.000000000 +0000
@@ -287,7 +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_or_die(void) FAST_FUNC;
+extern int get_console_fd_or_die(const char *device) 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;
 /* bb_copyfd_XX print read/write errors and return -1 if they occur */
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 14:43:33.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-04 14:11:45.000000000 +0000
@@ -38,7 +38,7 @@
  * if someone else used X (which does a chown on /dev/console).
  */
 
-int FAST_FUNC get_console_fd_or_die(void)
+int FAST_FUNC get_console_fd_or_die(const char *device)
 {
 	static const char *const console_names[] = {
 		DEV_CONSOLE, CURRENT_VC, CURRENT_TTY
@@ -46,6 +46,13 @@
 
 	int fd;
 
+	if (device) {
+		fd = open_a_console(device);
+		if (fd != -1)
+			return fd;
+		goto die;
+	}
+
 	for (fd = 2; fd >= 0; fd--) {
 		int fd4name;
 		int choice_fd;
@@ -65,6 +72,7 @@
 		}
 	}
 
+die:
 	bb_error_msg_and_die("can't open console");
 	/*return fd; - total failure */
 }
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox

Reply via email to