Subject: xsrc/35919: some minor cleanups of WSCONS/PCVT setup messages
To: None <xsrc-manager@netbsd.org, gnats-admin@netbsd.org,>
From: Greg A. Woods <woods@planix.com>
List: netbsd-bugs
Date: 03/05/2007 03:35:00
>Number:         35919
>Category:       xsrc
>Synopsis:       some minor cleanups of WSCONS/PCVT setup messages
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    xsrc-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Mar 05 03:35:00 +0000 2007
>Originator:     Greg A. Woods
>Release:        NetBSD xsrc-current
>Organization:
Planix, Inc.; Toronto, Ontario; Canada
>Environment:
System: NetBSD
>Description:

	some minor cleanups of WSCONS/PCVT setup messages

>How-To-Repeat:

>Fix:

Index: xfree/xc/programs/Xserver/hw/xfree86/os-support/bsd/bsd_init.c
===================================================================
RCS file: /cvs/master/m-NetBSD/main/xsrc/xfree/xc/programs/Xserver/hw/xfree86/os-support/bsd/bsd_init.c,v
retrieving revision 1.2
diff -u -r1.2 bsd_init.c
--- xfree/xc/programs/Xserver/hw/xfree86/os-support/bsd/bsd_init.c	26 Jan 2005 22:19:04 -0000	1.2
+++ xfree/xc/programs/Xserver/hw/xfree86/os-support/bsd/bsd_init.c	28 Jan 2005 21:50:59 -0000
@@ -36,6 +36,7 @@
 #include <sys/param.h>
 #include <sys/utsname.h>
 #include <stdlib.h>
+#include <paths.h>
 
 static Bool KeepTty = FALSE;
 static int devConsoleFd = -1;
@@ -73,7 +74,7 @@
 #endif
 
 #if defined(WSCONS_SUPPORT) && defined(__NetBSD__)
-/* NetBSD's new console driver */
+/* NetBSD's new console driver, in PCVT compatability mode, "options WSDISPLAY_COMPAT_PCVT" */
 #define WSCONS_PCVT_COMPAT_CONSOLE_DEV "/dev/ttyE0"
 #endif
 
@@ -163,7 +164,7 @@
 	/* check if we are run with euid==0 */
 	if (geteuid() != 0)
 	{
-	    FatalError("xf86OpenConsole: Server must be suid root");
+	    FatalError("xf86OpenConsole: Server must be run as root");
 	}
 
 	if (!KeepTty)
@@ -224,11 +225,11 @@
 	     * Hack to prevent keyboard hanging when syslogd closes
 	     * /dev/console
 	     */
-	    if ((devConsoleFd = open("/dev/console", O_WRONLY,0)) < 0)
+	    if ((devConsoleFd = open(_PATH_CONSOLE, O_WRONLY,0)) < 0)
 	    {
 		xf86Msg(X_WARNING,
-			"xf86OpenConsole: couldn't open /dev/console (%s)\n",
-			strerror(errno));
+			"xf86OpenConsole: couldn't open %s (%s)\n",
+			_PATH_CONSOLE, strerror(errno));
 	    }
 	    break;
 #endif
