X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Fcompat%2Fclone.h;h=c3605080e8eac4ad38ec96557bbae96b77da4277;hb=1d76b9222464f9e10128ae867cd56a9317da5d65;hp=08aa10dcd199a0431845bc0a279fc9b4b30896f8;hpb=89831a7431103178268b5f1dccbf094e7c4f4095;p=lttng-tools.git diff --git a/src/common/compat/clone.h b/src/common/compat/clone.h index 08aa10dcd..c3605080e 100644 --- a/src/common/compat/clone.h +++ b/src/common/compat/clone.h @@ -23,23 +23,41 @@ #include static inline -int lttng_clone_files(int (*fn)(void *), void *child_stack, void *arg) +pid_t lttng_clone_files(int (*fn)(void *), void *child_stack, void *arg) { return clone(fn, child_stack, CLONE_FILES | SIGCHLD, arg); } -#elif __FreeBSD__ +#elif defined(__FreeBSD__) #include static inline -int lttng_clone_files(int (*fn)(void *), void *child_stack, void *arg) +pid_t lttng_clone_files(int (*fn)(void *), void *child_stack, void *arg) { - return rfork(RFPROC | RFTHREAD); + pid_t pid; + + pid = rfork(RFPROC | RFTHREAD); + if (pid == 0) { + /* child */ + int ret; + + ret = fn(arg); + exit(ret); + } else if (pid > 0) { + /* parent */ + /* + * Just return, the caller will wait for the child. + */ + return pid; + } else { + /* Error */ + return pid; + } } #else -#error "Please add support for your OS into compat/clone.h." +#error "Please add support for your OS." #endif /* __linux__ , __FreeBSD__ */ #endif /* _COMPAT_CLONE_H */