Skip to content

Commit

Permalink
Improve pidfile logging
Browse files Browse the repository at this point in the history
  • Loading branch information
hebasto committed Jan 28, 2019
1 parent 5e0c0fd commit f5fb1bc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/init.cpp
Expand Up @@ -262,7 +262,9 @@ void Shutdown(InitInterfaces& interfaces)

#ifndef WIN32
try {
fs::remove(GetPidFile());
if (!fs::remove(GetPidFile())) {
LogPrintf("%s: Unable to remove pidfile: File does not exist\n", __func__);
}
} catch (const fs::filesystem_error& e) {
LogPrintf("%s: Unable to remove pidfile: %s\n", __func__, e.what());
}
Expand Down
6 changes: 4 additions & 2 deletions src/util/system.cpp
Expand Up @@ -30,6 +30,7 @@
#endif // __linux__

#include <algorithm>
#include <cerrno>
#include <fcntl.h>
#include <sched.h>
#include <sys/resource.h>
Expand Down Expand Up @@ -967,10 +968,11 @@ fs::path GetPidFile()
void CreatePidFile(const fs::path &path, pid_t pid)
{
FILE* file = fsbridge::fopen(path, "w");
if (file)
{
if (file) {
fprintf(file, "%d\n", pid);
fclose(file);
} else {
LogPrintf("%s: Unable to create pidfile: %s\n", __func__, std::strerror(errno));
}
}
#endif
Expand Down

0 comments on commit f5fb1bc

Please sign in to comment.