summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Gilles <jgilles@multitech.com>2015-04-21 10:38:00 -0500
committerJesse Gilles <jgilles@multitech.com>2015-04-21 10:38:00 -0500
commita259a536ee561c992d971db240c9cc8a7b7aa74d (patch)
tree51d26b25d9f444c6080de2bdb21e82e33f81b00e
parentd84d880627bcc1e1898a8f96b861bc25863ec86c (diff)
downloadlibmts-io-a259a536ee561c992d971db240c9cc8a7b7aa74d.tar.gz
libmts-io-a259a536ee561c992d971db240c9cc8a7b7aa74d.tar.bz2
libmts-io-a259a536ee561c992d971db240c9cc8a7b7aa74d.zip
MTS_IO_Lockfile.cpp: check lock file write result
-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);