pid_t fork(void)
{
static pid_t (*plibc_func)(void) = NULL;
- ust_fork_info_t fork_info;
+ sigset_t sigset;
pid_t retval;
if (plibc_func == NULL) {
}
}
- ust_before_fork(&fork_info);
+ ust_before_fork(&sigset);
/* Do the real fork */
retval = plibc_func();
if (retval == 0) {
/* child */
- ust_after_fork_child(&fork_info);
+ ust_after_fork_child(&sigset);
} else {
- ust_after_fork_parent(&fork_info);
+ ust_after_fork_parent(&sigset);
+ }
+ 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;
- ust_fork_info_t fork_info;
+ sigset_t sigset;
};
static int clone_fn(void *arg)
struct ustfork_clone_info *info = (struct ustfork_clone_info *) arg;
/* clone is now done and we are in child */
- ust_after_fork_child(&info->fork_info);
+ ust_after_fork_child(&info->sigset);
return info->fn(info->arg);
}
tls, ctid);
} else {
/* Creating a real process, we need to intervene. */
- struct ustfork_clone_info info = { fn: fn, arg: arg };
+ struct ustfork_clone_info info = { fn = fn, arg = arg };
- ust_before_fork(&info.fork_info);
+ ust_before_fork(&info.sigset);
retval = plibc_func(clone_fn, child_stack, flags, &info,
ptid, tls, ctid);
/* The child doesn't get here. */
- ust_after_fork_parent(&info.fork_info);
+ ust_after_fork_parent(&info.sigset);
}
return retval;
}