Page MenuHomeFreeBSD

libxo: Need to support fflush and error reporting from fflush
AbandonedPublic

Authored by marcel on Dec 25 2014, 5:43 AM.
Tags
None
Referenced Files
Unknown Object (File)
Dec 19 2023, 9:47 PM
Unknown Object (File)
Aug 23 2023, 8:55 PM
Unknown Object (File)
Jun 9 2023, 9:39 PM
Unknown Object (File)
Nov 28 2022, 4:18 PM
Unknown Object (File)
Dec 18 2016, 7:10 PM
Unknown Object (File)
Sep 30 2016, 7:00 AM
Unknown Object (File)
Sep 10 2016, 4:31 AM
Unknown Object (File)
Sep 9 2016, 11:33 AM
Subscribers

Details

Reviewers
alfred
ngie
adrian
Group Reviewers
manpages
Summary

libxo needs to allow for explicit flushing of output streams when doing
time series output. example: 'netstat --libxo json 1'

Without the flush, then the output is buffered until the stdio buffer
fills.

This patch adds a non-standard (but yet standard in glibc and
solaris) function to peek into stdio buffers to determine if they are
line buffered so that libxo can properly buffer based on lines.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

alfred retitled this revision from to libxo: Need to support fflush and error reporting from fflush.
alfred updated this object.
alfred edited the test plan for this revision. (Show Details)
  1. xo_emit(3) needs to be updated for the API changes.
  2. The library version probably needs to be bumped (I would do that because you're changing a lot of return types and arguments to functions). marcel and other Juniper folks should be consulted on that though.
  3. I think this is a good change to make by default, but this could make things more painful on the I/O side, depending on how frequently the code is called. It might be better to move the flushing outside loops to use I/O buffering a bit more intelligently instead of putting it explicitly at the end of xo_flush_h, or having a tunable way to avoid auto-flushing the I/O out to stderr/stdout/etc.
alfred edited edge metadata.
  • Using getbufmode() for a second...
  • use __flbf() instead of getbufmode
  • Need __flbf()
marcel edited reviewers, added: alfred; removed: marcel.

netstat has been converted without this change. The best approach to the problem this change failed to address is that netstat et al is to call the utility every so often and not have the utility produce the equivalent of a line of output every so often. Parsers for structural languages do not yield incomplete objects in the in the interim. Note also that the utility needs a SIGINT to stop, which also aborts the output, leaving with invalid JSON, XML or HTML.

wblock added inline comments.
lib/libc/stdio/setbuf.3
35

Remember to update this just before commit.

172

No paragraph break needed here.

174

s/steam/stream/

"returns if" is kind of ambiguous. Maybe

function tests a stream to determine if it is line buffered.