[PATCH] openvt improvements

James Simmons jsimmons at infradead.org
Fri Apr 18 14:43:41 UTC 2008


Implemented -s and -ws behavior for openvt.

Index: console-tools/openvt.c
===================================================================
--- console-tools/openvt.c	(revision 21761)
+++ console-tools/openvt.c	(working copy)
@@ -107,8 +107,9 @@
 int openvt_main(int argc ATTRIBUTE_UNUSED, char **argv)
 {
 	char vtname[sizeof(VC_FORMAT) + sizeof(int)*3];
+	struct vt_stat vtstat;
+	int vtno, consfd;
 	char *str_c;
-	int vtno;
 	int flags;
 	enum {
 		OPT_c = (1 << 0),
@@ -136,11 +137,12 @@
 	bb_daemonize_or_rexec(DAEMON_CLOSE_EXTRA_FDS | DAEMON_ONLY_SANITIZE, NULL);
 	close(0);
 	/*setsid(); - BAD IDEA: after we exit, child is SIGHUPed... */
-	xopen(vtname, O_RDWR);
+	consfd = xopen(vtname, O_RDWR);
+	xioctl(consfd, VT_GETSTATE, &vtstat);	
 
 	if (flags & OPT_s) {
-		xioctl(0, VT_ACTIVATE, (void*)(ptrdiff_t)vtno);
-		xioctl(0, VT_WAITACTIVE, (void*)(ptrdiff_t)vtno);
+		xioctl(consfd, VT_ACTIVATE, (void*)(ptrdiff_t)vtno);
+		xioctl(consfd, VT_WAITACTIVE, (void*)(ptrdiff_t)vtno);
 	}
 
 	if (!argv[0]) {
@@ -151,8 +153,8 @@
 		/*argv[1] = NULL; - already is */
 	}
 
-	xdup2(0, STDOUT_FILENO);
-	xdup2(0, STDERR_FILENO);
+	xdup2(consfd, STDOUT_FILENO);
+	xdup2(consfd, STDERR_FILENO);
 
 #ifdef BLOAT
 	/* Handle -l (login shell) option */
@@ -164,8 +166,11 @@
 	vfork_child(argv);
 	if (flags & OPT_w) {
 		wait(NULL);
-// TODO: -ws handling should be here
+		if (flags & OPT_s) {
+			xioctl(consfd, VT_ACTIVATE, vtstat.v_active);
+			xioctl(consfd, VT_WAITACTIVE, vtstat.v_active);
+			xioctl(consfd, VT_DISALLOCATE, (void*)(ptrdiff_t)vtno);
+		}
 	}
-
 	return EXIT_SUCCESS;
 }



More information about the busybox mailing list