diff --git a/slsDetectorSoftware/tests/Caller/test-Caller-acquire.cpp b/slsDetectorSoftware/tests/Caller/test-Caller-acquire.cpp index 8084efd84..86e0a2e0b 100644 --- a/slsDetectorSoftware/tests/Caller/test-Caller-acquire.cpp +++ b/slsDetectorSoftware/tests/Caller/test-Caller-acquire.cpp @@ -8,11 +8,14 @@ #include "acquire/ExpectedState.h" #include "acquire/FileState.h" #include "checks/MasterFileChecks.h" +#include "tests/globals.h" namespace sls { namespace acq = sls::test::acquire; namespace checks = sls::test::checks; +using test::GET; +using test::PUT; void acquire_and_check_file_size( Detector &det, std::optional ctb_state = std::nullopt) { @@ -270,4 +273,29 @@ TEST_CASE("acquire_check_binary_file_size", REQUIRE_NOTHROW(acquire_and_check_file_size(det)); } +TEST_CASE("rx_start_fails_fpath_permissions", "[.detectorintegration]") { + Detector det; + Caller caller(&det); + auto det_type = + det.getDetectorType().tsquash("Inconsistent detector types to test"); + + // not needed to test for every detector type, just one is enough + if (det_type == defs::JUNGFRAU) { + std::vector formats{defs::BINARY}; +#ifdef HDF5C + formats.push_back(defs::HDF5); +#endif + for (auto format : formats) { + INFO("File format: " << ToString(format)); + auto file_state = acq::default_file_state(); + file_state.file_format = format; + file_state.file_write = true; + // no write permission, rx_start fails later + file_state.file_path = "/"; + acq::FileStateGuard file_guard(det, file_state); + REQUIRE_THROWS(caller.call("rx_start", {}, -1, PUT)); + } + } +} + } // namespace sls diff --git a/slsReceiverSoftware/src/HDF5DataFile.cpp b/slsReceiverSoftware/src/HDF5DataFile.cpp index 8dc2f4598..1e8381c1d 100644 --- a/slsReceiverSoftware/src/HDF5DataFile.cpp +++ b/slsReceiverSoftware/src/HDF5DataFile.cpp @@ -136,7 +136,7 @@ void HDF5DataFile::CreateFile() { '_' + std::to_string(fileIndex) + ".h5"); fileName = p.string(); - std::lock_guard lock(*hdf5Lib); + std::unique_lock lock(*hdf5Lib); uint64_t framestosave = ((maxFramesPerFile == 0) ? numImages : // infinite images @@ -207,8 +207,11 @@ void HDF5DataFile::CreateFile() { } } catch (const H5::Exception &error) { error.printErrorStack(); + lock.unlock(); // CloseFile() also wants the mutex --> need to unlock + // here CloseFile(); - throw RuntimeError("Could not create HDF5 handles in object " + index); + throw RuntimeError("Could not create HDF5 handles in object " + + std::to_string(index)); } if (!silentMode) { LOG(logINFO) << "[" << udpPortNumber