Bug 210543 - tip & cu busyloop when stdin is /dev/null
Summary: tip & cu busyloop when stdin is /dev/null
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 10.2-RELEASE
Hardware: Any Any
: --- Affects Many People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2016-06-24 22:12 UTC by heikki
Modified: 2016-07-02 00:40 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description heikki 2016-06-24 22:12:54 UTC
This is likely present in 10.2 and earlier.

tip/cu busyloops when stdin is redirected to /dev/null.  Using cu this way is a simple way of logging data from serial ports, so this is not completely uncommon thing to do.

The problem seems to be that this has never been written in, just a comment which says:

"XXX does not check for EOF"

tipin function is not intended to exit, however, by a quick glance, it does not seem to be that there is any harm done doing so.  As there is no input for commands, the tipout will not exit until killed or until it encounters some sort of error, so simply exiting from tipin seems workable solution.  It will simply return to main function and exit normally, and the tipout will continue to run.  The other alternative could be waiting for tipout, but I have not figured out any reason to do that, as the input process is useless without input.

A quick patch:

--- tip.c.orig  2015-08-12 17:22:33.000000000 +0300
+++ tip.c       2016-06-25 00:49:36.812976000 +0300
@@ -400,8 +400,11 @@
        }

        while (1) {
-               gch = getchar()&STRIP_PAR;
-               /* XXX does not check for EOF */
+               gch = getchar();
+               if (gch == EOF)
+                       break;
+
+               gch = gch&STRIP_PAR;
                if ((gch == character(value(ESCAPE))) && bol) {
                        if (!noesc) {
                                if (!(gch = escape()))