2006-02-05  Guillem Jover  <guillem@hadrons.org>

	* hurd/process.defs (proc_mark_essential): New routine definition.
	* hurd/process_request.defs (proc_mark_essential_request): New
	simpleroutine definition.
	* init/init.c (launch_core_servers): Mark auth, proc and fs servers
	as essential.
	(frob_kernel_process): Mark the kernel as essential.
	* proc/mgt.c (create_startup_proc): Mark init as essential.
	* proc/pgrp.c (S_proc_getpgrppids): Understand PGID of -1 as meaning
	all processes in the system but essential ones.
	(S_proc_mark_essential): New function.
	* proc/proc.h (struct proc): Add p_essential member.


Index: hurd/process.defs
===================================================================
RCS file: /sources/hurd/hurd/hurd/process.defs,v
retrieving revision 1.28
diff -u -r1.28 process.defs
--- hurd/process.defs	21 May 2002 23:07:16 -0000	1.28
+++ hurd/process.defs	5 Feb 2006 19:10:37 -0000
@@ -1,5 +1,5 @@
 /* Definitions for process server interface
-   Copyright (C) 1992,93,94,95,96,97,2001 Free Software Foundation
+   Copyright (C) 1992,93,94,95,96,97,2001,06 Free Software Foundation
 
 This file is part of the GNU Hurd.
 
@@ -364,3 +364,7 @@
 	calling_process: process_t;
 	target_process: pid_t;
 	out tty: mach_port_send_t);
+
+/* Inform the process server that the process is essential.  */
+routine proc_mark_essential (
+	process: process_t);
Index: hurd/process_request.defs
===================================================================
RCS file: /sources/hurd/hurd/hurd/process_request.defs,v
retrieving revision 1.3
diff -u -r1.3 process_request.defs
--- hurd/process_request.defs	24 Jul 1998 23:39:10 -0000	1.3
+++ hurd/process_request.defs	5 Feb 2006 19:10:37 -0000
@@ -1,6 +1,6 @@
 /* Definitions for process server interface (request-only version)
 
-   Copyright (C) 1992, 93, 94, 95, 96, 98 Free Software Foundation, Inc.
+   Copyright (C) 1992, 93, 94, 95, 96, 98, 2006 Free Software Foundation, Inc.
 
 This file is part of the GNU Hurd.
 
@@ -365,3 +365,8 @@
 	process: process_t;
 	ureplyport reply: reply_port_t;
 	pid: pid_t);
+
+/* Inform the process server that the process is essential.  */
+simpleroutine proc_mark_essential_request (
+	process: process_t;
+	ureplyport reply: reply_port_t);
Index: init/init.c
===================================================================
RCS file: /sources/hurd/hurd/init/init.c,v
retrieving revision 1.130
diff -u -r1.130 init.c
--- init/init.c	24 Feb 2005 01:48:44 -0000	1.130
+++ init/init.c	5 Feb 2006 19:10:37 -0000
@@ -1,6 +1,6 @@
 /* Start and maintain hurd core servers and system run state
 
-   Copyright (C) 1993,94,95,96,97,98,99,2000,01,02
+   Copyright (C) 1993,94,95,96,97,98,99,2000,01,02,06
    	Free Software Foundation, Inc.
    This file is part of the GNU Hurd.
 
@@ -649,6 +649,7 @@
   proc_child (procserver, authtask);
 
   proc_task2proc (procserver, authtask, &authproc);
+  proc_mark_essential (authproc);
   proc_mark_exec (authproc);
   startup_authinit_reply (authreply, authreplytype, 0, authproc,
 			  MACH_MSG_TYPE_COPY_SEND);
@@ -671,6 +672,7 @@
   err = proc_task2proc (procserver, proctask, &procproc);
   if (!err)
     {
+      proc_mark_essential (procproc);
       proc_mark_exec (procproc);
       mach_port_deallocate (mach_task_self (), procproc);
     }
@@ -680,6 +682,7 @@
   /* Get the bootstrap filesystem's proc server port.
      We must do this before calling proc_setmsgport below.  */
   proc_task2proc (procserver, fstask, &fsproc);
+  proc_mark_essential (fsproc);
   proc_mark_exec (fsproc);
 
 #if 0
@@ -784,8 +787,10 @@
       return;
     }
 
-  /* Mark the kernel task as an essential task so that we never
-     want to task_terminate it.  */
+  /* Mark the kernel task as an essential task so that we or the proc server
+     never want to task_terminate it.  */
+  proc_mark_essential (proc);
+
   err = record_essential_task ("kernel", task);
   assert_perror (err);
 
