X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=libinterfork%2Finterfork.c;h=e9dce9bfb188d7f60032d04a5f2b9d9dfd5f9f2b;hb=fbca6b624335eef18c8d86194aeb101a720168f4;hp=cfdd2c475b79ae016ff470c0bb04a4dd0b358bf2;hpb=97b042a3085a90b776471390a79a4e9dc02b75e9;p=ust.git diff --git a/libinterfork/interfork.c b/libinterfork/interfork.c index cfdd2c4..e9dce9b 100644 --- a/libinterfork/interfork.c +++ b/libinterfork/interfork.c @@ -19,7 +19,8 @@ #include #include #include -#include "share/usterr.h" +#include +#include "usterr.h" extern void ust_fork(void); extern void ust_potential_exec(void); @@ -30,6 +31,10 @@ pid_t fork(void) pid_t retval; + int result; + sigset_t all_sigs; + sigset_t orig_sigs; + if(plibc_func == NULL) { plibc_func = dlsym(RTLD_NEXT, "fork"); if(plibc_func == NULL) { @@ -38,10 +43,38 @@ pid_t fork(void) } } + /* Disable interrupts. This is to avoid that the child + * intervenes before it is properly setup for tracing. It is + * safer to disable all signals, because then we know we are not + * breaking anything by restoring the original mask. + */ + + /* FIXME: + - only do this if tracing is active + */ + + /* Disable signals */ + sigfillset(&all_sigs); + result = sigprocmask(SIG_BLOCK, &all_sigs, &orig_sigs); + if(result == -1) { + PERROR("sigprocmask"); + return -1; + } + + /* Do the real fork */ retval = plibc_func(); - if(retval == 0) + if(retval == 0) { + /* child */ ust_fork(); + } + + /* Restore signals */ + result = sigprocmask(SIG_BLOCK, &orig_sigs, NULL); + if(result == -1) { + PERROR("sigprocmask"); + return -1; + } return retval; }