Subject: bin/33944: usbhidctl -l does not flush stdout when input events are printed
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: None <tomsbsd04@tiscali.de>
List: netbsd-bugs
Date: 07/07/2006 22:35:00
>Number:         33944
>Category:       bin
>Synopsis:       usbhidctl -l does not flush stdout when input events are printed
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jul 07 22:35:00 +0000 2006
>Originator:     Thomas Bieg
>Release:        3.0_STABLE
>Organization:
>Environment:
>Description:
Due to the interactive nature of its output, "usbhidctl -l" should flush
stdout after each printed event, so that redirecting the output becomes
usable.

In its current state when stdout is redirected nothing is output unless
stdout buffer becomes full and thus is flushed. If the command is aborted
before the buffer filled up nothing is output at all.

>How-To-Repeat:
Execute "usbhidctl -f0 -a -l | cat" with any USB HID input device attached
to /dev/uhid0 and start producing input events.

>Fix:
This works for me, don't know if it's the recommended way:

*** src/usr.bin/usbhidctl/usbhid.c.orig     Wed May 10 23:53:48 2006
--- src/usr.bin/usbhidctl/usbhid.c  Fri Jul  7 22:00:28 2006
***************
*** 657,662 ****
--- 657,663 ----
                }
                hid_end_parse(hdata);
                printf("\n");
+               fflush(stdout);
        }
        /* NOTREACHED */
  }