summaryrefslogtreecommitdiff
path: root/src/MTS_IO_LockFile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/MTS_IO_LockFile.cpp')
-rw-r--r--src/MTS_IO_LockFile.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/MTS_IO_LockFile.cpp b/src/MTS_IO_LockFile.cpp
index c013699..a4879de 100644
--- a/src/MTS_IO_LockFile.cpp
+++ b/src/MTS_IO_LockFile.cpp
@@ -84,10 +84,22 @@ bool LockFile::lock(uint32_t attemptMillis) {
// Mgetty treats 4-bytes lock files as binary,
// not text, PID. Making 5+ char file. Brrr...
char buf[256] = {0};
+ size_t written = 0;
+
sprintf(buf, "%4d\n", getpid());
- write(m_iLockFd, buf, strlen(buf));
- close(m_iLockFd);
- return true;
+ size_t wsize = strlen(buf);
+
+ written = write(m_iLockFd, buf, wsize);
+
+ if (wsize != written) {
+ printError("LockFile| Error writing to lock file [%s] [%d][%s]", m_sFile.c_str(), errno, strerror(errno));
+ close(m_iLockFd);
+ return false;
+ }
+ else {
+ close(m_iLockFd);
+ return true;
+ }
}
uint32_t randomSleepTime = ((rand() % 10) + 1) * 100000; //Sleep from 100ms to 1 Second
::usleep(randomSleepTime);