Source-Changes-HG archive

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

[src/trunk]: src/lib/librumphijack Wrap daemon() since it forks. Otherwise w...



details:   https://anonhg.NetBSD.org/src/rev/d4ea74aa2477
branches:  trunk
changeset: 761703:d4ea74aa2477
user:      pooka <pooka%NetBSD.org@localhost>
date:      Sat Feb 05 16:57:39 2011 +0000

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

diffstat:

 lib/librumphijack/hijack.c |  27 +++++++++++++++++++++++----
 1 files changed, 23 insertions(+), 4 deletions(-)

diffs (69 lines):

diff -r 4a1a0bc488ba -r d4ea74aa2477 lib/librumphijack/hijack.c
--- a/lib/librumphijack/hijack.c        Sat Feb 05 16:42:42 2011 +0000
+++ b/lib/librumphijack/hijack.c        Sat Feb 05 16:57:39 2011 +0000
@@ -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.
  */



Home | Main Index | Thread Index | Old Index