summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoern Engel <joern@logfs.org>2012-01-16 14:29:39 -0800
committerJoern Engel <joern@logfs.org>2012-01-16 14:29:39 -0800
commitb94965242daa03117a50f8551f9866f347b91548 (patch)
tree1fec4936b09490168ec05b4f08284a06cb4b3c61
parentb3e1f0769bca367119d7e80be1a063f1a345fdf0 (diff)
downloadcancd-b94965242daa03117a50f8551f9866f347b91548.tar.gz
Hack around short writes
Actual netconsole packets can be shorter than a line. So instead of creating a new line plus timestamp for every fragment, remember whether we had a newline before and only add a timestamp in those cases. Currently this is still semi-broken. We have no memory across packets, so timestamps are never printed for the first line of a packet. Signed-off-by: Joern Engel <joern@logfs.org>
-rw-r--r--cancd.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/cancd.c b/cancd.c
index 4d79a3d..8c58b1c 100644
--- a/cancd.c
+++ b/cancd.c
@@ -305,6 +305,7 @@ static int write_formatted(int fd, char *buf, int count)
size_t n, len, err;
time_t now = time(NULL);
struct tm *tm = localtime(&now);
+ int had_newline = 0;
/*
* buf must be NUL-terminated. We add 1 to count for the terminating
@@ -313,18 +314,26 @@ static int write_formatted(int fd, char *buf, int count)
*/
count += 1;
while (count > 1) {
- end = strchrnul(buf, 0xa);
- *end = 0xa;
+ if (had_newline) {
+ n = strftime(timestr, sizeof(timestr), format, tm);
+ err = do_write(fd, timestr, n);
+ if (err)
+ return err;
+ }
+ end = strchr(buf, 0xa);
+ if (!end) {
+ /* no newline, just write what we have */
+ do_write(fd, buf, count - 1);
+ had_newline = 0;
+ break;
+ }
len = end - buf + 1;
- n = strftime(timestr, sizeof(timestr), format, tm);
- err = do_write(fd, timestr, n);
- if (err)
- return err;
err = do_write(fd, buf, len);
if (err)
return err;
buf += len;
count -= len;
+ had_newline = 1;
}
return 0;
}