diff options
author | Steven Rostedt (Google) <rostedt@goodmis.org> | 2023-06-07 14:01:53 -0400 |
---|---|---|
committer | Steven Rostedt (Google) <rostedt@goodmis.org> | 2023-06-07 14:33:30 -0400 |
commit | c508713e0966a083a9088bda9e9340d29c0506dd (patch) | |
tree | 31b2dfdb9fae23cdcdde706ed60a3c43ad3ab04f | |
parent | 8ec026f0fa13f3d97343af20049d34da0405e58f (diff) | |
download | trace-cmd-c508713e0966a083a9088bda9e9340d29c0506dd.tar.gz |
trace-cmd test: Quiet valgrind from reporting forked children
valgrind triggers its reports when the application exits. If the application
does a fork() and the child exits, it will still trigger a report saying that
the memory that was currently allocated by the parent has leaked.
To prevent this, call execl() on a shell script that will simply exit with the
proper error code. This will keep valgrind from producing a report on the
child for the memory that is still allocated by the parent.
Link: https://lore.kernel.org/linux-trace-devel/20230607140153.161b43a0@gandalf.local.home
Cc: Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
-rw-r--r-- | utest/tracecmd-utest.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/utest/tracecmd-utest.c b/utest/tracecmd-utest.c index 34fed1e1..6ba2318e 100644 --- a/utest/tracecmd-utest.c +++ b/utest/tracecmd-utest.c @@ -131,6 +131,7 @@ static int pipe_it(int *ofd, int *efd, int (*func)(void *), goto fail; if (!pid) { + char shret[32]; close(obrass[0]); close(STDOUT_FILENO); @@ -143,6 +144,23 @@ static int pipe_it(int *ofd, int *efd, int (*func)(void *), exit(-1); ret = func(data); + + /* + * valgrind triggers its reports when the application + * exits. If the application does a fork() and the child + * exits, it will still trigger the valgrind report for + * all the allocations that were not freed by the parent. + * + * To prevent valgrind from triggering, do an execl() on + * a basic shell that will simply exit with the return value. + * This will quiet valgrind from reporting memory that has + * been allocated by the parent up to here. + */ + snprintf(shret, 32, "exit %d", ret); + execl("/usr/bin/sh", "/usr/bin/sh", "-c", shret, NULL); + execl("/bin/sh", "/bin/sh", "-c", shret, NULL); + + /* If the above execl() fails, simply do an exit */ exit(ret); } |