Ntpd config file support

Denys Vlasenko vda.linux at googlemail.com
Thu Mar 20 10:47:34 UTC 2014


On Tue, Mar 18, 2014 at 11:37 AM, Laszlo Papp <lpapp at kde.org> wrote:
> it seems that the ntpd util currently does not support config files.
> Currently, it means that I need to work this around in Yocto for my
> purposes, but as I see Zoltan Gyarmati here (*) also tried to do
> similar things in buildroot.

I don't understand the problem.

The way I use ntpd can be seen in this file:

busybox/examples/var_service/ntpd/run

In the real system, ntpd/ sits in /var/service/ directory.

Network configuration tools such as DHCP drop configuration files
into /var/run/service/ntpd directory. For example, my machine has
dhcp_em1.ntpconf file with this content:

let cfg=cfg+1
ntpip[$cfg]='10.5.26.10'
let cfg=cfg+1
ntpip[$cfg]='10.5.27.10'

(sorry, bashisms). When they do that, they restart ntpd service,
which runs this script.

The script sources these config files:

cfg=-1
for f in rundir/*.ntpconf; do
        test -f "$f" || continue
        . "$f"
done

Then it builds a list of -p PEER options:

p_opt=""
cfg=0
while test x"${ntpip[$cfg]}" != x""; do
        p_opt="$p_opt -p ${ntpip[$cfg]}"
        let cfg=cfg+1
done

If there were none, we fall back to default
pool="us.pool.ntp.org"
default_p_opt="-p 0.$pool -p 1.$pool -p 2.$pool -p 3.$pool"

And finally, we exec ntpd:
ntpd -nNl -S ./ntp.script $p_opt


Anyway, the basic idea is that you run a script such as this one instead
of running ntpd directly, which allows you to be smart, and
system/distro-specific in selecting peers.

With ntpd configuration file feature, in many cases you are likely
to still need a script such as this to regenerate the config file.
Where is the win?

-- 
vda


More information about the busybox mailing list