aboutsummaryrefslogtreecommitdiff
path: root/aufgabe4/log.c
diff options
context:
space:
mode:
authorMichael Stapelberg <michael@stapelberg.de>2010-12-06 19:55:19 +0100
committerMichael Stapelberg <michael@stapelberg.de>2010-12-06 19:55:19 +0100
commit0c9d712a77bbede4808142944776d35f502bffa7 (patch)
tree1955e375d404308aa1d79b9d355e37dba739b9bf /aufgabe4/log.c
parent9af2bea582c083653c08abb965eba6f63de997fa (diff)
downloadprozesskommunikation-0c9d712a77bbede4808142944776d35f502bffa7.tar.gz
prozesskommunikation-0c9d712a77bbede4808142944776d35f502bffa7.tar.bz2
IPC implementiert
Hat noch einen Bug, sollte aber als Beispiel für die anderen Aufgaben gut genug sein.
Diffstat (limited to 'aufgabe4/log.c')
-rw-r--r--aufgabe4/log.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/aufgabe4/log.c b/aufgabe4/log.c
index 405cdbd..105f2d3 100644
--- a/aufgabe4/log.c
+++ b/aufgabe4/log.c
@@ -1,18 +1,44 @@
/*
* vim:ts=4:sw=4:expandtab
+ *
+ * © 2010 Michael Stapelberg
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
+#include "queue.h"
+
+FILE *file;
+
+/*
+ * Logprozess. Schreibt die empfangenen Daten in eine Datei.
+ *
+ */
void log() {
- printf("log started\n");
- for (;;) {
+ /* Datei zum Schreiben öffnen */
+ if ((file = fopen("log.txt", "w")) == NULL) {
+ perror("fopen");
+ exit(EXIT_FAILURE);
+ }
+
+ while (1) {
+ /* Wir warten auf Nachrichten des CONV-Prozesses */
+ while (queue_get_dir() != D_CONV_TO_LOG)
+ usleep(1);
+
+ uint8_t data = queue_get_data();
+ fprintf(file, "%d\n", data);
}
}
+/*
+ * Cleanup-Funktion (wird als Signalhandler gesetzt). Schließt die Logdatei.
+ *
+ */
void log_cleanup() {
printf("log cleanup\n");
+ fclose(file);
_exit(EXIT_SUCCESS);
}