From 8772163cf9b0219c372fdcfc37def8bbbfc3ecd7 Mon Sep 17 00:00:00 2001 From: Frediano Ziglio Date: Wed, 15 Apr 2020 14:35:10 +0100 Subject: [PATCH] Fix compatibility with mremap and Darwin Darwin does not have mremap. Use munmap+mmap instead. That code is not in a hot path, number of nodes do not change very often. Signed-off-by: Frediano Ziglio --- tools/reds_stat.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tools/reds_stat.c b/tools/reds_stat.c index deffec1b..7d35c45b 100644 --- a/tools/reds_stat.c +++ b/tools/reds_stat.c @@ -86,7 +86,6 @@ int main(int argc, char **argv) pid_t kvm_pid = 0; uint32_t num_of_nodes = 0; size_t shm_size; - size_t shm_old_size; int shm_name_len; int ret = EXIT_FAILURE; int fd; @@ -142,11 +141,11 @@ int main(int argc, char **argv) printf("spice statistics\n\n"); if (num_of_nodes != reds_stat->num_of_nodes) { num_of_nodes = reds_stat->num_of_nodes; - shm_old_size = shm_size; + munmap(reds_stat, shm_size); shm_size = header_size + num_of_nodes * sizeof(SpiceStatNode); - reds_stat = mremap(reds_stat, shm_old_size, shm_size, MREMAP_MAYMOVE); + reds_stat = (SpiceStat *)mmap(NULL, shm_size, PROT_READ, MAP_SHARED, fd, 0); if (reds_stat == (SpiceStat *)MAP_FAILED) { - perror("mremap"); + perror("mmap"); goto error; } reds_nodes = (SpiceStatNode *)((char *) reds_stat + header_size);