@@ -336,6 +337,7 @@
 {
     int fd = -1;
 
+    xf86Msg(X_INFO, "xf86OpenPccons: trying %s or %s\n", PCCONS_CONSOLE_DEV1, PCCONS_CONSOLE_DEV1);
     if ((fd = open(PCCONS_CONSOLE_DEV1, PCCONS_CONSOLE_MODE, 0))
 	>= 0 ||
 	(fd = open(PCCONS_CONSOLE_DEV2, PCCONS_CONSOLE_MODE, 0))
@@ -370,6 +372,7 @@
     long syscons_version;
     MessageType from;
 
+    xf86Msg(X_INFO, "xf86OpenSyscons: trying %s\n", SYSCONS_CONSOLE_DEV);
     /* Check for syscons */
     if ((fd = open(SYSCONS_CONSOLE_DEV1, SYSCONS_CONSOLE_MODE, 0)) >= 0
 	|| (fd = open(SYSCONS_CONSOLE_DEV2, SYSCONS_CONSOLE_MODE, 0)) >= 0)
@@ -465,7 +468,8 @@
 		FatalError("xf86OpenSyscons: VT_GETMODE failed");
 	    }
 	    xf86Info.consType = SYSCONS;
-	    xf86Msg(X_PROBED, "Using syscons driver with X support");
+	    xf86Info.screenName = strdup(vtname);
+	    xf86Msg(X_PROBED, "Using syscons driver via %s with X support", vtname);
 	    if (syscons_version >= 0x100)
 	    {
 		xf86ErrorF(" (version %ld.%ld)\n", syscons_version >> 8,
@@ -508,10 +512,12 @@
     vtprefix = "/dev/ttyC";
 #endif
 
+    xf86Msg(X_INFO, "xf86OpenPcvt: trying %s\n", PCVT_CONSOLE_DEV);
     fd = open(PCVT_CONSOLE_DEV, PCVT_CONSOLE_MODE, 0);
 #ifdef WSCONS_PCVT_COMPAT_CONSOLE_DEV
     if (fd < 0)
     {
+	xf86Msg(X_INFO, "xf86OpenPcvt: (WSCONS_PCVT_COMPAT) trying %s\n", WSCONS_PCVT_COMPAT_CONSOLE_DEV);
 	fd = open(WSCONS_PCVT_COMPAT_CONSOLE_DEV, PCVT_CONSOLE_MODE, 0);
 	vtprefix = "/dev/ttyE";
     }
@@ -574,6 +580,7 @@
 		FatalError("xf86OpenPcvt: Cannot open %s (%s)",
 			   vtname, strerror(errno));
 	    }
+	    xf86Info.screenName = strdup(vtname);
 	    if (ioctl(fd, VT_GETMODE, &vtmode) < 0)
 	    {
 		FatalError("xf86OpenPcvt: VT_GETMODE failed");
@@ -581,12 +588,13 @@
 	    xf86Info.consType = PCVT;
 #ifdef WSCONS_SUPPORT
 	    xf86Msg(X_PROBED,
-		    "Using wscons driver in pcvt compatibility mode "
+		    "Using wscons driver via %s in pcvt compatibility mode "
 		    "(version %d.%d)\n",
+		    vtname,
 		    pcvt_version.rmajor, pcvt_version.rminor);
 #else
-	    xf86Msg(X_PROBED, "Using pcvt driver (version %d.%d)\n",
-		    pcvt_version.rmajor, pcvt_version.rminor);
+	    xf86Msg(X_PROBED, "Using pcvt driver via %s (version %d.%d)\n",
+		    vtname, pcvt_version.rmajor, pcvt_version.rminor);
 #endif
 	}
 	else
@@ -617,18 +625,24 @@
 	sprintf(ttyname, "/dev/ttyE%d", i);
 #elif defined(__OpenBSD__)
 	sprintf(ttyname, "/dev/ttyC%d", i);
+#else
+# include "ERROR: WSCONS_SUPPORT is currently only available for NetBSD and OpenBSD"
 #endif
-	if ((fd = open(ttyname, 2)) != -1)
+	xf86Msg(X_INFO, "xf86OpenWScons: trying %s\n", ttyname);
+	if ((fd = open(ttyname, O_RDWR, 0)) != -1) {
+	    xf86Msg(X_WARNING, "xf86OpenWScons: open(%s) failed: %s\n", ttyname, strerror(errno));
 	    break;
+	}
     }
     if (fd != -1) {
 	if (ioctl(fd, WSDISPLAYIO_SMODE, &mode) < 0) {
-	    FatalError("%s: WSDISPLAYIO_MODE_MAPPED failed (%s)\n%s",
-		       "xf86OpenConsole", strerror(errno),
+	    FatalError("%s: WSDISPLAYIO_MODE_MAPPED failed on %s (%s)\n%s", 
+		       ttyname, "xf86OpenConsole", strerror(errno),
 		       CHECK_DRIVER_MSG);
 	}
+	xf86Info.screenName = strdup(ttyname);
 	xf86Info.consType = WSCONS;
-	xf86Msg(X_PROBED, "Using wscons driver\n");
+	xf86Msg(X_PROBED, "Using wscons driver on %s\n", ttyname);
     }
     return fd;
 }
@@ -683,10 +697,14 @@
     {
 	close(xf86Info.screenFd);
 	close(xf86Info.consoleFd);
-	if ((xf86Info.consoleFd = open("/dev/console",O_RDONLY,0)) <0)
+	/* XXX Why the hell bother doing this just to close it again immediately!?!?!?!? */
+	if ((xf86Info.consoleFd = open(_PATH_CONSOLE, O_RDONLY, 0)) <0)
 	{
-	    xf86FatalError("xf86CloseConsole: Cannot open /dev/console (%s)",
-			   strerror(errno));
+	    char *fmsg;
+
+	    asprintf(&fmsg, "%s: %s", _PATH_CONSOLE, strerror(errno));
+	    xf86FatalError("xf86CloseConsole: Cannot open console read-only (%s)", fmsg);
+	    free(fmsg);
 	}
     }
     close(xf86Info.consoleFd);