From 21ceba885544272bca731ebdb61c49b1c1d2acf4 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Tue, 28 Mar 2017 10:44:04 -0700 Subject: [PATCH] app/trace: exit if shm mmap fails Signed-off-by: Jim Harris Change-Id: Icbe76cafddf5bd1e457c87e8241e68cb18a044dd --- app/trace/trace.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/trace/trace.cpp b/app/trace/trace.cpp index 50fe2eeda..9f53b010f 100644 --- a/app/trace/trace.cpp +++ b/app/trace/trace.cpp @@ -360,13 +360,21 @@ int main(int argc, char **argv) } else { snprintf(shm_name, sizeof(shm_name), "/%s_trace.pid%d", app_name, shm_pid); } + fd = shm_open(shm_name, O_RDONLY, 0600); if (fd < 0) { fprintf(stderr, "Could not open shm %s.\n", shm_name); usage(); exit(-1); } + history_ptr = mmap(NULL, sizeof(*g_histories), PROT_READ, MAP_SHARED, fd, 0); + if (history_ptr == MAP_FAILED) { + fprintf(stderr, "Could not mmap shm %s.\n", shm_name); + usage(); + exit(-1); + } + g_histories = (struct spdk_trace_histories *)history_ptr; tsc_rate = g_histories->tsc_rate;