X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=liblttng-ust-fork%2Fustfork.c;fp=liblttng-ust-fork%2Fustfork.c;h=af7a6afa32283ed915c3664e3f510cd7062a9e2b;hb=25297d71946d0c2430c860a00da8236ec09a2475;hp=9ed087c2eff59bc1b6dd53f37e9d6f5ce9b7e555;hpb=9d9d9767f7e2cbc25682f77aad0b06e3c63e54c8;p=lttng-ust.git diff --git a/liblttng-ust-fork/ustfork.c b/liblttng-ust-fork/ustfork.c index 9ed087c2..af7a6afa 100644 --- a/liblttng-ust-fork/ustfork.c +++ b/liblttng-ust-fork/ustfork.c @@ -56,6 +56,34 @@ pid_t fork(void) return retval; } +int daemon(int nochdir, int noclose) +{ + static int (*plibc_func)(int nochdir, int noclose) = NULL; + sigset_t sigset; + int retval; + + if (plibc_func == NULL) { + plibc_func = dlsym(RTLD_NEXT, "daemon"); + if (plibc_func == NULL) { + fprintf(stderr, "libustfork: unable to find \"daemon\" symbol\n"); + errno = ENOSYS; + return -1; + } + } + + ust_before_fork(&sigset); + /* Do the real daemon call */ + retval = plibc_func(nochdir, noclose); + if (retval == 0) { + /* child, parent called _exit() directly */ + ust_after_fork_child(&sigset); + } else { + /* on error in the parent */ + ust_after_fork_parent(&sigset); + } + return retval; +} + struct ustfork_clone_info { int (*fn)(void *); void *arg;