X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=stream.cpp;h=4e5ca24cceab8870dfdfa00e66b161aecc61f729;hp=6a5ef99f78fa80a8294b6bf9d3bf8ee52d0bb1c0;hb=HEAD;hpb=980ac162414c9fce62af4fdb9cfc282865b31572 diff --git a/stream.cpp b/stream.cpp index 6a5ef99..c79391a 100644 --- a/stream.cpp +++ b/stream.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -53,6 +54,7 @@ Stream::~Stream() Stream::Stream(const StreamProto &serialized, int data_fd) : url(serialized.url()), + unavailable(serialized.unavailable()), http_header(serialized.http_header()), stream_header(serialized.stream_header()), encoding(Stream::STREAM_ENCODING_RAW), // Will be changed later. @@ -66,6 +68,9 @@ Stream::Stream(const StreamProto &serialized, int data_fd) exit(1); } + // Set the close-on-exec parameter back on the backlog fd. + fcntl(data_fd, F_SETFD, FD_CLOEXEC); + for (ssize_t point : serialized.suitable_starting_point()) { if (point == -1) { // Can happen when upgrading from before 1.1.3, @@ -84,6 +89,7 @@ Stream::Stream(const StreamProto &serialized, int data_fd) StreamProto Stream::serialize() { StreamProto serialized; + serialized.set_unavailable(unavailable); serialized.set_http_header(http_header); serialized.set_stream_header(stream_header); serialized.add_data_fds(data_fd); @@ -101,6 +107,10 @@ StreamProto Stream::serialize() serialized.set_first_fragment_index(first_fragment_index); serialized.set_discontinuity_counter(discontinuity_counter); + // Unset the close-on-exec flag for the backlog fd. + // (This can't leak into a child, since there's only one thread left.) + fcntl(data_fd, F_SETFD, 0); + serialized.set_url(url); data_fd = -1; return serialized; @@ -154,6 +164,7 @@ void Stream::set_backlog_size(size_t new_size) void Stream::set_header(const std::string &new_http_header, const std::string &new_stream_header) { + unavailable = false; http_header = new_http_header; if (new_stream_header == stream_header) { return;