]> git.sesse.net Git - cubemap/blobdiff - stream.cpp
Create $(libdir) on make install.
[cubemap] / stream.cpp
index 6a5ef99f78fa80a8294b6bf9d3bf8ee52d0bb1c0..c79391a81990b2f94ddef1b460beb08b62de0274 100644 (file)
@@ -1,5 +1,6 @@
 #include <assert.h>
 #include <errno.h>
+#include <fcntl.h>
 #include <inttypes.h>
 #include <limits.h>
 #include <math.h>
@@ -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;