X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=input_stats.cpp;h=5b7dc59ae762696f2eca6e9ad12fc4e54fc6272b;hp=6bd1529450a3e3ce08af839faf3c36eda70cdbc6;hb=HEAD;hpb=b05c2965d3d5bfc4f24f17a27716a69ddf03a3cc diff --git a/input_stats.cpp b/input_stats.cpp index 6bd1529..5b7dc59 100644 --- a/input_stats.cpp +++ b/input_stats.cpp @@ -31,7 +31,7 @@ void InputStatsThread::do_work() // Open a new, temporary file. char *filename = strdup((stats_file + ".new.XXXXXX").c_str()); - fd = mkostemp(filename, O_WRONLY); + fd = mkostemp(filename, O_WRONLY | O_CLOEXEC); if (fd == -1) { log_perror(filename); free(filename); @@ -39,7 +39,7 @@ void InputStatsThread::do_work() } fp = fdopen(fd, "w"); - if (fp == NULL) { + if (fp == nullptr) { log_perror("fdopen"); safe_close(fd); if (unlink(filename) == -1) { @@ -49,10 +49,17 @@ void InputStatsThread::do_work() goto sleep; } - now = time(NULL); + now = time(nullptr); for (size_t i = 0; i < inputs.size(); ++i) { InputStats stats = inputs[i]->get_stats(); - fprintf(fp, "%s %llu %llu", stats.url.c_str(), + for (const char ch : stats.url) { + if (isspace(ch) || !isprint(ch)) { + putc('_', fp); + } else { + putc(ch, fp); + } + } + fprintf(fp, " %llu %llu", (long long unsigned)(stats.bytes_received), (long long unsigned)(stats.data_bytes_received)); if (stats.connect_time == -1) {