Merge remote-tracking branch 'upstream/master'

This commit is contained in:
SteveGilvarry 2015-12-05 16:07:45 +11:00
commit 709cf07fa9
3 changed files with 31 additions and 2 deletions

View File

@ -9,10 +9,10 @@ set(zoneminder_VERSION "1.28.109")
set(zoneminder_API_VERSION "${zoneminder_VERSION}.1") set(zoneminder_API_VERSION "${zoneminder_VERSION}.1")
# Make sure the submodules are there # 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 message( SEND_ERROR "The git submodules are not available. Please run
git submodule update --init --recursive") 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 # CMake does not allow out-of-source build if CMakeCache.exists
# in the source folder. Abort and notify the user # in the source folder. Abort and notify the user

View File

@ -18,6 +18,10 @@
// //
#include <sys/un.h> #include <sys/un.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/file.h>
#include "zm.h" #include "zm.h"
#include "zm_mpeg.h" #include "zm_mpeg.h"
@ -286,6 +290,23 @@ void StreamBase::openComms()
{ {
if ( connkey > 0 ) 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 ); sd = socket( AF_UNIX, SOCK_DGRAM, 0 );
if ( sd < 0 ) if ( sd < 0 )
{ {
@ -321,6 +342,11 @@ void StreamBase::closeComms()
{ {
unlink( loc_sock_path ); 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);
}
} }
} }

View File

@ -78,6 +78,8 @@ protected:
struct sockaddr_un loc_addr; struct sockaddr_un loc_addr;
char rem_sock_path[PATH_MAX]; char rem_sock_path[PATH_MAX];
struct sockaddr_un rem_addr; struct sockaddr_un rem_addr;
char sock_path_lock[PATH_MAX];
int lock_fd;
protected: protected:
bool paused; bool paused;
@ -127,6 +129,7 @@ public:
connkey = 0; connkey = 0;
sd = -1; sd = -1;
lock_fd = 0;
memset( &loc_sock_path, 0, sizeof(loc_sock_path) ); memset( &loc_sock_path, 0, sizeof(loc_sock_path) );
memset( &loc_addr, 0, sizeof(loc_addr) ); memset( &loc_addr, 0, sizeof(loc_addr) );
memset( &rem_sock_path, 0, sizeof(rem_sock_path) ); memset( &rem_sock_path, 0, sizeof(rem_sock_path) );