Index: proc/mgt.c
===================================================================
RCS file: /sources/hurd/hurd/proc/mgt.c,v
retrieving revision 1.67
diff -u -r1.67 mgt.c
--- proc/mgt.c	16 Aug 2003 22:19:37 -0000	1.67
+++ proc/mgt.c	5 Feb 2006 19:10:38 -0000
@@ -1,5 +1,6 @@
 /* Process management
-   Copyright (C) 1992,93,94,95,96,99,2000,01,02 Free Software Foundation, Inc.
+   Copyright (C) 1992,93,94,95,96,99,2000,01,02,06
+	Free Software Foundation, Inc.
 
 This file is part of the GNU Hurd.
 
@@ -592,6 +593,8 @@
 
   p->p_deadmsg = 1;		/* Force initial "re-"fetch of msgport.  */
 
+  p->p_essential = 1;
+
   p->p_noowner = 0;
   p->p_id = make_ids (&zero, 1);
   assert (p->p_id);
Index: proc/pgrp.c
===================================================================
RCS file: /sources/hurd/hurd/proc/pgrp.c,v
retrieving revision 1.23
diff -u -r1.23 pgrp.c
--- proc/pgrp.c	8 May 2002 09:24:52 -0000	1.23
+++ proc/pgrp.c	5 Feb 2006 19:10:38 -0000
@@ -1,5 +1,5 @@
 /* Session and process group manipulation
-   Copyright (C) 1992,93,94,95,96,99,2001,02 Free Software Foundation, Inc.
+   Copyright (C) 1992,93,94,95,96,99,2001,02,06 Free Software Foundation, Inc.
 
 This file is part of the GNU Hurd.
 
@@ -264,9 +264,18 @@
     }
 
   count = 0;
-  for (p = pg->pg_plist; p; p = p->p_gnext)
-    if (++count <= npids)
-      *pp++ = p->p_pid;
+  if (pgid == 1)
+    {
+      for (p = pg->pg_plist; p; p = p->p_gnext)
+	if (++count <= npids && !p->p_essential)
+	  *pp++ = p->p_pid;
+    }
+  else
+    {
+      for (p = pg->pg_plist; p; p = p->p_gnext)
+	if (++count <= npids)
+	  *pp++ = p->p_pid;
+    }
 
   if (count > npids)
     /* They didn't all fit. */
@@ -277,8 +286,17 @@
 	return errno;
 
       pp = *pids;
-      for (p = pg->pg_plist; p; p = p->p_gnext)
-	*pp++ = p->p_pid;
+      if (pgid == 1)
+	{
+	  for (p = pg->pg_plist; p; p = p->p_gnext)
+	    if (!p->p_essential)
+	      *pp++ = p->p_pid;
+	}
+      else
+	{
+	  for (p = pg->pg_plist; p; p = p->p_gnext)
+	    *pp++ = p->p_pid;
+	}
       /* Dealloc ? XXX */
     }
   *npidsp = count;
@@ -380,6 +398,16 @@
   return 0;
 }
 
+/* Implement proc_mark_essential as described in <hurd/process.defs>. */
+kern_return_t
+S_proc_mark_essential (struct proc *p)
+{
+  if (!p)
+    return EOPNOTSUPP;
+  p->p_essential = 1;
+  return 0;
+}
+
 /* Make process P no longer a member of its process group.
    Note that every process is always a member of some process group;
    this must be followed by setting P->p_pgrp and then calling
Index: proc/proc.h
===================================================================
RCS file: /sources/hurd/hurd/proc/proc.h,v
retrieving revision 1.28
diff -u -r1.28 proc.h
--- proc/proc.h	1 Mar 2004 09:58:44 -0000	1.28
+++ proc/proc.h	5 Feb 2006 19:10:38 -0000
@@ -1,5 +1,5 @@
 /* Process server definitions
-   Copyright (C) 1992,93,94,95,96,99,2000,01 Free Software Foundation, Inc.
+   Copyright (C) 1992,93,94,95,96,99,2000,01,06 Free Software Foundation, Inc.
 
 This file is part of the GNU Hurd.
 
@@ -84,6 +84,7 @@
   unsigned int p_noowner:1;	/* has no owner known */
   unsigned int p_loginleader:1;	/* leader of login collection */
   unsigned int p_dead:1;	/* process is dead */
+  unsigned int p_essential:1;	/* has called proc_mark_essential */
 };
 
 typedef struct proc *pstruct_t;
