Fix --timeout to accept s/ms suffix for user convenience#472
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds support for 'ms' and 's' suffixes to the timeout option (-t) in fping.c. However, a critical bug was identified where the timeout multipliers are off by a factor of 1000 because opt_timeout is internally represented in nanoseconds rather than microseconds. Correcting these multipliers is necessary to prevent premature timeouts on remote hosts.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
The --timeout option previously rejected values with a trailing 's' or 'ms' suffix (e.g. --timeout 5s) because strtod_strict() validates that no trailing characters remain. Strip recognized time unit suffixes before parsing — opt_timeout is in nanoseconds, so seconds multiply by 1e9 and milliseconds by 1e6.
1850b27 to
06d03c3
Compare
|
Good catch — |
Summary
The
--timeoutoption previously rejected values with a trailingsormssuffix (e.g.--timeout 5s) becausestrtod_strict()validatesthat no trailing characters remain after the number.
This change strips recognized time unit suffixes (
sfor seconds,msfor milliseconds) from the argument before parsing, so users canwrite more natural forms like
--timeout 5sinstead of--timeout 500.Changes
-t/--timeoutcase handler insrc/fping.ctodetect and strip trailing
sormssuffixssuffix uses 1,000,000(seconds to microseconds),
mssuffix uses 1,000 (milliseconds tomicroseconds)
work as before
Test plan
fping --timeout 5s localhost→ alivefping --timeout 500ms localhost→ alivefping --timeout 5 localhost→ alive (backward compat)fping --timeout 5x localhost→ usage error (invalid suffix rejected)