-
Notifications
You must be signed in to change notification settings - Fork 0
/
1-patch_better-logs.patch
2252 lines (2016 loc) · 73.6 KB
/
1-patch_better-logs.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
From: Pekka Helenius <[email protected]>
Date: Tue, 04 Aug 2020 01:52:09 +0300
Subject: Provide human-readable error messages for easier process interpretation
--- a/src/client.c 2020-08-01 00:19:23.432392415 +0300
+++ b/src/client.c 2020-08-02 02:02:37.850286445 +0300
@@ -52,7 +52,7 @@ int
client_peer_init(struct ntp_peer *p)
{
if ((p->query = calloc(1, sizeof(struct ntp_query))) == NULL)
- fatal("client_peer_init calloc");
+ fatal("NTP client: can't allocate memory for a new NTP peer connection");
p->query->fd = -1;
p->query->msg.status = MODE_CLIENT | (NTP_VERSION << 3);
p->state = STATE_NONE;
@@ -86,9 +86,14 @@ client_addr_init(struct ntp_peer *p)
p->state = STATE_DNS_DONE;
break;
default:
- fatalx("king bula sez: wrong AF in client_addr_init");
+ fatalx("NTP client: NTP peer %s has wrong network address family",
+ p->addr_head.name
+ );
/* NOTREACHED */
}
+ log_info("NTP client: DNS query found IP address %s for NTP peer %s",
+ log_sockaddr((struct sockaddr *)&h->ss),
+ p->addr_head.name);
}
p->query->fd = -1;
@@ -129,6 +134,16 @@ int
client_query(struct ntp_peer *p)
{
int val;
+ struct ntp_addr *h;
+ h = p->addr;
+/*
+ if (h != NULL) {
+
+ log_debug("NTP client: listening on NTP peer %s on remote UDP port %d",
+ log_sockaddr((struct sockaddr *)&h->ss),
+ p->addr_head.port);
+ }
+*/
if (p->addr == NULL && client_nextaddr(p) == -1) {
if (conf->settime)
@@ -156,21 +171,23 @@ client_query(struct ntp_peer *p)
p->query->fd = socket(p->addr->ss.ss_family, SOCK_DGRAM, 0);
if (p->query->fd == -1) {
if (errno == EAFNOSUPPORT) {
- log_warn("client_query socket");
+ log_warn("NTP client: can't create UDP socket");
client_nextaddr(p);
set_next(p, error_interval());
return (-1);
} else
- fatal("client_query socket");
+ fatal("NTP client: NTP peer has unknown network address family %s",
+ log_sockaddr((struct sockaddr *)&h->ss)
+ );
}
if (p->addr->ss.ss_family == qa4->sa_family) {
if (bind(p->query->fd, qa4, SA_LEN(qa4)) == -1)
- fatal("couldn't bind to IPv4 query address: %s",
+ fatal("NTP client: can't bind to NTP peer IPv4 query address %s",
log_sockaddr(qa4));
} else if (p->addr->ss.ss_family == qa6->sa_family) {
if (bind(p->query->fd, qa6, SA_LEN(qa6)) == -1)
- fatal("couldn't bind to IPv6 query address: %s",
+ fatal("NTP client: can't bind to NTP peer IPv6 query address %s",
log_sockaddr(qa6));
}
@@ -187,17 +204,17 @@ client_query(struct ntp_peer *p)
p->senderrors++;
return (-1);
} else
- fatal("client_query connect");
+ fatal("NTP client: can't connect to NTP peer due to socket error");
}
val = IPTOS_LOWDELAY;
if (p->addr->ss.ss_family == AF_INET && setsockopt(p->query->fd,
IPPROTO_IP, IP_TOS, &val, sizeof(val)) == -1)
- log_warn("setsockopt IPTOS_LOWDELAY");
+ log_warn("NTP client: can't set NTP peer IPv4 socket field IP_TOS");
#ifdef SO_TIMESTAMP
val = 1;
if (setsockopt(p->query->fd, SOL_SOCKET, SO_TIMESTAMP,
&val, sizeof(val)) == -1)
- fatal("setsockopt SO_TIMESTAMP");
+ fatal("NTP client: can't set NTP peer IPv4 socket control option SO_TIMESTAMP");
#endif
}
@@ -256,7 +273,7 @@ handle_auto(uint8_t trusted, double offs
if (offset < AUTO_THRESHOLD) {
/* don't bother */
- priv_settime(0, "offset is negative or close enough");
+ priv_settime(0, "NTP client: NTP peer offset is negative or close enough");
return;
}
/* collect some more */
@@ -305,21 +322,21 @@ client_dispatch(struct ntp_peer *p, u_in
errno == ENETUNREACH || errno == ENETDOWN ||
errno == ECONNREFUSED || errno == EADDRNOTAVAIL ||
errno == ENOPROTOOPT || errno == ENOENT) {
- client_log_error(p, "recvmsg", errno);
+ client_log_error(p, "socket message reception", errno);
set_next(p, error_interval());
return (0);
} else
- fatal("recvfrom");
+ fatal("NTP client: can't get socket message for an unknown reason");
}
if (somsg.msg_flags & MSG_TRUNC) {
- client_log_error(p, "recvmsg packet", EMSGSIZE);
+ client_log_error(p, "socket packet message reception", EMSGSIZE);
set_next(p, error_interval());
return (0);
}
if (somsg.msg_flags & MSG_CTRUNC) {
- client_log_error(p, "recvmsg control data", E2BIG);
+ client_log_error(p, "socket control data message reception", E2BIG);
set_next(p, error_interval());
return (0);
}
@@ -359,7 +376,7 @@ client_dispatch(struct ntp_peer *p, u_in
}
interval = error_interval();
set_next(p, interval);
- log_info("reply from %s: not synced (%s), next query %llds",
+ log_info("NTP client: reply from %-16s is not synced (%s), next query in %llds",
log_sockaddr((struct sockaddr *)&p->addr->ss), s,
(long long)interval);
return (0);
@@ -387,7 +404,7 @@ client_dispatch(struct ntp_peer *p, u_in
/* Detect liars */
if (!p->trusted && conf->constraint_median != 0 &&
(constraint_check(T2) != 0 || constraint_check(T3) != 0)) {
- log_info("reply from %s: constraint check failed",
+ log_info("NTP client: reply from %-16s constraint check failed",
log_sockaddr((struct sockaddr *)&p->addr->ss));
set_next(p, error_interval());
return (0);
@@ -399,8 +416,8 @@ client_dispatch(struct ntp_peer *p, u_in
if (p->reply[p->shift].delay < 0) {
interval = error_interval();
set_next(p, interval);
- log_info("reply from %s: negative delay %fs, "
- "next query %llds",
+ log_info("NTP client: reply from %-16s has negative delay %9fs, "
+ "next query in %llds",
log_sockaddr((struct sockaddr *)&p->addr->ss),
p->reply[p->shift].delay, (long long)interval);
return (0);
@@ -449,13 +466,13 @@ client_dispatch(struct ntp_peer *p, u_in
if (p->trustlevel < TRUSTLEVEL_MAX) {
if (p->trustlevel < TRUSTLEVEL_BADPEER &&
p->trustlevel + 1 >= TRUSTLEVEL_BADPEER)
- log_info("peer %s now valid",
+ log_info("NTP client: NTP peer %s is valid now",
log_sockaddr((struct sockaddr *)&p->addr->ss));
p->trustlevel++;
}
- log_debug("reply from %s: offset %f delay %f, "
- "next query %llds",
+ log_debug("NTP client: reply from %-16s offset: %9fs, delay: %9fs, "
+ "next query in %llds",
log_sockaddr((struct sockaddr *)&p->addr->ss),
p->reply[p->shift].offset, p->reply[p->shift].delay,
(long long)interval);
@@ -518,9 +535,9 @@ client_log_error(struct ntp_peer *peer,
address = log_sockaddr((struct sockaddr *)&peer->addr->ss);
if (peer->lasterror == error) {
- log_debug("%s %s: %s", operation, address, strerror(error));
+ log_debug("NTP client: NTP peer %s, error in %s: %s", operation, address, strerror(error));
return;
}
peer->lasterror = error;
- log_warn("%s %s", operation, address);
+ log_warn("NTP client: NTP peer %s, error in %s", operation, address);
}
--- a/src/config.c 2020-08-01 00:19:23.449059082 +0300
+++ b/src/config.c 2020-07-31 23:11:30.429054797 +0300
@@ -44,7 +44,7 @@ host(const char *s, struct ntp_addr **hn
if (!strcmp(s, "*")) {
if ((h = calloc(1, sizeof(*h))) == NULL)
- fatal(NULL);
+ fatal("can't allocate memory for NTP peer address");
} else {
if ((h = host_ip(s)) == NULL) {
non_numeric = 1;
@@ -69,7 +69,7 @@ host_ip(const char *s)
if (res->ai_family == AF_INET ||
res->ai_family == AF_INET6) {
if ((h = calloc(1, sizeof(*h))) == NULL)
- fatal(NULL);
+ fatal("can't allocate memory for NTP peer IP address");
memcpy(&h->ss, res->ai_addr, res->ai_addrlen);
}
freeaddrinfo(res);
@@ -110,7 +110,7 @@ host_dns1(const char *s, struct ntp_addr
return (0);
}
if (error) {
- log_warnx("could not parse \"%s\": %s", s,
+ log_warnx("DNS process: can't parse \"%s\": %s", s,
gai_strerror(error));
return (-1);
}
@@ -120,7 +120,7 @@ host_dns1(const char *s, struct ntp_addr
res->ai_family != AF_INET6)
continue;
if ((h = calloc(1, sizeof(*h))) == NULL)
- fatal(NULL);
+ fatal("DNS process: can't allocate memory for NTP peer address");
memcpy(&h->ss, res->ai_addr, res->ai_addrlen);
h->notauth = notauth;
@@ -139,19 +139,19 @@ host_dns(const char *s, int synced, stru
{
int error;
- log_debug("trying to resolve %s", s);
+ log_debug("DNS process: trying to resolve %s", s);
error = host_dns1(s, hn, 0);
#ifdef RES_USE_CD
if (!synced && error <= 0) {
int save_opts;
- log_debug("no luck, trying to resolve %s without checking", s);
+ log_debug("DNS process: trying to resolve %s without checking", s);
save_opts = _res.options;
_res.options |= RES_USE_CD;
error = host_dns1(s, hn, 1);
_res.options = save_opts;
}
#endif
- log_debug("resolve %s done: %d", s, error);
+ log_debug("DNS process: resolve for %s done: %d", s, error);
return error;
}
@@ -161,7 +161,7 @@ new_peer(void)
struct ntp_peer *p;
if ((p = calloc(1, sizeof(struct ntp_peer))) == NULL)
- fatal("new_peer calloc");
+ fatal("NTP client: can't allocate memory for a new NTP peer");
p->id = ++maxid;
return (p);
@@ -173,9 +173,9 @@ new_sensor(char *device)
struct ntp_conf_sensor *s;
if ((s = calloc(1, sizeof(struct ntp_conf_sensor))) == NULL)
- fatal("new_sensor calloc");
+ fatal("sensor: can't allocate memory for a new sensor");
if ((s->device = strdup(device)) == NULL)
- fatal("new_sensor strdup");
+ fatal("sensor: can't duplicate memory address for a new sensor");
return (s);
}
@@ -186,12 +186,12 @@ new_constraint(void)
struct constraint *p;
if ((p = calloc(1, sizeof(struct constraint))) == NULL)
- fatal("new_constraint calloc");
+ fatal("constraint: can't allocate memory for a new constraint");
p->id = ++constraint_maxid;
p->fd = -1;
#ifndef HAVE_LIBTLS
- log_warnx("constraint configured without libtls support");
+ log_warnx("constraint configured without LibreSSL support");
#endif
return (p);
}
--- a/src/constraint.c 2020-08-01 00:19:23.425725748 +0300
+++ b/src/constraint.c 2020-08-02 01:55:31.236952662 +0300
@@ -135,8 +135,7 @@ constraint_addr_init(struct constraint *
cstr->state = STATE_DNS_DONE;
break;
default:
- /* XXX king bula sez it? */
- fatalx("wrong AF in constraint_addr_init");
+ fatalx("constraint id %d: wrong network address family", cstr->id);
/* NOTREACHED */
}
@@ -238,23 +237,23 @@ priv_constraint_msg(u_int32_t id, u_int8
int rv;
if ((cstr = constraint_byid(id)) != NULL) {
- log_warnx("IMSG_CONSTRAINT_QUERY repeated for id %d", id);
+ log_warnx("constraint id %d: repeated query", id);
return;
}
if (len < sizeof(am)) {
- log_warnx("invalid IMSG_CONSTRAINT_QUERY received");
+ log_warnx("constraint id %d: longer query expected", id);
return;
}
memcpy(&am, data, sizeof(am));
if (len != (sizeof(am) + am.namelen + am.pathlen)) {
- log_warnx("invalid IMSG_CONSTRAINT_QUERY received");
+ log_warnx("constraint id %d: invalid query received", id);
return;
}
/* Additional imsg data is obtained in the unpriv child */
if ((h = calloc(1, sizeof(*h))) == NULL)
- fatal("calloc ntp_addr");
+ fatal("constraint id %d: can't allocate memory for network address", id);
memcpy(h, &am.a, sizeof(*h));
h->next = NULL;
@@ -267,19 +266,23 @@ priv_constraint_msg(u_int32_t id, u_int8
if (socketpair(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, AF_UNSPEC,
pipes) == -1)
- fatal("%s pipes", __func__);
+ fatal("constraint id %d: can't create required socket pairs (%s)",
+ id, __func__
+ );
/* Prepare and send constraint data to child. */
cstr->fd = pipes[0];
imsg_init(&cstr->ibuf, cstr->fd);
if (imsg_compose(&cstr->ibuf, IMSG_CONSTRAINT_QUERY, id, 0, -1,
data, len) == -1)
- fatal("%s: imsg_compose", __func__);
+ fatal("constraint id %d: can't compose data from parent process (%s)",
+ id, __func__
+ );
do {
rv = imsg_flush(&cstr->ibuf);
} while (rv == -1 && errno == EAGAIN);
if (rv == -1)
- fatal("imsg_flush");
+ fatal("constraint id %d: can't flush old data", id);
/*
* Fork child handlers and make sure to do any sensitive work in the
@@ -301,11 +304,14 @@ priv_constraint_readquery(struct constra
/* Read the message our parent left us. */
if (((n = imsg_read(&cstr->ibuf)) == -1 && errno != EAGAIN) || n == 0)
- fatal("%s: imsg_read", __func__);
+ fatal("constraint: can't read message from parent process (%s)",
+ __func__);
if (((n = imsg_get(&cstr->ibuf, &imsg)) == -1) || n == 0)
- fatal("%s: imsg_get", __func__);
+ fatal("constraint: can't get message from parent process (%s)",
+ __func__);
if (imsg.hdr.type != IMSG_CONSTRAINT_QUERY)
- fatalx("%s: invalid message type", __func__);
+ fatalx("constraint: invalid message type from parent process (%s)",
+ __func__);
/*
* Copy the message contents just like our father:
@@ -313,16 +319,19 @@ priv_constraint_readquery(struct constra
*/
mlen = imsg.hdr.len - IMSG_HEADER_SIZE;
if (mlen < sizeof(*am))
- fatalx("%s: mlen < sizeof(*am)", __func__);
+ fatalx("constraint: expected longer message from parent process (%s)",
+ __func__
+ );
memcpy(am, imsg.data, sizeof(*am));
if (mlen != (sizeof(*am) + am->namelen + am->pathlen))
- fatalx("%s: mlen < sizeof(*am) + am->namelen + am->pathlen",
- __func__);
+ fatalx("constraint: invalid message length received from parent process (%s)",
+ __func__
+ );
if ((h = calloc(1, sizeof(*h))) == NULL ||
(*data = calloc(1, mlen)) == NULL)
- fatal("%s: calloc", __func__);
+ fatal("constraint: can't allocate memory (%s)", __func__);
memcpy(h, &am->a, sizeof(*h));
h->next = NULL;
@@ -349,29 +358,27 @@ priv_constraint_child(const char *pw_dir
struct iovec iov[2];
int i, rv;
- log_procinit("constraint");
-
if (setpriority(PRIO_PROCESS, 0, 0) == -1)
- log_warn("could not set priority");
+ log_warn("constraint: can't set priority for subprocess");
#ifdef HAVE_LIBTLS
/* Init TLS and load CA certs before chroot() */
if (tls_init() == -1)
- fatalx("tls_init");
+ fatalx("constraint: can't initialize LibreSSL engine");
if ((conf->ca = tls_load_file(tls_default_ca_cert_file(),
&conf->ca_len, NULL)) == NULL)
- fatalx("failed to load constraint ca");
+ log_warnx("constraint: failed to load CA certificate bundle file");
#endif
if (chroot(pw_dir) == -1)
- fatal("chroot");
+ fatal("constraint: can't set isolated working directory for subprocess");
if (chdir("/") == -1)
- fatal("chdir(\"/\")");
+ fatal("constraint: can't change subprocess working directory");
if (setgroups(1, &pw_gid) ||
setresgid(pw_gid, pw_gid, pw_gid) ||
setresuid(pw_uid, pw_uid, pw_uid))
- fatal("can't drop privileges");
+ fatal("constraint: can't drop subprocess privileges");
/* Reset all signal handlers */
memset(&sa, 0, sizeof(sa));
@@ -382,7 +389,7 @@ priv_constraint_child(const char *pw_dir
sigaction(i, &sa, NULL);
if (pledge("stdio inet", NULL) == -1)
- fatal("pledge");
+ fatal("constraint: can't restrict subprocess privileges");
cstr.fd = CONSTRAINT_PASSFD;
imsg_init(&cstr.ibuf, cstr.fd);
@@ -398,10 +405,11 @@ priv_constraint_child(const char *pw_dir
SA_LEN((struct sockaddr *)&cstr.addr->ss),
addr, sizeof(addr), NULL, 0,
NI_NUMERICHOST) != 0)
- fatalx("%s getnameinfo", __func__);
+ fatalx("constraint %s: can't get host and service name from IP address"
+ " (getnameinfo) (%s)", addr, __func__);
- log_debug("constraint request to %s", addr);
- setproctitle("constraint from %s", addr);
+ log_debug("constraint %s: setting HTTPS request", addr);
+ setproctitle("constraint %s: new HTTPS request", addr);
(void)closefrom(CONSTRAINT_PASSFD + 1);
/*
@@ -411,25 +419,27 @@ priv_constraint_child(const char *pw_dir
* but we keep it as a safety belt; especially for portability.
*/
if (fcntl(CONSTRAINT_PASSFD, F_SETFD, FD_CLOEXEC) == -1)
- fatal("%s fcntl F_SETFD", __func__);
+ fatal("constraint %s: unexpected file descriptor %d closure after execution (%s fcntl F_SETFD)",
+ addr, CONSTRAINT_PASSFD, __func__);
/* Get remaining data from imsg in the unpriv child */
if (am.namelen) {
if ((cstr.addr_head.name =
get_string(data, am.namelen)) == NULL)
- fatalx("invalid IMSG_CONSTRAINT_QUERY name");
+ fatalx("constraint %s: invalid name", addr);
data += am.namelen;
}
if (am.pathlen) {
if ((cstr.addr_head.path =
get_string(data, am.pathlen)) == NULL)
- fatalx("invalid IMSG_CONSTRAINT_QUERY path");
+ fatalx("constraint %s: invalid path", addr);
}
/* Run! */
if ((ctx = httpsdate_query(addr,
CONSTRAINT_PORT, cstr.addr_head.name, cstr.addr_head.path,
conf->ca, conf->ca_len, &rectv, &xmttv)) == NULL) {
+ log_debug("constraint %s: failed to get proper time results", addr);
/* Abort with failure but without warning */
exit(1);
}
@@ -464,7 +474,7 @@ priv_constraint_check_child(pid_t pid, i
if (WEXITSTATUS(status) != 0)
fail = 1;
} else
- fatalx("unexpected cause of SIGCHLD");
+ fatalx("constraint: unexpected closure in check (SIGCHLD)");
if ((cstr = constraint_bypid(pid)) != NULL) {
if (sig) {
@@ -489,7 +499,7 @@ priv_constraint_kill(u_int32_t id)
struct constraint *cstr;
if ((cstr = constraint_byid(id)) == NULL) {
- log_warnx("IMSG_CONSTRAINT_KILL for invalid id %d", id);
+ log_warnx("constraint id %d: kill failed: invalid id", id);
return;
}
@@ -541,7 +551,7 @@ constraint_close(u_int32_t id)
struct constraint *cstr;
if ((cstr = constraint_byid(id)) == NULL) {
- log_warn("%s: id %d: not found", __func__, id);
+ log_warn("constraint id %d: id not found (%s)", id, __func__);
return (0);
}
@@ -569,7 +579,7 @@ priv_constraint_close(int fd, int fail)
u_int32_t id;
if ((cstr = constraint_byfd(fd)) == NULL) {
- log_warn("%s: fd %d: not found", __func__, fd);
+ log_warn("constraint id %d: constraint file descriptor %d not found (%s)", cstr->id, fd, __func__);
return;
}
@@ -643,7 +653,9 @@ priv_constraint_dispatch(struct pollfd *
switch (imsg.hdr.type) {
case IMSG_CONSTRAINT_RESULT:
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(tv))
- fatalx("invalid IMSG_CONSTRAINT received");
+ fatalx("constraint id %d: invalid header length received in dispatch",
+ cstr->id
+ );
/* state is maintained by child, but we want to
remember we've seen the result */
@@ -669,12 +681,12 @@ constraint_msg_result(u_int32_t id, u_in
double offset;
if ((cstr = constraint_byid(id)) == NULL) {
- log_warnx("IMSG_CONSTRAINT_CLOSE with invalid constraint id");
+ log_warnx("constraint id %d: invalid constraint id in result", id);
return;
}
if (len != sizeof(tv)) {
- log_warnx("invalid IMSG_CONSTRAINT received");
+ log_warnx("constraint id %d: invalid header length %zu received in result", id, len);
return;
}
@@ -683,7 +695,7 @@ constraint_msg_result(u_int32_t id, u_in
offset = gettime_from_timeval(&tv[0]) -
gettime_from_timeval(&tv[1]);
- log_info("constraint reply from %s: offset %f",
+ log_info("constraint %s: reply received: offset %fs",
log_sockaddr((struct sockaddr *)&cstr->addr->ss),
offset);
@@ -702,20 +714,22 @@ constraint_msg_close(u_int32_t id, u_int
static int total_fails;
if ((cstr = constraint_byid(id)) == NULL) {
- log_warnx("IMSG_CONSTRAINT_CLOSE with invalid constraint id");
+ log_warnx("constraint id %d: closure failed: invalid constraint id", id);
return;
}
if (len != sizeof(int)) {
- log_warnx("invalid IMSG_CONSTRAINT_CLOSE received");
+ log_warnx("constraint id %d: closure failed: invalid header length %zu received",
+ id,
+ len);
return;
}
memcpy(&fail, data, len);
if (fail) {
- log_debug("no constraint reply from %s"
- " received in time, next query %ds",
+ log_debug("constraint %s: no reply"
+ " received in time, next query in %ds",
log_sockaddr((struct sockaddr *)
&cstr->addr->ss), CONSTRAINT_SCAN_INTERVAL);
@@ -724,7 +738,7 @@ constraint_msg_close(u_int32_t id, u_int
cnt++;
if (cnt > 0 && ++total_fails >= cnt &&
conf->constraint_median == 0) {
- log_warnx("constraints configured but none available");
+ log_warnx("constraint: constraints configured but none available");
total_fails = 0;
}
}
@@ -743,21 +757,21 @@ constraint_msg_dns(u_int32_t id, u_int8_
struct ntp_addr *h;
if ((cstr = constraint_byid(id)) == NULL) {
- log_debug("IMSG_CONSTRAINT_DNS with invalid constraint id");
+ log_warnx("constraint id %d: DNS dispatching failed: invalid constraint id", id);
return;
}
if (cstr->addr != NULL) {
- log_warnx("IMSG_CONSTRAINT_DNS but addr != NULL!");
+ log_warnx("constraint id %d: DNS dispatching failed: address is not empty", id);
return;
}
if (len == 0) {
- log_debug("%s FAILED", __func__);
+ log_debug("constraint id %d: DNS dispatching failed: invalid header length %zu (%s FAILED)", id, len, __func__);
cstr->state = STATE_DNS_TEMPFAIL;
return;
}
if (len % (sizeof(struct sockaddr_storage) + sizeof(int)) != 0)
- fatalx("IMSG_CONSTRAINT_DNS len");
+ fatalx("constraint id %d: DNS dispatching failed: invalid header length", id);
if (cstr->addr_head.pool) {
struct constraint *n, *tmp;
@@ -772,7 +786,7 @@ constraint_msg_dns(u_int32_t id, u_int8_
p = data;
do {
if ((h = calloc(1, sizeof(*h))) == NULL)
- fatal("calloc ntp_addr");
+ fatal("constraint id %d: DNS dispatching failed: can't allocate memory", id);
memcpy(&h->ss, p, sizeof(h->ss));
p += sizeof(h->ss);
len -= sizeof(h->ss);
@@ -788,7 +802,7 @@ constraint_msg_dns(u_int32_t id, u_int8_
ncstr->addr_head.path = strdup(cstr->addr_head.path);
if (ncstr->addr_head.name == NULL ||
ncstr->addr_head.path == NULL)
- fatal("calloc name");
+ fatal("constraint id %d: DNS dispatching failed: invalid data", id);
ncstr->addr_head.pool = cstr->addr_head.pool;
ncstr->state = STATE_DNS_DONE;
constraint_add(ncstr);
@@ -831,7 +845,7 @@ constraint_update(void)
return;
if ((values = calloc(cnt, sizeof(time_t))) == NULL)
- fatal("calloc");
+ fatal("constraint: can't allocate memory for constraint time");
i = 0;
TAILQ_FOREACH(cstr, &conf->constraints, entry) {
@@ -979,11 +993,14 @@ httpsdate_request(struct httpsdate *http
* does not trigger any DNS operation and is safe to be called
* without the dns pledge.
*/
+ log_debug("constraint %s: establishing connection", httpsdate->tls_addr);
if (tls_connect_servername(httpsdate->tls_ctx, httpsdate->tls_addr,
httpsdate->tls_port, httpsdate->tls_hostname) == -1) {
- log_debug("tls connect failed: %s (%s): %s",
- httpsdate->tls_addr, httpsdate->tls_hostname,
- tls_error(httpsdate->tls_ctx));
+ log_debug("constraint %s: TLS connection failed (%s): %s",
+ httpsdate->tls_addr,
+ httpsdate->tls_hostname,
+ tls_error(httpsdate->tls_ctx)
+ );
goto fail;
}
@@ -994,9 +1011,11 @@ httpsdate_request(struct httpsdate *http
if (ret == TLS_WANT_POLLIN || ret == TLS_WANT_POLLOUT)
continue;
if (ret == -1) {
- log_warnx("tls write failed: %s (%s): %s",
- httpsdate->tls_addr, httpsdate->tls_hostname,
- tls_error(httpsdate->tls_ctx));
+ log_warnx("constraint %s: TLS write operation failed (%s): %s",
+ httpsdate->tls_addr,
+ httpsdate->tls_hostname,
+ tls_error(httpsdate->tls_ctx)
+ );
goto fail;
}
buf += ret;
@@ -1022,7 +1041,9 @@ httpsdate_request(struct httpsdate *http
*/
if (strptime(p, IMF_FIXDATE,
&httpsdate->tls_tm) == NULL) {
- log_warnx("unsupported date format");
+ log_warnx("constraint %s: unsupported date format",
+ httpsdate->tls_addr
+ );
free(line);
return (-1);
}
@@ -1050,8 +1071,8 @@ httpsdate_request(struct httpsdate *http
if (strftime(timebuf2, sizeof(timebuf2), X509_DATE,
&httpsdate->tls_tm) == 0)
goto fail;
- log_warnx("tls certificate not yet valid: %s (%s): "
- "not before %s, now %s", httpsdate->tls_addr,
+ log_warnx("constraint %s: TLS certificate not yet valid (%s): "
+ "not before %s, now is %s", httpsdate->tls_addr,
httpsdate->tls_hostname, timebuf1, timebuf2);
goto fail;
}
@@ -1063,8 +1084,8 @@ httpsdate_request(struct httpsdate *http
if (strftime(timebuf2, sizeof(timebuf2), X509_DATE,
&httpsdate->tls_tm) == 0)
goto fail;
- log_warnx("tls certificate expired: %s (%s): "
- "not after %s, now %s", httpsdate->tls_addr,
+ log_warnx("constraint %s: TLS certificate has been expired (%s): "
+ "not after %s, now is %s", httpsdate->tls_addr,
httpsdate->tls_hostname, timebuf1, timebuf2);
goto fail;
}
@@ -1117,11 +1138,11 @@ tls_readline(struct tls *tls, size_t *le
len = 128;
if ((buf = malloc(len)) == NULL)
- fatal("Can't allocate memory for transfer buffer");
+ fatal("constraint: can't allocate memory for TLS transfer buffer");
for (i = 0; ; i++) {
if (i >= len - 1) {
if ((q = reallocarray(buf, len, 2)) == NULL)
- fatal("Can't expand transfer buffer");
+ fatal("constraint: can't expand TLS transfer buffer");
buf = q;
len *= 2;
}
@@ -1136,7 +1157,7 @@ tls_readline(struct tls *tls, size_t *le
}
if (maxlength != NULL && (*maxlength)-- == 0) {
- log_warnx("maximum length exceeded");
+ log_warnx("constraint: maximum HTTP header length exceeded");
free(buf);
return (NULL);
}
@@ -1147,7 +1168,7 @@ tls_readline(struct tls *tls, size_t *le
}
*lenp = i;
if (gettimeofday(when, NULL) == -1)
- fatal("gettimeofday");
+ fatal("constraint: can't get a valid time stamp");
return (buf);
}
--- a/src/control.c 2020-08-01 00:19:21.849059080 +0300
+++ b/src/control.c 2020-07-31 23:23:56.959055574 +0300
@@ -47,12 +47,12 @@ control_check(char *path)
strlcpy(sun.sun_path, path, sizeof(sun.sun_path));
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
- log_debug("control_check: socket check");
+ log_debug("control socket: socket error in check");
return (-1);
}
if (connect(fd, (struct sockaddr *)&sun, sizeof(sun)) == 0) {
- log_debug("control_check: socket in use");
+ log_debug("control socket: socket is in use");
close(fd);
return (-1);
}
@@ -70,7 +70,7 @@ control_init(char *path)
mode_t old_umask;
if ((fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0)) == -1) {
- log_warn("control_init: socket");
+ log_warn("control socket: can't create UDP socket");
return (-1);
}
@@ -78,18 +78,18 @@ control_init(char *path)
sa.sun_family = AF_UNIX;
if (strlcpy(sa.sun_path, path, sizeof(sa.sun_path)) >=
sizeof(sa.sun_path))
- errx(1, "ctl socket name too long");
+ errx(1, "control socket: name is too long");
if (unlink(path) == -1)
if (errno != ENOENT) {
- log_warn("control_init: unlink %s", path);
+ log_warn("control socket: can't unlink %s", path);
close(fd);
return (-1);
}
old_umask = umask(S_IXUSR|S_IXGRP|S_IWOTH|S_IROTH|S_IXOTH);
if (bind(fd, (struct sockaddr *)&sa, sizeof(sa)) == -1) {
- log_warn("control_init: bind: %s", path);
+ log_warn("control socket: can't bind %s", path);
close(fd);
umask(old_umask);
return (-1);
@@ -97,7 +97,7 @@ control_init(char *path)
umask(old_umask);
if (chmod(path, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) == -1) {
- log_warn("control_init: chmod");
+ log_warn("control socket: can't set owner permission bits for %s", path);
close(fd);
(void)unlink(path);
return (-1);
@@ -112,7 +112,7 @@ int
control_listen(int fd)
{
if (fd != -1 && listen(fd, CONTROL_BACKLOG) == -1) {
- log_warn("control_listen: listen");
+ log_warn("control socket: can't initialize listening interface");
return (-1);
}
@@ -137,14 +137,14 @@ control_accept(int listenfd)
if ((connfd = accept(listenfd,
(struct sockaddr *)&sa, &len)) == -1) {
if (errno != EWOULDBLOCK && errno != EINTR)
- log_warn("control_accept: accept");
+ log_warn("control socket: unable to accept connections");
return (0);
}
session_socket_nonblockmode(connfd);
if ((ctl_conn = calloc(1, sizeof(struct ctl_conn))) == NULL) {
- log_warn("control_accept");
+ log_warn("control socket: can't allocate memory for NTP server");
close(connfd);
return (0);
}
@@ -175,7 +175,7 @@ control_close(int fd)
struct ctl_conn *c;
if ((c = control_connbyfd(fd)) == NULL) {
- log_warn("control_close: fd %d: not found", fd);
+ log_warn("control socket: file descriptor %d not found while closing", fd);
return (0);
}
@@ -202,7 +202,7 @@ control_dispatch_msg(struct pollfd *pfd,
ssize_t n;
if ((c = control_connbyfd(pfd->fd)) == NULL) {
- log_warn("control_dispatch_msg: fd %d: not found", pfd->fd);
+ log_warn("control socket: file descriptor %d not found while preparing NTP server subprocess", pfd->fd);
return (0);
}
@@ -298,12 +298,12 @@ session_socket_nonblockmode(int fd)
int flags;
if ((flags = fcntl(fd, F_GETFL)) == -1)
- fatal("fcntl F_GETFL");
+ fatal("control socket: unable to get file descriptor %d status flags", fd);
flags |= O_NONBLOCK;
if ((flags = fcntl(fd, F_SETFL, flags)) == -1)
- fatal("fcntl F_SETFL");
+ fatal("control socket: unable to set file descriptor %d status flags", fd);
}
void
@@ -349,7 +349,7 @@ build_show_peer(struct ctl_show_peer *cp
if (p->addr) {
a = log_sockaddr((struct sockaddr *)&p->addr->ss);
if (p->addr->notauth)
- auth = " (non-dnssec lookup)";
+ auth = " (non-DNSSEC lookup)";
}
if (p->addr_head.pool)
pool = "from pool ";
--- a/src/ntp.c 2020-08-01 00:19:21.849059080 +0300
+++ b/src/ntp.c 2020-07-31 23:34:32.462389577 +0300
@@ -93,38 +93,38 @@ ntp_main(struct ntpd_conf *nconf, struct
if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, PF_UNSPEC,
pipe_dns) == -1)
- fatal("socketpair");
+ fatal("main process: can't set socket pair for DNS");
start_child(NTPDNS_PROC_NAME, pipe_dns[1], argc, argv);
log_init(nconf->debug ? LOG_TO_STDERR : LOG_TO_SYSLOG, nconf->verbose,
LOG_DAEMON);
if (!nconf->debug && setsid() == -1)
- fatal("setsid");
- log_procinit("ntp");
+ fatal("main process: can't create a new session");
+ log_procinit("NTP");
if ((se = getservbyname("ntp", "udp")) == NULL)
- fatal("getservbyname");
+ fatal("main process: can't find default system information for NTP protocol (getservbyname)");
/* Start control socket. */
if ((fd_ctl = control_init(CTLSOCKET)) == -1)
- fatalx("control socket init failed");
+ fatalx("control socket: unable to initialize");
if (control_listen(fd_ctl) == -1)
- fatalx("control socket listen failed");
+ fatalx("control socket: unable to listen");
if ((nullfd = open("/dev/null", O_RDWR, 0)) == -1)
- fatal(NULL);
+ fatal("control socket: can't read /dev/null");
if (stat(pw->pw_dir, &stb) == -1) {
- fatal("privsep dir %s could not be opened", pw->pw_dir);
+ fatal("main process: can't open working directory %s", pw->pw_dir);
}
if (stb.st_uid != 0 || (stb.st_mode & (S_IWGRP|S_IWOTH)) != 0) {
- fatalx("bad privsep dir %s permissions: %o",
+ fatalx("main process: working directory %s has bad permissions (%o)",
pw->pw_dir, stb.st_mode);
}
if (chroot(pw->pw_dir) == -1)
- fatal("chroot");
+ fatal("main process: can't set isolated working directory");
if (chdir("/") == -1)
- fatal("chdir(\"/\")");
+ fatal("main process: can't change subprocess working directory");
if (!nconf->debug) {
dup2(nullfd, STDIN_FILENO);
@@ -133,21 +133,22 @@ ntp_main(struct ntpd_conf *nconf, struct
}
close(nullfd);
- setproctitle("ntp engine");
+ setproctitle("NTP engine");
conf = nconf;
setup_listeners(se, conf, &listener_cnt);
+ log_debug("main process: setting up listeners");
if (setgroups(1, &pw->pw_gid) ||
setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) ||
setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid))
- fatal("can't drop privileges");
+ fatal("main process: can't drop privileges");
endservent();
/* The ntp process will want to open NTP client sockets -> "inet" */
if (pledge("stdio inet", NULL) == -1)
- err(1, "pledge");
+ err(1, "main process: can't restrict NTP process privileges");
signal(SIGTERM, ntp_sighdlr);
signal(SIGINT, ntp_sighdlr);
@@ -156,10 +157,10 @@ ntp_main(struct ntpd_conf *nconf, struct
signal(SIGCHLD, SIG_DFL);
if ((ibuf_main = malloc(sizeof(struct imsgbuf))) == NULL)
- fatal(NULL);
+ fatal("main process: can't allocate memory for main data buffer");
imsg_init(ibuf_main, PARENT_SOCK_FILENO);
if ((ibuf_dns = malloc(sizeof(struct imsgbuf))) == NULL)
- fatal(NULL);
+ fatal("main process: can't allocate memory for DNS data buffer");
imsg_init(ibuf_dns, pipe_dns[0]);
constraint_cnt = 0;
@@ -192,7 +193,7 @@ ntp_main(struct ntpd_conf *nconf, struct
TAILQ_INIT(&ctl_conns);
sensor_init();
- log_info("ntp engine ready");
+ log_info("NTP engine ready");
ctl_cnt = 0;
peer_cnt = 0;
@@ -204,7 +205,7 @@ ntp_main(struct ntpd_conf *nconf, struct
if ((newp = reallocarray(idx2peer, peer_cnt,
sizeof(*idx2peer))) == NULL) {
/* panic for now */
- log_warn("could not resize idx2peer from %u -> "
+ log_warn("main process: could not resize server pool from %u -> "
"%u entries", idx2peer_elms, peer_cnt);
fatalx("exiting");
}
@@ -218,7 +219,7 @@ ntp_main(struct ntpd_conf *nconf, struct
if ((newp = reallocarray(pfd, new_cnt,
sizeof(*pfd))) == NULL) {
/* panic for now */
- log_warn("could not resize pfd from %u -> "
+ log_warn("main process: could not resize process file descriptor pool from %u -> "
"%u entries", pfd_elms, new_cnt);
fatalx("exiting");
}
@@ -258,12 +259,12 @@ ntp_main(struct ntpd_conf *nconf, struct
}
if (p->deadline > 0 && p->deadline <= getmonotime()) {
timeout = 300;
- log_debug("no reply from %s received in time, "
- "next query %ds", log_sockaddr(
+ log_debug("NTP client: NTP peer %s - no reply received in time, "
+ "next query in %ds", log_sockaddr(
(struct sockaddr *)&p->addr->ss), timeout);
if (p->trustlevel >= TRUSTLEVEL_BADPEER &&
(p->trustlevel /= 2) < TRUSTLEVEL_BADPEER)