OpenNTPD daemon with OpenSSL implementation & flexible configurability
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2252 lines
74 KiB

  1. From: Pekka Helenius <fincer89@hotmail.com>
  2. Date: Tue, 04 Aug 2020 01:52:09 +0300
  3. Subject: Provide human-readable error messages for easier process interpretation
  4. --- a/src/client.c 2020-08-01 00:19:23.432392415 +0300
  5. +++ b/src/client.c 2020-08-02 02:02:37.850286445 +0300
  6. @@ -52,7 +52,7 @@ int
  7. client_peer_init(struct ntp_peer *p)
  8. {
  9. if ((p->query = calloc(1, sizeof(struct ntp_query))) == NULL)
  10. - fatal("client_peer_init calloc");
  11. + fatal("NTP client: can't allocate memory for a new NTP peer connection");
  12. p->query->fd = -1;
  13. p->query->msg.status = MODE_CLIENT | (NTP_VERSION << 3);
  14. p->state = STATE_NONE;
  15. @@ -86,9 +86,14 @@ client_addr_init(struct ntp_peer *p)
  16. p->state = STATE_DNS_DONE;
  17. break;
  18. default:
  19. - fatalx("king bula sez: wrong AF in client_addr_init");
  20. + fatalx("NTP client: NTP peer %s has wrong network address family",
  21. + p->addr_head.name
  22. + );
  23. /* NOTREACHED */
  24. }
  25. + log_info("NTP client: DNS query found IP address %s for NTP peer %s",
  26. + log_sockaddr((struct sockaddr *)&h->ss),
  27. + p->addr_head.name);
  28. }
  29. p->query->fd = -1;
  30. @@ -129,6 +134,16 @@ int
  31. client_query(struct ntp_peer *p)
  32. {
  33. int val;
  34. + struct ntp_addr *h;
  35. + h = p->addr;
  36. +/*
  37. + if (h != NULL) {
  38. +
  39. + log_debug("NTP client: listening on NTP peer %s on remote UDP port %d",
  40. + log_sockaddr((struct sockaddr *)&h->ss),
  41. + p->addr_head.port);
  42. + }
  43. +*/
  44. if (p->addr == NULL && client_nextaddr(p) == -1) {
  45. if (conf->settime)
  46. @@ -156,21 +171,23 @@ client_query(struct ntp_peer *p)
  47. p->query->fd = socket(p->addr->ss.ss_family, SOCK_DGRAM, 0);
  48. if (p->query->fd == -1) {
  49. if (errno == EAFNOSUPPORT) {
  50. - log_warn("client_query socket");
  51. + log_warn("NTP client: can't create UDP socket");
  52. client_nextaddr(p);
  53. set_next(p, error_interval());
  54. return (-1);
  55. } else
  56. - fatal("client_query socket");
  57. + fatal("NTP client: NTP peer has unknown network address family %s",
  58. + log_sockaddr((struct sockaddr *)&h->ss)
  59. + );
  60. }
  61. if (p->addr->ss.ss_family == qa4->sa_family) {
  62. if (bind(p->query->fd, qa4, SA_LEN(qa4)) == -1)
  63. - fatal("couldn't bind to IPv4 query address: %s",
  64. + fatal("NTP client: can't bind to NTP peer IPv4 query address %s",
  65. log_sockaddr(qa4));
  66. } else if (p->addr->ss.ss_family == qa6->sa_family) {
  67. if (bind(p->query->fd, qa6, SA_LEN(qa6)) == -1)
  68. - fatal("couldn't bind to IPv6 query address: %s",
  69. + fatal("NTP client: can't bind to NTP peer IPv6 query address %s",
  70. log_sockaddr(qa6));
  71. }
  72. @@ -187,17 +204,17 @@ client_query(struct ntp_peer *p)
  73. p->senderrors++;
  74. return (-1);
  75. } else
  76. - fatal("client_query connect");
  77. + fatal("NTP client: can't connect to NTP peer due to socket error");
  78. }
  79. val = IPTOS_LOWDELAY;
  80. if (p->addr->ss.ss_family == AF_INET && setsockopt(p->query->fd,
  81. IPPROTO_IP, IP_TOS, &val, sizeof(val)) == -1)
  82. - log_warn("setsockopt IPTOS_LOWDELAY");
  83. + log_warn("NTP client: can't set NTP peer IPv4 socket field IP_TOS");
  84. #ifdef SO_TIMESTAMP
  85. val = 1;
  86. if (setsockopt(p->query->fd, SOL_SOCKET, SO_TIMESTAMP,
  87. &val, sizeof(val)) == -1)
  88. - fatal("setsockopt SO_TIMESTAMP");
  89. + fatal("NTP client: can't set NTP peer IPv4 socket control option SO_TIMESTAMP");
  90. #endif
  91. }
  92. @@ -256,7 +273,7 @@ handle_auto(uint8_t trusted, double offs
  93. if (offset < AUTO_THRESHOLD) {
  94. /* don't bother */
  95. - priv_settime(0, "offset is negative or close enough");
  96. + priv_settime(0, "NTP client: NTP peer offset is negative or close enough");
  97. return;
  98. }
  99. /* collect some more */
  100. @@ -305,21 +322,21 @@ client_dispatch(struct ntp_peer *p, u_in
  101. errno == ENETUNREACH || errno == ENETDOWN ||
  102. errno == ECONNREFUSED || errno == EADDRNOTAVAIL ||
  103. errno == ENOPROTOOPT || errno == ENOENT) {
  104. - client_log_error(p, "recvmsg", errno);
  105. + client_log_error(p, "socket message reception", errno);
  106. set_next(p, error_interval());
  107. return (0);
  108. } else
  109. - fatal("recvfrom");
  110. + fatal("NTP client: can't get socket message for an unknown reason");
  111. }
  112. if (somsg.msg_flags & MSG_TRUNC) {
  113. - client_log_error(p, "recvmsg packet", EMSGSIZE);
  114. + client_log_error(p, "socket packet message reception", EMSGSIZE);
  115. set_next(p, error_interval());
  116. return (0);
  117. }
  118. if (somsg.msg_flags & MSG_CTRUNC) {
  119. - client_log_error(p, "recvmsg control data", E2BIG);
  120. + client_log_error(p, "socket control data message reception", E2BIG);
  121. set_next(p, error_interval());
  122. return (0);
  123. }
  124. @@ -359,7 +376,7 @@ client_dispatch(struct ntp_peer *p, u_in
  125. }
  126. interval = error_interval();
  127. set_next(p, interval);
  128. - log_info("reply from %s: not synced (%s), next query %llds",
  129. + log_info("NTP client: reply from %-16s is not synced (%s), next query in %llds",
  130. log_sockaddr((struct sockaddr *)&p->addr->ss), s,
  131. (long long)interval);
  132. return (0);
  133. @@ -387,7 +404,7 @@ client_dispatch(struct ntp_peer *p, u_in
  134. /* Detect liars */
  135. if (!p->trusted && conf->constraint_median != 0 &&
  136. (constraint_check(T2) != 0 || constraint_check(T3) != 0)) {
  137. - log_info("reply from %s: constraint check failed",
  138. + log_info("NTP client: reply from %-16s constraint check failed",
  139. log_sockaddr((struct sockaddr *)&p->addr->ss));
  140. set_next(p, error_interval());
  141. return (0);
  142. @@ -399,8 +416,8 @@ client_dispatch(struct ntp_peer *p, u_in
  143. if (p->reply[p->shift].delay < 0) {
  144. interval = error_interval();
  145. set_next(p, interval);
  146. - log_info("reply from %s: negative delay %fs, "
  147. - "next query %llds",
  148. + log_info("NTP client: reply from %-16s has negative delay %9fs, "
  149. + "next query in %llds",
  150. log_sockaddr((struct sockaddr *)&p->addr->ss),
  151. p->reply[p->shift].delay, (long long)interval);
  152. return (0);
  153. @@ -449,13 +466,13 @@ client_dispatch(struct ntp_peer *p, u_in
  154. if (p->trustlevel < TRUSTLEVEL_MAX) {
  155. if (p->trustlevel < TRUSTLEVEL_BADPEER &&
  156. p->trustlevel + 1 >= TRUSTLEVEL_BADPEER)
  157. - log_info("peer %s now valid",
  158. + log_info("NTP client: NTP peer %s is valid now",
  159. log_sockaddr((struct sockaddr *)&p->addr->ss));
  160. p->trustlevel++;
  161. }
  162. - log_debug("reply from %s: offset %f delay %f, "
  163. - "next query %llds",
  164. + log_debug("NTP client: reply from %-16s offset: %9fs, delay: %9fs, "
  165. + "next query in %llds",
  166. log_sockaddr((struct sockaddr *)&p->addr->ss),
  167. p->reply[p->shift].offset, p->reply[p->shift].delay,
  168. (long long)interval);
  169. @@ -518,9 +535,9 @@ client_log_error(struct ntp_peer *peer,
  170. address = log_sockaddr((struct sockaddr *)&peer->addr->ss);
  171. if (peer->lasterror == error) {
  172. - log_debug("%s %s: %s", operation, address, strerror(error));
  173. + log_debug("NTP client: NTP peer %s, error in %s: %s", operation, address, strerror(error));
  174. return;
  175. }
  176. peer->lasterror = error;
  177. - log_warn("%s %s", operation, address);
  178. + log_warn("NTP client: NTP peer %s, error in %s", operation, address);
  179. }
  180. --- a/src/config.c 2020-08-01 00:19:23.449059082 +0300
  181. +++ b/src/config.c 2020-07-31 23:11:30.429054797 +0300
  182. @@ -44,7 +44,7 @@ host(const char *s, struct ntp_addr **hn
  183. if (!strcmp(s, "*")) {
  184. if ((h = calloc(1, sizeof(*h))) == NULL)
  185. - fatal(NULL);
  186. + fatal("can't allocate memory for NTP peer address");
  187. } else {
  188. if ((h = host_ip(s)) == NULL) {
  189. non_numeric = 1;
  190. @@ -69,7 +69,7 @@ host_ip(const char *s)
  191. if (res->ai_family == AF_INET ||
  192. res->ai_family == AF_INET6) {
  193. if ((h = calloc(1, sizeof(*h))) == NULL)
  194. - fatal(NULL);
  195. + fatal("can't allocate memory for NTP peer IP address");
  196. memcpy(&h->ss, res->ai_addr, res->ai_addrlen);
  197. }
  198. freeaddrinfo(res);
  199. @@ -110,7 +110,7 @@ host_dns1(const char *s, struct ntp_addr
  200. return (0);
  201. }
  202. if (error) {
  203. - log_warnx("could not parse \"%s\": %s", s,
  204. + log_warnx("DNS process: can't parse \"%s\": %s", s,
  205. gai_strerror(error));
  206. return (-1);
  207. }
  208. @@ -120,7 +120,7 @@ host_dns1(const char *s, struct ntp_addr
  209. res->ai_family != AF_INET6)
  210. continue;
  211. if ((h = calloc(1, sizeof(*h))) == NULL)
  212. - fatal(NULL);
  213. + fatal("DNS process: can't allocate memory for NTP peer address");
  214. memcpy(&h->ss, res->ai_addr, res->ai_addrlen);
  215. h->notauth = notauth;
  216. @@ -139,19 +139,19 @@ host_dns(const char *s, int synced, stru
  217. {
  218. int error;
  219. - log_debug("trying to resolve %s", s);
  220. + log_debug("DNS process: trying to resolve %s", s);
  221. error = host_dns1(s, hn, 0);
  222. #ifdef RES_USE_CD
  223. if (!synced && error <= 0) {
  224. int save_opts;
  225. - log_debug("no luck, trying to resolve %s without checking", s);
  226. + log_debug("DNS process: trying to resolve %s without checking", s);
  227. save_opts = _res.options;
  228. _res.options |= RES_USE_CD;
  229. error = host_dns1(s, hn, 1);
  230. _res.options = save_opts;
  231. }
  232. #endif
  233. - log_debug("resolve %s done: %d", s, error);
  234. + log_debug("DNS process: resolve for %s done: %d", s, error);
  235. return error;
  236. }
  237. @@ -161,7 +161,7 @@ new_peer(void)
  238. struct ntp_peer *p;
  239. if ((p = calloc(1, sizeof(struct ntp_peer))) == NULL)
  240. - fatal("new_peer calloc");
  241. + fatal("NTP client: can't allocate memory for a new NTP peer");
  242. p->id = ++maxid;
  243. return (p);
  244. @@ -173,9 +173,9 @@ new_sensor(char *device)
  245. struct ntp_conf_sensor *s;
  246. if ((s = calloc(1, sizeof(struct ntp_conf_sensor))) == NULL)
  247. - fatal("new_sensor calloc");
  248. + fatal("sensor: can't allocate memory for a new sensor");
  249. if ((s->device = strdup(device)) == NULL)
  250. - fatal("new_sensor strdup");
  251. + fatal("sensor: can't duplicate memory address for a new sensor");
  252. return (s);
  253. }
  254. @@ -186,12 +186,12 @@ new_constraint(void)
  255. struct constraint *p;
  256. if ((p = calloc(1, sizeof(struct constraint))) == NULL)
  257. - fatal("new_constraint calloc");
  258. + fatal("constraint: can't allocate memory for a new constraint");
  259. p->id = ++constraint_maxid;
  260. p->fd = -1;
  261. #ifndef HAVE_LIBTLS
  262. - log_warnx("constraint configured without libtls support");
  263. + log_warnx("constraint configured without LibreSSL support");
  264. #endif
  265. return (p);
  266. }
  267. --- a/src/constraint.c 2020-08-01 00:19:23.425725748 +0300
  268. +++ b/src/constraint.c 2020-08-02 01:55:31.236952662 +0300
  269. @@ -135,8 +135,7 @@ constraint_addr_init(struct constraint *
  270. cstr->state = STATE_DNS_DONE;
  271. break;
  272. default:
  273. - /* XXX king bula sez it? */
  274. - fatalx("wrong AF in constraint_addr_init");
  275. + fatalx("constraint id %d: wrong network address family", cstr->id);
  276. /* NOTREACHED */
  277. }
  278. @@ -238,23 +237,23 @@ priv_constraint_msg(u_int32_t id, u_int8
  279. int rv;
  280. if ((cstr = constraint_byid(id)) != NULL) {
  281. - log_warnx("IMSG_CONSTRAINT_QUERY repeated for id %d", id);
  282. + log_warnx("constraint id %d: repeated query", id);
  283. return;
  284. }
  285. if (len < sizeof(am)) {
  286. - log_warnx("invalid IMSG_CONSTRAINT_QUERY received");
  287. + log_warnx("constraint id %d: longer query expected", id);
  288. return;
  289. }
  290. memcpy(&am, data, sizeof(am));
  291. if (len != (sizeof(am) + am.namelen + am.pathlen)) {
  292. - log_warnx("invalid IMSG_CONSTRAINT_QUERY received");
  293. + log_warnx("constraint id %d: invalid query received", id);
  294. return;
  295. }
  296. /* Additional imsg data is obtained in the unpriv child */
  297. if ((h = calloc(1, sizeof(*h))) == NULL)
  298. - fatal("calloc ntp_addr");
  299. + fatal("constraint id %d: can't allocate memory for network address", id);
  300. memcpy(h, &am.a, sizeof(*h));
  301. h->next = NULL;
  302. @@ -267,19 +266,23 @@ priv_constraint_msg(u_int32_t id, u_int8
  303. if (socketpair(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, AF_UNSPEC,
  304. pipes) == -1)
  305. - fatal("%s pipes", __func__);
  306. + fatal("constraint id %d: can't create required socket pairs (%s)",
  307. + id, __func__
  308. + );
  309. /* Prepare and send constraint data to child. */
  310. cstr->fd = pipes[0];
  311. imsg_init(&cstr->ibuf, cstr->fd);
  312. if (imsg_compose(&cstr->ibuf, IMSG_CONSTRAINT_QUERY, id, 0, -1,
  313. data, len) == -1)
  314. - fatal("%s: imsg_compose", __func__);
  315. + fatal("constraint id %d: can't compose data from parent process (%s)",
  316. + id, __func__
  317. + );
  318. do {
  319. rv = imsg_flush(&cstr->ibuf);
  320. } while (rv == -1 && errno == EAGAIN);
  321. if (rv == -1)
  322. - fatal("imsg_flush");
  323. + fatal("constraint id %d: can't flush old data", id);
  324. /*
  325. * Fork child handlers and make sure to do any sensitive work in the
  326. @@ -301,11 +304,14 @@ priv_constraint_readquery(struct constra
  327. /* Read the message our parent left us. */
  328. if (((n = imsg_read(&cstr->ibuf)) == -1 && errno != EAGAIN) || n == 0)
  329. - fatal("%s: imsg_read", __func__);
  330. + fatal("constraint: can't read message from parent process (%s)",
  331. + __func__);
  332. if (((n = imsg_get(&cstr->ibuf, &imsg)) == -1) || n == 0)
  333. - fatal("%s: imsg_get", __func__);
  334. + fatal("constraint: can't get message from parent process (%s)",
  335. + __func__);
  336. if (imsg.hdr.type != IMSG_CONSTRAINT_QUERY)
  337. - fatalx("%s: invalid message type", __func__);
  338. + fatalx("constraint: invalid message type from parent process (%s)",
  339. + __func__);
  340. /*
  341. * Copy the message contents just like our father:
  342. @@ -313,16 +319,19 @@ priv_constraint_readquery(struct constra
  343. */
  344. mlen = imsg.hdr.len - IMSG_HEADER_SIZE;
  345. if (mlen < sizeof(*am))
  346. - fatalx("%s: mlen < sizeof(*am)", __func__);
  347. + fatalx("constraint: expected longer message from parent process (%s)",
  348. + __func__
  349. + );
  350. memcpy(am, imsg.data, sizeof(*am));
  351. if (mlen != (sizeof(*am) + am->namelen + am->pathlen))
  352. - fatalx("%s: mlen < sizeof(*am) + am->namelen + am->pathlen",
  353. - __func__);
  354. + fatalx("constraint: invalid message length received from parent process (%s)",
  355. + __func__
  356. + );
  357. if ((h = calloc(1, sizeof(*h))) == NULL ||
  358. (*data = calloc(1, mlen)) == NULL)
  359. - fatal("%s: calloc", __func__);
  360. + fatal("constraint: can't allocate memory (%s)", __func__);
  361. memcpy(h, &am->a, sizeof(*h));
  362. h->next = NULL;
  363. @@ -349,29 +358,27 @@ priv_constraint_child(const char *pw_dir
  364. struct iovec iov[2];
  365. int i, rv;
  366. - log_procinit("constraint");
  367. -
  368. if (setpriority(PRIO_PROCESS, 0, 0) == -1)
  369. - log_warn("could not set priority");
  370. + log_warn("constraint: can't set priority for subprocess");
  371. #ifdef HAVE_LIBTLS
  372. /* Init TLS and load CA certs before chroot() */
  373. if (tls_init() == -1)
  374. - fatalx("tls_init");
  375. + fatalx("constraint: can't initialize LibreSSL engine");
  376. if ((conf->ca = tls_load_file(tls_default_ca_cert_file(),
  377. &conf->ca_len, NULL)) == NULL)
  378. - fatalx("failed to load constraint ca");
  379. + log_warnx("constraint: failed to load CA certificate bundle file");
  380. #endif
  381. if (chroot(pw_dir) == -1)
  382. - fatal("chroot");
  383. + fatal("constraint: can't set isolated working directory for subprocess");
  384. if (chdir("/") == -1)
  385. - fatal("chdir(\"/\")");
  386. + fatal("constraint: can't change subprocess working directory");
  387. if (setgroups(1, &pw_gid) ||
  388. setresgid(pw_gid, pw_gid, pw_gid) ||
  389. setresuid(pw_uid, pw_uid, pw_uid))
  390. - fatal("can't drop privileges");
  391. + fatal("constraint: can't drop subprocess privileges");
  392. /* Reset all signal handlers */
  393. memset(&sa, 0, sizeof(sa));
  394. @@ -382,7 +389,7 @@ priv_constraint_child(const char *pw_dir
  395. sigaction(i, &sa, NULL);
  396. if (pledge("stdio inet", NULL) == -1)
  397. - fatal("pledge");
  398. + fatal("constraint: can't restrict subprocess privileges");
  399. cstr.fd = CONSTRAINT_PASSFD;
  400. imsg_init(&cstr.ibuf, cstr.fd);
  401. @@ -398,10 +405,11 @@ priv_constraint_child(const char *pw_dir
  402. SA_LEN((struct sockaddr *)&cstr.addr->ss),
  403. addr, sizeof(addr), NULL, 0,
  404. NI_NUMERICHOST) != 0)
  405. - fatalx("%s getnameinfo", __func__);
  406. + fatalx("constraint %s: can't get host and service name from IP address"
  407. + " (getnameinfo) (%s)", addr, __func__);
  408. - log_debug("constraint request to %s", addr);
  409. - setproctitle("constraint from %s", addr);
  410. + log_debug("constraint %s: setting HTTPS request", addr);
  411. + setproctitle("constraint %s: new HTTPS request", addr);
  412. (void)closefrom(CONSTRAINT_PASSFD + 1);
  413. /*
  414. @@ -411,25 +419,27 @@ priv_constraint_child(const char *pw_dir
  415. * but we keep it as a safety belt; especially for portability.
  416. */
  417. if (fcntl(CONSTRAINT_PASSFD, F_SETFD, FD_CLOEXEC) == -1)
  418. - fatal("%s fcntl F_SETFD", __func__);
  419. + fatal("constraint %s: unexpected file descriptor %d closure after execution (%s fcntl F_SETFD)",
  420. + addr, CONSTRAINT_PASSFD, __func__);
  421. /* Get remaining data from imsg in the unpriv child */
  422. if (am.namelen) {
  423. if ((cstr.addr_head.name =
  424. get_string(data, am.namelen)) == NULL)
  425. - fatalx("invalid IMSG_CONSTRAINT_QUERY name");
  426. + fatalx("constraint %s: invalid name", addr);
  427. data += am.namelen;
  428. }
  429. if (am.pathlen) {
  430. if ((cstr.addr_head.path =
  431. get_string(data, am.pathlen)) == NULL)
  432. - fatalx("invalid IMSG_CONSTRAINT_QUERY path");
  433. + fatalx("constraint %s: invalid path", addr);
  434. }
  435. /* Run! */
  436. if ((ctx = httpsdate_query(addr,
  437. CONSTRAINT_PORT, cstr.addr_head.name, cstr.addr_head.path,
  438. conf->ca, conf->ca_len, &rectv, &xmttv)) == NULL) {
  439. + log_debug("constraint %s: failed to get proper time results", addr);
  440. /* Abort with failure but without warning */
  441. exit(1);
  442. }
  443. @@ -464,7 +474,7 @@ priv_constraint_check_child(pid_t pid, i
  444. if (WEXITSTATUS(status) != 0)
  445. fail = 1;
  446. } else
  447. - fatalx("unexpected cause of SIGCHLD");
  448. + fatalx("constraint: unexpected closure in check (SIGCHLD)");
  449. if ((cstr = constraint_bypid(pid)) != NULL) {
  450. if (sig) {
  451. @@ -489,7 +499,7 @@ priv_constraint_kill(u_int32_t id)
  452. struct constraint *cstr;
  453. if ((cstr = constraint_byid(id)) == NULL) {
  454. - log_warnx("IMSG_CONSTRAINT_KILL for invalid id %d", id);
  455. + log_warnx("constraint id %d: kill failed: invalid id", id);
  456. return;
  457. }
  458. @@ -541,7 +551,7 @@ constraint_close(u_int32_t id)
  459. struct constraint *cstr;
  460. if ((cstr = constraint_byid(id)) == NULL) {
  461. - log_warn("%s: id %d: not found", __func__, id);
  462. + log_warn("constraint id %d: id not found (%s)", id, __func__);
  463. return (0);
  464. }
  465. @@ -569,7 +579,7 @@ priv_constraint_close(int fd, int fail)
  466. u_int32_t id;
  467. if ((cstr = constraint_byfd(fd)) == NULL) {
  468. - log_warn("%s: fd %d: not found", __func__, fd);
  469. + log_warn("constraint id %d: constraint file descriptor %d not found (%s)", cstr->id, fd, __func__);
  470. return;
  471. }
  472. @@ -643,7 +653,9 @@ priv_constraint_dispatch(struct pollfd *
  473. switch (imsg.hdr.type) {
  474. case IMSG_CONSTRAINT_RESULT:
  475. if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(tv))
  476. - fatalx("invalid IMSG_CONSTRAINT received");
  477. + fatalx("constraint id %d: invalid header length received in dispatch",
  478. + cstr->id
  479. + );
  480. /* state is maintained by child, but we want to
  481. remember we've seen the result */
  482. @@ -669,12 +681,12 @@ constraint_msg_result(u_int32_t id, u_in
  483. double offset;
  484. if ((cstr = constraint_byid(id)) == NULL) {
  485. - log_warnx("IMSG_CONSTRAINT_CLOSE with invalid constraint id");
  486. + log_warnx("constraint id %d: invalid constraint id in result", id);
  487. return;
  488. }
  489. if (len != sizeof(tv)) {
  490. - log_warnx("invalid IMSG_CONSTRAINT received");
  491. + log_warnx("constraint id %d: invalid header length %zu received in result", id, len);
  492. return;
  493. }
  494. @@ -683,7 +695,7 @@ constraint_msg_result(u_int32_t id, u_in
  495. offset = gettime_from_timeval(&tv[0]) -
  496. gettime_from_timeval(&tv[1]);
  497. - log_info("constraint reply from %s: offset %f",
  498. + log_info("constraint %s: reply received: offset %fs",
  499. log_sockaddr((struct sockaddr *)&cstr->addr->ss),
  500. offset);
  501. @@ -702,20 +714,22 @@ constraint_msg_close(u_int32_t id, u_int
  502. static int total_fails;
  503. if ((cstr = constraint_byid(id)) == NULL) {
  504. - log_warnx("IMSG_CONSTRAINT_CLOSE with invalid constraint id");
  505. + log_warnx("constraint id %d: closure failed: invalid constraint id", id);
  506. return;
  507. }
  508. if (len != sizeof(int)) {
  509. - log_warnx("invalid IMSG_CONSTRAINT_CLOSE received");
  510. + log_warnx("constraint id %d: closure failed: invalid header length %zu received",
  511. + id,
  512. + len);
  513. return;
  514. }
  515. memcpy(&fail, data, len);
  516. if (fail) {
  517. - log_debug("no constraint reply from %s"
  518. - " received in time, next query %ds",
  519. + log_debug("constraint %s: no reply"
  520. + " received in time, next query in %ds",
  521. log_sockaddr((struct sockaddr *)
  522. &cstr->addr->ss), CONSTRAINT_SCAN_INTERVAL);
  523. @@ -724,7 +738,7 @@ constraint_msg_close(u_int32_t id, u_int
  524. cnt++;
  525. if (cnt > 0 && ++total_fails >= cnt &&
  526. conf->constraint_median == 0) {
  527. - log_warnx("constraints configured but none available");
  528. + log_warnx("constraint: constraints configured but none available");
  529. total_fails = 0;
  530. }
  531. }
  532. @@ -743,21 +757,21 @@ constraint_msg_dns(u_int32_t id, u_int8_
  533. struct ntp_addr *h;
  534. if ((cstr = constraint_byid(id)) == NULL) {
  535. - log_debug("IMSG_CONSTRAINT_DNS with invalid constraint id");
  536. + log_warnx("constraint id %d: DNS dispatching failed: invalid constraint id", id);
  537. return;
  538. }
  539. if (cstr->addr != NULL) {
  540. - log_warnx("IMSG_CONSTRAINT_DNS but addr != NULL!");
  541. + log_warnx("constraint id %d: DNS dispatching failed: address is not empty", id);
  542. return;
  543. }
  544. if (len == 0) {
  545. - log_debug("%s FAILED", __func__);
  546. + log_debug("constraint id %d: DNS dispatching failed: invalid header length %zu (%s FAILED)", id, len, __func__);
  547. cstr->state = STATE_DNS_TEMPFAIL;
  548. return;
  549. }
  550. if (len % (sizeof(struct sockaddr_storage) + sizeof(int)) != 0)
  551. - fatalx("IMSG_CONSTRAINT_DNS len");
  552. + fatalx("constraint id %d: DNS dispatching failed: invalid header length", id);
  553. if (cstr->addr_head.pool) {
  554. struct constraint *n, *tmp;
  555. @@ -772,7 +786,7 @@ constraint_msg_dns(u_int32_t id, u_int8_
  556. p = data;
  557. do {
  558. if ((h = calloc(1, sizeof(*h))) == NULL)
  559. - fatal("calloc ntp_addr");
  560. + fatal("constraint id %d: DNS dispatching failed: can't allocate memory", id);
  561. memcpy(&h->ss, p, sizeof(h->ss));
  562. p += sizeof(h->ss);
  563. len -= sizeof(h->ss);
  564. @@ -788,7 +802,7 @@ constraint_msg_dns(u_int32_t id, u_int8_
  565. ncstr->addr_head.path = strdup(cstr->addr_head.path);
  566. if (ncstr->addr_head.name == NULL ||
  567. ncstr->addr_head.path == NULL)
  568. - fatal("calloc name");
  569. + fatal("constraint id %d: DNS dispatching failed: invalid data", id);
  570. ncstr->addr_head.pool = cstr->addr_head.pool;
  571. ncstr->state = STATE_DNS_DONE;
  572. constraint_add(ncstr);
  573. @@ -831,7 +845,7 @@ constraint_update(void)
  574. return;
  575. if ((values = calloc(cnt, sizeof(time_t))) == NULL)
  576. - fatal("calloc");
  577. + fatal("constraint: can't allocate memory for constraint time");
  578. i = 0;
  579. TAILQ_FOREACH(cstr, &conf->constraints, entry) {
  580. @@ -979,11 +993,14 @@ httpsdate_request(struct httpsdate *http
  581. * does not trigger any DNS operation and is safe to be called
  582. * without the dns pledge.
  583. */
  584. + log_debug("constraint %s: establishing connection", httpsdate->tls_addr);
  585. if (tls_connect_servername(httpsdate->tls_ctx, httpsdate->tls_addr,
  586. httpsdate->tls_port, httpsdate->tls_hostname) == -1) {
  587. - log_debug("tls connect failed: %s (%s): %s",
  588. - httpsdate->tls_addr, httpsdate->tls_hostname,
  589. - tls_error(httpsdate->tls_ctx));
  590. + log_debug("constraint %s: TLS connection failed (%s): %s",
  591. + httpsdate->tls_addr,
  592. + httpsdate->tls_hostname,
  593. + tls_error(httpsdate->tls_ctx)
  594. + );
  595. goto fail;
  596. }
  597. @@ -994,9 +1011,11 @@ httpsdate_request(struct httpsdate *http
  598. if (ret == TLS_WANT_POLLIN || ret == TLS_WANT_POLLOUT)
  599. continue;
  600. if (ret == -1) {
  601. - log_warnx("tls write failed: %s (%s): %s",
  602. - httpsdate->tls_addr, httpsdate->tls_hostname,
  603. - tls_error(httpsdate->tls_ctx));
  604. + log_warnx("constraint %s: TLS write operation failed (%s): %s",
  605. + httpsdate->tls_addr,
  606. + httpsdate->tls_hostname,
  607. + tls_error(httpsdate->tls_ctx)
  608. + );
  609. goto fail;
  610. }
  611. buf += ret;
  612. @@ -1022,7 +1041,9 @@ httpsdate_request(struct httpsdate *http
  613. */
  614. if (strptime(p, IMF_FIXDATE,
  615. &httpsdate->tls_tm) == NULL) {
  616. - log_warnx("unsupported date format");
  617. + log_warnx("constraint %s: unsupported date format",
  618. + httpsdate->tls_addr
  619. + );
  620. free(line);
  621. return (-1);
  622. }
  623. @@ -1050,8 +1071,8 @@ httpsdate_request(struct httpsdate *http
  624. if (strftime(timebuf2, sizeof(timebuf2), X509_DATE,
  625. &httpsdate->tls_tm) == 0)
  626. goto fail;
  627. - log_warnx("tls certificate not yet valid: %s (%s): "
  628. - "not before %s, now %s", httpsdate->tls_addr,
  629. + log_warnx("constraint %s: TLS certificate not yet valid (%s): "
  630. + "not before %s, now is %s", httpsdate->tls_addr,
  631. httpsdate->tls_hostname, timebuf1, timebuf2);
  632. goto fail;
  633. }
  634. @@ -1063,8 +1084,8 @@ httpsdate_request(struct httpsdate *http
  635. if (strftime(timebuf2, sizeof(timebuf2), X509_DATE,
  636. &httpsdate->tls_tm) == 0)
  637. goto fail;
  638. - log_warnx("tls certificate expired: %s (%s): "
  639. - "not after %s, now %s", httpsdate->tls_addr,
  640. + log_warnx("constraint %s: TLS certificate has been expired (%s): "
  641. + "not after %s, now is %s", httpsdate->tls_addr,
  642. httpsdate->tls_hostname, timebuf1, timebuf2);
  643. goto fail;
  644. }
  645. @@ -1117,11 +1138,11 @@ tls_readline(struct tls *tls, size_t *le
  646. len = 128;
  647. if ((buf = malloc(len)) == NULL)
  648. - fatal("Can't allocate memory for transfer buffer");
  649. + fatal("constraint: can't allocate memory for TLS transfer buffer");
  650. for (i = 0; ; i++) {
  651. if (i >= len - 1) {
  652. if ((q = reallocarray(buf, len, 2)) == NULL)
  653. - fatal("Can't expand transfer buffer");
  654. + fatal("constraint: can't expand TLS transfer buffer");
  655. buf = q;
  656. len *= 2;
  657. }
  658. @@ -1136,7 +1157,7 @@ tls_readline(struct tls *tls, size_t *le
  659. }
  660. if (maxlength != NULL && (*maxlength)-- == 0) {
  661. - log_warnx("maximum length exceeded");
  662. + log_warnx("constraint: maximum HTTP header length exceeded");
  663. free(buf);
  664. return (NULL);
  665. }
  666. @@ -1147,7 +1168,7 @@ tls_readline(struct tls *tls, size_t *le
  667. }
  668. *lenp = i;
  669. if (gettimeofday(when, NULL) == -1)
  670. - fatal("gettimeofday");
  671. + fatal("constraint: can't get a valid time stamp");
  672. return (buf);
  673. }
  674. --- a/src/control.c 2020-08-01 00:19:21.849059080 +0300
  675. +++ b/src/control.c 2020-07-31 23:23:56.959055574 +0300
  676. @@ -47,12 +47,12 @@ control_check(char *path)
  677. strlcpy(sun.sun_path, path, sizeof(sun.sun_path));
  678. if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
  679. - log_debug("control_check: socket check");
  680. + log_debug("control socket: socket error in check");
  681. return (-1);
  682. }
  683. if (connect(fd, (struct sockaddr *)&sun, sizeof(sun)) == 0) {
  684. - log_debug("control_check: socket in use");
  685. + log_debug("control socket: socket is in use");
  686. close(fd);
  687. return (-1);
  688. }
  689. @@ -70,7 +70,7 @@ control_init(char *path)
  690. mode_t old_umask;
  691. if ((fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0)) == -1) {
  692. - log_warn("control_init: socket");
  693. + log_warn("control socket: can't create UDP socket");
  694. return (-1);
  695. }
  696. @@ -78,18 +78,18 @@ control_init(char *path)
  697. sa.sun_family = AF_UNIX;
  698. if (strlcpy(sa.sun_path, path, sizeof(sa.sun_path)) >=
  699. sizeof(sa.sun_path))
  700. - errx(1, "ctl socket name too long");
  701. + errx(1, "control socket: name is too long");
  702. if (unlink(path) == -1)
  703. if (errno != ENOENT) {
  704. - log_warn("control_init: unlink %s", path);
  705. + log_warn("control socket: can't unlink %s", path);
  706. close(fd);
  707. return (-1);
  708. }
  709. old_umask = umask(S_IXUSR|S_IXGRP|S_IWOTH|S_IROTH|S_IXOTH);
  710. if (bind(fd, (struct sockaddr *)&sa, sizeof(sa)) == -1) {
  711. - log_warn("control_init: bind: %s", path);
  712. + log_warn("control socket: can't bind %s", path);
  713. close(fd);
  714. umask(old_umask);
  715. return (-1);
  716. @@ -97,7 +97,7 @@ control_init(char *path)
  717. umask(old_umask);
  718. if (chmod(path, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) == -1) {
  719. - log_warn("control_init: chmod");
  720. + log_warn("control socket: can't set owner permission bits for %s", path);
  721. close(fd);
  722. (void)unlink(path);
  723. return (-1);
  724. @@ -112,7 +112,7 @@ int
  725. control_listen(int fd)
  726. {
  727. if (fd != -1 && listen(fd, CONTROL_BACKLOG) == -1) {
  728. - log_warn("control_listen: listen");
  729. + log_warn("control socket: can't initialize listening interface");
  730. return (-1);
  731. }
  732. @@ -137,14 +137,14 @@ control_accept(int listenfd)
  733. if ((connfd = accept(listenfd,
  734. (struct sockaddr *)&sa, &len)) == -1) {
  735. if (errno != EWOULDBLOCK && errno != EINTR)
  736. - log_warn("control_accept: accept");
  737. + log_warn("control socket: unable to accept connections");
  738. return (0);
  739. }
  740. session_socket_nonblockmode(connfd);
  741. if ((ctl_conn = calloc(1, sizeof(struct ctl_conn))) == NULL) {
  742. - log_warn("control_accept");
  743. + log_warn("control socket: can't allocate memory for NTP server");
  744. close(connfd);
  745. return (0);
  746. }
  747. @@ -175,7 +175,7 @@ control_close(int fd)
  748. struct ctl_conn *c;
  749. if ((c = control_connbyfd(fd)) == NULL) {
  750. - log_warn("control_close: fd %d: not found", fd);
  751. + log_warn("control socket: file descriptor %d not found while closing", fd);
  752. return (0);
  753. }
  754. @@ -202,7 +202,7 @@ control_dispatch_msg(struct pollfd *pfd,
  755. ssize_t n;
  756. if ((c = control_connbyfd(pfd->fd)) == NULL) {
  757. - log_warn("control_dispatch_msg: fd %d: not found", pfd->fd);
  758. + log_warn("control socket: file descriptor %d not found while preparing NTP server subprocess", pfd->fd);
  759. return (0);
  760. }
  761. @@ -298,12 +298,12 @@ session_socket_nonblockmode(int fd)
  762. int flags;
  763. if ((flags = fcntl(fd, F_GETFL)) == -1)
  764. - fatal("fcntl F_GETFL");
  765. + fatal("control socket: unable to get file descriptor %d status flags", fd);
  766. flags |= O_NONBLOCK;
  767. if ((flags = fcntl(fd, F_SETFL, flags)) == -1)
  768. - fatal("fcntl F_SETFL");
  769. + fatal("control socket: unable to set file descriptor %d status flags", fd);
  770. }
  771. void
  772. @@ -349,7 +349,7 @@ build_show_peer(struct ctl_show_peer *cp
  773. if (p->addr) {
  774. a = log_sockaddr((struct sockaddr *)&p->addr->ss);
  775. if (p->addr->notauth)
  776. - auth = " (non-dnssec lookup)";
  777. + auth = " (non-DNSSEC lookup)";
  778. }
  779. if (p->addr_head.pool)
  780. pool = "from pool ";
  781. --- a/src/ntp.c 2020-08-01 00:19:21.849059080 +0300
  782. +++ b/src/ntp.c 2020-07-31 23:34:32.462389577 +0300
  783. @@ -93,38 +93,38 @@ ntp_main(struct ntpd_conf *nconf, struct
  784. if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, PF_UNSPEC,
  785. pipe_dns) == -1)
  786. - fatal("socketpair");
  787. + fatal("main process: can't set socket pair for DNS");
  788. start_child(NTPDNS_PROC_NAME, pipe_dns[1], argc, argv);
  789. log_init(nconf->debug ? LOG_TO_STDERR : LOG_TO_SYSLOG, nconf->verbose,
  790. LOG_DAEMON);
  791. if (!nconf->debug && setsid() == -1)
  792. - fatal("setsid");
  793. - log_procinit("ntp");
  794. + fatal("main process: can't create a new session");
  795. + log_procinit("NTP");
  796. if ((se = getservbyname("ntp", "udp")) == NULL)
  797. - fatal("getservbyname");
  798. + fatal("main process: can't find default system information for NTP protocol (getservbyname)");
  799. /* Start control socket. */
  800. if ((fd_ctl = control_init(CTLSOCKET)) == -1)
  801. - fatalx("control socket init failed");
  802. + fatalx("control socket: unable to initialize");
  803. if (control_listen(fd_ctl) == -1)
  804. - fatalx("control socket listen failed");
  805. + fatalx("control socket: unable to listen");
  806. if ((nullfd = open("/dev/null", O_RDWR, 0)) == -1)
  807. - fatal(NULL);
  808. + fatal("control socket: can't read /dev/null");
  809. if (stat(pw->pw_dir, &stb) == -1) {
  810. - fatal("privsep dir %s could not be opened", pw->pw_dir);
  811. + fatal("main process: can't open working directory %s", pw->pw_dir);
  812. }
  813. if (stb.st_uid != 0 || (stb.st_mode & (S_IWGRP|S_IWOTH)) != 0) {
  814. - fatalx("bad privsep dir %s permissions: %o",
  815. + fatalx("main process: working directory %s has bad permissions (%o)",
  816. pw->pw_dir, stb.st_mode);
  817. }
  818. if (chroot(pw->pw_dir) == -1)
  819. - fatal("chroot");
  820. + fatal("main process: can't set isolated working directory");
  821. if (chdir("/") == -1)
  822. - fatal("chdir(\"/\")");
  823. + fatal("main process: can't change subprocess working directory");
  824. if (!nconf->debug) {
  825. dup2(nullfd, STDIN_FILENO);
  826. @@ -133,21 +133,22 @@ ntp_main(struct ntpd_conf *nconf, struct
  827. }
  828. close(nullfd);
  829. - setproctitle("ntp engine");
  830. + setproctitle("NTP engine");
  831. conf = nconf;
  832. setup_listeners(se, conf, &listener_cnt);
  833. + log_debug("main process: setting up listeners");
  834. if (setgroups(1, &pw->pw_gid) ||
  835. setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
  836. setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
  837. - fatal("can't drop privileges");
  838. + fatal("main process: can't drop privileges");
  839. endservent();
  840. /* The ntp process will want to open NTP client sockets -> "inet" */
  841. if (pledge("stdio inet", NULL) == -1)
  842. - err(1, "pledge");
  843. + err(1, "main process: can't restrict NTP process privileges");
  844. signal(SIGTERM, ntp_sighdlr);
  845. signal(SIGINT, ntp_sighdlr);
  846. @@ -156,10 +157,10 @@ ntp_main(struct ntpd_conf *nconf, struct
  847. signal(SIGCHLD, SIG_DFL);
  848. if ((ibuf_main = malloc(sizeof(struct imsgbuf))) == NULL)
  849. - fatal(NULL);
  850. + fatal("main process: can't allocate memory for main data buffer");
  851. imsg_init(ibuf_main, PARENT_SOCK_FILENO);
  852. if ((ibuf_dns = malloc(sizeof(struct imsgbuf))) == NULL)
  853. - fatal(NULL);
  854. + fatal("main process: can't allocate memory for DNS data buffer");
  855. imsg_init(ibuf_dns, pipe_dns[0]);
  856. constraint_cnt = 0;
  857. @@ -192,7 +193,7 @@ ntp_main(struct ntpd_conf *nconf, struct
  858. TAILQ_INIT(&ctl_conns);
  859. sensor_init();
  860. - log_info("ntp engine ready");
  861. + log_info("NTP engine ready");
  862. ctl_cnt = 0;
  863. peer_cnt = 0;
  864. @@ -204,7 +205,7 @@ ntp_main(struct ntpd_conf *nconf, struct
  865. if ((newp = reallocarray(idx2peer, peer_cnt,
  866. sizeof(*idx2peer))) == NULL) {
  867. /* panic for now */
  868. - log_warn("could not resize idx2peer from %u -> "
  869. + log_warn("main process: could not resize server pool from %u -> "
  870. "%u entries", idx2peer_elms, peer_cnt);
  871. fatalx("exiting");
  872. }
  873. @@ -218,7 +219,7 @@ ntp_main(struct ntpd_conf *nconf, struct
  874. if ((newp = reallocarray(pfd, new_cnt,
  875. sizeof(*pfd))) == NULL) {
  876. /* panic for now */
  877. - log_warn("could not resize pfd from %u -> "
  878. + log_warn("main process: could not resize process file descriptor pool from %u -> "
  879. "%u entries", pfd_elms, new_cnt);
  880. fatalx("exiting");
  881. }
  882. @@ -258,12 +259,12 @@ ntp_main(struct ntpd_conf *nconf, struct
  883. }
  884. if (p->deadline > 0 && p->deadline <= getmonotime()) {
  885. timeout = 300;
  886. - log_debug("no reply from %s received in time, "
  887. - "next query %ds", log_sockaddr(
  888. + log_debug("NTP client: NTP peer %s - no reply received in time, "
  889. + "next query in %ds", log_sockaddr(
  890. (struct sockaddr *)&p->addr->ss), timeout);
  891. if (p->trustlevel >= TRUSTLEVEL_BADPEER &&
  892. (p->trustlevel /= 2) < TRUSTLEVEL_BADPEER)
  893. - log_info("peer %s now invalid",
  894. + log_info("NTP client: NTP peer %s is invalid now",
  895. log_sockaddr(
  896. (struct sockaddr *)&p->addr->ss));
  897. if (client_nextaddr(p) == 1) {
  898. @@ -273,8 +274,8 @@ ntp_main(struct ntpd_conf *nconf, struct
  899. set_next(p, timeout);
  900. }
  901. if (p->senderrors > MAX_SEND_ERRORS) {
  902. - log_debug("failed to send query to %s, "
  903. - "next query %ds", log_sockaddr(
  904. + log_debug("NTP client: NTP peer %s - failed to send query, "
  905. + "next query in %ds", log_sockaddr(
  906. (struct sockaddr *)&p->addr->ss),
  907. INTERVAL_QUERY_PATHETIC);
  908. p->senderrors = 0;
  909. @@ -323,7 +324,7 @@ ntp_main(struct ntpd_conf *nconf, struct
  910. if (conf->settime &&
  911. ((trial_cnt > 0 && sent_cnt == 0) ||
  912. (peer_cnt == 0 && sensors_cnt == 0)))
  913. - priv_settime(0, "no valid peers configured");
  914. + priv_settime(0, "NTP client: no valid peers configured");
  915. TAILQ_FOREACH(cstr, &conf->constraints, entry) {
  916. if (constraint_query(cstr) == -1)
  917. @@ -351,21 +352,21 @@ ntp_main(struct ntpd_conf *nconf, struct
  918. if ((nfds = poll(pfd, i, timeout ? timeout * 1000 : 1)) == -1)
  919. if (errno != EINTR) {
  920. - log_warn("poll error");
  921. + log_warn("file descriptor: poll error");
  922. ntp_quit = 1;
  923. }
  924. if (nfds > 0 && (pfd[PFD_PIPE_MAIN].revents & POLLOUT))
  925. if (msgbuf_write(&ibuf_main->w) <= 0 &&
  926. errno != EAGAIN) {
  927. - log_warn("pipe write error (to parent)");
  928. + log_warn("file descriptor: pipe write error (to parent)");
  929. ntp_quit = 1;
  930. }
  931. if (nfds > 0 && pfd[PFD_PIPE_MAIN].revents & (POLLIN|POLLERR)) {
  932. nfds--;
  933. if (ntp_dispatch_imsg() == -1) {
  934. - log_debug("pipe read error (from main)");
  935. + log_warn("file descriptor: pipe write error (from main)");
  936. ntp_quit = 1;
  937. }
  938. }
  939. @@ -373,14 +374,14 @@ ntp_main(struct ntpd_conf *nconf, struct
  940. if (nfds > 0 && (pfd[PFD_PIPE_DNS].revents & POLLOUT))
  941. if (msgbuf_write(&ibuf_dns->w) <= 0 &&
  942. errno != EAGAIN) {
  943. - log_warn("pipe write error (to dns engine)");
  944. + log_warn("file descriptor: pipe write error (to DNS engine)");
  945. ntp_quit = 1;
  946. }
  947. if (nfds > 0 && pfd[PFD_PIPE_DNS].revents & (POLLIN|POLLERR)) {
  948. nfds--;
  949. if (ntp_dispatch_imsg_dns() == -1) {
  950. - log_warn("pipe read error (from dns engine)");
  951. + log_warn("file descriptor: pipe write error (from DNS engine)");
  952. ntp_quit = 1;
  953. }
  954. }
  955. @@ -394,7 +395,7 @@ ntp_main(struct ntpd_conf *nconf, struct
  956. if (pfd[j].revents & (POLLIN|POLLERR)) {
  957. nfds--;
  958. if (server_dispatch(pfd[j].fd, conf) == -1) {
  959. - log_warn("pipe write error (conf)");
  960. + log_warn("file descriptor: pipe write error (in configuration)");
  961. ntp_quit = 1;
  962. }
  963. }
  964. @@ -404,7 +405,7 @@ ntp_main(struct ntpd_conf *nconf, struct
  965. nfds--;
  966. if (client_dispatch(idx2peer[j - idx_peers],
  967. conf->settime, conf->automatic) == -1) {
  968. - log_warn("pipe write error (settime)");
  969. + log_warn("file descriptor: pipe write error (in settime)");
  970. ntp_quit = 1;
  971. }
  972. }
  973. @@ -429,7 +430,7 @@ ntp_main(struct ntpd_conf *nconf, struct
  974. msgbuf_clear(&ibuf_dns->w);
  975. free(ibuf_dns);
  976. - log_info("ntp engine exiting");
  977. + log_info("NTP engine exiting");
  978. exit(0);
  979. }
  980. @@ -453,12 +454,12 @@ ntp_dispatch_imsg(void)
  981. case IMSG_ADJTIME:
  982. memcpy(&n, imsg.data, sizeof(n));
  983. if (n == 1 && !conf->status.synced) {
  984. - log_info("clock is now synced");
  985. + log_info("main process: clock is synced now");
  986. conf->status.synced = 1;
  987. priv_dns(IMSG_SYNCED, NULL, 0);
  988. constraint_reset();
  989. } else if (n == 0 && conf->status.synced) {
  990. - log_info("clock is now unsynced");
  991. + log_info("main process: clock is unsynced now");
  992. conf->status.synced = 0;
  993. priv_dns(IMSG_UNSYNCED, NULL, 0);
  994. }
  995. @@ -529,11 +530,11 @@ ntp_dispatch_imsg_dns(void)
  996. if (peer->id == imsg.hdr.peerid)
  997. break;
  998. if (peer == NULL) {
  999. - log_warnx("IMSG_HOST_DNS with invalid peerID");
  1000. + log_warnx("NTP client: invalid NTP peer ID retrieved in DNS dispatch initialization");
  1001. break;
  1002. }
  1003. if (peer->addr != NULL) {
  1004. - log_warnx("IMSG_HOST_DNS but addr != NULL!");
  1005. + log_warnx("NTP client: invalid NTP peer ID retrieved in DNS dispatch initialization");
  1006. break;
  1007. }
  1008. @@ -556,10 +557,10 @@ ntp_dispatch_imsg_dns(void)
  1009. dlen = imsg.hdr.len - IMSG_HEADER_SIZE;
  1010. if (dlen == 0) { /* no data -> temp error */
  1011. - log_warnx("DNS lookup tempfail");
  1012. + log_warnx("DNS lookup temporary failed");
  1013. peer->state = STATE_DNS_TEMPFAIL;
  1014. if (conf->tmpfail++ == TRIES_AUTO_DNSFAIL)
  1015. - priv_settime(0, "of dns failures");
  1016. + priv_settime(0, "of DNS failures");
  1017. break;
  1018. }
  1019. @@ -571,7 +572,7 @@ ntp_dispatch_imsg_dns(void)
  1020. sizeof(int)) {
  1021. if ((h = calloc(1, sizeof(struct ntp_addr))) ==
  1022. NULL)
  1023. - fatal(NULL);
  1024. + fatal("NTP client: can't allocate memory for NTP peer address");
  1025. memcpy(&h->ss, p, sizeof(h->ss));
  1026. p += sizeof(h->ss);
  1027. dlen -= sizeof(h->ss);
  1028. @@ -588,7 +589,7 @@ ntp_dispatch_imsg_dns(void)
  1029. free(h);
  1030. continue;
  1031. }
  1032. - log_debug("Adding address %s to %s",
  1033. + log_debug("NTP client: adding address %s to %s",
  1034. log_sockaddr((struct sockaddr *)
  1035. &h->ss), peer->addr_head.name);
  1036. npeer = new_peer();
  1037. @@ -614,7 +615,7 @@ ntp_dispatch_imsg_dns(void)
  1038. }
  1039. }
  1040. if (dlen != 0)
  1041. - fatalx("IMSG_HOST_DNS: dlen != 0");
  1042. + fatalx("NTP client: didn't expect data for stored NTP peer network address in DNS dispatch initialization");
  1043. if (peer->addr_head.pool)
  1044. peer_remove(peer);
  1045. else
  1046. @@ -627,10 +628,10 @@ ntp_dispatch_imsg_dns(void)
  1047. case IMSG_PROBE_ROOT:
  1048. dlen = imsg.hdr.len - IMSG_HEADER_SIZE;
  1049. if (dlen != sizeof(int))
  1050. - fatalx("IMSG_PROBE_ROOT");
  1051. + fatalx("NTP client: invalid header length in data buffer for DNS probe");
  1052. memcpy(&n, imsg.data, sizeof(int));
  1053. if (n < 0)
  1054. - priv_settime(0, "dns probe failed");
  1055. + priv_settime(0, "NTP client: DNS probe failed");
  1056. break;
  1057. default:
  1058. break;
  1059. @@ -738,7 +739,7 @@ priv_adjtime(void)
  1060. return (1);
  1061. if ((offsets = calloc(offset_cnt, sizeof(struct ntp_offset *))) == NULL)
  1062. - fatal("calloc priv_adjtime");
  1063. + fatal("main process: can't allocate memory for time adjustment");
  1064. TAILQ_FOREACH(p, &conf->ntp_peers, entry) {
  1065. if (p->trustlevel < TRUSTLEVEL_BADPEER)
  1066. @@ -815,7 +816,7 @@ void
  1067. priv_settime(double offset, char *msg)
  1068. {
  1069. if (offset == 0)
  1070. - log_info("cancel settime because %s", msg);
  1071. + log_info("NTP client: setting time was cancelled because %s", msg);
  1072. imsg_compose(ibuf_main, IMSG_SETTIME, 0, 0, -1,
  1073. &offset, sizeof(offset));
  1074. conf->settime = 0;
  1075. --- a/src/ntpd.c 2020-08-01 00:19:23.455725749 +0300
  1076. +++ b/src/ntpd.c 2020-08-03 23:31:10.898621932 +0300
  1077. @@ -102,7 +102,7 @@ writepid(struct ntpd_conf *lconf)
  1078. if (lconf->pid_file != NULL) {
  1079. FILE *f = fopen(lconf->pid_file, "w");
  1080. if (f == NULL)
  1081. - fatal("couldn't open pid file");
  1082. + fatal("main process: couldn't open pid file");
  1083. fprintf(f, "%ld\n", (long) getpid());
  1084. fclose(f);
  1085. }
  1086. @@ -131,7 +131,7 @@ auto_preconditions(const struct ntpd_con
  1087. int mib[2] = { CTL_KERN, KERN_SECURELVL };
  1088. size_t sz = sizeof(int);
  1089. if (sysctl(mib, 2, &securelevel, &sz, NULL, 0) == -1)
  1090. - err(1, "sysctl");
  1091. + err(1, "error while processing kernel security level");
  1092. #endif
  1093. constraints = !TAILQ_EMPTY(&cnf->constraints);
  1094. return !cnf->settime && (constraints || cnf->trusted_peers ||
  1095. @@ -244,15 +244,15 @@ main(int argc, char *argv[])
  1096. exit(1);
  1097. if (lconf.noaction) {
  1098. - fprintf(stderr, "configuration OK\n");
  1099. + fprintf(stderr, "main process: configuration OK\n");
  1100. exit(0);
  1101. }
  1102. if (geteuid())
  1103. - errx(1, "need root privileges");
  1104. + errx(1, "main process: need root privileges");
  1105. if ((pw = getpwnam(NTPD_USER)) == NULL)
  1106. - errx(1, "unknown user %s", NTPD_USER);
  1107. + errx(1, "main process: unknown user %s", NTPD_USER);
  1108. lconf.automatic = auto_preconditions(&lconf);
  1109. if (lconf.automatic)
  1110. @@ -261,7 +261,7 @@ main(int argc, char *argv[])
  1111. if (pname != NULL) {
  1112. /* Remove our proc arguments, so child doesn't need to. */
  1113. if (sanitize_argv(&argc0, &argv0) == -1)
  1114. - fatalx("sanitize_argv");
  1115. + fatalx("main process: can't sanitize environment for subprocesses");
  1116. if (strcmp(NTP_PROC_NAME, pname) == 0)
  1117. ntp_main(&lconf, pw, argc0, argv0);
  1118. @@ -271,17 +271,16 @@ main(int argc, char *argv[])
  1119. priv_constraint_child(pw->pw_dir, pw->pw_uid,
  1120. pw->pw_gid);
  1121. else
  1122. - fatalx("%s: invalid process name '%s'", __func__,
  1123. - pname);
  1124. + fatalx("main process: invalid process name '%s' (%s)", pname, __func__);
  1125. - fatalx("%s: process '%s' failed", __func__, pname);
  1126. + fatalx("main process: process '%s' failed (%s)", pname, __func__);
  1127. } else {
  1128. if ((control_check(CTLSOCKET)) == -1)
  1129. - fatalx("ntpd already running");
  1130. + fatalx("OpenNTPD is already running");
  1131. }
  1132. if (setpriority(PRIO_PROCESS, 0, -20) == -1)
  1133. - warn("can't set priority");
  1134. + warn("main process: can't set priority");
  1135. reset_adjtime();
  1136. logdest = lconf.debug ? LOG_TO_STDERR : LOG_TO_SYSLOG;
  1137. @@ -289,7 +288,7 @@ main(int argc, char *argv[])
  1138. log_init(logdest, lconf.verbose, LOG_DAEMON);
  1139. if (!lconf.debug) {
  1140. if (daemon(1, 0))
  1141. - fatal("daemon");
  1142. + fatal("main process: can't daemonize process");
  1143. writepid(&lconf);
  1144. }
  1145. } else {
  1146. @@ -299,10 +298,10 @@ main(int argc, char *argv[])
  1147. if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, PF_UNSPEC,
  1148. pipe_chld) == -1)
  1149. - fatal("socketpair");
  1150. + fatal("main process: can't set socket pair for child processes");
  1151. if (chdir("/") == -1)
  1152. - fatal("chdir(\"/\")");
  1153. + fatal("main process: can't change working directory");
  1154. signal(SIGCHLD, sighdlr);
  1155. @@ -319,7 +318,7 @@ main(int argc, char *argv[])
  1156. constraint_purge();
  1157. if ((ibuf = malloc(sizeof(struct imsgbuf))) == NULL)
  1158. - fatal(NULL);
  1159. + fatal("main process: can't allocate memory for data buffer");
  1160. imsg_init(ibuf, pipe_chld[0]);
  1161. constraint_cnt = 0;
  1162. @@ -329,11 +328,11 @@ main(int argc, char *argv[])
  1163. * then privdrop into chroot before speaking to the outside world.
  1164. */
  1165. if (unveil(tls_default_ca_cert_file(), "r") == -1)
  1166. - err(1, "unveil");
  1167. + err(1, "main process: can't unveil certificate file for reading");
  1168. if (unveil("/usr/sbin/ntpd", "x") == -1)
  1169. - err(1, "unveil");
  1170. + err(1, "main process: can't unveil ntpd executable for execute operations");
  1171. if (pledge("stdio rpath inet settime proc exec id", NULL) == -1)
  1172. - err(1, "pledge");
  1173. + err(1, "main process: can't restrict privileges for constraints");
  1174. while (quit == 0) {
  1175. new_cnt = PFD_MAX + constraint_cnt;
  1176. @@ -341,7 +340,7 @@ main(int argc, char *argv[])
  1177. if ((newp = reallocarray(pfd, new_cnt,
  1178. sizeof(*pfd))) == NULL) {
  1179. /* panic for now */
  1180. - log_warn("could not resize pfd from %u -> "
  1181. + log_warn("main process: could not resize pfd from %u -> "
  1182. "%u entries", pfd_elms, new_cnt);
  1183. fatalx("exiting");
  1184. }
  1185. @@ -364,7 +363,7 @@ main(int argc, char *argv[])
  1186. if ((nfds = poll(pfd, i, timeout)) == -1)
  1187. if (errno != EINTR) {
  1188. - log_warn("poll error");
  1189. + log_warn("file descriptor: poll error");
  1190. quit = 1;
  1191. }
  1192. @@ -373,18 +372,18 @@ main(int argc, char *argv[])
  1193. lconf.settime = 0;
  1194. timeout = INFTIM;
  1195. log_init(logdest, lconf.verbose, LOG_DAEMON);
  1196. - log_warnx("no reply received in time, skipping initial "
  1197. - "time setting");
  1198. + log_warnx("main process: no reply received in time, skipping initial "
  1199. + "time setting for constraint");
  1200. if (!lconf.debug) {
  1201. if (daemon(1, 0))
  1202. - fatal("daemon");
  1203. + fatal("main process: can't daemonize process");
  1204. writepid(&lconf);
  1205. }
  1206. }
  1207. if (nfds > 0 && (pfd[PFD_PIPE].revents & POLLOUT))
  1208. if (msgbuf_write(&ibuf->w) <= 0 && errno != EAGAIN) {
  1209. - log_warn("pipe write error (to child)");
  1210. + log_warn("file descriptor: pipe write error (to child)");
  1211. quit = 1;
  1212. }
  1213. @@ -412,7 +411,7 @@ main(int argc, char *argv[])
  1214. do {
  1215. if ((pid = wait(NULL)) == -1 &&
  1216. errno != EINTR && errno != ECHILD)
  1217. - fatal("wait");
  1218. + fatal("main process: can't get child process ID");
  1219. } while (pid != -1 || (pid == -1 && errno == EINTR));
  1220. msgbuf_clear(&ibuf->w);
  1221. @@ -458,7 +457,7 @@ dispatch_imsg(struct ntpd_conf *lconf, i
  1222. switch (imsg.hdr.type) {
  1223. case IMSG_ADJTIME:
  1224. if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(d))
  1225. - fatalx("invalid IMSG_ADJTIME received");
  1226. + fatalx("main process: invalid stored data for time adjustment");
  1227. memcpy(&d, imsg.data, sizeof(d));
  1228. n = ntpd_adjtime(d);
  1229. imsg_compose(ibuf, IMSG_ADJTIME, 0, 0, -1,
  1230. @@ -466,13 +465,13 @@ dispatch_imsg(struct ntpd_conf *lconf, i
  1231. break;
  1232. case IMSG_ADJFREQ:
  1233. if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(d))
  1234. - fatalx("invalid IMSG_ADJFREQ received");
  1235. + fatalx("main process: invalid stored data for frequency adjustment");
  1236. memcpy(&d, imsg.data, sizeof(d));
  1237. ntpd_adjfreq(d, 1);
  1238. break;
  1239. case IMSG_SETTIME:
  1240. if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(d))
  1241. - fatalx("invalid IMSG_SETTIME received");
  1242. + fatalx("main process: invalid stored data for setting time");
  1243. if (!lconf->settime)
  1244. break;
  1245. log_init(lconf->debug ? LOG_TO_STDERR : LOG_TO_SYSLOG,
  1246. @@ -482,7 +481,7 @@ dispatch_imsg(struct ntpd_conf *lconf, i
  1247. /* daemonize now */
  1248. if (!lconf->debug) {
  1249. if (daemon(1, 0))
  1250. - fatal("daemon");
  1251. + fatal("main process: can't daemonize process");
  1252. writepid(lconf);
  1253. }
  1254. lconf->settime = 0;
  1255. @@ -511,7 +510,7 @@ reset_adjtime(void)
  1256. timerclear(&tv);
  1257. if (adjtime(&tv, NULL) == -1)
  1258. - log_warn("reset adjtime failed");
  1259. + log_warn("main process: time adjustment reset failed");
  1260. }
  1261. int
  1262. @@ -523,9 +522,9 @@ ntpd_adjtime(double d)
  1263. d += getoffset();
  1264. if (d >= threshold || d <= -1 * threshold)
  1265. - log_info("adjusting local clock by %fs", d);
  1266. + log_info("main process: adjusting local clock by %fs", d);
  1267. else
  1268. - log_debug("adjusting local clock by %fs", d);
  1269. + log_debug("main process: adjusting local clock by %fs", d);
  1270. #ifdef HAVE_ADJTIMEX
  1271. int rc;
  1272. @@ -541,9 +540,9 @@ ntpd_adjtime(double d)
  1273. if (rc == TIME_ERROR) {
  1274. if ((tx.status & ~STA_UNSYNC))
  1275. - log_warn("adjtimex returned TIME_ERROR");
  1276. + log_warn("main process: time adjustment failed due to time error");
  1277. } else if (rc < 0) {
  1278. - log_warn("adjtimex failed");
  1279. + log_warn("main process: time adjustment failed");
  1280. } else if (!firstadj && tx.offset == offset) {
  1281. synced = 1;
  1282. }
  1283. @@ -551,7 +550,7 @@ ntpd_adjtime(double d)
  1284. struct timeval tv, olddelta;
  1285. d_to_tv(d, &tv);
  1286. if (adjtime(&tv, &olddelta) == -1)
  1287. - log_warn("adjtime failed");
  1288. + log_warn("main process: time adjustment failed");
  1289. else if (!firstadj && olddelta.tv_sec == 0 && olddelta.tv_usec == 0)
  1290. synced = 1;
  1291. #endif
  1292. @@ -568,7 +567,7 @@ ntpd_adjfreq(double relfreq, int wrlog)
  1293. int r;
  1294. if (adjfreq(NULL, &curfreq) == -1) {
  1295. - log_warn("adjfreq failed");
  1296. + log_warn("main process: frequency adjustment failed");
  1297. return;
  1298. }
  1299. @@ -582,17 +581,17 @@ ntpd_adjfreq(double relfreq, int wrlog)
  1300. if (wrlog) {
  1301. if (ppmfreq >= LOG_NEGLIGIBLE_ADJFREQ ||
  1302. ppmfreq <= -LOG_NEGLIGIBLE_ADJFREQ)
  1303. - log_info("adjusting clock frequency by %f to %fppm%s",
  1304. + log_info("main process: adjusting clock frequency by %f to %f ppm%s",
  1305. ppmfreq, curfreq / 1e3 / (1LL << 32),
  1306. r ? "" : " (no drift file)");
  1307. else
  1308. - log_debug("adjusting clock frequency by %f to %fppm%s",
  1309. + log_debug("main process: adjusting clock frequency by %f to %f ppm%s",
  1310. ppmfreq, curfreq / 1e3 / (1LL << 32),
  1311. r ? "" : " (no drift file)");
  1312. }
  1313. if (adjfreq(&curfreq, NULL) == -1)
  1314. - log_warn("adjfreq failed");
  1315. + log_warn("main process: frequency adjustment failed");
  1316. }
  1317. void
  1318. @@ -606,7 +605,7 @@ ntpd_settime(double d)
  1319. return;
  1320. if (gettimeofday(&curtime, NULL) == -1) {
  1321. - log_warn("gettimeofday");
  1322. + log_warn("main process: can't get current time");
  1323. return;
  1324. }
  1325. d_to_tv(d, &tv);
  1326. @@ -615,13 +614,13 @@ ntpd_settime(double d)
  1327. curtime.tv_usec %= 1000000;
  1328. if (settimeofday(&curtime, NULL) == -1) {
  1329. - log_warn("settimeofday");
  1330. + log_warn("main process: can't set time");
  1331. return;
  1332. }
  1333. tval = curtime.tv_sec;
  1334. strftime(buf, sizeof(buf), "%a %b %e %H:%M:%S %Z %Y",
  1335. localtime(&tval));
  1336. - log_info("set local clock to %s (offset %fs)", buf, d);
  1337. + log_info("main process: set local clock to %s (offset %fs)", buf, d);
  1338. }
  1339. static FILE *freqfp;
  1340. @@ -635,10 +634,10 @@ readfreq(void)
  1341. fd = open(DRIFTFILE, O_RDWR);
  1342. if (fd == -1) {
  1343. - log_warnx("creating new %s", DRIFTFILE);
  1344. + log_warnx("main process: creating new drift file %s", DRIFTFILE);
  1345. current = 0;
  1346. if (adjfreq(&current, NULL) == -1)
  1347. - log_warn("adjfreq reset failed");
  1348. + log_warn("main process: frequency reset failed");
  1349. freqfp = fopen(DRIFTFILE, "w");
  1350. return;
  1351. }
  1352. @@ -647,13 +646,13 @@ readfreq(void)
  1353. /* if we're adjusting frequency already, don't override */
  1354. if (adjfreq(NULL, &current) == -1)
  1355. - log_warn("adjfreq failed");
  1356. + log_warn("main process: frequency adjustment failed");
  1357. else if (current == 0 && freqfp) {
  1358. if (fscanf(freqfp, "%lf", &d) == 1) {
  1359. d /= 1e6; /* scale from ppm */
  1360. ntpd_adjfreq(d, 0);
  1361. } else
  1362. - log_warnx("%s is empty", DRIFTFILE);
  1363. + log_warnx("main process: drift file %s is empty", DRIFTFILE);
  1364. }
  1365. }
  1366. @@ -670,7 +669,7 @@ writefreq(double d)
  1367. r = fprintf(freqfp, "%.3f\n", d * 1e6); /* scale to ppm */
  1368. if (r < 0 || fflush(freqfp) != 0) {
  1369. if (warnonce) {
  1370. - log_warnx("can't write %s", DRIFTFILE);
  1371. + log_warnx("main process: can't write drift file %s", DRIFTFILE);
  1372. warnonce = 0;
  1373. }
  1374. clearerr(freqfp);
  1375. @@ -678,7 +677,7 @@ writefreq(double d)
  1376. }
  1377. off = ftello(freqfp);
  1378. if (off == -1 || ftruncate(fileno(freqfp), off) == -1)
  1379. - log_warnx("can't truncate %s", DRIFTFILE);
  1380. + log_warnx("main process: can't truncate drift file %s", DRIFTFILE);
  1381. fsync(fileno(freqfp));
  1382. return 1;
  1383. }
  1384. @@ -704,7 +703,7 @@ ctl_main(int argc, char *argv[])
  1385. case 's':
  1386. showopt = ctl_lookup_option(optarg, ctl_showopt_list);
  1387. if (showopt == NULL) {
  1388. - warnx("Unknown show modifier '%s'", optarg);
  1389. + warnx("control socket: unknown show modifier '%s'", optarg);
  1390. usage();
  1391. }
  1392. break;
  1393. @@ -736,21 +735,21 @@ ctl_main(int argc, char *argv[])
  1394. /* NOTREACHED */
  1395. if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
  1396. - err(1, "ntpctl: socket");
  1397. + err(1, "ntpctl: socket error");
  1398. memset(&sa, 0, sizeof(sa));
  1399. sa.sun_family = AF_UNIX;
  1400. if (strlcpy(sa.sun_path, sockname, sizeof(sa.sun_path)) >=
  1401. sizeof(sa.sun_path))
  1402. - errx(1, "ctl socket name too long");
  1403. + errx(1, "ntpctl: control socket name is too long");
  1404. if (connect(fd, (struct sockaddr *)&sa, sizeof(sa)) == -1)
  1405. - err(1, "connect: %s", sockname);
  1406. + err(1, "ntpctl: failed to connect to socket %s", sockname);
  1407. if (pledge("stdio", NULL) == -1)
  1408. - err(1, "pledge");
  1409. + err(1, "ntpctl: can't restrict privileges");
  1410. if ((ibuf_ctl = malloc(sizeof(struct imsgbuf))) == NULL)
  1411. - err(1, NULL);
  1412. + err(1, "ntpctl: can't allocate memory for data buffer");
  1413. imsg_init(ibuf_ctl, fd);
  1414. switch (action) {
  1415. @@ -771,24 +770,24 @@ ctl_main(int argc, char *argv[])
  1416. 0, 0, -1, NULL, 0);
  1417. break;
  1418. default:
  1419. - errx(1, "invalid action");
  1420. + errx(1, "ntpctl: invalid action");
  1421. break; /* NOTREACHED */
  1422. }
  1423. while (ibuf_ctl->w.queued)
  1424. if (msgbuf_write(&ibuf_ctl->w) <= 0 && errno != EAGAIN)
  1425. - err(1, "ibuf_ctl: msgbuf_write error");
  1426. + err(1, "ntpctl: stored control message buffer data: write error");
  1427. done = 0;
  1428. while (!done) {
  1429. if ((n = imsg_read(ibuf_ctl)) == -1 && errno != EAGAIN)
  1430. - err(1, "ibuf_ctl: imsg_read error");
  1431. + err(1, "ntpctl: stored control message buffer data: read error");
  1432. if (n == 0)
  1433. errx(1, "ntpctl: pipe closed");
  1434. while (!done) {
  1435. if ((n = imsg_get(ibuf_ctl, &imsg)) == -1)
  1436. - err(1, "ibuf_ctl: imsg_get error");
  1437. + err(1, "ntpctl: stored control message buffer data: get error");
  1438. if (n == 0)
  1439. break;
  1440. @@ -853,7 +852,7 @@ ctl_lookup_option(char *cmd, const char
  1441. if (item == NULL)
  1442. item = *list;
  1443. else
  1444. - errx(1, "%s is ambiguous", cmd);
  1445. + errx(1, "ntpctl: optional argument %s is ambiguous", cmd);
  1446. }
  1447. return (item);
  1448. }
  1449. @@ -866,16 +865,17 @@ show_status_msg(struct imsg *imsg)
  1450. struct timeval tv;
  1451. if (imsg->hdr.len != IMSG_HEADER_SIZE + sizeof(struct ctl_show_status))
  1452. - fatalx("invalid IMSG_CTL_SHOW_STATUS received");
  1453. + fatalx("ntpctl: invalid control socket data size for status check");
  1454. cstatus = (struct ctl_show_status *)imsg->data;
  1455. + printf("ntpctl: ");
  1456. if (cstatus->peercnt > 0)
  1457. - printf("%d/%d peers valid, ",
  1458. + printf("%d/%d peers are valid, ",
  1459. cstatus->valid_peers, cstatus->peercnt);
  1460. if (cstatus->sensorcnt > 0)
  1461. - printf("%d/%d sensors valid, ",
  1462. + printf("%d/%d sensors are valid, ",
  1463. cstatus->valid_sensors, cstatus->sensorcnt);
  1464. if (cstatus->constraint_median) {
  1465. @@ -895,9 +895,9 @@ show_status_msg(struct imsg *imsg)
  1466. printf("no peers and no sensors configured\n");
  1467. if (cstatus->synced == 1)
  1468. - printf("clock synced, stratum %u\n", cstatus->stratum);
  1469. + printf("clock is synced, stratum %u\n", cstatus->stratum);
  1470. else {
  1471. - printf("clock unsynced");
  1472. + printf("clock is unsynced");
  1473. clock_offset = cstatus->clock_offset < 0 ?
  1474. -1.0 * cstatus->clock_offset : cstatus->clock_offset;
  1475. if (clock_offset > 5e-7)
  1476. @@ -918,20 +918,20 @@ show_peer_msg(struct imsg *imsg, int cal
  1477. if (imsg->hdr.type == IMSG_CTL_SHOW_PEERS_END) {
  1478. if (imsg->hdr.len != IMSG_HEADER_SIZE + sizeof(cnt))
  1479. - fatalx("invalid IMSG_CTL_SHOW_PEERS_END received");
  1480. + fatalx("ntpctl: invalid control socket data size for a NTP peer end check");
  1481. memcpy(&cnt, imsg->data, sizeof(cnt));
  1482. if (cnt == 0)
  1483. - printf("no peers configured\n");
  1484. + printf("ntpctl: no peers configured\n");
  1485. return;
  1486. }
  1487. if (imsg->hdr.len != IMSG_HEADER_SIZE + sizeof(struct ctl_show_peer))
  1488. - fatalx("invalid IMSG_CTL_SHOW_PEERS received");
  1489. + fatalx("ntpctl: invalid control socket data size for NTP peer check");
  1490. cpeer = (struct ctl_show_peer *)imsg->data;
  1491. if (strlen(cpeer->peer_desc) > MAX_DISPLAY_WIDTH - 1)
  1492. - fatalx("peer_desc is too long");
  1493. + fatalx("ntpctl: NTP peer description is too long");
  1494. if (firsttime) {
  1495. firsttime = 0;
  1496. @@ -968,20 +968,20 @@ show_sensor_msg(struct imsg *imsg, int c
  1497. if (imsg->hdr.type == IMSG_CTL_SHOW_SENSORS_END) {
  1498. if (imsg->hdr.len != IMSG_HEADER_SIZE + sizeof(cnt))
  1499. - fatalx("invalid IMSG_CTL_SHOW_SENSORS_END received");
  1500. + fatalx("ntpctl: invalid control socket data size for sensor end check");
  1501. memcpy(&cnt, imsg->data, sizeof(cnt));
  1502. if (cnt == 0)
  1503. - printf("no sensors configured\n");
  1504. + printf("ntpctl: no sensors configured\n");
  1505. return;
  1506. }
  1507. if (imsg->hdr.len != IMSG_HEADER_SIZE + sizeof(struct ctl_show_sensor))
  1508. - fatalx("invalid IMSG_CTL_SHOW_SENSORS received");
  1509. + fatalx("ntpctl: invalid control socket data size for a sensor end check");
  1510. csensor = (struct ctl_show_sensor *)imsg->data;
  1511. if (strlen(csensor->sensor_desc) > MAX_DISPLAY_WIDTH - 1)
  1512. - fatalx("sensor_desc is too long");
  1513. + fatalx("ntpctl: sensor description is too long");
  1514. if (firsttime) {
  1515. firsttime = 0;
  1516. --- a/src/ntp_dns.c 2020-08-01 00:19:23.449059082 +0300
  1517. +++ b/src/ntp_dns.c 2020-07-31 23:26:26.505722398 +0300
  1518. @@ -66,16 +66,16 @@ ntp_dns(struct ntpd_conf *nconf, struct
  1519. res_init();
  1520. if (setpriority(PRIO_PROCESS, 0, 0) == -1)
  1521. - log_warn("could not set priority");
  1522. + log_warn("DNS process: can't set priority");
  1523. log_init(nconf->debug ? LOG_TO_STDERR : LOG_TO_SYSLOG, nconf->verbose,
  1524. LOG_DAEMON);
  1525. if (!nconf->debug && setsid() == -1)
  1526. - fatal("setsid");
  1527. - log_procinit("dns");
  1528. + fatal("DNS process: can't create a new session");
  1529. + log_procinit("DNS");
  1530. if ((nullfd = open("/dev/null", O_RDWR, 0)) == -1)
  1531. - fatal(NULL);
  1532. + fatal("DNS process: can't read /dev/null");
  1533. if (!nconf->debug) {
  1534. dup2(nullfd, STDIN_FILENO);
  1535. @@ -84,28 +84,28 @@ ntp_dns(struct ntpd_conf *nconf, struct
  1536. }
  1537. close(nullfd);
  1538. - setproctitle("dns engine");
  1539. + setproctitle("DNS engine");
  1540. if (setgroups(1, &pw->pw_gid) ||
  1541. setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
  1542. setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
  1543. - fatal("can't drop privileges");
  1544. + fatal("DNS process: can't drop privileges");
  1545. signal(SIGTERM, sighdlr_dns);
  1546. signal(SIGINT, sighdlr_dns);
  1547. signal(SIGHUP, SIG_IGN);
  1548. if ((ibuf_dns = malloc(sizeof(struct imsgbuf))) == NULL)
  1549. - fatal(NULL);
  1550. + fatal("DNS process: can't allocate memory for data buffer");
  1551. imsg_init(ibuf_dns, PARENT_SOCK_FILENO);
  1552. if (pledge("stdio dns", NULL) == -1)
  1553. - err(1, "pledge");
  1554. + err(1, "DNS process: can't restrict privileges");
  1555. if (non_numeric)
  1556. probe_root();
  1557. else
  1558. - log_debug("all addresses numeric, no dns probe");
  1559. + log_debug("DNS process: all addresses numeric, no DNS probe");
  1560. while (quit_dns == 0) {
  1561. pfd[0].fd = ibuf_dns->fd;
  1562. @@ -115,14 +115,14 @@ ntp_dns(struct ntpd_conf *nconf, struct
  1563. if ((nfds = poll(pfd, 1, INFTIM)) == -1)
  1564. if (errno != EINTR) {
  1565. - log_warn("poll error");
  1566. + log_warn("file descriptor: poll error");
  1567. quit_dns = 1;
  1568. }
  1569. if (nfds > 0 && (pfd[0].revents & POLLOUT))
  1570. if (msgbuf_write(&ibuf_dns->w) <= 0 &&
  1571. errno != EAGAIN) {
  1572. - log_warn("pipe write error (to ntp engine)");
  1573. + log_warn("file descriptor: pipe write error (to NTP engine)");
  1574. quit_dns = 1;
  1575. }
  1576. @@ -168,11 +168,11 @@ dns_dispatch_imsg(struct ntpd_conf *ncon
  1577. str = "IMSG_CONSTRAINT_DNS";
  1578. name = imsg.data;
  1579. if (imsg.hdr.len < 1 + IMSG_HEADER_SIZE)
  1580. - fatalx("invalid %s received", str);
  1581. + fatalx("DNS process: invalid header size received (%s)", str);
  1582. len = imsg.hdr.len - 1 - IMSG_HEADER_SIZE;
  1583. if (name[len] != '\0' ||
  1584. strlen(name) != len)
  1585. - fatalx("invalid %s received", str);
  1586. + fatalx("DNS process: invalid name received (%s)", str);
  1587. if ((cnt = host_dns(name, nconf->status.synced,
  1588. &hn)) == -1)
  1589. break;
  1590. @@ -252,5 +252,5 @@ probe_root(void)
  1591. }
  1592. if (imsg_compose(ibuf_dns, IMSG_PROBE_ROOT, 0, 0, -1, &n,
  1593. sizeof(int)) == -1)
  1594. - fatalx("probe_root");
  1595. + fatalx("DNS process: can't compose data buffer for probe");
  1596. }
  1597. --- a/src/ntp_msg.c 2020-08-01 00:19:21.849059080 +0300
  1598. +++ b/src/ntp_msg.c 2020-07-31 23:27:44.465722482 +0300
  1599. @@ -29,7 +29,7 @@ int
  1600. ntp_getmsg(struct sockaddr *sa, char *p, ssize_t len, struct ntp_msg *msg)
  1601. {
  1602. if (len != NTP_MSGSIZE_NOAUTH && len != NTP_MSGSIZE) {
  1603. - log_debug("malformed packet received from %s",
  1604. + log_debug("NTP message: malformed packet received from %s",
  1605. log_sockaddr(sa));
  1606. return (-1);
  1607. }
  1608. @@ -57,12 +57,12 @@ ntp_sendmsg(int fd, struct sockaddr *sa,
  1609. /* logging is futile */
  1610. return (-1);
  1611. }
  1612. - log_warn("sendto");
  1613. + log_warn("NTP message: can't send data to destination socket");
  1614. return (-1);
  1615. }
  1616. if (n != sizeof(*msg)) {
  1617. - log_warnx("ntp_sendmsg: only %zd of %zu bytes sent", n,
  1618. + log_warnx("NTP message: only %zd of %zu bytes sent", n,
  1619. sizeof(*msg));
  1620. return (-1);
  1621. }
  1622. --- a/src/parse.y 2020-08-01 00:19:23.405725749 +0300
  1623. +++ b/src/parse.y 2020-07-31 23:57:08.642391006 +0300
  1624. @@ -122,7 +122,7 @@ main : LISTEN ON address listen_opts {
  1625. next = h->next;
  1626. la = calloc(1, sizeof(struct listen_addr));
  1627. if (la == NULL)
  1628. - fatal("listen on calloc");
  1629. + fatal("can't allocate memory for listening address");
  1630. la->fd = -1;
  1631. la->rtable = $4.rtable;
  1632. memcpy(&la->sa, &h->ss,
  1633. @@ -348,7 +348,7 @@ urllist : urllist address {
  1634. if (inet_pton(AF_INET, $2->name, &ina) != 1 &&
  1635. inet_pton(AF_INET6, $2->name, &in6a) != 1) {
  1636. - yyerror("url can only be followed by IP "
  1637. + yyerror("URL can only be followed by IP "
  1638. "addresses");
  1639. free($2->name);
  1640. free($2);
  1641. @@ -376,7 +376,7 @@ url : STRING {
  1642. if (($$ = calloc(1, sizeof(struct ntp_addr_wrap))) ==
  1643. NULL)
  1644. - fatal("calloc");
  1645. + fatal("can't allocate memory for URL");
  1646. if (strncmp("https://", $1,
  1647. strlen("https://")) != 0) {
  1648. @@ -388,16 +388,16 @@ url : STRING {
  1649. path = hname + strcspn(hname, "/\\");
  1650. if (*path != '\0') {
  1651. if (($$->path = strdup(path)) == NULL)
  1652. - fatal("strdup");
  1653. + fatal("can't allocate memory for %s", path);
  1654. *path = '\0';
  1655. }
  1656. host(hname, &$$->a);
  1657. if (($$->name = strdup(hname)) == NULL)
  1658. - fatal("strdup");
  1659. + fatal("can't allocate memory for %s", hname);
  1660. }
  1661. if ($$->path == NULL &&
  1662. ($$->path = strdup("/")) == NULL)
  1663. - fatal("strdup");
  1664. + fatal("can't allocate memory space for new URL");
  1665. }
  1666. ;
  1667. @@ -453,7 +453,7 @@ refid : REFID STRING {
  1668. size_t l = strlen($2);
  1669. if (l < 1 || l > 4) {
  1670. - yyerror("refid must be 1 to 4 characters");
  1671. + yyerror("refid length must be from 1 to 4 characters");
  1672. free($2);
  1673. YYERROR;
  1674. }
  1675. @@ -482,7 +482,7 @@ rtable : RTABLE NUMBER {
  1676. #ifdef RT_TABLEID_MAX
  1677. if ($2 < 0 || $2 > RT_TABLEID_MAX) {
  1678. yyerror("rtable must be between 1"
  1679. - " and RT_TABLEID_MAX");
  1680. + " and %d", RT_TABLEID_MAX);
  1681. YYERROR;
  1682. }
  1683. #endif
  1684. @@ -518,7 +518,7 @@ yyerror(const char *fmt, ...)
  1685. file->errors++;
  1686. va_start(ap, fmt);
  1687. if (vasprintf(&msg, fmt, ap) == -1)
  1688. - fatalx("yyerror vasprintf");
  1689. + fatalx("can't create error string");
  1690. va_end(ap);
  1691. log_warnx("%s:%d: %s", file->name, yylval.lineno, msg);
  1692. free(msg);
  1693. @@ -710,7 +710,7 @@ yylex(void)
  1694. }
  1695. yylval.v.string = strdup(buf);
  1696. if (yylval.v.string == NULL)
  1697. - fatal("yylex: strdup");
  1698. + fatal("can't allocate memory for buffered quote string");
  1699. return (STRING);
  1700. }
  1701. @@ -721,7 +721,7 @@ yylex(void)
  1702. do {
  1703. *p++ = c;
  1704. if ((size_t)(p-buf) >= sizeof(buf)) {
  1705. - yyerror("string too long");
  1706. + yyerror("string is too long");
  1707. return (findeol());
  1708. }
  1709. } while ((c = lgetc(0)) != EOF && isdigit(c));
  1710. @@ -760,7 +760,7 @@ nodigits:
  1711. do {
  1712. *p++ = c;
  1713. if ((size_t)(p-buf) >= sizeof(buf)) {
  1714. - yyerror("string too long");
  1715. + yyerror("string is too long");
  1716. return (findeol());
  1717. }
  1718. } while ((c = lgetc(0)) != EOF && (allowed_in_string(c)));
  1719. @@ -768,7 +768,7 @@ nodigits:
  1720. *p = '\0';
  1721. if ((token = lookup(buf)) == STRING)
  1722. if ((yylval.v.string = strdup(buf)) == NULL)
  1723. - fatal("yylex: strdup");
  1724. + fatal("can't allocate memory for buffered string");
  1725. return (token);
  1726. }
  1727. if (c == '\n') {
  1728. @@ -786,16 +786,16 @@ pushfile(const char *name)
  1729. struct file *nfile;
  1730. if ((nfile = calloc(1, sizeof(struct file))) == NULL) {
  1731. - log_warn("%s", __func__);
  1732. + log_warn("can't allocate space for file");
  1733. return (NULL);
  1734. }
  1735. if ((nfile->name = strdup(name)) == NULL) {
  1736. - log_warn("%s", __func__);
  1737. + log_warn("can't allocate memory for file name");
  1738. free(nfile);
  1739. return (NULL);
  1740. }
  1741. if ((nfile->stream = fopen(nfile->name, "r")) == NULL) {
  1742. - log_warn("%s: %s", __func__, nfile->name);
  1743. + log_warn("can't open file %s", nfile->name);
  1744. free(nfile->name);
  1745. free(nfile);
  1746. return (NULL);
  1747. --- a/src/sensors.c 2020-08-01 00:19:21.849059080 +0300
  1748. +++ b/src/sensors.c 2020-07-31 23:58:46.572391110 +0300
  1749. @@ -90,7 +90,7 @@ sensor_probe(int devid, char *dxname, st
  1750. return (0);
  1751. if (errno == ENOENT)
  1752. return (-1);
  1753. - log_warn("sensor_probe sysctl");
  1754. + log_warn("sensor: can't set probe device from kernel data");
  1755. }
  1756. if (sensordev.maxnumt[SENSOR_TIMEDELTA] == 0)
  1757. @@ -101,7 +101,9 @@ sensor_probe(int devid, char *dxname, st
  1758. slen = sizeof(*sensor);
  1759. if (sysctl(mib, 5, sensor, &slen, NULL, 0) == -1) {
  1760. if (errno != ENOENT)
  1761. - log_warn("sensor_probe sysctl");
  1762. + log_warn("sensor %s: can't set probe device from kernel data",
  1763. + sensor->device);
  1764. + );
  1765. return (0);
  1766. }
  1767. @@ -128,7 +130,9 @@ sensor_add(int sensordev, char *dxname)
  1768. return;
  1769. if ((s = calloc(1, sizeof(*s))) == NULL)
  1770. - fatal("sensor_add calloc");
  1771. + fatal("sensor %s: can't allocate memory for the device",
  1772. + s->device
  1773. + );
  1774. s->next = getmonotime();
  1775. s->weight = cs->weight;
  1776. @@ -136,7 +140,8 @@ sensor_add(int sensordev, char *dxname)
  1777. s->stratum = cs->stratum - 1;
  1778. s->trusted = cs->trusted;
  1779. if ((s->device = strdup(dxname)) == NULL)
  1780. - fatal("sensor_add strdup");
  1781. + fatal("sensor %s: can't allocate memory for the device",
  1782. + s->device);
  1783. s->sensordevid = sensordev;
  1784. if (cs->refstr == NULL)
  1785. @@ -148,7 +153,7 @@ sensor_add(int sensordev, char *dxname)
  1786. TAILQ_INSERT_TAIL(&conf->ntp_sensors, s, entry);
  1787. - log_debug("sensor %s added (weight %d, correction %.6f, refstr %.4u, "
  1788. + log_debug("sensor %s: added (weight %d, correction %.6f, refstr %.4u, "
  1789. "stratum %d)", s->device, s->weight, s->correction / 1e6,
  1790. s->refid, s->stratum);
  1791. }
  1792. @@ -244,7 +249,7 @@ sensor_update(struct ntp_sensor *s)
  1793. if ((offsets = calloc(SENSOR_OFFSETS, sizeof(struct ntp_offset *))) ==
  1794. NULL)
  1795. - fatal("calloc sensor_update");
  1796. + fatal("sensor %s: can't allocate memory for data update", s->device);
  1797. for (i = 0; i < SENSOR_OFFSETS; i++)
  1798. offsets[i] = &s->offsets[i];
  1799. @@ -260,6 +265,6 @@ sensor_update(struct ntp_sensor *s)
  1800. }
  1801. free(offsets);
  1802. - log_debug("sensor update %s: offset %f", s->device, s->update.offset);
  1803. + log_debug("sensor %s: update: offset %fs", s->device, s->update.offset);
  1804. priv_adjtime();
  1805. }
  1806. --- a/src/server.c 2020-08-01 00:19:23.439059082 +0300
  1807. +++ b/src/server.c 2020-08-01 00:04:05.369058112 +0300
  1808. @@ -53,7 +53,7 @@ setup_listeners(struct servent *se, stru
  1809. switch (lap->sa.ss_family) {
  1810. case AF_UNSPEC:
  1811. if (getifaddrs(&ifa) == -1)
  1812. - fatal("getifaddrs");
  1813. + fatal("NTP server: can't get network interfaces");
  1814. for (ifap = ifa; ifap != NULL; ifap = ifap->ifa_next) {
  1815. sa = ifap->ifa_addr;
  1816. @@ -87,7 +87,7 @@ setup_listeners(struct servent *se, stru
  1817. if ((la = calloc(1, sizeof(struct listen_addr))) ==
  1818. NULL)
  1819. - fatal("setup_listeners calloc");
  1820. + fatal("NTP server: can't allocate memory for listening address");
  1821. memcpy(&la->sa, sa, SA_LEN(sa));
  1822. #ifdef SO_RTABLE
  1823. @@ -123,36 +123,37 @@ setup_listeners(struct servent *se, stru
  1824. la = nla;
  1825. continue;
  1826. default:
  1827. - fatalx("king bula sez: af borked");
  1828. + fatalx("NTP server: wrong network address family");
  1829. }
  1830. - log_info("listening on %s %s",
  1831. + log_info("NTP server: listening on %s %s (UDP port %d)",
  1832. log_sockaddr((struct sockaddr *)&la->sa),
  1833. - print_rtable(la->rtable));
  1834. + print_rtable(la->rtable),
  1835. + ntohs((((struct sockaddr_in *)&la->sa)->sin_port)));
  1836. if ((la->fd = socket(la->sa.ss_family, SOCK_DGRAM, 0)) == -1)
  1837. - fatal("socket");
  1838. + fatal("NTP server: socket error");
  1839. if (la->sa.ss_family == AF_INET && setsockopt(la->fd,
  1840. IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) == -1)
  1841. - log_warn("setsockopt IPTOS_LOWDELAY");
  1842. + log_warn("NTP server: can't set IPv4 socket field IP_TOS");
  1843. #ifdef IPV6_V6ONLY
  1844. if (la->sa.ss_family == AF_INET6 && setsockopt(la->fd,
  1845. IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) == -1)
  1846. - log_warn("setsockopt IPV6_V6ONLY");
  1847. + log_warn("NTP server: can't set IPv6 socket field IPV6_V6ONLY");
  1848. #endif
  1849. #ifdef SO_RTABLE
  1850. if (la->rtable != -1 &&
  1851. setsockopt(la->fd, SOL_SOCKET, SO_RTABLE, &la->rtable,
  1852. sizeof(la->rtable)) == -1)
  1853. - fatal("setup_listeners setsockopt SO_RTABLE");
  1854. + log_warn("NTP server: can't set socket field SO_RTABLE");
  1855. #endif
  1856. if (bind(la->fd, (struct sockaddr *)&la->sa,
  1857. SA_LEN((struct sockaddr *)&la->sa)) == -1) {
  1858. - log_warn("bind on %s failed, skipping",
  1859. + log_warn("NTP server %s: bind failed, skipping",
  1860. log_sockaddr((struct sockaddr *)&la->sa));
  1861. close(la->fd);
  1862. nla = TAILQ_NEXT(la, entry);
  1863. @@ -185,11 +186,12 @@ server_dispatch(int fd, struct ntpd_conf
  1864. (struct sockaddr *)&fsa, &fsa_len)) == -1) {
  1865. if (errno == EHOSTUNREACH || errno == EHOSTDOWN ||
  1866. errno == ENETUNREACH || errno == ENETDOWN) {
  1867. - log_warn("recvfrom %s",
  1868. + log_warn("NTP server %s: can't receive socket message: "
  1869. + "network is down or host is unreachable",
  1870. log_sockaddr((struct sockaddr *)&fsa));
  1871. return (0);
  1872. } else
  1873. - fatal("recvfrom");
  1874. + fatal("NTP server: can't receive socket message");
  1875. }
  1876. rectime = gettime_corrected();
  1877. --- a/src/util.c 2020-08-01 00:19:23.449059082 +0300
  1878. +++ b/src/util.c 2020-08-01 01:35:02.868060038 +0300
  1879. @@ -46,7 +46,7 @@ gettime(void)
  1880. struct timeval tv;
  1881. if (gettimeofday(&tv, NULL) == -1)
  1882. - fatal("gettimeofday");
  1883. + fatal("can't get time value");
  1884. return (gettime_from_timeval(&tv));
  1885. }
  1886. @@ -66,7 +66,7 @@ getmonotime(void)
  1887. struct timespec ts;
  1888. if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0)
  1889. - fatal("clock_gettime");
  1890. + fatal("can't get elapsed clock time");
  1891. return (ts.tv_sec);
  1892. }
  1893. @@ -172,7 +172,7 @@ start_child(char *pname, int cfd, int ar
  1894. /* Prepare the child process new argv. */
  1895. nargv = calloc(argc + 3, sizeof(char *));
  1896. if (nargv == NULL)
  1897. - fatal("%s: calloc", __func__);
  1898. + fatal("main process: can't allocate enough memory for child (%s)", __func__);
  1899. /* Copy the program name first. */
  1900. nargc = 0;
  1901. @@ -188,18 +188,18 @@ start_child(char *pname, int cfd, int ar
  1902. switch (pid = fork()) {
  1903. case -1:
  1904. - fatal("%s: fork", __func__);
  1905. + fatal("main process: can't fork (%s)", __func__);
  1906. break;
  1907. case 0:
  1908. /* Prepare the parent socket and execute. */
  1909. if (cfd != PARENT_SOCK_FILENO) {
  1910. if (dup2(cfd, PARENT_SOCK_FILENO) == -1)
  1911. - fatal("dup2");
  1912. + fatal("parent socket: can't duplicate file descriptor %d", cfd);
  1913. } else if (fcntl(cfd, F_SETFD, 0) == -1)
  1914. - fatal("fcntl");
  1915. + fatal("child file descriptor %d: can't reset flags", cfd);
  1916. execvp(argv[0], nargv);
  1917. - fatal("%s: execvp", __func__);
  1918. + fatal("child process: duplication of actions (%s: execvp)", __func__);
  1919. break;
  1920. default:
  1921. --- a/compat/adjfreq_freebsd.c 2020-08-01 00:19:08.772392399 +0300
  1922. +++ b/compat/adjfreq_freebsd.c 2020-08-01 00:14:17.172392093 +0300
  1923. @@ -38,19 +38,19 @@ adjfreq(const int64_t *freq, int64_t *ol
  1924. txc.freq = *freq / 1e3 / (1LL << 16);
  1925. if ((ntp_adjtime(&txc)) == -1)
  1926. - log_warn("ntp_adjtime (2) failed");
  1927. + log_warn("clock: adjustment failed");
  1928. - log_debug("ntp_adjtime adjusted frequency by %fppm",
  1929. + log_debug("clock: frequency adjusted by %fppm",
  1930. ((txc.freq * 1e3) * (1LL<<16) / 1e3 / (1LL << 32)));
  1931. }
  1932. if (oldfreq != NULL) {
  1933. txc.modes = 0;
  1934. if ((ntp_adjtime(&txc)) == -1) {
  1935. - log_warn("ntp_adjtime (1) failed");
  1936. + log_warn("clock: adjustment failed");
  1937. return -1;
  1938. }
  1939. newfreq = (txc.freq * 1e3) * (1LL<<16);
  1940. - log_debug("ntp_adjtime returns frequency of %fppm",
  1941. + log_debug("clock: adjustment returns frequency of %fppm",
  1942. newfreq / 1e3 / (1LL << 32));
  1943. *oldfreq = newfreq;
  1944. }
  1945. @@ -74,6 +74,6 @@ update_time_sync_status(int synced)
  1946. } else
  1947. txc.status = STA_UNSYNC;
  1948. if (ntp_adjtime(&txc) == -1)
  1949. - log_warn("ntp_adjtime (3) failed");
  1950. + log_warn("clock: adjustment failed");
  1951. return;
  1952. }
  1953. --- a/compat/adjfreq_linux.c 2020-08-01 00:19:08.772392399 +0300
  1954. +++ b/compat/adjfreq_linux.c 2020-08-01 00:13:49.995725398 +0300
  1955. @@ -38,19 +38,19 @@ adjfreq(const int64_t *freq, int64_t *ol
  1956. txc.freq = *freq / 1e3 / (1LL << 16);
  1957. if ((adjtimex(&txc)) == -1)
  1958. - log_warn("adjtimex failed");
  1959. + log_warn("clock: adjustment failed");
  1960. - log_debug("adjtimex adjusted frequency by %fppm",
  1961. + log_debug("clock: frequency adjusted by %fppm",
  1962. ((txc.freq * 1e3) * (1LL<<16) / 1e3 / (1LL << 32)));
  1963. }
  1964. if (oldfreq != NULL) {
  1965. txc.modes = 0;
  1966. if ((adjtimex(&txc)) == -1) {
  1967. - log_warn("adjtimex failed");
  1968. + log_warn("clock: adjustment failed");
  1969. return -1;
  1970. }
  1971. newfreq = (txc.freq * 1e3) * (1LL<<16);
  1972. - log_debug("adjtimex returns frequency of %fppm",
  1973. + log_debug("clock: adjustment returns frequency of %fppm",
  1974. newfreq / 1e3 / (1LL << 32));
  1975. *oldfreq = newfreq;
  1976. }
  1977. @@ -74,6 +74,6 @@ update_time_sync_status(int synced)
  1978. } else
  1979. txc.status = STA_UNSYNC;
  1980. if (adjtimex(&txc) == -1)
  1981. - log_warn("ntp_adjtime (3) failed");
  1982. + log_warn("clock: adjustment failed");
  1983. return;
  1984. }
  1985. --- a/compat/adjfreq_netbsd.c 2020-08-01 00:19:08.772392399 +0300
  1986. +++ b/compat/adjfreq_netbsd.c 2020-08-01 00:15:45.465725518 +0300
  1987. @@ -39,19 +39,19 @@ adjfreq(const int64_t *freq, int64_t *ol
  1988. txc.freq = *freq / 1e3 / (1LL << 16);
  1989. if ((ntp_adjtime(&txc)) == -1)
  1990. - log_warn("ntp_adjtime (2) failed");
  1991. + log_warn("clock: adjustment failed");
  1992. - log_debug("ntp_adjtime adjusted frequency by %fppm",
  1993. + log_debug("clock: frequency adjusted by %fppm",
  1994. ((txc.freq * 1e3) * (1LL<<16) / 1e3 / (1LL << 32)));
  1995. }
  1996. if (oldfreq != NULL) {
  1997. txc.modes = 0;
  1998. if ((ntp_adjtime(&txc)) == -1) {
  1999. - log_warn("ntp_adjtime (1) failed");
  2000. + log_warn("clock: adjustment failed");
  2001. return -1;
  2002. }
  2003. newfreq = (txc.freq * 1e3) * (1LL<<16);
  2004. - log_debug("ntp_adjtime returns frequency of %fppm",
  2005. + log_debug("clock: adjustment returns frequency of %fppm",
  2006. newfreq / 1e3 / (1LL << 32));
  2007. *oldfreq = newfreq;
  2008. }
  2009. @@ -75,6 +75,6 @@ update_time_sync_status(int synced)
  2010. } else
  2011. txc.status = STA_UNSYNC;
  2012. if (ntp_adjtime(&txc) == -1)
  2013. - log_warn("ntp_adjtime (3) failed");
  2014. + log_warn("clock: adjustment failed");
  2015. return;
  2016. }