diff options
| author | Michael Stapelberg <michael@stapelberg.de> | 2010-12-06 21:46:16 +0100 |
|---|---|---|
| committer | Michael Stapelberg <michael@stapelberg.de> | 2010-12-06 21:46:16 +0100 |
| commit | 4686794ee64a72404237ead53ea3e967023c0cf3 (patch) | |
| tree | fed2d252d1d53544432ca9d7c75ab734e8d1c091 /aufgabe4 | |
| parent | df93ba205e0bb387fae51f9706823a38d054ba08 (diff) | |
| download | prozesskommunikation-4686794ee64a72404237ead53ea3e967023c0cf3.tar.gz prozesskommunikation-4686794ee64a72404237ead53ea3e967023c0cf3.tar.bz2 | |
fd nicht global offen lassen, kann direkt geschlossen werden. Speicher mit nullen initialisieren
Diffstat (limited to 'aufgabe4')
| -rw-r--r-- | aufgabe4/queue.c | 7 |
1 files changed, 5 insertions, 2 deletions
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 */ |
