summarylogtreecommitdiffstats
path: root/0001-simplify-writelog.patch
blob: cc28f14bc75060cb2d478ae9573a355f36f79235 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
From 5577552eb1344ddd661893564b1e628f8edcf13d Mon Sep 17 00:00:00 2001
From: Florian Pritz <bluewind@xinu.at>
Date: Fri, 15 Jun 2012 16:41:52 +0200
Subject: [PATCH 1/2] simplify writelog()

All we do is prepend the date and remove \r. We don't handle color
codes, but the user can just cat the log file in a terminal and it will
interpret the codes correctly.

Signed-off-by: Florian Pritz <bluewind@xinu.at>
---
 bootlogd.c |   76 +++++++++++++++++-------------------------------------------
 1 file changed, 21 insertions(+), 55 deletions(-)

diff --git a/bootlogd.c b/bootlogd.c
index 570d382..e36e261 100644
--- a/bootlogd.c
+++ b/bootlogd.c
@@ -68,11 +68,6 @@ int didnl = 1;
 int createlogfile = 0;
 int syncalot = 0;
 
-struct line {
-	char buf[256];
-	int pos;
-} line;
-
 /*
  *	Console devices as listed on the kernel command line and
  *	the mapping to actual devices in /dev
@@ -351,63 +346,34 @@ int consolename(char *res, int rlen)
  */
 void writelog(FILE *fp, unsigned char *ptr, int len)
 {
-	time_t		t;
-	char		*s;
-	char		tmp[8];
-	int		olen = len;
-	int		dosync = 0;
-	int		tlen;
-
-	while (len > 0) {
-		tmp[0] = 0;
-		if (didnl) {
+	int dosync = 0;
+	int i;
+	static int first_run = 1;
+
+	for (i = 0; i < len; i++) {
+		int ignore = 0;
+
+		/* prepend date to every line */
+		if (*(ptr-1) == '\n' || first_run) {
+			time_t t;
+			char *s;
 			time(&t);
 			s = ctime(&t);
 			fprintf(fp, "%.24s: ", s);
-			didnl = 0;
+			dosync = 1;
+			first_run = 0;
 		}
-		switch (*ptr) {
-			case 27: /* ESC */
-				strcpy(tmp, "^[");
-				break;
-			case '\r':
-				line.pos = 0;
-				break;
-			case 8: /* ^H */
-				if (line.pos > 0) line.pos--;
-				break;
-			case '\n':
-				didnl = 1;
-				dosync = 1;
-				break;
-			case '\t':
-				line.pos += (line.pos / 8 + 1) * 8;
-				if (line.pos >= (int)sizeof(line.buf))
-					line.pos = sizeof(line.buf) - 1;
-				break;
-			case  32 ... 127:
-			case 161 ... 255:
-				tmp[0] = *ptr;
-				tmp[1] = 0;
-				break;
-			default:
-				sprintf(tmp, "\\%03o", *ptr);
-				break;
-		}
-		ptr++;
-		len--;
 
-		tlen = strlen(tmp);
-		if (tlen && (line.pos + tlen < (int)sizeof(line.buf))) {
-			memcpy(line.buf + line.pos, tmp, tlen);
-			line.pos += tlen;
+		if (*ptr == '\r') {
+			ignore = 1;
 		}
-		if (didnl) {
-			fprintf(fp, "%s\n", line.buf);
-			memset(&line, 0, sizeof(line));
+
+		if (!ignore) {
+			fwrite(ptr, sizeof(char), 1, fp);
 		}
-	}
 
+		ptr++;
+	}
 	if (dosync) {
 		fflush(fp);
 		if (syncalot) {
@@ -415,7 +381,7 @@ void writelog(FILE *fp, unsigned char *ptr, int len)
 		}
 	}
 
-	outptr += olen;
+	outptr += len;
 	if (outptr >= endptr)
 		outptr = ringbuf;
 
-- 
1.7.10.4