Package: ttylog
Version: 0.1.d
Using ttylog to capture serial console output from a machine under test,
I found that it has a few shortcomings:
1. It injects an extra newline at the end of every line it prints.
2. It always drops the first line it reads from the serial port.
3. The manpage does not list the -f option.
It appears that:
#1 is caused by inappropriately adding a newline when calling printf()
to produce output; fgets() leaves the newlines in the input, so no
addition is needed. It was then necessary to disable output buffers in
order to get output to be flushed when writing to a pipe.
#2 is caused by trying to flush the input buffer with a blocking call to
fgets(); if no data is in the buffer then it eats the first line it
receives. If it was being used for binary data, it could eat quite a lot
(everything up to the first 0x0d)
Testing was done on Ubuntu 12.04 x86_64.
I've attached a patch that I believe fixes the above issues.
Thanks,
--
Doug Brunner
Project Engineer
Ebus Inc.
diff -rupN ttylog-0.1.d/ChangeLog ttylog-0.1.e/ChangeLog
--- ttylog-0.1.d/ChangeLog 2011-02-16 17:15:15.000000000 -0800
+++ ttylog-0.1.e/ChangeLog 2014-02-21 17:04:14.123182620 -0800
@@ -1,3 +1,11 @@
+2014-02-21 Doug Brunner <dbrun...@ebus.com> 0.1.e
+
+ * Fixed extra newlines being added to output.
+ * Fixed dropping of lines at high baud rates.
+ * Fixed dropping of first input line.
+ * Added command line switch -n to disable hardware RTS/CTS flow control.
+
+
2011-02-16 Robert James Clay <j...@rocasa.us> 0.1.d
* Corrected a misspelling of the word 'version' in ttylog.c.
diff -rupN ttylog-0.1.d/debian/changelog ttylog-0.1.e/debian/changelog
--- ttylog-0.1.d/debian/changelog 2014-02-21 16:57:30.000000000 -0800
+++ ttylog-0.1.e/debian/changelog 2014-02-21 17:32:45.801572134 -0800
@@ -1,3 +1,10 @@
+ttylog (0.1.e-1) unstable; urgency=low
+
+ * Fixed extra newlines being added to output.
+ * Fixed dropping of first input line.
+
+ -- Doug Brunner <dbrun...@ebus.com> Fri, 21 Feb 2014 17:32:32 -0800
+
ttylog (0.1.d-1) unstable; urgency=low
* New upstream release.
diff -rupN ttylog-0.1.d/ttylog.8 ttylog-0.1.e/ttylog.8
--- ttylog-0.1.d/ttylog.8 2011-02-15 17:54:52.000000000 -0800
+++ ttylog-0.1.e/ttylog.8 2014-02-21 17:35:53.239671660 -0800
@@ -20,6 +20,9 @@ Baud rate of the device. Available baud
.TP
.B -d --device
The serial device. For example /dev/ttyS1
+.TP
+.B -f --flush
+Causes output buffers to be flushed after every write
.SH AUTHOR
This manual page was originally written by Tibor Koleszar <t.koles...@somogy.hu>,
for the Debian GNU/Linux system. Modifications and updates written by
diff -rupN ttylog-0.1.d/ttylog.c ttylog-0.1.e/ttylog.c
--- ttylog-0.1.d/ttylog.c 2011-02-16 17:15:15.000000000 -0800
+++ ttylog-0.1.e/ttylog.c 2014-02-21 17:34:13.896679203 -0800
@@ -25,7 +25,7 @@
#include <sys/types.h>
#include <fcntl.h>
-#define VERSION "0.1.d"
+#define VERSION "0.1.e"
#define BAUDN 9
char flush = 0;
@@ -134,9 +134,15 @@ main (int argc, char *argv[])
tcsetattr (fd, TCSANOW, &newtio);
/* Clear the device */
- FD_ZERO (&rfds);
- FD_SET (fd, &rfds);
- fgets (line, 1024, logfile);
+ {
+ int flags = fcntl (fd, F_GETFL, 0);
+ fcntl (fd, F_SETFL, flags | O_NONBLOCK);
+ while (fgets (line, 1024, logfile) );
+ fcntl (fd, F_SETFL, flags);
+ }
+
+ if (flush)
+ setbuf(stdout, NULL);
while (1)
{
@@ -146,7 +152,7 @@ main (int argc, char *argv[])
if (retval)
{
fgets (line, 1024, logfile);
- printf ("%s\n", line);
+ fputs (line, stdout);
if (flush) { fflush(stdout); }
}
}