From 4b20109b6968a5524ca59e0ca2fdb8f105b27a38 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 25 Jul 2023 16:35:28 -0400 Subject: [PATCH] Use the same open semantics regardless of blocking or non so that we always have an fd to lock. Fixes logging of unable to lock jpeg in streaming with buffering --- src/zm_image.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/zm_image.cpp b/src/zm_image.cpp index e30a41c08..19e27e28b 100644 --- a/src/zm_image.cpp +++ b/src/zm_image.cpp @@ -1164,19 +1164,17 @@ bool Image::WriteJpeg(const std::string &filename, } if (!on_blocking_abort) { - if ((outfile = fopen(filename.c_str(), "wb")) == nullptr) { - Error("Can't open %s for writing: %s", filename.c_str(), strerror(errno)); - return false; - } + raw_fd = open(filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); } else { raw_fd = open(filename.c_str(), O_WRONLY | O_NONBLOCK | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); - if (raw_fd < 0) - return false; - outfile = fdopen(raw_fd, "wb"); - if (outfile == nullptr) { - close(raw_fd); - return false; - } + } + + if (raw_fd < 0) + return false; + outfile = fdopen(raw_fd, "wb"); + if (outfile == nullptr) { + close(raw_fd); + return false; } struct flock fl = { F_WRLCK, SEEK_SET, 0, 0, 0 };