From 250195924e60d5f77d495368b1c8231232a1a274 Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 15 Oct 2020 08:39:09 +0200 Subject: [PATCH] Throw better error if lockfile is not writable. --- src/files.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/files.cpp b/src/files.cpp index 7f48893..80b0151 100644 --- a/src/files.cpp +++ b/src/files.cpp @@ -229,8 +229,16 @@ bool create_lockfile() ofstream file; file.exceptions(std::ofstream::failbit | std::ofstream::badbit); - file.open(lockfile); - file << getpid(); + try + { + file.open(lockfile); + file << getpid(); + } + catch (const std::ofstream::failure &e) + { + const auto msg{string("Could not write lockfile: ") += e.what()}; + throw std::runtime_error{msg.c_str()}; + } return true; }