Module Name:    src
Committed By:   pooka
Date:           Sat Feb  5 16:57:39 UTC 2011

Modified Files:
        src/lib/librumphijack: hijack.c

Log Message:
Wrap daemon() since it forks.  Otherwise we lose the rumpclient kq
descriptor and have multiple processes using the commfd.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/lib/librumphijack/hijack.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/librumphijack/hijack.c
diff -u src/lib/librumphijack/hijack.c:1.24 src/lib/librumphijack/hijack.c:1.25
--- src/lib/librumphijack/hijack.c:1.24	Sat Feb  5 12:38:19 2011
+++ src/lib/librumphijack/hijack.c	Sat Feb  5 16:57:39 2011
@@ -1,4 +1,4 @@
-/*      $NetBSD: hijack.c,v 1.24 2011/02/05 12:38:19 pooka Exp $	*/
+/*      $NetBSD: hijack.c,v 1.25 2011/02/05 16:57:39 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2011 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: hijack.c,v 1.24 2011/02/05 12:38:19 pooka Exp $");
+__RCSID("$NetBSD: hijack.c,v 1.25 2011/02/05 16:57:39 pooka Exp $");
 
 #define __ssp_weak_name(fun) _hijack_ ## fun
 
@@ -127,7 +127,8 @@
 } syscalls[DUALCALL__NUM];
 #define GETSYSCALL(which, name) syscalls[DUALCALL_##name].bs_##which
 
-pid_t (*host_fork)(void);
+pid_t	(*host_fork)(void);
+int	(*host_daemon)(int, int);
 
 static unsigned dup2mask;
 #define ISDUP2D(fd) (1<<(fd) & dup2mask)
@@ -189,6 +190,7 @@
 
 	rumpclient_dlsym = hijackdlsym;
 	host_fork = dlsym(RTLD_NEXT, "fork");
+	host_daemon = dlsym(RTLD_NEXT, "daemon");
 
 	/*
 	 * In theory cannot print anything during lookups because
@@ -423,7 +425,7 @@
 		break;
 	case 0:
 		if (rumpclient_fork_init(rf) == -1)
-			rv = -1;
+			return -1;
 		break;
 	default:
 		break;
@@ -433,6 +435,23 @@
 	return rv;
 }
 
+int
+daemon(int nochdir, int noclose)
+{
+	struct rumpclient_fork *rf;
+
+	if ((rf = rumpclient_prefork()) == NULL)
+		return -1;
+
+	if (host_daemon(nochdir, noclose) == -1)
+		return -1;
+
+	if (rumpclient_fork_init(rf) == -1)
+		return -1;
+
+	return 0;
+}
+
 /*
  * select is done by calling poll.
  */

Reply via email to