- # Note the & at the end. We *must* detach otherwise the script hangs.
- system("valgrind -v --tool=memcheck --leak-check=yes --num-callers=10 --time-stamp=yes --log-file=$valgrindlogpath/valdebug.%p $binpath/$executable -nofork -debug -nolog >> $basepath/valdebug.insp.out &");
- # Sleep 5 seconds to give valgrind time to initialize before chmodding the logdir for apache access.
- sleep(5);
- system("chmod 644 $valgrindlogpath/*");
+ my $pid = fork;
+ if ($pid == 0) {
+ POSIX::setsid();
+ umask 022;
+ open STDERR, '>', "$valgrindlogpath/valdebug.$$" or die $!;
+ umask 066;
+ open STDIN, '/dev/null' or die $!;
+ open STDOUT, '>', "$valgrindlogpath/out.$$" or die $!;
+ exec "valgrind -v --tool=memcheck --leak-check=yes --num-callers=10 --time-stamp=yes --log-fd=2 $binpath/$executable -nofork -debug -nolog";
+ exit 1;
+ }