Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 16 Oct 2000 11:32:12 +0300
From:      Valentin Nechayev <netch@segfault.kiev.ua>
To:        markm@freebsd.org, freebsd-current@freebsd.org
Subject:   random fallback init
Message-ID:  <20001016113212.A241@nn.kiev.ua>

next in thread | raw e-mail | index | archive | help
The problem that when random device was not seeded, boot simply hangs (on
ldconfig! why?) Ugly init(8) gives no chance to stop booting and fall to
reboot or single mode again via ctrl-alt-del or another key combination;
sleeping on "rndblk" channel in ldconfig is not interruptible; only DDB or
Reset button save, with respective results as fsck need;(

Patch below is not simply patch (I suppose Mark Murray is good programmer,
and I am too lame to learn him how to program), but quick (and dirty?)
realization of requirement that random device must work even when it was not
seeded externally, and it works in patched variant at my system:

==={{{ screenshot part
Starting final network daemons:.
setting ELF ldconfig path: /usr/lib /usr/lib/compat /usr/X11R6/lib /usr/local/li
b
random_read: no seed yet, provide fallback
setting a.out ldconfig path: /usr/lib/aout /usr/lib/compat/aout /usr/X11R6/lib/a
out
starting standard daemons: cron sendmail sshd.
===}}}

Of course, it should be combined with patch of /etc/rc (see letter to -current:
`From: Doug Barton <DougB@gorean.org>
Message-ID: <39EA211D.2F2695AF@gorean.org>').

diff -rNu src.orig/sys/dev/random/randomdev.c src/sys/dev/random/randomdev.c
--- src.orig/sys/dev/random/randomdev.c	Sat Oct 14 13:59:54 2000
+++ src/sys/dev/random/randomdev.c	Mon Oct 16 11:07:29 2000
@@ -113,7 +113,11 @@
 		error =  EWOULDBLOCK;
 	}
 	else {
-		if (random_state.seeded) {
+		if (!random_state.seeded) {
+			printf("random_read: no seed yet, provide fallback\n");
+			reseed(FAST);
+		}
+		if (1) {	/* if(random_state.seeded) was here */
 			c = min(uio->uio_resid, PAGE_SIZE);
 			random_buf = (void *)malloc(c, M_TEMP, M_WAITOK);
 			while (uio->uio_resid > 0 && error == 0) {
@@ -122,8 +126,6 @@
 			}
 			free(random_buf, M_TEMP);
 		}
-		else
-			error = tsleep(&random_state, 0, "rndblk", 0);
 	}
 	return error;
 }
diff -rNu src.orig/sys/dev/random/yarrow.c src/sys/dev/random/yarrow.c
--- src.orig/sys/dev/random/yarrow.c	Sat Oct 14 13:59:54 2000
+++ src/sys/dev/random/yarrow.c	Mon Oct 16 11:02:17 2000
@@ -268,7 +268,7 @@
 #endif
 }
 
-static void
+void
 reseed(int fastslow)
 {
 	/* Interrupt-context stack is a limited resource; make large
@@ -355,9 +355,6 @@
 	/* 7. Dump to seed file */
 	/* XXX Not done here yet */
 
-	/* Release the reseed mutex */
-	mtx_exit(&random_reseed_mtx, MTX_DEF);
-
 #ifdef DEBUG
 	printf("Reseed finish\n");
 #endif
@@ -367,6 +364,9 @@
 		selwakeup(&random_state.rsel);
 		wakeup(&random_state);
 	}
+
+	/* Release the reseed mutex */
+	mtx_exit(&random_reseed_mtx, MTX_DEF);
 
 }
 
diff -rNu src.orig/sys/dev/random/yarrow.h src/sys/dev/random/yarrow.h
--- src.orig/sys/dev/random/yarrow.h	Sat Oct 14 13:59:54 2000
+++ src/sys/dev/random/yarrow.h	Mon Oct 16 11:02:32 2000
@@ -46,6 +46,7 @@
 void random_init_harvester(void (*)(struct timespec *, void *, u_int, u_int, u_int, enum esource), u_int (*)(void *, u_int));
 void random_deinit_harvester(void);
 void random_set_wakeup_exit(void *);
+void reseed(int);
 
 u_int read_random_real(void *, u_int);
 void write_random(void *, u_int);


/netch


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20001016113212.A241>