chiark / gitweb /
valgrind: make running PID 1 in valgrind useful
authorLennart Poettering <lennart@poettering.net>
Wed, 20 Nov 2013 21:11:10 +0000 (22:11 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 20 Nov 2013 21:12:47 +0000 (22:12 +0100)
Since valgrind only generates useful output on exit() (rather than
exec()) we need to explicitly exit when valgrind is detected.

configure.ac
src/core/main.c

index bb196f541493a2a5bb0b3dd43996b7f627f054d4..7794541964c4e9e215171c7d81fa84759f7c76ea 100644 (file)
@@ -838,7 +838,7 @@ AC_DEFINE_UNQUOTED(TELINIT, ["$TELINIT"], [Path to telinit])
 
 AC_SUBST(TELINIT)
 
 
 AC_SUBST(TELINIT)
 
-AC_CHECK_HEADERS_ONCE([valgrind/memcheck.h])
+AC_CHECK_HEADERS_ONCE([valgrind/memcheck.h valgrind/valgrind.h])
 
 # ------------------------------------------------------------------------------
 have_myhostname=no
 
 # ------------------------------------------------------------------------------
 have_myhostname=no
index f342cdd2895559c6a322d9cdc8e2f5a12f6a85dd..4d4f6e8f4caf664f772406840213b6f73326c8e8 100644 (file)
 #include <sys/prctl.h>
 #include <sys/mount.h>
 
 #include <sys/prctl.h>
 #include <sys/mount.h>
 
+#ifdef HAVE_VALGRIND_VALGRIND_H
+#include <valgrind/valgrind.h>
+#endif
+
 #include "sd-daemon.h"
 #include "sd-messages.h"
 #include "sd-bus.h"
 #include "sd-daemon.h"
 #include "sd-messages.h"
 #include "sd-bus.h"
@@ -1830,6 +1834,15 @@ finish:
         if (fds)
                 fdset_free(fds);
 
         if (fds)
                 fdset_free(fds);
 
+#ifdef HAVE_VALGRIND_VALGRIND_H
+        /* If we are PID 1 and running under valgrind, then let's exit
+         * here explicitly. valgrind will only generate nice output on
+         * exit(), not on exec(), hence let's do the former not the
+         * latter here. */
+        if (getpid() == 1 && RUNNING_ON_VALGRIND)
+                return 0;
+#endif
+
         if (shutdown_verb) {
                 const char * command_line[] = {
                         SYSTEMD_SHUTDOWN_BINARY_PATH,
         if (shutdown_verb) {
                 const char * command_line[] = {
                         SYSTEMD_SHUTDOWN_BINARY_PATH,