From 4686794ee64a72404237ead53ea3e967023c0cf3 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 6 Dec 2010 21:46:16 +0100 Subject: fd nicht global offen lassen, kann direkt geschlossen werden. Speicher mit nullen initialisieren --- aufgabe4/queue.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'aufgabe4/queue.c') diff --git a/aufgabe4/queue.c b/aufgabe4/queue.c index 62a888c..9bf2725 100644 --- a/aufgabe4/queue.c +++ b/aufgabe4/queue.c @@ -20,7 +20,6 @@ static const int queue_size = sizeof(struct queueheader) + (sizeof(struct msg) * 255); -static int fd; static uint8_t *shm; static struct queueheader *shmheader; static struct msg *shmdata; @@ -55,6 +54,7 @@ static void unlock() { * */ void queue_init() { + int fd; int flags = O_RDWR | O_CREAT | O_TRUNC; if ((fd = shm_open("/bts-sem", flags, S_IREAD | S_IWRITE)) == -1) { perror("shm_open"); @@ -69,10 +69,13 @@ void queue_init() { exit(EXIT_FAILURE); } + close(fd); + shmheader = (struct queueheader*)shm; shmdata = (struct msg*)(shm + sizeof(struct queueheader)); - shmheader->cur = 0; + /* Speicher mit 0 initialisieren */ + memset(shmheader, 0, sizeof(struct queueheader)); shmdata->dir = D_INVALID; /* Semaphor initialisieren */ -- cgit v1.2.3-70-g09d2