summaryrefslogtreecommitdiff
path: root/proc
diff options
context:
space:
mode:
authorJustus Winter <4winter@informatik.uni-hamburg.de>2013-09-18 15:59:31 +0200
committerJustus Winter <4winter@informatik.uni-hamburg.de>2014-11-21 05:48:19 +0100
commit8d16db0cc28b2d911aee918d5c3582ad29ddfeed (patch)
tree4d957d790ce8a0470ad2dee353d3718a614b7e7d /proc
parentc99cb9e4ab1bd2683759f35a6878a685bf5e8dd7 (diff)
Add proc_set_init_task, make runsystem pid 1
* hurd/process.defs (proc_set_init_task): New procedure. * hurd/process_reply.defs (proc_set_init_task): Likewise. * hurd/process_request.defs (proc_set_init_task): Likewise. * include/pids.h: Add HURD_PID_INIT as 1, adjust others accordingly. * init/init.c (start_child): Register the child task. * proc/proc.h (init_proc): New variable. (create_startup_proc): Rename to create_init_proc. * proc/main.c (main): Create placeholder proc object for pid 1. * proc/mgt.c: Use init_proc instead of startup_proc, as the former is the new root of the process tree. (create_startup_proc): Rename to create_init_proc. (S_proc_set_init_task): New function. * doc/hurd.texi (Server Bootstrap): Update accordingly. * procfs/main.c: Do not hard-code kernel pid, use pids.h instead.
Diffstat (limited to 'proc')
-rw-r--r--proc/main.c9
-rw-r--r--proc/mgt.c76
-rw-r--r--proc/proc.h8
3 files changed, 68 insertions, 25 deletions
diff --git a/proc/main.c b/proc/main.c
index 73742edd..f1f4e1b0 100644
--- a/proc/main.c
+++ b/proc/main.c
@@ -1,5 +1,5 @@
/* Initialization of the proc server
- Copyright (C) 1993,94,95,96,97,99,2000,01 Free Software Foundation, Inc.
+ Copyright (C) 1993,94,95,96,97,99,2000,01,13 Free Software Foundation, Inc.
This file is part of the GNU Hurd.
@@ -88,7 +88,12 @@ main (int argc, char **argv, char **envp)
generic_port = ports_get_right (genport);
/* Create the initial proc object for init (PID 1). */
- startup_proc = create_startup_proc ();
+ init_proc = create_init_proc ();
+
+ /* Create the startup proc object for /hurd/init (PID 2). */
+ startup_proc = allocate_proc (MACH_PORT_NULL);
+ startup_proc->p_deadmsg = 1;
+ complete_proc (startup_proc, HURD_PID_STARTUP);
/* Create our own proc object. */
self_proc = allocate_proc (mach_task_self ());
diff --git a/proc/mgt.c b/proc/mgt.c
index b8aa0fc1..02d69db4 100644
--- a/proc/mgt.c
+++ b/proc/mgt.c
@@ -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,13
+ Free Software Foundation, Inc.
This file is part of the GNU Hurd.
@@ -184,7 +185,7 @@ S_proc_child (struct proc *parentp,
/* Process hierarchy. Remove from our current location
and place us under our new parent. Sanity check to make sure
parent is currently init. */
- assert (childp->p_parent == startup_proc);
+ assert (childp->p_parent == init_proc);
if (childp->p_sib)
childp->p_sib->p_prevsib = childp->p_prevsib;
*childp->p_prevsib = childp->p_sib;
@@ -586,7 +587,7 @@ allocate_proc (task_t task)
/* Allocate and initialize the proc structure for init (PID 1),
the original parent of all other procs. */
struct proc *
-create_startup_proc (void)
+create_init_proc (void)
{
static const uid_t zero;
struct proc *p;
@@ -595,7 +596,7 @@ create_startup_proc (void)
p = allocate_proc (MACH_PORT_NULL);
assert (p);
- p->p_pid = HURD_PID_STARTUP;
+ p->p_pid = HURD_PID_INIT;
p->p_parent = p;
p->p_sib = 0;
@@ -643,7 +644,7 @@ proc_death_notify (struct proc *p)
}
/* Complete a new process that has been allocated but not entirely initialized.
- This gets called for every process except startup_proc (PID 1). */
+ This gets called for every process except init_proc (PID 1). */
void
complete_proc (struct proc *p, pid_t pid)
{
@@ -662,30 +663,47 @@ complete_proc (struct proc *p, pid_t pid)
p->p_pid = pid;
- ids_ref (&nullids);
- p->p_id = &nullids;
+ if (pid == HURD_PID_STARTUP)
+ {
+ /* Equip HURD_PID_STARTUP with the same credentials as
+ HURD_PID_INIT. */
+ static const uid_t zero;
+ p->p_id = make_ids (&zero, 1);
+ assert (p->p_id);
+ }
+ else
+ {
+ ids_ref (&nullids);
+ p->p_id = &nullids;
+ }
p->p_login = nulllogin;
p->p_login->l_refcnt++;
/* Our parent is init for now. */
- p->p_parent = startup_proc;
+ p->p_parent = init_proc;
- p->p_sib = startup_proc->p_ochild;
- p->p_prevsib = &startup_proc->p_ochild;
+ p->p_sib = init_proc->p_ochild;
+ p->p_prevsib = &init_proc->p_ochild;
if (p->p_sib)
p->p_sib->p_prevsib = &p->p_sib;
- startup_proc->p_ochild = p;
+ init_proc->p_ochild = p;
p->p_loginleader = 0;
p->p_ochild = 0;
p->p_parentset = 0;
p->p_noowner = 1;
- p->p_pgrp = startup_proc->p_pgrp;
+ p->p_pgrp = init_proc->p_pgrp;
- proc_death_notify (p);
- add_proc_to_hash (p);
+ /* At this point, we do not know the task of the startup process,
+ defer registering death notifications and adding it to the hash
+ tables. */
+ if (pid != HURD_PID_STARTUP)
+ {
+ proc_death_notify (p);
+ add_proc_to_hash (p);
+ }
join_pgrp (p);
}
@@ -747,7 +765,7 @@ process_has_exited (struct proc *p)
nowait_msg_proc_newids (tp->p_msgport, tp->p_task,
1, tp->p_pgrp->pg_pgid,
!tp->p_pgrp->pg_orphcnt);
- tp->p_parent = startup_proc;
+ tp->p_parent = init_proc;
if (tp->p_dead)
isdead = 1;
}
@@ -755,17 +773,17 @@ process_has_exited (struct proc *p)
nowait_msg_proc_newids (tp->p_msgport, tp->p_task,
1, tp->p_pgrp->pg_pgid,
!tp->p_pgrp->pg_orphcnt);
- tp->p_parent = startup_proc;
+ tp->p_parent = init_proc;
/* And now append the lists. */
- tp->p_sib = startup_proc->p_ochild;
+ tp->p_sib = init_proc->p_ochild;
if (tp->p_sib)
tp->p_sib->p_prevsib = &tp->p_sib;
- startup_proc->p_ochild = p->p_ochild;
- p->p_ochild->p_prevsib = &startup_proc->p_ochild;
+ init_proc->p_ochild = p->p_ochild;
+ p->p_ochild->p_prevsib = &init_proc->p_ochild;
if (isdead)
- alert_parent (startup_proc);
+ alert_parent (init_proc);
}
/* If an operation is in progress for this process, cause it
@@ -883,6 +901,24 @@ genpid ()
return nextpid++;
}
+/* Implement proc_set_init_task as described in <hurd/process.defs>. */
+error_t
+S_proc_set_init_task(struct proc *callerp,
+ task_t task)
+{
+ if (! callerp)
+ return EOPNOTSUPP;
+
+ if (callerp != startup_proc)
+ return EPERM;
+
+ init_proc->p_task = task;
+ proc_death_notify (init_proc);
+ add_proc_to_hash (init_proc);
+
+ return 0;
+}
+
/* Implement proc_mark_important as described in <hurd/process.defs>. */
kern_return_t
S_proc_mark_important (struct proc *p)
diff --git a/proc/proc.h b/proc/proc.h
index a2e3c537..61966971 100644
--- a/proc/proc.h
+++ b/proc/proc.h
@@ -1,5 +1,6 @@
/* 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,13
+ Free Software Foundation, Inc.
This file is part of the GNU Hurd.
@@ -134,7 +135,8 @@ struct exc
mach_port_t authserver;
struct proc *self_proc; /* process HURD_PID_PROC (us) */
-struct proc *startup_proc; /* process 1 (init) */
+struct proc *init_proc; /* process 1 (sysvinit) */
+struct proc *startup_proc; /* process 2 (hurd/init) */
struct port_bucket *proc_bucket;
struct port_class *proc_class;
@@ -183,7 +185,7 @@ void exc_clean (void *);
struct proc *add_tasks (task_t);
int pidfree (pid_t);
-struct proc *create_startup_proc (void);
+struct proc *create_init_proc (void);
struct proc *allocate_proc (task_t);
void proc_death_notify (struct proc *);
void complete_proc (struct proc *, pid_t);