Subject: kern/2236: [dM] missing /dev/console causes trouble
To: None <gnats-bugs@NetBSD.ORG>
From: der Mouse <mouse@Collatz.McRCIM.McGill.EDU>
List: netbsd-bugs
Date: 03/17/1996 20:43:23
>Number:         2236
>Category:       kern
>Synopsis:       [dM] missing /dev/console causes trouble
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    kern-bug-people (Kernel Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sun Mar 17 21:05:01 1996
>Last-Modified:
>Originator:     der Mouse
>Organization:
	Dis-
>Release:        NetBSD-current as of Feb 27
>Environment:
	Sun-3/110, but it doesn't matter
>Description:
	If /dev/console is missing (usually because /dev/MAKEDEV hasn't
	been run for a new installation), the machine appears to go
	catatonic immediately after announcing its swap location.  This
	confuses people, sometimes even the same person multiple times,
	and leads to unnecessary noise on current-users and assorted
	port-* lists. :-)
>How-To-Repeat:
	Blow away /dev and reboot.  Watch the machine go catatonic with
	no indication of why.
>Fix:
	This patch makes the kernel check for /dev/console just before
	it execs init.  If it doesn't find it, it prints a warning (but
	goes ahead anyway on the theory that even if it does hang,
	that's no worse than anything else that could be done at that
	point, and there _might_ be an unusual user-land in place that
	doesn't mind the missing /dev/console).

	On my Sun-3/110, with this patch the kernel compiles, links,
	and runs under normal circumstances; in a simple test I did
	with a completely empty /dev (booting off my zip drive), it did
	print the "warning: no /dev/console" message.  I have not tried
	any test circumstances under which I would expect the other
	warning message.

	Arguably, the kernel should check that /dev/console is a
	character special device node whose major number indexes into
	cdevsw to point to the console driver.  Personally, I feel that
	is more work than it's worth, since the usual failure case is
	completely forgetting about MAKEDEV and thus having a
	nonexistent /dev/console.

	I don't like having the kernel know about a path like
	/dev/console, but it's only a warning and /dev/console is a
	fairly ubiquitous path (= it would be fairly hard to construct
	a scenario where one could reasonably want it absent), and thus
	the benefit seems to me to outweigh the uglitude.

--- OLD/sys/kern/init_main.c	Thu Jan  1 00:00:00 1970
+++ NEW/sys/kern/init_main.c	Thu Jan  1 00:00:00 1970
@@ -370,6 +370,26 @@
 	/* NOTREACHED */
 }
 
+static void check_console(struct proc *p)
+{
+ struct nameidata nd;
+ int error;
+
+ NDINIT(&nd,LOOKUP,FOLLOW,UIO_SYSSPACE,"/dev/console",p);
+ error = namei(&nd);
+ if (error)
+  { if (error == ENOENT)
+     { printf("warning: no /dev/console\n");
+     }
+    else
+     { printf("warning: lookup /dev/console: error %d\n",error);
+     }
+  }
+ else
+  { vrele(nd.ni_vp);
+  }
+}
+
 /*
  * List of paths to try when searching for "init".
  */
@@ -414,6 +434,8 @@
 	 */
 	cpu_set_init_frame(p, initframep);
 #endif
+
+	check_console(p);
 
 	/*
 	 * Need just enough stack to hold the faked-up "execve()" arguments.

					der Mouse

			    mouse@collatz.mcrcim.mcgill.edu
>Audit-Trail:
>Unformatted: