Throw better error if lockfile is not writable.

This commit is contained in:
tastytea 2020-10-15 08:39:09 +02:00
parent f59f9ebd5f
commit 250195924e
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
1 changed files with 10 additions and 2 deletions

View File

@ -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;
}