From 0c024698e35d2ca5dc51819e5442d77ffcacf597 Mon Sep 17 00:00:00 2001 From: Ivaylo Ivanov Date: Sat, 12 Jan 2019 13:27:02 +0100 Subject: [PATCH] Move the truncation outside of the open function --- fb_arc_set/shared/shm.c | 4 +++- fb_arc_set/supervisor.c | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/fb_arc_set/shared/shm.c b/fb_arc_set/shared/shm.c index d581ec0..fe16f55 100644 --- a/fb_arc_set/shared/shm.c +++ b/fb_arc_set/shared/shm.c @@ -22,12 +22,14 @@ int create_shmfd(char *shm_name) { return shmfd; } -void* open_shm(int shmfd, size_t shm_size) { +void truncate_shm(int shmfd, size_t shm_size) { if(ftruncate(shmfd, shm_size) < 0) { fprintf(stderr, "ERROR: Failed truncating shared memory object\n"); exit(EXIT_FAILURE); } +} +void* open_shm(int shmfd, size_t shm_size) { void* shm; shm = mmap(NULL, shm_size, PROT_READ | PROT_WRITE, MAP_SHARED, shmfd, 0); diff --git a/fb_arc_set/supervisor.c b/fb_arc_set/supervisor.c index 7a18201..20ec17c 100644 --- a/fb_arc_set/supervisor.c +++ b/fb_arc_set/supervisor.c @@ -33,6 +33,7 @@ int main(int argc, char *argv[]) { /// Open shared memory objects int buffer_shmfd = create_shmfd(BUFFER_SHM_NAME); + truncate_shm(buffer_shmfd, BUFF_SIZE); circ_buffer = (buffer_t *)open_shm(buffer_shmfd, sizeof(buffer_t)); /// Open semaphores