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
F160937985: D57884.id180712.diff
Mon, Jun 29, 6:22 AM
F160937407: D57884.id.diff
Mon, Jun 29, 6:13 AM
F160935917: D57884.diff
Mon, Jun 29, 5:51 AM
F160843375: D57884.diff
Sun, Jun 28, 12:55 PM
Unknown Object (File)
Fri, Jun 26, 2:18 PM
Unknown Object (File)
Fri, Jun 26, 2:17 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 Not Applicable
Unit
Tests Not Applicable

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.