app/trace: exit if shm mmap fails

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: Icbe76cafddf5bd1e457c87e8241e68cb18a044dd
This commit is contained in:
Jim Harris 2017-03-28 10:44:04 -07:00 committed by Daniel Verkamp
parent 57986fb884
commit 21ceba8855

View File

@ -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;