Being `well and truly up the creek'

Chris Torek chris at umcp-cs.UUCP
Tue Nov 12 20:12:49 AEST 1985


One of the most, er, `interesting' things that can happen to a root
file system is to lose /dev (have it turn into an ordinary file or
soemthing).  If you have lost /dev, *and nothing else*, it would
seem perfectly reasonable that /etc/init could come up single user
by creating a new console device.  Of course, it will not, and one
is forced to recover with standalone programs or a 4.2-style minifs.

Here is an *untested* change to init that should be easy enough
to install in a 4.2 system to do this.

*** /usr/src/etc/init.c	Wed Sep 18 21:40:02 1985
--- init.c	Tue Nov 12 05:11:46 1985
***************
*** 193,197 ****
  			signal(SIGALRM, SIG_DFL);
  			signal(SIGTSTP, SIG_IGN);
! 			(void) open(ctty, O_RDWR);
  			dup2(0, 1);
  			dup2(0, 2);
--- 193,197 ----
  			signal(SIGALRM, SIG_DFL);
  			signal(SIGTSTP, SIG_IGN);
! 			get_console();
  			dup2(0, 1);
  			dup2(0, 2);
***************
*** 203,206 ****
--- 203,221 ----
  				break;
  	} while (xpid == -1);
+ }
+ 
+ /*
+  * Open the console, and if it fails make a last ditch attempt to
+  * create a new one.  Assumes fd 0 is not currently open.
+  */
+ get_console()
+ {
+ 
+ 	if (open(ctty, O_RDWR) == 0)
+ 		return;
+ 	(void) strcpy(ctty, "/#console");
+ 	(void) mknod(ctty, S_IFCHR|0644, 0);
+ 	(void) open(ctty, O_RDWR);
+ 	(void) write(0, "WARNING: /dev/console gone, made /#console\n", 43);
  }
  
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at mimsy.umd.edu



More information about the Comp.unix.wizards mailing list