diff --git a/CMakeLists.txt b/CMakeLists.txt index 63425f4b3..b07156919 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,10 +9,10 @@ set(zoneminder_VERSION "1.28.109") set(zoneminder_API_VERSION "${zoneminder_VERSION}.1") # Make sure the submodules are there -if( NOT EXISTS "${CMAKE_SOURCE_DIR}/web/api/app/Plugin/Crud/.git" ) +if( NOT EXISTS "${CMAKE_SOURCE_DIR}/web/api/app/Plugin/Crud/Lib/CrudControllerTrait.php" ) message( SEND_ERROR "The git submodules are not available. Please run git submodule update --init --recursive") -endif( NOT EXISTS "${CMAKE_SOURCE_DIR}/web/api/app/Plugin/Crud/.git" ) +endif( NOT EXISTS "${CMAKE_SOURCE_DIR}/web/api/app/Plugin/Crud/Lib/CrudControllerTrait.php" ) # CMake does not allow out-of-source build if CMakeCache.exists # in the source folder. Abort and notify the user diff --git a/src/zm_stream.cpp b/src/zm_stream.cpp index 30a420bb1..c66638759 100644 --- a/src/zm_stream.cpp +++ b/src/zm_stream.cpp @@ -18,6 +18,10 @@ // #include +#include +#include +#include +#include #include "zm.h" #include "zm_mpeg.h" @@ -286,6 +290,23 @@ void StreamBase::openComms() { if ( connkey > 0 ) { + + snprintf( sock_path_lock, sizeof(sock_path_lock), "%s/zms-%06d.lock", config.path_socks, connkey); + + lock_fd = open(sock_path_lock, O_CREAT|O_WRONLY, S_IRUSR | S_IWUSR); + if (lock_fd <= 0 || flock(lock_fd, LOCK_EX) != 0) + { + Error("Unable to lock sock lock file %s: %s", sock_path_lock, strerror(errno) ); + + close(lock_fd); + lock_fd = 0; + } + else + { + Debug( 1, "We have obtained a lock on %s fd: %d", sock_path_lock, lock_fd); + } + + sd = socket( AF_UNIX, SOCK_DGRAM, 0 ); if ( sd < 0 ) { @@ -321,6 +342,11 @@ void StreamBase::closeComms() { unlink( loc_sock_path ); } + if (lock_fd > 0) + { + close(lock_fd); //close it rather than unlock it incase it got deleted. + unlink(sock_path_lock); + } } } diff --git a/src/zm_stream.h b/src/zm_stream.h index ef442ab8e..9936688a8 100644 --- a/src/zm_stream.h +++ b/src/zm_stream.h @@ -78,6 +78,8 @@ protected: struct sockaddr_un loc_addr; char rem_sock_path[PATH_MAX]; struct sockaddr_un rem_addr; + char sock_path_lock[PATH_MAX]; + int lock_fd; protected: bool paused; @@ -127,6 +129,7 @@ public: connkey = 0; sd = -1; + lock_fd = 0; memset( &loc_sock_path, 0, sizeof(loc_sock_path) ); memset( &loc_addr, 0, sizeof(loc_addr) ); memset( &rem_sock_path, 0, sizeof(rem_sock_path) );