Source-Changes-HG archive

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

[src/trunk]: src/sys/compat/darwin More hacks to make Darwin's /sbin/init hap...



details:   https://anonhg.NetBSD.org/src/rev/584d5feaeb7a
branches:  trunk
changeset: 540891:584d5feaeb7a
user:      manu <manu%NetBSD.org@localhost>
date:      Sat Dec 28 00:15:23 2002 +0000

description:
More hacks to make Darwin's /sbin/init happy with its pid.

diffstat:

 sys/compat/darwin/darwin_exec.c   |  31 ++++++++++++++++++++++++++++---
 sys/compat/darwin/darwin_exec.h   |   3 ++-
 sys/compat/darwin/darwin_sysctl.c |  32 ++++++++++++--------------------
 3 files changed, 42 insertions(+), 24 deletions(-)

diffs (159 lines):

diff -r c3298e258e6e -r 584d5feaeb7a sys/compat/darwin/darwin_exec.c
--- a/sys/compat/darwin/darwin_exec.c   Fri Dec 27 23:43:15 2002 +0000
+++ b/sys/compat/darwin/darwin_exec.c   Sat Dec 28 00:15:23 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: darwin_exec.c,v 1.8 2002/12/24 12:15:45 manu Exp $ */
+/*     $NetBSD: darwin_exec.c,v 1.9 2002/12/28 00:15:23 manu Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: darwin_exec.c,v 1.8 2002/12/24 12:15:45 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: darwin_exec.c,v 1.9 2002/12/28 00:15:23 manu Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -195,8 +195,17 @@
        struct proc *p;
        struct exec_package *epp;
 {
+       struct darwin_emuldata *ded;
+
        darwin_e_proc_init(p, p->p_vmspace);
 
+       ded = (struct darwin_emuldata *)p->p_emuldata;
+       if (p->p_pid == darwin_init_pid)
+               ded->ded_fakepid = 1;
+
+#ifdef DEBUG_DARWIN
+       printf("pid %d exec'd: fakepid = %d\n", p->p_pid, ded->ded_fakepid);
+#endif
        return;
 }
 
@@ -218,6 +227,16 @@
 
        (void)memcpy(ded1, ded2, sizeof(struct darwin_emuldata));
 
+       if (ded2->ded_fakepid == 1) {
+               darwin_init_pid = 0;
+               ded1->ded_fakepid = 2;
+       } else {
+               ded1->ded_fakepid = 0;
+       }
+#ifdef DEBUG_DARWIN
+       printf("pid %d fork'd: fakepid = %d\n", p->p_pid, ded1->ded_fakepid);
+#endif
+
        return;
 }
 
@@ -226,10 +245,16 @@
        struct proc *p;
        struct vmspace *vmspace;
 {
-       if (!p->p_emuldata)
+       struct darwin_emuldata *ded;
+
+       if (!p->p_emuldata) {
                p->p_emuldata = malloc(sizeof(struct darwin_emuldata),
                    M_EMULDATA, M_WAITOK | M_ZERO);
 
+               ded = (struct darwin_emuldata *)p->p_emuldata;
+               ded->ded_fakepid = 0;
+       }
+
        mach_e_proc_init(p, vmspace);
 
        return;
diff -r c3298e258e6e -r 584d5feaeb7a sys/compat/darwin/darwin_exec.h
--- a/sys/compat/darwin/darwin_exec.h   Fri Dec 27 23:43:15 2002 +0000
+++ b/sys/compat/darwin/darwin_exec.h   Sat Dec 28 00:15:23 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: darwin_exec.h,v 1.3 2002/12/07 15:33:03 manu Exp $ */
+/*     $NetBSD: darwin_exec.h,v 1.4 2002/12/28 00:15:23 manu Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -47,6 +47,7 @@
  */
 struct darwin_emuldata {
        struct mach_emuldata ded_mach_emuldata;
+       pid_t ded_fakepid;
 };
 
 int exec_darwin_copyargs(struct proc *, struct exec_package *, 
diff -r c3298e258e6e -r 584d5feaeb7a sys/compat/darwin/darwin_sysctl.c
--- a/sys/compat/darwin/darwin_sysctl.c Fri Dec 27 23:43:15 2002 +0000
+++ b/sys/compat/darwin/darwin_sysctl.c Sat Dec 28 00:15:23 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: darwin_sysctl.c,v 1.6 2002/12/27 19:54:54 manu Exp $ */
+/*     $NetBSD: darwin_sysctl.c,v 1.7 2002/12/28 00:15:23 manu Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: darwin_sysctl.c,v 1.6 2002/12/27 19:54:54 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: darwin_sysctl.c,v 1.7 2002/12/28 00:15:23 manu Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -52,10 +52,11 @@
 #include <compat/mach/mach_types.h>
 #include <compat/mach/mach_vm.h>
 
+#include <compat/darwin/darwin_exec.h>
 #include <compat/darwin/darwin_sysctl.h>
 #include <compat/darwin/darwin_syscallargs.h>
 
-static pid_t darwin_init_pid;
+pid_t darwin_init_pid;
 
 static int darwin_kern_sysctl
     (int *, u_int, void *, size_t *, void *, size_t, struct proc *);
@@ -400,8 +401,7 @@
  * The same problem exists after mach_init has forked init: the fork libc stub
  * really insist on the child to have PID 2 (if PID is not 2, then the stub
  * will issue bootstrap calls to an already running mach_init, which fails,
- * of course). There should not be any more getpid after this, so we can
- * forget the mach_init process PID after the second getpid.
+ * of course). 
  */
 int 
 darwin_sys_getpid(p, v, retval)
@@ -409,22 +409,14 @@
        void *v;
        register_t *retval;
 {
-       if (darwin_init_pid == 0) {
-               *retval = p->p_pid;
-               return 0;
-       }
+       struct darwin_emuldata *ded;
+
+       ded = (struct darwin_emuldata *)p->p_emuldata;
 
-       if (p->p_pid == darwin_init_pid) {
-               *retval = 1;
-               return 0;
-       }
-        
-       if (p->p_pptr->p_pid == darwin_init_pid) {
-               *retval = 2;
-               darwin_init_pid = 0;
-               return 0;
-       }
+       if (ded->ded_fakepid != 0)
+               *retval = ded->ded_fakepid;
+       else
+               *retval = p->p_pid;
 
-       *retval = p->p_pid;
        return 0;
 }



Home | Main Index | Thread Index | Old Index