Source-Changes-HG archive

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

[src/trunk]: src/lib/librumpclient Take reasonable precautions against init i...



details:   https://anonhg.NetBSD.org/src/rev/86741ad15a55
branches:  trunk
changeset: 762755:86741ad15a55
user:      pooka <pooka%NetBSD.org@localhost>
date:      Sun Feb 27 12:58:29 2011 +0000

description:
Take reasonable precautions against init in a parent process
which did a rump-transparent host-only fork().

diffstat:

 lib/librumpclient/rumpclient.c |  22 +++++++++++++++++-----
 1 files changed, 17 insertions(+), 5 deletions(-)

diffs (52 lines):

diff -r facf4140b94f -r 86741ad15a55 lib/librumpclient/rumpclient.c
--- a/lib/librumpclient/rumpclient.c    Sun Feb 27 12:42:44 2011 +0000
+++ b/lib/librumpclient/rumpclient.c    Sun Feb 27 12:58:29 2011 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: rumpclient.c,v 1.37 2011/02/25 15:12:06 pooka Exp $   */
+/*      $NetBSD: rumpclient.c,v 1.38 2011/02/27 12:58:29 pooka Exp $   */
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: rumpclient.c,v 1.37 2011/02/25 15:12:06 pooka Exp $");
+__RCSID("$NetBSD: rumpclient.c,v 1.38 2011/02/27 12:58:29 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/event.h>
@@ -727,7 +727,7 @@
 }
 __weak_alias(rumphijack_dlsym,rumpclient__dlsym);
 
-static int init_done = 0;
+static pid_t init_done = 0;
 
 int
 rumpclient_init()
@@ -736,10 +736,22 @@
        int error;
        int rv = -1;
        int hstype;
+       pid_t mypid;
 
-       if (init_done)
+       /*
+        * Make sure we're not riding the context of a previous
+        * host fork.  Note: it's *possible* that after n>1 forks
+        * we have the same pid as one of our exited parents, but
+        * I'm pretty sure there are 0 practical implications, since
+        * it means generations would have to skip rumpclient init.
+        */
+       if (init_done == (mypid = getpid()))
                return 0;
-       init_done = 1;
+
+       /* kq does not traverse fork() */
+       if (init_done != 0)
+               kq = -1;
+       init_done = mypid;
 
        sigfillset(&fullset);
 



Home | Main Index | Thread Index | Old Index