Bug 13766 - adjtimex: actually return the return value
Summary: adjtimex: actually return the return value
Status: NEW
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: 1.33.x
Hardware: All Linux
: P5 enhancement
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-04-22 12:21 UTC by Martin von Wittich
Modified: 2021-06-07 15:21 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin von Wittich 2021-04-22 12:21:54 UTC
adjtimex can be used to query if the system time is synchronized, e.g. whether NTP is working or not. Example output of a machine where ntpd can't connect to any peers (status: UNSYNC, return value: 5 (clock not synchronized)):

host ~ # busybox adjtimex; echo $?
    mode:         0
-o  offset:       0 us
-f  freq.adjust:  2126708 (65536 = 1ppm)
    maxerror:     16000000
    esterror:     16000000
    status:       16449 (PLL | UNSYNC)
-p  timeconstant: 7
    precision:    1 us
    tolerance:    32768000
-t  tick:         10000 us
    time.tv_sec:  1619093972
    time.tv_usec: 354882
    return value: 5 (clock not synchronized)
0

Unfortunately this has to be parsed from the output because the return value is only printed and not actually returned. It would be useful if adjtimex had a flag for this purpose, e.g. -r to actually return the call's return value. This would allow scripts to use `adjtime -qr` to suppress the output and determine the synchronization state efficiently by examining the return code.
Comment 1 Denys Vlasenko 2021-06-07 14:07:11 UTC
Does upstream do it?
Comment 2 Martin von Wittich 2021-06-07 15:21:37 UTC
(In reply to Denys Vlasenko from comment #1)

No, unfortunately it doesn't either:

host ~ # adjtimex -p; echo $?
         mode: 0
       offset: 0
    frequency: 246768
     maxerror: 16000000
     esterror: 15
       status: 8257
time_constant: 9
    precision: 1
    tolerance: 32768000
         tick: 10000
     raw time:  1623078713s 98145560ns = 1623078713.098145560
 return value = 5
0

I haven't found a bugtracker for the original adjtimex; it apparently originates from http://metalab.unc.edu/pub/Linux/system/admin/time and the last release was in 2009. There is a fork maintained by the current adjtimex Debian maintainer, so I've went ahead and filed essentially the same feature request there: https://github.com/rogers0/adjtimex/issues/4