X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=udpinput.cpp;h=873b0b952911a226d8f08255f80e2d092e163801;hp=a2915e8333dff36c1b3cc1fa2efcb1cfbf1d27cf;hb=7c23f706733b12405c0cb8793866b57ba5800c98;hpb=20e85bd6901355cc40a6cfb4c0deb7232d9aa63f diff --git a/udpinput.cpp b/udpinput.cpp index a2915e8..873b0b9 100644 --- a/udpinput.cpp +++ b/udpinput.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -120,6 +121,10 @@ UDPInput::UDPInput(const InputProto &serialized) : url(serialized.url()), sock(serialized.sock()) { + // Set back the close-on-exec flag for the socket. + // (This can't leak into a child, since we haven't been started yet.) + fcntl(sock, F_SETFD, O_CLOEXEC); + // Should be verified by the caller. string protocol; bool ok = parse_url(url, &protocol, &user, &host, &port, &path); @@ -139,6 +144,10 @@ UDPInput::UDPInput(const InputProto &serialized) InputProto UDPInput::serialize() const { + // Unset the close-on-exec flag for the socket. + // (This can't leak into a child, since there's only one thread left.) + fcntl(sock, F_SETFD, 0); + InputProto serialized; serialized.set_url(url); serialized.set_sock(sock); @@ -210,7 +219,7 @@ void UDPInput::do_work() ret = recv(sock, packet_buf, sizeof(packet_buf), 0); } while (ret == -1 && errno == EINTR); - if (ret <= 0) { + if (ret < 0) { // Note that zero-byte packets are legal. log_perror("recv"); close_socket(); continue;