From 1a6b26f2abfe89d1f5298370492c54fbf2a54676 Mon Sep 17 00:00:00 2001 From: Peter Keresztes Schmidt Date: Tue, 2 Feb 2021 21:08:05 +0100 Subject: [PATCH 1/5] build: Add fmt as a required dependency --- .cirrus.yml | 2 +- .github/workflows/codeql-analysis.yml | 2 +- CMakeLists.txt | 2 ++ distros/redhat/zoneminder.spec | 2 ++ distros/ubuntu2004/control | 2 ++ 5 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index 98047298e..117aadf78 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -4,7 +4,7 @@ task: image_family: freebsd-12-2 prepare_script: - - pkg install -yq git cmake jpeg-turbo mysql80-client ffmpeg libvncserver libjwt catch p5-DBI p5-DBD-mysql p5-Date-Manip p5-Test-LWP-UserAgent p5-Sys-Mmap + - pkg install -yq git cmake jpeg-turbo mysql80-client ffmpeg libvncserver libjwt libfmt catch p5-DBI p5-DBD-mysql p5-Date-Manip p5-Test-LWP-UserAgent p5-Sys-Mmap configure_script: - git submodule update --init --recursive diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index aed08288d..1efdaf96b 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -54,7 +54,7 @@ jobs: sudo apt-get update sudo apt-get install libx264-dev libmp4v2-dev libavdevice-dev libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev sudo apt-get install libbz2-dev libgcrypt20-dev libcurl4-gnutls-dev libjpeg-turbo8-dev libturbojpeg0-dev - sudo apt-get install default-libmysqlclient-dev libpcre3-dev libpolkit-gobject-1-dev libv4l-dev libvlc-dev + sudo apt-get install default-libmysqlclient-dev libpcre3-dev libpolkit-gobject-1-dev libv4l-dev libvlc-dev libfmt-dev sudo apt-get install libdate-manip-perl libdbd-mysql-perl libphp-serialization-perl libsys-mmap-perl sudo apt-get install libwww-perl libdata-uuid-perl libssl-dev libcrypt-eksblowfish-perl libdata-entropy-perl diff --git a/CMakeLists.txt b/CMakeLists.txt index 9acaedc9b..c3fc4ae8f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -644,6 +644,8 @@ else() set(HAVE_RTSP_SERVER 0) endif() +find_package(fmt REQUIRED) + # # *** END OF LIBRARY CHECKS *** diff --git a/distros/redhat/zoneminder.spec b/distros/redhat/zoneminder.spec index b0b3c1abe..86b72b74f 100644 --- a/distros/redhat/zoneminder.spec +++ b/distros/redhat/zoneminder.spec @@ -83,6 +83,7 @@ BuildRequires: libv4l-devel BuildRequires: desktop-file-utils BuildRequires: gzip BuildRequires: zlib-devel +BuildRequires: fmt-devel # ZoneMinder looks for and records the location of the ffmpeg binary during build BuildRequires: ffmpeg @@ -131,6 +132,7 @@ Requires: perl(Net::FTP) Requires: perl(LWP::Protocol::https) Requires: ca-certificates Requires: zip +Requires: fmt %{?systemd_requires} Requires(post): %{_bindir}/gpasswd diff --git a/distros/ubuntu2004/control b/distros/ubuntu2004/control index 28c9374a1..e02ff0e14 100644 --- a/distros/ubuntu2004/control +++ b/distros/ubuntu2004/control @@ -32,6 +32,7 @@ Build-Depends: debhelper (>= 12), sphinx-doc, python3-sphinx, dh-linktree, dh-ap ,libcrypt-eksblowfish-perl ,libdata-entropy-perl ,libvncserver-dev + ,libfmt-dev Standards-Version: 4.5.0 Homepage: https://www.zoneminder.com/ @@ -74,6 +75,7 @@ Depends: ${shlibs:Depends}, ${misc:Depends}, ${perl:Depends} ,libcrypt-eksblowfish-perl ,libdata-entropy-perl ,libvncclient1|libvncclient0 + ,libfmt Recommends: ${misc:Recommends} ,libapache2-mod-php | php-fpm ,default-mysql-server | mariadb-server | virtual-mysql-server From 589e5fec26d4cb1ccdab257f819deab0dbefc956 Mon Sep 17 00:00:00 2001 From: Peter Keresztes Schmidt Date: Tue, 2 Feb 2021 16:20:17 +0100 Subject: [PATCH 2/5] zms: Use fmt to construct the log ID --- src/CMakeLists.txt | 1 + src/zms.cpp | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 46c1a0368..94eea7e67 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -108,6 +108,7 @@ target_link_libraries(zms PRIVATE zm-core-interface zm + fmt::fmt ${ZM_EXTRA_LIBS} ${ZM_BIN_LIBS} ${CMAKE_DL_LIBS}) diff --git a/src/zms.cpp b/src/zms.cpp index 01df67fc7..b462e1352 100644 --- a/src/zms.cpp +++ b/src/zms.cpp @@ -24,6 +24,7 @@ #include "zm_monitorstream.h" #include "zm_eventstream.h" #include "zm_fifo.h" +#include #include bool ValidateAccess(User *user, int mon_id) { @@ -81,8 +82,7 @@ int main(int argc, const char *argv[], char **envp) { nph = true; } - char log_id_string[32] = "zms"; - logInit(log_id_string); + logInit("zms"); zmLoadStaticConfig(); zmDbConnect(); zmLoadDBConfig(); @@ -181,12 +181,13 @@ int main(int argc, const char *argv[], char **envp) { } // end if possible parameter names } // end foreach parm + std::string logId; if ( monitor_id ) { - snprintf(log_id_string, sizeof(log_id_string), "zms_m%d", monitor_id); + logId = fmt::format("zms_m{}", monitor_id); } else { - snprintf(log_id_string, sizeof(log_id_string), "zms_e%" PRIu64, event_id); + logId = fmt::format("zms_e{}", event_id); } - logInit(log_id_string); + logInit(logId.c_str()); if ( config.opt_use_auth ) { User *user = nullptr; From 6dc132df27858f4b8801417bc501a8d68038cb46 Mon Sep 17 00:00:00 2001 From: Peter Keresztes Schmidt Date: Tue, 2 Feb 2021 16:29:55 +0100 Subject: [PATCH 3/5] zmc: Use fmt to construct the log ID --- src/CMakeLists.txt | 1 + src/zmc.cpp | 17 +++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 94eea7e67..f4167dd8e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -92,6 +92,7 @@ target_link_libraries(zmc PRIVATE zm-core-interface zm + fmt::fmt ${ZM_EXTRA_LIBS} ${ZM_BIN_LIBS} ${CMAKE_DL_LIBS}) diff --git a/src/zmc.cpp b/src/zmc.cpp index b197e5019..578841729 100644 --- a/src/zmc.cpp +++ b/src/zmc.cpp @@ -63,6 +63,7 @@ possible, this should run at more or less constant speed. #include "zm_signal.h" #include "zm_time.h" #include "zm_utils.h" +#include #include #include @@ -169,24 +170,24 @@ int main(int argc, char *argv[]) { exit(0); } - char log_id_string[32] = ""; + std::string logId; if ( device[0] ) { const char *slash_ptr = strrchr(device, '/'); - snprintf(log_id_string, sizeof(log_id_string), "zmc_d%s", slash_ptr?slash_ptr+1:device); + logId = fmt::format("zmc_d{}", slash_ptr ? slash_ptr + 1 : device); } else if ( host[0] ) { - snprintf(log_id_string, sizeof(log_id_string), "zmc_h%s", host); + logId = fmt::format("zmc_h{}", host); } else if ( file[0] ) { const char *slash_ptr = strrchr(file, '/'); - snprintf(log_id_string, sizeof(log_id_string), "zmc_f%s", slash_ptr?slash_ptr+1:file); + logId = fmt::format("zmc_f{}", slash_ptr ? slash_ptr + 1 : file); } else { - snprintf(log_id_string, sizeof(log_id_string), "zmc_m%d", monitor_id); + logId = fmt::format("zmc_m{}", monitor_id); } - logInit(log_id_string); + logInit(logId.c_str()); zmLoadStaticConfig(); zmDbConnect(); zmLoadDBConfig(); - logInit(log_id_string); + logInit(logId.c_str()); hwcaps_detect(); @@ -409,7 +410,7 @@ int main(int argc, char *argv[]) { monitor->Reload(); } logTerm(); - logInit(log_id_string); + logInit(logId.c_str()); zm_reload = false; } // end if zm_reload } // end while ! zm_terminate outer connection loop From e18750bb795fa7e96f11515534ccf22f595165f3 Mon Sep 17 00:00:00 2001 From: Peter Keresztes Schmidt Date: Tue, 2 Feb 2021 16:36:42 +0100 Subject: [PATCH 4/5] logger: Pass std::string as ID during logInit --- src/zm_logger.cpp | 4 ++-- src/zm_logger.h | 4 ++-- src/zmc.cpp | 6 +++--- src/zms.cpp | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/zm_logger.cpp b/src/zm_logger.cpp index 16f66835c..aef3e45fa 100644 --- a/src/zm_logger.cpp +++ b/src/zm_logger.cpp @@ -556,13 +556,13 @@ void Logger::logPrint(bool hex, const char * const filepath, const int line, con } } // end logPrint -void logInit(const char *name, const Logger::Options &options) { +void logInit(const std::string &id, const Logger::Options &options) { if (Logger::smInstance) { delete Logger::smInstance; } Logger::smInstance = new Logger(); - Logger::smInstance->initialise(name, options); + Logger::smInstance->initialise(id, options); } void logTerm() { diff --git a/src/zm_logger.h b/src/zm_logger.h index ee358b206..80b6e7ba7 100644 --- a/src/zm_logger.h +++ b/src/zm_logger.h @@ -137,7 +137,7 @@ private: static void usrHandler(int sig); public: - friend void logInit(const char *name, const Options &options); + friend void logInit(const std::string &id, const Options &options); friend void logTerm(); static Logger *fetch() { @@ -177,7 +177,7 @@ public: void logPrint(bool hex, const char * const filepath, const int line, const int level, const char *fstring, ...); }; -void logInit(const char *name, const Logger::Options &options=Logger::Options()); +void logInit(const std::string &id, const Logger::Options &options=Logger::Options()); void logTerm(); inline const std::string &logId() { return Logger::fetch()->id(); diff --git a/src/zmc.cpp b/src/zmc.cpp index 578841729..fc3fe78a3 100644 --- a/src/zmc.cpp +++ b/src/zmc.cpp @@ -183,11 +183,11 @@ int main(int argc, char *argv[]) { logId = fmt::format("zmc_m{}", monitor_id); } - logInit(logId.c_str()); + logInit(logId); zmLoadStaticConfig(); zmDbConnect(); zmLoadDBConfig(); - logInit(logId.c_str()); + logInit(logId); hwcaps_detect(); @@ -410,7 +410,7 @@ int main(int argc, char *argv[]) { monitor->Reload(); } logTerm(); - logInit(logId.c_str()); + logInit(logId); zm_reload = false; } // end if zm_reload } // end while ! zm_terminate outer connection loop diff --git a/src/zms.cpp b/src/zms.cpp index b462e1352..9ad8f32c8 100644 --- a/src/zms.cpp +++ b/src/zms.cpp @@ -187,7 +187,7 @@ int main(int argc, const char *argv[], char **envp) { } else { logId = fmt::format("zms_e{}", event_id); } - logInit(logId.c_str()); + logInit(logId); if ( config.opt_use_auth ) { User *user = nullptr; From 4027520b944e4cbddf92db3e1629ac1a8bf83fa9 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 16 Nov 2021 15:19:30 -0500 Subject: [PATCH 5/5] fix removed libfmt-dev package --- .github/workflows/codeql-analysis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 80b4f9bf2..9406c40c0 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -55,7 +55,7 @@ jobs: sudo apt-get install libavcodec-dev libavformat-dev libavutil-dev libswresample-dev libswscale-dev libjwt-gnutls-dev sudo apt-get install libbz2-dev libcurl4-gnutls-dev libjpeg-turbo8-dev libturbojpeg0-dev - sudo apt-get install default-libmysqlclient-dev libpcre3-dev libpolkit-gobject-1-dev libv4l-dev libvlc-dev ab9c538c3 + sudo apt-get install default-libmysqlclient-dev libpcre3-dev libpolkit-gobject-1-dev libv4l-dev libvlc-dev libfmt-dev sudo apt-get install libdate-manip-perl libdbd-mysql-perl libphp-serialization-perl libsys-mmap-perl sudo apt-get install libwww-perl libdata-uuid-perl libssl-dev libcrypt-eksblowfish-perl libdata-entropy-perl