summaryrefslogtreecommitdiffstats
path: root/src/basic/macro.h
diff options
context:
space:
mode:
authorFrantisek Sumsal <frantisek@sumsal.cz>2022-04-06 19:41:01 +0200
committerFrantisek Sumsal <frantisek@sumsal.cz>2022-04-07 10:06:44 +0200
commitc6552ad381003a23cde7c3228e7071f30465df35 (patch)
tree037e2b3069de0aeff460151723abb2443eca083c /src/basic/macro.h
parentMerge pull request #22975 from poettering/logind-longpress-followup (diff)
downloadsystemd-c6552ad381003a23cde7c3228e7071f30465df35.tar.xz
systemd-c6552ad381003a23cde7c3228e7071f30465df35.zip
macro: call __gcov_dump() before _exit() w/ coverage enabled
_exit() skips at-exit hooks, causing lost coverage from processes utilizing it. Hopefully resolves systemd/systemd-centos-ci#482
Diffstat (limited to 'src/basic/macro.h')
-rw-r--r--src/basic/macro.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/basic/macro.h b/src/basic/macro.h
index 68d8b062e8..685de73449 100644
--- a/src/basic/macro.h
+++ b/src/basic/macro.h
@@ -29,6 +29,19 @@
#define _alignptr_ __attribute__((__aligned__(sizeof(void*))))
#define _warn_unused_result_ __attribute__((__warn_unused_result__))
+#if defined(BUILT_WITH_COVERAGE) && BUILT_WITH_COVERAGE
+/* We need to explicitly call __gcov_dump() in places where we use _exit(), since
+ * _exit() skips at-exit hooks resulting in lost coverage */
+# include <unistd.h>
+extern void __gcov_dump(void);
+
+_noreturn_ static inline void _coverage__exit(int status) {
+ __gcov_dump();
+ _exit(status);
+}
+# define _exit(x) _coverage__exit(x)
+#endif
+
#if !defined(HAS_FEATURE_MEMORY_SANITIZER)
# if defined(__has_feature)
# if __has_feature(memory_sanitizer)