{"action":"opened","issue":{"url":"https://api.github.com/repos/openntpd-portable/openntpd-portable/issues/51","repository_url":"https://api.github.com/repos/openntpd-portable/openntpd-portable","labels_url":"https://api.github.com/repos/openntpd-portable/openntpd-portable/issues/51/labels{/name}","comments_url":"https://api.github.com/repos/openntpd-portable/openntpd-portable/issues/51/comments","events_url":"https://api.github.com/repos/openntpd-portable/openntpd-portable/issues/51/events","html_url":"https://github.com/openntpd-portable/openntpd-portable/issues/51","id":355968630,"node_id":"MDU6SXNzdWUzNTU5Njg2MzA=","number":51,"title":"openntpd cannot adjust clock with TIME_ERROR reason","user":{"login":"ilyaevseev","id":3008348,"node_id":"MDQ6VXNlcjMwMDgzNDg=","avatar_url":"https://avatars1.githubusercontent.com/u/3008348?v=4","gravatar_id":"","url":"https://api.github.com/users/ilyaevseev","html_url":"https://github.com/ilyaevseev","followers_url":"https://api.github.com/users/ilyaevseev/followers","following_url":"https://api.github.com/users/ilyaevseev/following{/other_user}","gists_url":"https://api.github.com/users/ilyaevseev/gists{/gist_id}","starred_url":"https://api.github.com/users/ilyaevseev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ilyaevseev/subscriptions","organizations_url":"https://api.github.com/users/ilyaevseev/orgs","repos_url":"https://api.github.com/users/ilyaevseev/repos","events_url":"https://api.github.com/users/ilyaevseev/events{/privacy}","received_events_url":"https://api.github.com/users/ilyaevseev/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-08-31T12:53:16Z","updated_at":"2018-08-31T12:53:16Z","closed_at":null,"author_association":"NONE","body":"There is an CentOS 7 host with 4.12 kernel from ELrepo and Openntpd 6.2p3.\r\n\r\n/var/log/messages is filled by tons of messages:\r\n\r\n    openntpd: adjusting local clock by -XX.YYs\r\n\r\nXX.YY is increased slowly but steadily.\r\n\r\nInitially detected delta was relatively small (15 seconds), but current value is >350 secs.\r\n\r\nstrace -p$ntpd_pid says:\r\n\r\n    adjtimex({modes=ADJ_OFFSET|ADJ_NANO|0x8000,\r\n    offset=-351879120,\r\n    freq=32768000,\r\n    maxerror=16000000,\r\n    esterror=16000000,\r\n    status=STA_UNSYNC,\r\n    constant=2,\r\n    precision=1,\r\n    tolerance=32768000,\r\n    time={1535711264, 1056},\r\n    tick=10000,\r\n    ppsfreq=0, jitter=0, shift=0, stabil=0, jitcnt=0, calcnt=0, errcnt=0, stbcnt=0, tai=0\r\n    }) = 5 (TIME_ERROR)\r\n\r\nIt seems that [ntpd_adjtime](https://github.com/openntpd-portable/openntpd-openbsd/blob/master/src/usr.sbin/ntpd/ntpd.c#L424) calls adjtime() from glibc, and [adjtime](https://code.woboq.org/userspace/glibc/sysdeps/unix/sysv/linux/adjtime.c.html) calls adjtimex() and ignores positive return values.\r\n\r\nSo adjtimex() returns TIME_ERROR to adjtime(), but openntpd dont knows about that because adjtime() returns 0.\r\n\r\nIt would be useful to change ntpd_adjtime() behaviour:\r\n\r\n* call adjtimex() instead of adjtime()\r\n* handle TIME_ERROR result -- for example, decrease requested delta and call adjtimex() again:\r\n\r\n      do {\r\n          d_to_tx(d, &tx);\r\n          rc = adjtimex(&tx);\r\n      } while(rc == TIME_ERROR && (d /= 2) > (LOG_NEGLIGIBLE_ADJTIME / 1000));\r\n\r\n      if (rc == TIME_ERROR) {\r\n          log_warn(\"adjtimex returned TIME_ERROR\");\r\n      } else if (rc < 0) {\r\n          log_warn(\"adjtimex failed\");\r\n      }\r\n"}}
{"actor":{"display_login":"ilyaevseev"}}