From 630b9400d2823e1d0233bb643580ec37a3a2a90c Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Sat, 28 Apr 2012 15:32:38 +0200 Subject: [PATCH] solaris locking fix --- src/utils/pathut.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/utils/pathut.cpp b/src/utils/pathut.cpp index 75e60c4e..ad888f04 100644 --- a/src/utils/pathut.cpp +++ b/src/utils/pathut.cpp @@ -547,11 +547,26 @@ pid_t Pidfile::read_pid() int Pidfile::flopen() { const char *path = m_path.c_str(); - int operation = LOCK_EX | LOCK_NB; if ((m_fd = ::open(path, O_RDWR|O_CREAT, 0644)) == -1) { m_reason = "Open failed"; return -1; } + +#ifdef sun + struct flock lockdata; + lockdata.l_start = 0; + lockdata.l_len = 0; + lockdata.l_type = F_WRLCK; + lockdata.l_whence = SEEK_SET; + if (fcntl(m_fd, F_SETLK, &lockdata) != 0) { + int serrno = errno; + (void)::close(m_fd); + errno = serrno; + m_reason = "fcntl lock failed"; + return -1; + } +#else + int operation = LOCK_EX | LOCK_NB; if (flock(m_fd, operation) == -1) { int serrno = errno; (void)::close(m_fd); @@ -559,6 +574,8 @@ int Pidfile::flopen() m_reason = "flock failed"; return -1; } +#endif // ! sun + if (ftruncate(m_fd, 0) != 0) { /* can't happen [tm] */ int serrno = errno;