X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/blobdiff_plain/6ce6b5a9430b1b8749d832ecabe840a7b65d74de..95ceb9eae3ff08162d7e17be5ce82090d78cb269:/tests/udplog.c diff --git a/tests/udplog.c b/tests/udplog.c index 4d52efc..0aa8f59 100644 --- a/tests/udplog.c +++ b/tests/udplog.c @@ -61,7 +61,7 @@ static void help(void) { /* display version number and terminate */ static void version(void) { - xprintf("disorder-udplog version %s\n", disorder_version_string); + xprintf("%s", disorder_version_string); xfclose(stdout); exit(0); } @@ -78,6 +78,8 @@ int main(int argc, char **argv) { struct sockaddr_in6 sin6; } sa; socklen_t len; + fd_set fds; + struct timeval tv; static const struct addrinfo pref = { 0, /* ai_flags */ AF_UNSPEC, /* ai_family */ @@ -110,9 +112,17 @@ int main(int argc, char **argv) { if(!(ai = get_address(&a, &pref, &name))) exit(1); fd = xsocket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); + nonblock(fd); if(bind(fd, ai->ai_addr, ai->ai_addrlen) < 0) fatal(errno, "error binding to %s", name); while(getppid() != 1) { + /* Wait for something to happen. We don't just block forever in recvfrom() + * as otherwise we'd never die if the parent terminated uncontrolledly. */ + FD_ZERO(&fds); + FD_SET(fd, &fds); + tv.tv_sec = 1; + tv.tv_usec = 0; + select(fd + 1, &fds, 0, 0, &tv); len = sizeof sa; n = recvfrom(fd, buffer, sizeof buffer, 0, &sa.sa, &len); if(n < 0) {