]> granicus.if.org Git - strace/commitdiff
Always define WCOREDUMP
authorEugene Syromyatnikov <evgsyr@gmail.com>
Wed, 3 Oct 2018 08:31:30 +0000 (10:31 +0200)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 17 Dec 2018 19:19:23 +0000 (19:19 +0000)
wait.c does it already, now strace.c also does.

* wait.h: New file.
* Makefile.am (strace_SOURCES): Add it.
* strace.c: Replace <sys/wait.h> with "wait.h".
[!WCOREDUMP]: Remove.
* wait.c: Replace <sys/wait.h> with "wait.h".
[!WCOREFLAG] (WCOREFLAG), [!WCOREDUMP] (WCOREDUMP): Move to wait.h,
rework.
[!W_STOPCODE] (W_STOPCODE), [!W_EXITCODE] (W_EXITCODE),
[!W_CONTINUED] (W_CONTINUED): Move to wait.h.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
Makefile.am
strace.c
wait.c
wait.h [new file with mode: 0644]

index 1bc77bb724ceb65d3a039d8ca99248e81346c6e5..71d25581ec027c2b00221ca1e5fab3395293e040 100644 (file)
@@ -337,6 +337,7 @@ strace_SOURCES =    \
        utimes.c        \
        v4l2.c          \
        wait.c          \
+       wait.h          \
        xattr.c         \
        xfs_quota_stat.h \
        xlat.c          \
index a87d6729616b8353bcc4b3b08bfc7eb164971168..1ea74f93e91b7c53bace50a5602b83d1d8893dc8 100644 (file)
--- a/strace.c
+++ b/strace.c
@@ -16,7 +16,6 @@
 #include "ptrace.h"
 #include <signal.h>
 #include <sys/resource.h>
-#include <sys/wait.h>
 #include <sys/stat.h>
 #ifdef HAVE_PATHS_H
 # include <paths.h>
@@ -41,6 +40,7 @@
 #include "trace_event.h"
 #include "xstring.h"
 #include "delay.h"
+#include "wait.h"
 
 /* In some libc, these aren't declared. Do it ourself: */
 extern char **environ;
@@ -1977,14 +1977,9 @@ print_debug_info(const int pid, int status)
 
        strcpy(buf, "???");
        if (WIFSIGNALED(status))
-#ifdef WCOREDUMP
                xsprintf(buf, "WIFSIGNALED,%ssig=%s",
                                WCOREDUMP(status) ? "core," : "",
                                signame(WTERMSIG(status)));
-#else
-               xsprintf(buf, "WIFSIGNALED,sig=%s",
-                               signame(WTERMSIG(status)));
-#endif
        if (WIFEXITED(status))
                xsprintf(buf, "WIFEXITED,exitcode=%u", WEXITSTATUS(status));
        if (WIFSTOPPED(status))
@@ -2107,14 +2102,9 @@ print_signalled(struct tcb *tcp, const int pid, int status)
        if (cflag != CFLAG_ONLY_STATS
            && is_number_in_set(WTERMSIG(status), signal_set)) {
                printleader(tcp);
-#ifdef WCOREDUMP
                tprintf("+++ killed by %s %s+++\n",
                        signame(WTERMSIG(status)),
                        WCOREDUMP(status) ? "(core dumped) " : "");
-#else
-               tprintf("+++ killed by %s +++\n",
-                       signame(WTERMSIG(status)));
-#endif
                line_ended();
        }
 }
diff --git a/wait.c b/wait.c
index 1712ed4174a180227cfec6dc0cc5453fc101f36e..46c50aa992675360f1889f6953725737b11fba6e 100644 (file)
--- a/wait.c
+++ b/wait.c
 #include "defs.h"
 #include "ptrace.h"
 
-#include <sys/wait.h>
+#include "wait.h"
 
 #include "xlat/wait4_options.h"
-
-#if !defined WCOREFLAG && defined WCOREFLG
-# define WCOREFLAG WCOREFLG
-#endif
-#ifndef WCOREFLAG
-# define WCOREFLAG 0x80
-#endif
-#ifndef WCOREDUMP
-# define WCOREDUMP(status)  ((status) & 0200)
-#endif
-#ifndef W_STOPCODE
-# define W_STOPCODE(sig)  ((sig) << 8 | 0x7f)
-#endif
-#ifndef W_EXITCODE
-# define W_EXITCODE(ret, sig)  ((ret) << 8 | (sig))
-#endif
-#ifndef W_CONTINUED
-# define W_CONTINUED 0xffff
-#endif
-
 #include "xlat/ptrace_events.h"
 
 static int
diff --git a/wait.h b/wait.h
new file mode 100644 (file)
index 0000000..529daf1
--- /dev/null
+++ b/wait.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2004-2018 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#ifndef STRACE_WAIT_H
+#define STRACE_WAIT_H
+
+#include "defs.h"
+
+#include <sys/wait.h>
+
+#include "static_assert.h"
+
+/*
+ * On Linux, the "core dumped" flag is hard-coded to 0x80:
+ * fs/coredump.c:coredump_finish() after v3.10-rc1~143^2~41,
+ * fs/coredump.c:do_coredump() between v3.7-rc1~134^2~4 and v3.10-rc1~143^2~41,
+ * or fs/exec.c:do_coredump() before v3.7-rc1~134^2~4
+ */
+#ifndef WCOREFLAG
+# define WCOREFLAG 0x80
+#else
+static_assert((WCOREFLAG) == 0x80, "WCOREFLAG != 0x80");
+#endif
+#ifndef WCOREDUMP
+# define WCOREDUMP(status) ((status) & (WCOREFLAG))
+#endif
+
+#ifndef W_STOPCODE
+# define W_STOPCODE(sig)  ((sig) << 8 | 0x7f)
+#endif
+#ifndef W_EXITCODE
+# define W_EXITCODE(ret, sig)  ((ret) << 8 | (sig))
+#endif
+#ifndef W_CONTINUED
+# define W_CONTINUED 0xffff
+#endif
+
+#endif /* STRACE_WAIT_H */