aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichał Łyszczek <michal.lyszczek@bofc.pl>2020-12-07 19:56:04 +0100
committerMichał Łyszczek <michal.lyszczek@bofc.pl>2020-12-07 19:56:04 +0100
commitba29d87838b8716c8364ea91956318a644630021 (patch)
treef0aa25e01c2a9d79ed5775f9c1dd6b56188eec10
parent83d829c2da62214295a2a346d73d50430cd7b492 (diff)
downloadntpd-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.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/main.c b/main.c
index 7b3fd69..f3df901 100644
--- a/main.c
+++ b/main.c
@@ -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?