Module Name:    src
Committed By:   pooka
Date:           Sun Feb 27 12:58:29 UTC 2011

Modified Files:
        src/lib/librumpclient: rumpclient.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/lib/librumpclient/rumpclient.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpclient/rumpclient.c
diff -u src/lib/librumpclient/rumpclient.c:1.37 src/lib/librumpclient/rumpclient.c:1.38
--- src/lib/librumpclient/rumpclient.c:1.37	Fri Feb 25 15:12:06 2011
+++ src/lib/librumpclient/rumpclient.c	Sun Feb 27 12:58:29 2011
@@ -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);
 

Reply via email to