'How do I prevent valgrind from creating extra log files when using popen?
valgrind-3.15.0
I have a weird issue with valgrind when I use switches --trace-children, --trace-children-skip and --log-file along with popen().
My code:
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
FILE *fp = NULL;
fp = popen("ls -l", "r");
pclose(fp);
fp = popen("ls -l", "r");
pclose(fp);
fp = popen("ls -l", "r");
pclose(fp);
fp = popen("ls -l", "r");
pclose(fp);
fp = popen("ls -l", "r");
pclose(fp);
return EXIT_SUCCESS;
}
Command 1: valgrind --leak-check=full --track-origins=yes --trace-children=yes --trace-children-skip=*/sh,*/ls ./test
When I run this command I get only one process output in STDOUT. That's what I expect because I'm specifying with the --trace-children-skip to ignore what I'm doing with popen().
Command 2: valgrind --leak-check=full --track-origins=yes --trace-children=yes --trace-children-skip=*/sh,*/ls --log-file=logs/%p ./test
When I run this command I get 6 log files. One for the main process and one for each of the popen() calls. valgrind reports the command as ./test. This is not what I'd expect. I'd expect the same as above, only one process log.
Running without --trace-children-skip I'd get 11 files; one for the main process and two for each of the popen() calls (sh and ls as the commands). This is what I'd expect since I'm not skipping anything and popen() calls sh which then calls ls.
I'm not sure what the deal is here. --trace-children-skip with --log-file is working in that it's not showing the sh and ls logs, but it's still creating a process for each popen() call which doesn't happen if I don't use --log-file. Am I missing something?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
