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