aboutsummaryrefslogtreecommitdiff
path: root/aufgabe2/log.c
diff options
context:
space:
mode:
authorThorsten Töpper <atsutane@freethoughts.de>2011-01-10 20:02:33 +0100
committerThorsten Töpper <atsutane@freethoughts.de>2011-01-10 20:02:33 +0100
commit7d28c089b45d465b18df1c5cda72abed3748118f (patch)
treeef76676071fab64337bf4e5a13a4746737a2320f /aufgabe2/log.c
parentab2f94a13428cbf1ea5f1f7acf9cf4fc33a114fb (diff)
downloadprozesskommunikation-7d28c089b45d465b18df1c5cda72abed3748118f.tar.gz
prozesskommunikation-7d28c089b45d465b18df1c5cda72abed3748118f.tar.bz2
Aufgabe 2: main.c, log.c und conv.c ausgebaut.
* main.c: Öffnen der Pipes * conv.c: Pseudozufallszahlen, schreiben in die Pipes zum log und statistic Prozess * log.c: log() implementiert
Diffstat (limited to 'aufgabe2/log.c')
-rw-r--r--aufgabe2/log.c39
1 files changed, 37 insertions, 2 deletions
diff --git a/aufgabe2/log.c b/aufgabe2/log.c
index 405cdbd..96b2a4f 100644
--- a/aufgabe2/log.c
+++ b/aufgabe2/log.c
@@ -1,18 +1,53 @@
/*
* vim:ts=4:sw=4:expandtab
- *
+ *
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
+#include "queue.h"
+
+FILE *pipe_conv;
+FILE *logfile;
+char *message;
+
void log() {
+ int buffer;
printf("log started\n");
- for (;;) {
+
+ /* Die Pipe zum lesen öffnen */
+ if ((pipe_conv = fdopen(queue[D_CONV_TO_LOG][READ], "r")) == NULL) {
+ perror("log.c fdopen()");
+ exit(EXIT_FAILURE);
+ }
+
+ /* Logdatei öffnen */
+ if ((logfile = fopen("logfile.txt", "w")) == NULL) {
+ perror("log.c fopen()");
+ exit(EXIT_FAILURE);
+ }
+
+ /* Speicher für Nachricht reservieren */
+ if ((message = calloc(1, sizeof(char)*SIZE_HEX+1)) == NULL) {
+ perror("log.c calloc()");
+ exit(EXIT_FAILURE);
+ }
+
+ /* Nachricht aus der Pipe lesen, als Endian abhängiger
+ * HEX-Wert in die Log Datei schreiben. Für portable
+ * Rückkonvertierung ins Dezimalsystem siehe Aufgabe 3.
+ */
+ while (fgets(message, SIZE_HEX+1, pipe_conv)) {
+ fputs(message, logfile);
}
}
void log_cleanup() {
printf("log cleanup\n");
+ fclose(logfile);
+ fclose(pipe_conv);
+ free(message);
+ close(queue[D_CONV_TO_LOG][READ]);
_exit(EXIT_SUCCESS);
}