You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by jp...@apache.org on 2014/11/15 06:11:33 UTC
trafficserver git commit: TS-3195: build fixes for various platforms
Repository: trafficserver
Updated Branches:
refs/heads/master 70227c26c -> bbd53a8db
TS-3195: build fixes for various platforms
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/bbd53a8d
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/bbd53a8d
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/bbd53a8d
Branch: refs/heads/master
Commit: bbd53a8db281321e5aa60b6f40d9fdbb15c72ccf
Parents: 70227c2
Author: James Peach <jp...@apache.org>
Authored: Fri Nov 14 21:06:21 2014 -0800
Committer: James Peach <jp...@apache.org>
Committed: Fri Nov 14 21:06:21 2014 -0800
----------------------------------------------------------------------
cmd/traffic_crashlog/procinfo.cc | 20 ++++++++------------
cmd/traffic_crashlog/traffic_crashlog.h | 20 +++++++++++++++++++-
proxy/Crash.cc | 17 +++++++++++++----
3 files changed, 40 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/bbd53a8d/cmd/traffic_crashlog/procinfo.cc
----------------------------------------------------------------------
diff --git a/cmd/traffic_crashlog/procinfo.cc b/cmd/traffic_crashlog/procinfo.cc
index 979c86e..52c2176 100644
--- a/cmd/traffic_crashlog/procinfo.cc
+++ b/cmd/traffic_crashlog/procinfo.cc
@@ -24,12 +24,6 @@
#include "traffic_crashlog.h"
#include <sys/utsname.h>
-// ucontext.h is deprecated on Darwin, and we really only need it on Linux, so only
-// include it if we are planning to use it.
-#if defined(__linux__)
-#include <ucontext.h>
-#endif
-
static int
procfd_open(pid_t pid, const char * fname)
{
@@ -240,7 +234,7 @@ crashlog_write_siginfo(FILE * fp, const crashlog_target& target)
snprintf(tmp, sizeof(tmp), "0x%x (%d)", target.siginfo.si_code, target.siginfo.si_code);
fprintf(fp, LABELFMT LABELFMT, "siginfo.si_code:", tmp);
- fprintf(fp, LABELFMT ADDRFMT, "siginfo.si_addr:", (long long)target.siginfo.si_addr);
+ fprintf(fp, LABELFMT ADDRFMT, "siginfo.si_addr:", ADDRCAST(target.siginfo.si_addr));
fprintf(fp, "\n");
if (target.siginfo.si_code == SI_USER) {
@@ -257,7 +251,7 @@ crashlog_write_siginfo(FILE * fp, const crashlog_target& target)
case SEGV_ACCERR: msg = "Invalid permissions for mapped object"; break;
}
- fprintf(fp, "%s at address " ADDRFMT "\n", msg, (long long)target.siginfo.si_addr);
+ fprintf(fp, "%s at address " ADDRFMT "\n", msg, ADDRCAST(target.siginfo.si_addr));
return true;
}
@@ -270,7 +264,7 @@ crashlog_write_siginfo(FILE * fp, const crashlog_target& target)
case BUS_OBJERR: msg = "Object-specific hardware error"; break;
}
- fprintf(fp, "%s at address " ADDRFMT "\n", msg, (long long)target.siginfo.si_addr);
+ fprintf(fp, "%s at address " ADDRFMT "\n", msg, ADDRCAST(target.siginfo.si_addr));
return true;
}
@@ -289,7 +283,8 @@ crashlog_write_registers(FILE * fp, const crashlog_target& target)
// x86 register names as per ucontext.h.
#if defined(__i386__)
-#define REGFMT "0x%08x"
+#define REGFMT "0x%08" PRIx32
+#define ADDRCAST(x) ((uint32_t)(x))
static const char * names[NGREG] = {
"GS", "FS", "ES", "DS", "EDI", "ESI", "EBP", "ESP",
"EBX", "EDX", "ECX", "EAX", "TRAPNO", "ERR", "EIP", "CS",
@@ -298,7 +293,8 @@ crashlog_write_registers(FILE * fp, const crashlog_target& target)
#endif
#if defined(__x86_64__)
-#define REGFMT "0x%016llx"
+#define REGFMT "0x%016" PRIx64
+#define REGCAST(x) ((uint64_t)(x))
static const char * names[NGREG] = {
"R8", "R9", "R10", "R11", "R12", "R13", "R14", "R15",
"RDI", "RSI", "RBP", "RBX", "RDX", "RAX", "RCX", "RSP",
@@ -309,7 +305,7 @@ crashlog_write_registers(FILE * fp, const crashlog_target& target)
fprintf(fp, "CPU Registers:\n");
for (unsigned i = 0; i < countof(names); ++i) {
const char * trailer = ((i % 4) == 3) ? "\n" : " ";
- fprintf(fp, "%-3s:" REGFMT "%s", names[i], target.ucontext.uc_mcontext.gregs[i], trailer);
+ fprintf(fp, "%-3s:" REGFMT "%s", names[i], REGCAST(target.ucontext.uc_mcontext.gregs[i]), trailer);
}
fprintf(fp, "\n");
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/bbd53a8d/cmd/traffic_crashlog/traffic_crashlog.h
----------------------------------------------------------------------
diff --git a/cmd/traffic_crashlog/traffic_crashlog.h b/cmd/traffic_crashlog/traffic_crashlog.h
index 9b57ee3..f86a285 100644
--- a/cmd/traffic_crashlog/traffic_crashlog.h
+++ b/cmd/traffic_crashlog/traffic_crashlog.h
@@ -27,11 +27,25 @@
#include "libts.h"
#include "mgmtapi.h"
+// ucontext.h is deprecated on Darwin, and we really only need it on Linux, so only
+// include it if we are planning to use it.
+#if defined(__linux__)
+#include <ucontext.h>
+#endif
+
// Printf format for crash log field labels.
#define LABELFMT "%-20s"
// Printf format for memory addresses.
-#define ADDRFMT "0x%016llx"
+#if SIZEOF_VOID_POINTER == 8
+#define ADDRFMT "0x%016" PRIx64
+#define ADDRCAST(x) ((uint64_t)(x))
+#elif SIZEOF_VOID_POINTER == 4
+#define ADDRFMT "0x%08" PRIx32
+#define ADDRCAST(x) ((uint32_t)(x))
+#else
+#error unsupported pointer size
+#endif
#define CRASHLOG_HAVE_THREADINFO 0x1u
@@ -39,7 +53,11 @@ struct crashlog_target
{
pid_t pid;
siginfo_t siginfo;
+#if defined(__linux__)
ucontext_t ucontext;
+#else
+ char ucontext; // just a placeholder ...
+#endif
struct tm timestamp;
unsigned flags;
};
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/bbd53a8d/proxy/Crash.cc
----------------------------------------------------------------------
diff --git a/proxy/Crash.cc b/proxy/Crash.cc
index 83f917c..170f24c 100644
--- a/proxy/Crash.cc
+++ b/proxy/Crash.cc
@@ -27,6 +27,12 @@
#include "signals.h"
#include "ink_cap.h"
+// ucontext.h is deprecated on Darwin, and we really only need it on Linux, so only
+// include it if we are planning to use it.
+#if defined(__linux__)
+#include <ucontext.h>
+#endif
+
static pid_t crash_logger_pid = -1;
static int crash_logger_fd = NO_FD;
@@ -130,20 +136,23 @@ crash_logger_init()
void
crash_logger_invoke(int signo, siginfo_t * info, void * ctx)
{
- int status;
- ucontext_t * uctx = (ucontext_t *)ctx;
if (crash_logger_pid != -1) {
+ int status;
+
// Let the crash logger free ...
kill(crash_logger_pid, SIGCONT);
+#if defined(__linux__)
// Write the crashing thread information to the crash logger. While the siginfo_t is blesses by POSIX, the
// ucontext_t can contain pointers, so it's highly platform dependent. On Linux with glibc, however, it is
// a single memory block that we can just puke out.
- write(crash_logger_fd, info, sizeof(siginfo_t));
- write(crash_logger_fd, uctx, sizeof(ucontext_t));
+ ATS_UNUSED_RETURN(write(crash_logger_fd, info, sizeof(siginfo_t)));
+ ATS_UNUSED_RETURN(write(crash_logger_fd, (ucontext_t *)ctx, sizeof(ucontext_t)));
+#endif
close(crash_logger_fd);
+ crash_logger_fd = NO_FD;
// Wait for the logger to finish ...
waitpid(crash_logger_pid, &status, 0);