Skip to content

Commit

Permalink
Disable lockdev locking method on linux, can still be enabled manually
Browse files Browse the repository at this point in the history
  • Loading branch information
emericg committed Feb 20, 2017
1 parent cc8d7dd commit c22c8e7
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ endif(CMAKE_BUILD_TYPE STREQUAL "Debug")
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")

message(STATUS "Building on Linux plateform")
set(EXTRALIBS "lockdev")
#set(EXTRALIBS "lockdev")

endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")

Expand Down
2 changes: 1 addition & 1 deletion doc/BuildInstructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Build system:
* Doxygen (**ONLY** needed to generate the documentation)

Using Linux?
* liblockdev (used to lock the serial port to a single software instance, which will save you from a lot of potential head scratching errors...)
* liblockdev (OPTIONAL) (used to lock the serial port to a single software instance, which will save you from a lot of potential head scratching errors...)

### Building SmartServoFramework library (Linux and Mac OS X)

Expand Down
4 changes: 2 additions & 2 deletions doc/SerialCommunication.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ You will need to make sure your software can access your serial port:
It is important to guaranty that your application will be the only one to send commands and read the results back. Otherwise things will start to go wrong fast... We provide locking mechanisms in order to protect you against things like launching two instances of your application on the same port, or using one application and one SmartServoGui on two different ports.

The framework will handle locking/unlocking the serial port if a locking method is available with your serial port implementation:
* Linux: "flock()" support (default)
* Linux: "lockfile" support
* Linux: "liblockdev" support (default)
* Linux: "flock()" support
* Linux: "liblockdev" support
* macOS: "lockfile" support
* macOS: "TIOCEXCL ioctl" support (default)
* Windows: TODO!
Expand Down
1 change: 0 additions & 1 deletion gui/SmartServoGui.pro
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ unix {

unix:!macx {
message("Building on Linux/BSD plateform")
LIBS += -llockdev
}
unix:macx {
message("Building on MAC OS X plateform")
Expand Down
11 changes: 9 additions & 2 deletions src/SerialPortLinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,16 @@
#include <sys/time.h>

// Device lock support
#include <lockdev.h>
//#define LOCK_FLOCK
//#define LOCK_LOCKFILE
//#define LOCK_LOCKDEV

#ifdef LOCK_FLOCK
#include <sys/file.h>
#define LOCK_LOCKDEV
#endif
#ifdef LOCK_LOCKDEV
#include <lockdev.h>
#endif

// "open" and "close" calls
#include <unistd.h>
Expand Down
2 changes: 1 addition & 1 deletion src/SerialPortLinux.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ class SerialPortLinux: public SerialPort
* \return True if a lock has been placed successfully for this serial device, false otherwise.
*
* We have several ways of doing that:
* - Use flock(). Should work on Linux and Mac if carefully implemented. Not working ATM.
* - Use a file lock in "/tmp" directory. Will only work accross SmartServoFramework instances.
* - Use a file lock in "/var/lock/lockdev" directory. Almost standard way of locking devices, but need "lock" group credential.
* - Use a file lock with lockdev library. Standard way of locking devices, but need "lockdev" library.
* - Use flock(). Should work on Linux and Mac if carefully implemented. Not working ATM.
*/
bool setLock();

Expand Down

0 comments on commit c22c8e7

Please sign in to comment.