chiark
/
gitweb
/
~mdw
/
disorder
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
8a7ccdf
)
disorder-udplog exits more reliably when parent dies
author
Richard Kettlewell
<rjk@greenend.org.uk>
Tue, 18 Dec 2007 17:03:24 +0000
(17:03 +0000)
committer
Richard Kettlewell
<rjk@greenend.org.uk>
Tue, 18 Dec 2007 17:03:24 +0000
(17:03 +0000)
tests/udplog.c
patch
|
blob
|
blame
|
history
diff --git
a/tests/udplog.c
b/tests/udplog.c
index eb87651b13d90aa037b30db84658d9c23e2b8dfe..0aa8f595c4346e36a1316dd5f9bc2ceb41937943 100644
(file)
--- a/
tests/udplog.c
+++ b/
tests/udplog.c
@@
-78,6
+78,8
@@
int main(int argc, char **argv) {
struct sockaddr_in6 sin6;
} sa;
socklen_t len;
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 */
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);
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) {
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) {
len = sizeof sa;
n = recvfrom(fd, buffer, sizeof buffer, 0, &sa.sa, &len);
if(n < 0) {