aboutsummaryrefslogtreecommitdiff
path: root/aufgabe3
diff options
context:
space:
mode:
Diffstat (limited to 'aufgabe3')
-rw-r--r--aufgabe3/log.c52
-rw-r--r--aufgabe3/log.h4
2 files changed, 50 insertions, 6 deletions
diff --git a/aufgabe3/log.c b/aufgabe3/log.c
index 405cdbd..d38adfd 100644
--- a/aufgabe3/log.c
+++ b/aufgabe3/log.c
@@ -1,18 +1,62 @@
/*
* vim:ts=4:sw=4:expandtab
- *
+ *
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
-void log() {
- printf("log started\n");
+#include "queue.h"
+
+FILE *logfile;
+char *message;
+
+void logmsg() {
+ int random_number = 0;
+ mqd_t log;
+
+ /* Message Queue zur Kommunikation mit dem conv Prozess öffnen.
+ */
+ if ((log = mq_open(MQ_TO_LOG, O_RDWR)) == -1) {
+ perror("logmsg() mq_open");
+ exit(EXIT_FAILURE);
+ }
+
+ /* Logdatei öffnen */
+ if ((logfile = fopen("logfile.txt", "w")) == NULL) {
+ perror("logmsg() fopen");
+ exit(EXIT_FAILURE);
+ }
+
+ /*
+ * Speicher für Nachricht allokieren.
+ */
+ if ((message = calloc(1, MQ_MSG_SIZE_SEND)) == NULL) {
+ perror("logmsg()");
+ exit(EXIT_FAILURE);
+ }
+
for (;;) {
+
+ /* Nachricht über log Queue empfangen */
+ if (mq_receive(log, message, MQ_MSG_SIZE_RCV, NULL) == -1) {
+ perror("logmsg() mq_receive");
+ exit(EXIT_FAILURE);
+ }
+
+ /* Zufallszahl aus dem String zurück zur Dezimalzahl konvertieren */
+ sscanf(message, "%x", &random_number);
+
+ /* Die konvertierte Zahl in die Log datei schreiben */
+ fprintf(logfile, "%d\n", random_number);
+
}
}
-void log_cleanup() {
+void logmsg_cleanup() {
printf("log cleanup\n");
+ free(message);
+ mq_unlink(MQ_TO_LOG);
+ fclose(logfile);
_exit(EXIT_SUCCESS);
}
diff --git a/aufgabe3/log.h b/aufgabe3/log.h
index e6b171f..1d046f8 100644
--- a/aufgabe3/log.h
+++ b/aufgabe3/log.h
@@ -1,7 +1,7 @@
#ifndef _LOG_H
#define _LOG_H
-void log();
-void log_cleanup();
+void logmsg();
+void logmsg_cleanup();
#endif