[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

INIT: PID 1



I've grown tired of 'init' always having a different PID depending on what
has loaded before it.  Here's a simple patch to set it up so that the INIT
process always has PID 1 even if it isn't the first thing to run.

The patch is relative to an "h6"-patched MiNT 1.10.

diff -u orig/main.c ./main.c
--- orig/main.c	Tue Jul 19 04:40:40 1994
+++ ./main.c	Wed Jul 20 06:20:28 1994
@@ -882,6 +882,9 @@
 /* run any programs appearing after us in the AUTO folder */
 	run_auto_prgs();
 
+/* prepare to run the init program as PID 1. */
+	set_pid_1();
+
 /* run the initial program */
 /* if that program is in fact GEM, we start it via exec_os, otherwise
  * we do it with Pexec.
diff -u orig/proto.h ./proto.h
--- orig/proto.h	Wed Jul 20 06:34:38 1994
+++ ./proto.h	Wed Jul 20 06:33:12 1994
@@ -307,6 +307,7 @@
 MEMREGION *addr2mem P_((virtaddr a));
 PROC *pid2proc P_((int pid));
 int newpid P_((void));
+int set_pid_1 P_((void));
 void zero P_((char *place, long size));
 void * ARGS_ON_STACK kmalloc P_((long size));
 void *kcore P_((long size));
diff -u orig/util.c ./util.c
--- orig/util.c	Tue Jul 19 04:41:28 1994
+++ ./util.c	Wed Jul 20 06:20:18 1994
@@ -49,10 +49,10 @@
  * return a new pid
  */
 
+static int _maxpid = 2;
 int
 newpid()
 {
-	static int _maxpid = 1;
 	int i;
 #ifndef NDEBUG
 	int j = 0;
@@ -60,12 +60,24 @@
 
 	do {
 		i = _maxpid++;
-		if (_maxpid >= 1000) _maxpid = 1;
+		if (_maxpid >= 1000) _maxpid = 2;
 		assert(j++ < 1000);
 	} while (pid2proc(i));
 
 	return i;
 }
+
+/*
+ * set up to run the init program as PID 1
+ */
+int
+set_pid_1()
+{
+	if (pid2proc(1)) /* should never happen, only called once */
+		return -1;
+	_maxpid = 1;
+	return 0;
+}
 
 /*
  * zero out a block of memory, quickly; the block must be word-aligned,

--
entropy -- it's not just a good idea, it's the second law.
Personal mail:      entropy@gnu.ai.mit.edu
MiNT library mail:  entropy@terminator.rs.itd.umich.edu
"what do you have against octal?" -jrb