From 97380f009b0e6a8bb6ee4ecbf0436045342cdf1e Mon Sep 17 00:00:00 2001 From: abishai Date: Tue, 31 Jan 2017 10:42:57 +0300 Subject: [PATCH 1/6] implement platform-agnostic comparison without abs() --- src/zm_image.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/zm_image.cpp b/src/zm_image.cpp index 9c8c12fda..80a821376 100644 --- a/src/zm_image.cpp +++ b/src/zm_image.cpp @@ -1658,11 +1658,9 @@ Image *Image::Highlight( unsigned int n_images, Image *images[], const Rgb thres { uint8_t *psrc = images[j]->buffer+c; -#ifndef SOLARIS - if ( (unsigned)abs((*psrc)-RGB_VAL(ref_colour,c)) >= RGB_VAL(threshold,c) ) -#else - if ( (unsigned)std::abs((*psrc)-RGB_VAL(ref_colour,c)) >= RGB_VAL(threshold,c) ) -#endif + unsigned int diff = ((*psrc)-RGB_VAL(ref_colour,c)) > 0 ? (*psrc)-RGB_VAL(ref_colour,c) : RGB_VAL(ref_colour,c) - (*psrc); + + if (diff >= RGB_VAL(threshold,c)) { count++; } From 0f23809b35793ac3ffd3210d64c0b32840c2a991 Mon Sep 17 00:00:00 2001 From: abishai Date: Tue, 31 Jan 2017 10:59:22 +0300 Subject: [PATCH 2/6] rc.d is not require polkit provide alternate path for mysql headers --- CMakeLists.txt | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index baba4218d..508aea2e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -386,13 +386,13 @@ find_library(MYSQLCLIENT_LIBRARIES mysqlclient PATH_SUFFIXES mysql) if(MYSQLCLIENT_LIBRARIES) set(HAVE_LIBMYSQLCLIENT 1) list(APPEND ZM_BIN_LIBS "${MYSQLCLIENT_LIBRARIES}") - find_path(MYSQLCLIENT_INCLUDE_DIR mysql/mysql.h) + find_path(MYSQLCLIENT_INCLUDE_DIR mysql.h /usr/local/include/mysql /usr/include/mysql) if(MYSQLCLIENT_INCLUDE_DIR) include_directories("${MYSQLCLIENT_INCLUDE_DIR}") set(CMAKE_REQUIRED_INCLUDES "${MYSQLCLIENT_INCLUDE_DIR}") endif(MYSQLCLIENT_INCLUDE_DIR) mark_as_advanced(FORCE MYSQLCLIENT_LIBRARIES MYSQLCLIENT_INCLUDE_DIR) - check_include_file("mysql/mysql.h" HAVE_MYSQL_H) + check_include_file("mysql.h" HAVE_MYSQL_H) if(NOT HAVE_MYSQL_H) message(FATAL_ERROR "ZoneMinder requires MySQL headers - check that MySQL development packages are installed") @@ -660,11 +660,13 @@ message(STATUS "Using web user: ${ZM_WEB_USER}") message(STATUS "Using web group: ${ZM_WEB_GROUP}") # Check for polkit -find_package(Polkit) -if(NOT POLKIT_FOUND) - message(FATAL_ERROR - "Running ZoneMinder requires polkit. Building ZoneMinder requires the polkit development package.") -endif(NOT POLKIT_FOUND) +if(NOT BSD) + find_package(Polkit) + if(NOT POLKIT_FOUND) + message(FATAL_ERROR + "Running ZoneMinder requires polkit. Building ZoneMinder requires the polkit development package.") + endif(NOT POLKIT_FOUND) +endif(NOT BSD) # Some variables that zm expects set(ZM_PID "${ZM_RUNDIR}/zm.pid") From 1687217d1899870d8ffd05d7b375766aaba550ab Mon Sep 17 00:00:00 2001 From: abishai Date: Tue, 31 Jan 2017 11:10:25 +0300 Subject: [PATCH 3/6] switch to POSIX basename() --- src/zm_logger.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/zm_logger.cpp b/src/zm_logger.cpp index dee423503..06d61a0cb 100644 --- a/src/zm_logger.cpp +++ b/src/zm_logger.cpp @@ -31,9 +31,9 @@ #include #include #include +#include #ifdef __FreeBSD__ #include -#include #endif bool Logger::smInitialised = false; @@ -515,8 +515,9 @@ void Logger::logPrint( bool hex, const char * const filepath, const int line, co va_list argPtr; struct timeval timeVal; - const char * const file = basename(filepath); - + char *filecopy = strdup(filepath); + const char * const file = basename(filecopy); + if ( level < PANIC || level > DEBUG9 ) Panic( "Invalid logger level %d", level ); @@ -631,6 +632,8 @@ void Logger::logPrint( bool hex, const char * const filepath, const int line, co syslog( priority, "%s [%s]", classString, syslogStart ); } + free(filecopy); + if ( level <= FATAL ) { if ( level <= PANIC ) From 8d5a8f5512c3002c33cfe66993c110608c171de5 Mon Sep 17 00:00:00 2001 From: abishai Date: Fri, 3 Feb 2017 14:53:53 +0300 Subject: [PATCH 4/6] make clang happy --- src/zm_monitor.cpp | 8 ++++---- src/zmf.cpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index b7920c166..dd76e7845 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -160,7 +160,7 @@ bool Monitor::MonitorLink::connect() return( false ); } mem_ptr = (unsigned char *)shmat( shm_id, 0, 0 ); - if ( mem_ptr < 0 ) + if ( mem_ptr < (void *)0 ) { Debug( 3, "Can't shmat link memory: %s", strerror(errno) ); connected = false; @@ -194,7 +194,7 @@ bool Monitor::MonitorLink::disconnect() connected = false; #if ZM_MEM_MAPPED - if ( mem_ptr > 0 ) + if ( mem_ptr > (void *)0 ) { msync( mem_ptr, mem_size, MS_ASYNC ); munmap( mem_ptr, mem_size ); @@ -222,7 +222,7 @@ bool Monitor::MonitorLink::disconnect() } } - if ( shmdt( mem_ptr ) < 0 ) + if ( shmdt( mem_ptr ) < (void *)0 ) { Debug( 3, "Can't shmdt: %s", strerror(errno) ); return( false ); @@ -558,7 +558,7 @@ bool Monitor::connect() { exit( -1 ); } mem_ptr = (unsigned char *)shmat( shm_id, 0, 0 ); - if ( mem_ptr < 0 ) + if ( mem_ptr < (void *)0 ) { Error( "Can't shmat: %s", strerror(errno)); exit( -1 ); diff --git a/src/zmf.cpp b/src/zmf.cpp index 2245d9ba3..cf1810076 100644 --- a/src/zmf.cpp +++ b/src/zmf.cpp @@ -331,7 +331,7 @@ int main( int argc, char *argv[] ) Debug( 1, "Got image, writing to %s", path ); FILE *fd = 0; - if ( (fd = fopen( path, "w" )) < 0 ) + if ( (fd = fopen( path, "w" )) < (void *)0 ) { Error( "Can't fopen '%s': %s", path, strerror(errno) ); exit( -1 ); From 160aa1cac4f4fb30acb167dcfa26cb080e6f5a2d Mon Sep 17 00:00:00 2001 From: Andy Bauer Date: Sat, 4 Feb 2017 15:34:57 -0600 Subject: [PATCH 5/6] check for polkit only if systemd is present --- CMakeLists.txt | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 508aea2e3..2f75c5838 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,7 +85,8 @@ mark_as_advanced( ZM_PERL_MM_PARMS ZM_PERL_SEARCH_PATH ZM_TARGET_DISTRO - ZM_CONFIG_DIR) + ZM_CONFIG_DIR + ZM_SYSTEMD) set(ZM_RUNDIR "/var/run/zm" CACHE PATH "Location of transient process files, default: /var/run/zm") @@ -148,6 +149,8 @@ set(ZM_PERL_SEARCH_PATH "" CACHE PATH installed outside Perl's default search path.") set(ZM_TARGET_DISTRO "" CACHE STRING "Build ZoneMinder for a specific distribution. Currently, valid names are: fc24, fc25, el6, el7, OS13, FreeBSD") +set(ZM_SYSTEMD "OFF" CACHE BOOL + "Set to ON to force building ZM with systemd support. default: OFF") # Reassign some variables if a target distro has been specified if((ZM_TARGET_DISTRO STREQUAL "fc24") OR (ZM_TARGET_DISTRO STREQUAL "fc25")) @@ -205,6 +208,11 @@ include_directories("${CMAKE_BINARY_DIR}") # This is required to enable searching in lib64 (if exists), do not change set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS ON) +# Set the systemd flag if systemd is autodetected or ZM_SYSTEMD has been set +if(ZM_SYSTEMD OR (IS_DIRECTORY /usr/lib/systemd/system) OR (IS_DIRECTORY /lib/systemd/system)) + set(WITH_SYSTEMD 1) +endif(ZM_SYSTEMD OR (IS_DIRECTORY /usr/lib/systemd/system) OR (IS_DIRECTORY /lib/systemd/system)) + # System checks check_include_file("libv4l1-videodev.h" HAVE_LIBV4L1_VIDEODEV_H) if(NOT HAVE_LIBV4L1_VIDEODEV_H) @@ -659,14 +667,14 @@ endif(NOT ZM_WEB_GROUP) message(STATUS "Using web user: ${ZM_WEB_USER}") message(STATUS "Using web group: ${ZM_WEB_GROUP}") -# Check for polkit -if(NOT BSD) +if(WITH_SYSTEMD) + # Check for polkit find_package(Polkit) if(NOT POLKIT_FOUND) - message(FATAL_ERROR + message(FATAL_ERROR "Running ZoneMinder requires polkit. Building ZoneMinder requires the polkit development package.") endif(NOT POLKIT_FOUND) -endif(NOT BSD) +endif(WITH_SYSTEMD) # Some variables that zm expects set(ZM_PID "${ZM_RUNDIR}/zm.pid") From 74dd8ab0279a45ac3537b3d23e5a55f05e03e51a Mon Sep 17 00:00:00 2001 From: abishai Date: Mon, 6 Feb 2017 09:57:22 +0300 Subject: [PATCH 6/6] make clang happy take two --- src/zm_monitor.cpp | 2 +- src/zmf.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index dd76e7845..e25649cff 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -222,7 +222,7 @@ bool Monitor::MonitorLink::disconnect() } } - if ( shmdt( mem_ptr ) < (void *)0 ) + if ( shmdt( mem_ptr ) < 0 ) { Debug( 3, "Can't shmdt: %s", strerror(errno) ); return( false ); diff --git a/src/zmf.cpp b/src/zmf.cpp index cf1810076..addf2f053 100644 --- a/src/zmf.cpp +++ b/src/zmf.cpp @@ -331,7 +331,7 @@ int main( int argc, char *argv[] ) Debug( 1, "Got image, writing to %s", path ); FILE *fd = 0; - if ( (fd = fopen( path, "w" )) < (void *)0 ) + if ( (fd = fopen( path, "w" )) == NULL ) { Error( "Can't fopen '%s': %s", path, strerror(errno) ); exit( -1 );