Subject: bin/34305: [dM] screenblank as utility
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: netbsd-bugs
Date: 08/27/2006 23:15:00
>Number:         34305
>Category:       bin
>Synopsis:       screenblank could be more useful
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sun Aug 27 23:15:00 +0000 2006
>Originator:     der Mouse
>Release:        1.4T; -current is similar
>Organization:
	Dis-
>Environment:
	Any with a screenblankable framebuffer
>Description:
	In some cases (in mine, a SPARCstation Voyager running with a
	head but keyboardless, with serial console) a utility to just
	blank or unblank a framebuffer on command is useful.
	screenblank(1) seems like the obvious candidate, but it does
	too much.  These patches give it options to support such "just
	do this" operation.
>How-To-Repeat:
	Want the above.  Look for it.  Get frustrated. :-)
>Fix:
	These patches are to 1.4T, since that's what I have.  Looking
	at diffs between 1.4T screenblank and -current screenblank
	makes me think they should go fairly easily into -current.

	In passing, why is screenblank in /usr/sbin but nevertheless in
	manpage section 1?

diff -u /sources/postpatches/usr.sbin/screenblank/screenblank.1 ./screenblank.1
--- /sources/postpatches/usr.sbin/screenblank/screenblank.1	Tue Jul  1 19:34:10 2003
+++ ./screenblank.1	Sun Aug 27 17:43:54 2006
@@ -25,7 +25,7 @@
 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 
+.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
@@ -39,9 +39,10 @@
 .Os
 .Sh NAME
 .Nm screenblank
-.Nd screen saver daemon for wscons and FBIO machines 
+.Nd screen saver daemon for wscons and FBIO machines
 .Sh SYNOPSIS
 .Nm screenblank
+.Op Fl u | Fl b
 .Op Fl k | Fl m
 .Op Fl d Ar timeout
 .Op Fl e Ar timeout
@@ -78,6 +79,12 @@
 .Ar framebuffer
 instead of the default
 .Pa /dev/fb .
+.It Fl u
+Overriding the other options, simply try (once) to unblank the
+framebuffer, then exit.
+.It Fl b
+Overriding the other options, simply try (once) to blank the
+framebuffer, then exit.
 .El
 .Pp
 Note that the
diff -u /sources/postpatches/usr.sbin/screenblank/screenblank.c ./screenblank.c
--- /sources/postpatches/usr.sbin/screenblank/screenblank.c	Sun Jul 20 22:55:43 2003
+++ ./screenblank.c	Sun Aug 27 17:43:54 2006
@@ -26,7 +26,7 @@
  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
@@ -107,6 +107,8 @@
 	struct sigaction sa;
 	struct stat st;
 	int ch, change, fflag = 0, kflag = 0, mflag = 0, state;
+	int bflag;
+	int uflag;
 	const char *kbd, *mouse, *display;
 
 	LIST_INIT(&ds_list);
@@ -119,8 +121,13 @@
 	timo_off.tv_sec = 0;
 	timo_off.tv_usec = 250000;
 
-	while ((ch = getopt(argc, argv, "d:e:f:km")) != -1) {
+	while ((ch = getopt(argc, argv, "bd:e:f:kmu")) != -1) {
 		switch (ch) {
+		case 'b':
+			bflag = 1;
+			uflag = 0;
+			break;
+
 		case 'd':
 			cvt_arg(optarg, &timo_on);
 			break;
@@ -146,6 +153,11 @@
 			mflag = 1;
 			break;
 
+		case 'u':
+			uflag = 1;
+			bflag = 0;
+			break;
+
 		default:
 			usage();
 		}
@@ -188,6 +200,14 @@
 #endif
 
 	/*
+	 * Handle -b and -u modes.
+	 */
+	if (bflag || uflag) {
+		change_state(bflag?videooff:videoon);
+		exit(0);
+	}
+
+	/*
 	 * Add the keyboard, mouse, and default framebuffer devices
 	 * as necessary.  We _always_ check the console device.
 	 */
@@ -368,7 +388,7 @@
 	tvp->tv_sec = seconds;
 	if (factor > 1)
 		microseconds *= factor;
-		
+
 	tvp->tv_usec = microseconds;
 }
 
@@ -376,7 +396,7 @@
 usage()
 {
 
-	fprintf(stderr, "usage: %s [-k | -m] [-d timeout] [-e timeout] %s\n",
+	fprintf(stderr, "usage: %s [-b | -u] [-k | -m] [-d timeout] [-e timeout] %s\n",
 	    __progname, "[-f framebuffer]");
 	exit(1);
 }