diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2023-12-12 17:01:07 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2023-12-12 17:01:07 +0000 |
commit | 9f697d6c1de2979cc5e0f3689d10086ceac8a672 (patch) | |
tree | 9db01eb20527d3328607bce9e68ccedbfd5916a5 | |
parent | 9c4a097d900fb623abeb61d3a58cf58e9c5f383f (diff) | |
download | s6-networking-9f697d6c1de2979cc5e0f3689d10086ceac8a672.tar.xz |
Fix clock programs that recv46; fix s6-tcpserver-access exitcodes
Signed-off-by: Laurent Bercot <ska@appnovation.com>
-rw-r--r-- | src/clock/s6-sntpclock.c | 2 | ||||
-rw-r--r-- | src/clock/s6-taiclock.c | 2 | ||||
-rw-r--r-- | src/clock/s6-taiclockd.c | 4 | ||||
-rw-r--r-- | src/conn-tools/s6-tcpserver-access.c | 22 |
4 files changed, 22 insertions, 8 deletions
diff --git a/src/clock/s6-sntpclock.c b/src/clock/s6-sntpclock.c index 8a30b8a..644591a 100644 --- a/src/clock/s6-sntpclock.c +++ b/src/clock/s6-sntpclock.c @@ -46,7 +46,7 @@ int ntp_exchange (int s, ip46 const *ip, uint16_t port, tain *stamps, tain const r = socket_sendnb46_g(s, query, 48, ip, port, deadline) ; if (r < 0) return 0 ; if (r < 48) return (errno = EPIPE, 0) ; - r = socket_recvnb46_g(s, answer, 48, &dummyip, &dummyport, deadline) ; + r = socket_recvnb46_g(s, answer, 48, &dummyip, &dummyport, ip46_is6(ip), deadline) ; if (r < 0) return 0 ; if (r < 48) return (errno = EPROTO, 0) ; if (((answer[0] & 7) != 2) && ((answer[0] & 7) != 4)) return (errno = EPROTO, 0) ; diff --git a/src/clock/s6-taiclock.c b/src/clock/s6-taiclock.c index 1f0c399..353d767 100644 --- a/src/clock/s6-taiclock.c +++ b/src/clock/s6-taiclock.c @@ -37,7 +37,7 @@ int tain_exchange (int s, ip46 const *ip, uint16_t port, tain *serversays, tain r = socket_sendnb46_g(s, query, N, ip, port, deadline) ; if (r < 0) return 0 ; if (r < N) return (errno = EPIPE, 0) ; - r = socket_recvnb46_g(s, answer, N, &dummyip, &dummyport, deadline) ; + r = socket_recvnb46_g(s, answer, N, &dummyip, &dummyport, ip46_is6(ip), deadline) ; if (r < 0) return 0 ; if (r < N) return (errno = EPROTO, 0) ; if (memcmp(answer, "stai", 4)) return (errno = EPROTO, 0) ; diff --git a/src/clock/s6-taiclockd.c b/src/clock/s6-taiclockd.c index 9a000cc..9dabc5f 100644 --- a/src/clock/s6-taiclockd.c +++ b/src/clock/s6-taiclockd.c @@ -19,6 +19,7 @@ int main (int argc, char const *const *argv) ip46 ip = IP46_ZERO ; uint16_t port = 4014 ; subgetopt l = SUBGETOPT_ZERO ; + int is6 ; PROG = "s6-taiclockd" ; for (;;) { @@ -38,10 +39,11 @@ int main (int argc, char const *const *argv) if (socket_bind46_reuse(s, &ip, port) < 0) strerr_diefu1sys(111, "socket_bind_reuse") ; + is6 = ip46_is6(&ip) ; for (;;) { char packet[256] ; - ssize_t r = socket_recv46(s, packet, 256, &ip, &port) ; + ssize_t r = socket_recv46(s, packet, 256, &ip, &port, is6) ; if ((r >= 20) && !memcmp(packet, "ctai", 4)) { tain now ; diff --git a/src/conn-tools/s6-tcpserver-access.c b/src/conn-tools/s6-tcpserver-access.c index 10a9c5b..bfff4ee 100644 --- a/src/conn-tools/s6-tcpserver-access.c +++ b/src/conn-tools/s6-tcpserver-access.c @@ -60,6 +60,7 @@ static inline void log_deny (pid_t pid, ip46 const *ip) logit(pid, ip, 0) ; } +#define PROGNAME "s6-tcpserver-access" int main (int argc, char const *const *argv) { @@ -79,7 +80,9 @@ int main (int argc, char const *const *argv) int flagfatal = 1, flagnodelay = 0, flagdnslookup = 1, flaghosts = 0, flagident = 0, flagparanoid = 0, e = 0 ; uint16_t remoteport, localport ; - PROG = "s6-tcpserver-access" ; + char progbuf[sizeof(PROGNAME) + sizeof(": pid ") + PID_FMT] = PROGNAME ": pid " ; + memcpy(progbuf + sizeof(PROGNAME ": pid ") - 1 + pid_fmt(progbuf + sizeof(PROGNAME ": pid ") - 1, getpid()), ": ", 3) ; + PROG = PROGNAME ; { unsigned int timeout = 0 ; subgetopt l = SUBGETOPT_ZERO ; @@ -146,6 +149,7 @@ int main (int argc, char const *const *argv) if (!uint160_scan(x, &remoteport)) strerr_dieinvalid(100, tmp) ; } + PROG = progbuf ; if (flagnodelay) { if (socket_tcpnodelay(1) < 0) @@ -259,7 +263,11 @@ int main (int argc, char const *const *argv) if (r == -1) { if (verbosity >= 2) strerr_warnwu3sys("look up ", "remote", " ip in hosts database") ; - if (flagfatal) { e = 111 ; goto reject ; } + if (flagfatal) + { + e = 111 ; + goto reject ; + } } if (r) { @@ -275,7 +283,11 @@ int main (int argc, char const *const *argv) if (r == -1) { if (verbosity >= 2) strerr_warnwu3sys("look up ", "local", " ip in hosts database") ; - if (flagfatal) { e = 111 ; goto reject ; } + if (flagfatal) + { + e = 111 ; + goto reject ; + } } if (r) localname = sa.s + genalloc_s(size_t, &ga)[0] ; } @@ -311,7 +323,7 @@ int main (int argc, char const *const *argv) if (verbosity >= 3) strerr_warnwu2x("resolve IP addresses: ", s6dns_constants_error_str(errno)) ; if (flagfatal) { - e = 111 ; + e = errno == ENOENT ? 1 : 111 ; goto reject ; } } @@ -355,7 +367,7 @@ int main (int argc, char const *const *argv) if (verbosity >= 3) strerr_warnwu4x("(paranoidly) resolve ", remotebuf, ": ", s6dns_constants_error_str(errno)) ; if (flagfatal) { - e = errno == ETIMEDOUT ? 99 : 111 ; + e = errno == ETIMEDOUT ? 99 : errno == ENOENT ? 1 : 111 ; goto reject ; } remotelen = 0 ; |