diff options
author | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2020-12-07 19:56:04 +0100 |
---|---|---|
committer | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2020-12-07 19:56:04 +0100 |
commit | ba29d87838b8716c8364ea91956318a644630021 (patch) | |
tree | f0aa25e01c2a9d79ed5775f9c1dd6b56188eec10 | |
parent | 83d829c2da62214295a2a346d73d50430cd7b492 (diff) | |
download | ntpd-setwait-ba29d87838b8716c8364ea91956318a644630021.tar.gz ntpd-setwait-ba29d87838b8716c8364ea91956318a644630021.tar.bz2 ntpd-setwait-ba29d87838b8716c8364ea91956318a644630021.zip |
main.c: limit ntp probing to not hog cpu in case of errors
Signed-off-by: Michał Łyszczek <michal.lyszczek@bofc.pl>
-rw-r--r-- | main.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -421,10 +421,12 @@ int main for (;;) { /* probe for ntp time until we receive valid timestamp from - * ntp server + * ntp server, do not probe more often than once every 100ms, + * to not hog CPU in case network is no available at all, + * and get_ts_from_ntp() returns in an instant */ - while (get_ts_from_ntp(&ntp_ts, ip) != 0); + while (get_ts_from_ntp(&ntp_ts, ip) != 0) usleep(100 * 1000ul); fprintf(stderr, "n/ntp time is: %s", ctime(&ntp_ts)); /* what is localtime now? |