From e951f27aa82e9155e429782746fd1abc90984d04 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Sat, 6 Oct 2018 13:52:26 +0000 Subject: bugfix: have s6-tcpserver?d write localport to stdout on notif and not just a newline. --- src/conn-tools/s6-tcpserver4d.c | 13 ++++++++++++- src/conn-tools/s6-tcpserver6d.c | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/conn-tools/s6-tcpserver4d.c b/src/conn-tools/s6-tcpserver4d.c index 914e981..3432236 100644 --- a/src/conn-tools/s6-tcpserver4d.c +++ b/src/conn-tools/s6-tcpserver4d.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -333,7 +334,17 @@ int main (int argc, char const *const *argv, char const *const *envp) } if (flag1) { - fd_write(1, "\n", 1) ; + uint16_t port ; + uint16_t m = 0 ; + char ip[4] ; + char fmtport[UINT16_FMT] ; + if (socket_local4(0, ip, &port) == -1) + { + if (verbosity) strerr_warnwu1sys("socket_local4") ; + } + else m = uint16_fmt(fmtport, port) ; + fmtport[m++] = '\n' ; + allwrite(1, fmtport, m) ; fd_close(1) ; } } diff --git a/src/conn-tools/s6-tcpserver6d.c b/src/conn-tools/s6-tcpserver6d.c index 5a763b5..8000531 100644 --- a/src/conn-tools/s6-tcpserver6d.c +++ b/src/conn-tools/s6-tcpserver6d.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -330,7 +331,17 @@ int main (int argc, char const *const *argv, char const *const *envp) } if (flag1) { - fd_write(1, "\n", 1) ; + uint16_t port ; + uint16_t m = 0 ; + char ip[16] ; + char fmtport[UINT16_FMT] ; + if (socket_local6(0, ip, &port) == -1) + { + if (verbosity) strerr_warnwu1sys("socket_local6") ; + } + else m = uint16_fmt(fmtport, port) ; + fmtport[m++] = '\n' ; + allwrite(1, fmtport, m) ; fd_close(1) ; } fmtlocalmaxconn[1+uint_fmt(fmtlocalmaxconn+1, localmaxconn)] = 0 ; -- cgit v1.2.3