2

I am running an Embedded Linux. Need to know from my application, which is run by not a root user, if my NTP daemon is synchronized.

I tried to run ntpd that comes with Busybox as follows:

ntpd -n -p pool.ntp.org -q

but the problem is, that it requires root privileges to run, even if I add ntpd to /etc/busybox.conf [SUID]

Then, I also tried chronyd & chronyc. Similar problem, chronyd is run by root. I also disabled the internet command sockets (cmdport 0) for security reasons, and then I run chronyc as a non-root user, as follows:

chronyc waitsync

got the following error message:

506 Cannot talk to daemon

Checked ntpstat code but it seems to interact with chronyc or ntpd.

I am wondering if there is an available solution for this task? Or, if not, any suggestions how that could be done. Maybe it could be done somehow from C code? But the solution should meet the following key requirements:

1) work with no root privileges
2) be compact and easy implemented on Embedded Linux system
3) robust

The script, tool or C code should give me two outputs:

   synchronized -> wthe hen clock has already been synchronized with NTP server
   not synchronized -> otherwise
abunickabhi
  • 558
  • 2
  • 9
  • 31
Andy
  • 21
  • 4
  • Instead of `cmdport` you should look at `bindcmdaddress 127.0.0.1` so that only localhost can connect, but that seems to be the default, so your concerns on internet access may be unfounded. – meuh Apr 05 '19 at 20:51
  • @meuh, Thank you for your reply, it seems that you are right. But I am wondering if there is any other solution available. – Andy Apr 08 '19 at 06:18

1 Answers1

0

How about putting the

ntpd -n -p pool.ntp.org -q

into the init-routine (You would need root-access once to do that).

(Would have put this in a comment, but don't have enough credits.)

Toto
  • 79
  • 10