+/**
+ * Read data from a slow device
+ *
+ * return 1 when a complete NULL terminated line has been read
+ *
+ * return 0 when a partial line has been read and appended to the
+ * buffer at @offset
+ *
+ * return negative on error
+ */
+static int read_log_line(int infd, char *buf, size_t bufsize, int *offset)
+{
+ int ret;
+ int i;
+
+ ret = read(infd, buf + *offset, bufsize - *offset - 1);
+ if (read < 0) {
+ pr_err("read: %m\n");
+ return -1;
+ }
+
+ if (ret == 0) {
+ pr_err("Read EOF, stopping\n");
+ return -1;
+ }
+ buf[*offset + ret] = 0;
+
+ for (i = 0; i < ret; i++) {
+ if (buf[i + *offset] == '\n' ||
+ buf[i + *offset] == '\r') {
+ /*
+ * Got a complete line when there is a newline
+ * at the end. Remove the newline and possible
+ * other junk, such as '\r'
+ */
+ buf[i + *offset] = 0;
+ *offset = 0;
+
+ return 1;
+ }
+
+ /*
+ * Fixme! Nothing guarantees that there isn't actually
+ * more data (a part of a new log entry perhaps) after
+ * the newline. So in rare cases (we are prevented
+ * from reading the serial line in very long time) we
+ * might lose data from the stream..
+ */
+ }
+
+ *offset += ret;
+ return 0;
+}
+
+static int read_data(int infd, int outfd)