From: Lars Op den Kamp Date: Mon, 14 May 2012 20:26:12 +0000 (+0200) Subject: cec: don't use the pid in dev_lock()/dev_unlock() calls X-Git-Tag: upstream/2.2.0~1^2~28^2~3 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=e7602087a36a85313b834bfe40d6b0255a9ea1b4;p=deb_libcec.git cec: don't use the pid in dev_lock()/dev_unlock() calls --- diff --git a/src/lib/platform/posix/serialport.cpp b/src/lib/platform/posix/serialport.cpp index 2237b65..3764a15 100644 --- a/src/lib/platform/posix/serialport.cpp +++ b/src/lib/platform/posix/serialport.cpp @@ -54,14 +54,19 @@ using namespace std; using namespace PLATFORM; +inline bool RemoveLock(const char *strDeviceName) +{ + #if !defined(__APPLE__) && !defined(__FreeBSD__) + return dev_unlock(strDeviceName, 0) == 0; + #endif +} + void CSerialSocket::Close(void) { if (IsOpen()) { SocketClose(m_socket); - #if !defined(__APPLE__) && !defined(__FreeBSD__) - dev_unlock(m_strName.c_str(), m_lockPid); - #endif + RemoveLock(m_strName.c_str()); } } @@ -70,9 +75,7 @@ void CSerialSocket::Shutdown(void) if (IsOpen()) { SocketClose(m_socket); - #if !defined(__APPLE__) && !defined(__FreeBSD__) - dev_unlock(m_strName.c_str(), m_lockPid); - #endif + RemoveLock(m_strName.c_str()); } } @@ -119,8 +122,7 @@ bool CSerialSocket::Open(uint64_t iTimeoutMs /* = 0 */) } #if !defined(__APPLE__) && !defined(__FreeBSD__) - m_lockPid = dev_lock(m_strName.c_str()); - if (m_lockPid != 0) + if (dev_lock(m_strName.c_str()) != 0) { m_strError = "Couldn't lock the serial port"; m_iError = EBUSY; @@ -133,9 +135,7 @@ bool CSerialSocket::Open(uint64_t iTimeoutMs /* = 0 */) if (m_socket == INVALID_SERIAL_SOCKET_VALUE) { m_strError = strerror(errno); - #if !defined(__APPLE__) && !defined(__FreeBSD__) - m_lockPid = dev_unlock(m_strName.c_str(), m_lockPid); - #endif + RemoveLock(m_strName.c_str()); return false; } @@ -182,9 +182,7 @@ bool CSerialSocket::Open(uint64_t iTimeoutMs /* = 0 */) if (tcsetattr(m_socket, TCSANOW, &m_options) != 0) { m_strError = strerror(errno); - #if !defined(__APPLE__) && !defined(__FreeBSD__) - m_lockPid = dev_unlock(m_strName.c_str(), m_lockPid); - #endif + RemoveLock(m_strName.c_str()); return false; } diff --git a/src/lib/platform/sockets/serialport.h b/src/lib/platform/sockets/serialport.h index a16e3ca..eed05a0 100644 --- a/src/lib/platform/sockets/serialport.h +++ b/src/lib/platform/sockets/serialport.h @@ -73,8 +73,6 @@ namespace PLATFORM CCommonSocket(INVALID_SERIAL_SOCKET_VALUE, strName), #ifdef __WINDOWS__ m_iCurrentReadTimeout(MAXDWORD), - #else - m_lockPid(0), #endif m_bIsOpen(false), m_iBaudrate(iBaudrate), @@ -101,7 +99,6 @@ namespace PLATFORM protected: #ifndef __WINDOWS__ struct termios m_options; - pid_t m_lockPid; #else bool SetTimeouts(serial_socket_t socket, int* iError, DWORD iTimeoutMs); DWORD m_iCurrentReadTimeout;