Page MenuHomeFreeBSD

ping: Don't mix stdio and direct writes
ClosedPublic

Authored by des on Jun 26 2026, 2:03 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Aug 21, 6:32 AM
Unknown Object (File)
Fri, Aug 14, 4:51 PM
Unknown Object (File)
Wed, Aug 12, 7:43 PM
Unknown Object (File)
Tue, Aug 11, 11:43 PM
Unknown Object (File)
Tue, Aug 11, 12:41 PM
Unknown Object (File)
Tue, Aug 11, 1:19 AM
Unknown Object (File)
Mon, Aug 10, 2:15 PM
Unknown Object (File)
Mon, Aug 10, 9:49 AM
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 Not Applicable
Unit
Tests Not Applicable

Event Timeline

des requested review of this revision.Jun 26 2026, 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.Jun 26 2026, 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.Jun 26 2026, 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.Jun 26 2026, 2:45 PM
This revision was automatically updated to reflect the committed changes.