diff options
| author | Thorsten Töpper <atsutane@freethoughts.de> | 2010-12-31 20:59:53 +0100 |
|---|---|---|
| committer | Thorsten Töpper <atsutane@freethoughts.de> | 2010-12-31 20:59:53 +0100 |
| commit | 33a276e2ead6191bb5995c741efd4914d9cf44b0 (patch) | |
| tree | ff39a5f7525db06eec6dd95ffc80307f3a5b8198 /aufgabe3 | |
| parent | 78ba3b87b0526c2a783fd19cb720a15ea464b9b5 (diff) | |
| download | prozesskommunikation-33a276e2ead6191bb5995c741efd4914d9cf44b0.tar.gz prozesskommunikation-33a276e2ead6191bb5995c741efd4914d9cf44b0.tar.bz2 | |
Aufgabe 3: Überarbeitete main.c.
* Initialisierung schlägt durch das mq_attr struct fehl.
Invalid argument. Referenz: man 3 mq_open
Diffstat (limited to 'aufgabe3')
| -rw-r--r-- | aufgabe3/main.c | 45 | ||||
| -rw-r--r-- | aufgabe3/queue.h | 1 |
2 files changed, 25 insertions, 21 deletions
diff --git a/aufgabe3/main.c b/aufgabe3/main.c index ee54c6d..8950613 100644 --- a/aufgabe3/main.c +++ b/aufgabe3/main.c @@ -63,33 +63,33 @@ pid_t fork_child(funcptr work, funcptr cleanup) { return pid; } -mqd_t mqueue_init() { +mqd_t mqueue_init(const char *queue_name) { mqd_t msgqueue_id; + /* Eventuell existierende unbenutzte Message Queue terminieren, + * um Fehlern durch - eventuell bestehende - Datenreste vorzubeugen. + */ + mq_unlink(queue_name); + /* * Festlegung der Attribute. */ - struct *mq_attr attributes = calloc(1, sizeof(mq_attr)); - if (attributes == NULL) { - sprintf(stderr, "main.c mq_init: calloc failed\n"); - return -1; + struct mq_attr *attributes = calloc(1, sizeof(struct mq_attr)); + if (attributes != NULL) { /* NULL als Attribut nimmt die Standard Werte */ + attributes->mq_flags = 0; /* Queue blockiert bei mq_send()/mq_receive() */ + attributes->mq_maxmsg = 20; /* maximal 20 Messages in der Queue */ + attributes->mq_msgsize = 9; /* Maximale Länge einer Nachricht */ + attributes->mq_curmsgs = 0; /* Anzahl der Messages momentan in der Queue */ } - attributes->mq_flags = 0; /* Queue blockiert bei mq_send()/mq_receive() */ - attributes->mq_maxmsg = 50; /* maximal 50 Messages in der Queue */ - attributes->mq_msgsize = MAX_QMSG_SIZE; /* Maximale Länge einer Nachricht */ - attributes->mq_curmsgs = 0; /* Anzahl der Messages momentan in der Queue */ - /* * Erstellung der Message Queue. - * O_CREAT zur Erstellung, - * O_EXCL zur Fehlererzeugung, falls es bereits eine Queue mit diesem - * Namen gibt. - * 660 Schreib- und Leserechte für Prozessnutzer und -gruppe. */ - msgqueue_id = mq_open(MQ_ID, O_CREAT | O_EXCL, 660, attributes); - if (msgqueue_id == -1) - sprintf(stderr, "main.c mq_init: mq_open failed\n"); + msgqueue_id = mq_open(queue_name, O_RDWR | O_CREAT, S_IRWXU | S_IRWXG, attributes); + if (msgqueue_id == -1){ + perror("mq_init"); + exit(EXIT_FAILURE); + } return msgqueue_id; } @@ -101,12 +101,15 @@ mqd_t mqueue_init() { */ int main() { - mqd_t mq_id = mqueue_init(); - if (mq_id == -1) - return EXIT_FAILURE; + /* + * Erstellung der Queues. + */ + mqueue_init(MQ_TO_LOG); + mqueue_init(MQ_TO_STATISTIC); + mqueue_init(MQ_TO_MONITOR); pconv = fork_child(conv, conv_cleanup); - plog = fork_child(log, log_cleanup); + plog = fork_child(logmsg, logmsg_cleanup); pstatistic = fork_child(statistic, statistic_cleanup); pmonitor = fork_child(monitor, monitor_cleanup); diff --git a/aufgabe3/queue.h b/aufgabe3/queue.h index 01aaa9a..5d83d81 100644 --- a/aufgabe3/queue.h +++ b/aufgabe3/queue.h @@ -1,6 +1,7 @@ #ifndef _QUEUE_H #define _QUEUE_H #include <errno.h> +#include <fcntl.h> #include <sys/stat.h> #include <mqueue.h> |
