Page MenuHomeFreeBSD

ping: Don't mix stdio and direct writes
ClosedPublic

Authored by des on Fri, Jun 26, 2:03 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Jul 9, 10:59 PM
Unknown Object (File)
Thu, Jul 9, 1:43 AM
Unknown Object (File)
Sun, Jul 5, 11:41 PM
Unknown Object (File)
Sun, Jul 5, 11:37 PM
Unknown Object (File)
Sun, Jul 5, 9:38 PM
Unknown Object (File)
Sun, Jul 5, 9:35 PM
Unknown Object (File)
Sun, Jul 5, 7:46 PM
Unknown Object (File)
Sun, Jul 5, 7:43 PM
Subscribers

Details

Summary

POSIX does not allow mixing direct writes to STDOUT_FILENO with stdio
operations on stdout like we do here. More importantly, it causes
tests to fail randomly (or not-so-randomly after I added an fflush in
a previous commit).

MFC after: 1 week

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 74301
Build 71184: arc lint + arc unit

Event Timeline

des requested review of this revision.Fri, Jun 26, 2:03 PM

@siva this change is required for your PR to work reliably

sbin/ping/ping.c
986

Why not use putchar() throughout?

sbin/ping/ping.c
986

I don't like mixing explicit and implicit interfaces. If you're worried about performance, I suppose I can use putc() instead of fputc().

des marked an inline comment as done.Fri, Jun 26, 2:11 PM
markj added inline comments.
sbin/ping/ping.c
986

Okay, ping is still using printf() to print its messages though. As far as I can tell, putc() and fputc() are identical...

This revision is now accepted and ready to land.Fri, Jun 26, 2:22 PM
sbin/ping/ping.c
986

putc() is a macro which, if unthreaded (as is the case here) calls __sputc() directly without locking the stream, while fputc() is a function that first locks the stream before calling __sputc().

des marked an inline comment as done.Fri, Jun 26, 2:45 PM
This revision was automatically updated to reflect the committed changes.