Commit Graph

127 Commits

Author SHA1 Message Date
Isaac Connor
133553e630 Revert "Merge pull request #3119 from Carbenium/fmt"
This reverts commit 90d930c7c3, reversing
changes made to 0bcb9d276f.
2022-02-27 14:05:14 -05:00
Isaac Connor
a2ae63cefe Merge branch 'master' into fmt 2021-11-16 15:10:45 -05:00
Isaac Connor
883772295d spacing and log the new log level string as well as number 2021-11-11 13:51:17 -05:00
Isaac Connor
b0cf3a4732 Merge pull request #3314 from Carbenium/path-max
Fix Wformat for stringtf and convert path buffers depending on PATH_MAX to std::string
2021-07-07 11:34:03 -04:00
Peter Keresztes Schmidt
eaf2e51b0c utils: Make sure the compiler can emit format warnings for stringtf
Unfortunately the compilers can't emit Wformat warnings for variadic templates
and those can't be annotated with the format attribute.
Use a variadic function which can be annotated and thus warns on format string-args mismatches.

Ref 0796a2262e
2021-07-06 10:33:17 +02:00
Peter Keresztes Schmidt
cf9c47149f db: Add helper for escaping strings and use it 2021-07-06 10:20:45 +02:00
Peter Keresztes Schmidt
b0b2f5fc16 Logger: Convert internals to std::chrono 2021-06-08 19:45:23 +02:00
Peter Keresztes Schmidt
e881e97c06 Logger: Fix DB log messages not being populated
We need to `resize` the buffer string since `reserve` does not guarantee that the buffer is
actually available.

Follow-up on 298415fff3
2021-05-22 10:52:57 +02:00
Peter Keresztes Schmidt
298415fff3 Remove remaining usages of VLAs 2021-05-17 22:12:04 +02:00
Isaac Connor
8f27db5d6f Do not stop dbQueue in logTerm. dbQueue is not just for logging. 2021-05-04 14:22:02 -04:00
Isaac Connor
59b1927ad6 do dbQUeue.stop in logTerm so we don't have to have an extra line in every executable 2021-05-01 14:49:33 -04:00
Peter Keresztes Schmidt
c3dd8d8a47 Logger: Annotate logPrint with format attribute
This allows the compiler to check for mismatches in the format string and the passed parameters.
2021-04-29 17:12:44 +02:00
Isaac Connor
c0c5c07ecf Quiet cppcheck issues 2021-04-20 12:59:59 -04:00
Peter Keresztes Schmidt
e330f8553d utils: cleanup Split and Join 2021-04-04 00:30:18 +02:00
Peter Keresztes Schmidt
4e8c7d1f7c Eliminate non-thread-safe calls to localtime
localtime uses an internal static storage to which a pointer is given as return value.
Due to this it is not safe to call localtime from multiple threads since the same static storage is used.

Use localtime_r instead which allows to pass in a tm struct.

Fixes:
https://github.com/ZoneMinder/zoneminder/security/code-scanning/24
https://github.com/ZoneMinder/zoneminder/security/code-scanning/25
https://github.com/ZoneMinder/zoneminder/security/code-scanning/26
https://github.com/ZoneMinder/zoneminder/security/code-scanning/27
https://github.com/ZoneMinder/zoneminder/security/code-scanning/28
https://github.com/ZoneMinder/zoneminder/security/code-scanning/30
https://github.com/ZoneMinder/zoneminder/security/code-scanning/31
https://github.com/ZoneMinder/zoneminder/security/code-scanning/33
https://github.com/ZoneMinder/zoneminder/security/code-scanning/58
https://github.com/ZoneMinder/zoneminder/security/code-scanning/59
https://github.com/ZoneMinder/zoneminder/security/code-scanning/63
https://github.com/ZoneMinder/zoneminder/security/code-scanning/64
https://github.com/ZoneMinder/zoneminder/security/code-scanning/65
2021-03-21 21:42:02 +01:00
Isaac Connor
ebf1b7cbdc Only output to stdout if mTerminalLevel is something. zms for example SHOULD not output to stdout, ever except maybe when running from terminal to debug 2021-03-16 13:26:06 -04:00
Isaac Connor
86a26ef3b1 nvsnprintf won't exceed the buffer but it can hit the end of it so adding the ending ]\n can overflow. Test and prevent. 2021-03-11 13:16:32 -05:00
Isaac Connor
f99b8896ec Don't unlock the mutex around openFile. It is a recursive mutex so we should be able to stay locked 2021-03-05 14:13:10 -05:00
Peter Keresztes Schmidt
d9568a98c0 Drop zm_thread which has been replaced by STL implementations 2021-03-04 10:55:46 +01:00
Peter Keresztes Schmidt
e18750bb79 logger: Pass std::string as ID during logInit 2021-03-01 22:43:02 +01:00
Peter Keresztes Schmidt
3dd52a92eb db: Make sure to bind only rvalues when pushing to zmDbQueue
With this we can ensure that no copy-construction of the SQL string takes place.
Regarding calling semantics: The pushed SQL string will be moved and cannot be reused.
2021-02-25 23:08:43 +01:00
Isaac Connor
8aeb4ab758 Switch db_mutex to a std::mutex. Use modern locking with it. Use zmDbDo or dbQueue.push where appropriate. code cleanup. 2021-02-25 12:26:26 -05:00
Isaac Connor
fdf515ca10 rough in a db queue thread. Use it in zm_logger so that we don't have to aquire the db lock 2021-02-24 19:59:55 -05:00
Isaac Connor
6f89eba154 add missing () 2021-02-24 13:48:59 -05:00
Isaac Connor
778a4f1d84 We cannot wait for the db lock. Do not wait. 2021-02-24 13:48:36 -05:00
Isaac Connor
9959464ef7 Fix ]\n being included in the db Logs entry. Also removes a strlen so performance should improve 2021-02-24 12:37:09 -05:00
Isaac Connor
58e3d96f8c Instead of using basename and doing a strdup etc, just use strrchr because the filepath is going to one of the sources files in zm. 2021-02-24 12:23:02 -05:00
Isaac Connor
6c013f0e65 Put back includes needed on FreeBSD. Fixes #3165 2021-02-22 08:03:10 -05:00
Peter Keresztes Schmidt
7e7b1a0b1f Logger: Try harder to obtain the DB lock
Since we are now multi-threaded it can happen quite easily that a log message should be written to the DB on one thread while the other thread executes another query. Don't bail out immediately in the logging code, instead try to obtain the lock within 1s.
2021-02-08 19:07:01 +01:00
Isaac Connor
583779438b Don't unlock db_mutex if we don't get the lock in the first place 2021-02-08 11:09:44 -05:00
Peter Keresztes Schmidt
cc6ea04afe Reformat touched code 2021-02-07 13:55:08 +01:00
Peter Keresztes Schmidt
aec4dbc6ff DB: Make connection initialization more predictable and avoid double-initialization
Remove calls to zmDBConnect from various places to avoid possible side-effects/double initialization.
The function should be called once from the main thread of the daemon.

Also split config loading into 2 steps: static and DB config loading. Load the static config before zmDBConnect is called so it has a chance to succeed.
2021-02-07 13:44:41 +01:00
Peter Keresztes Schmidt
0dbc39ee25 Cleanup and reorganize includes
With this commit a unified structure for includes is introduced.
The general rules:
 * Only include what you need
 * Include wherever possible in the cpp and forward-declare in the header

 The includes are sorted in a local to global fashion. This means for the include order:
  0. If cpp file: The corresponding h file and an empty line
  1. Includes from the project sorted alphabetically
  2. System/library includes sorted alphabetically
  3. Conditional includes
2021-02-04 18:02:01 +01:00
Peter Keresztes Schmidt
5a57efdfe2 Replace deprecated C header includes with the C++ ones. 2021-02-04 05:39:03 +01:00
Isaac Connor
3e9a2f2651 It is actually importatnt that smInstance get cleared. The subsequent new Logger will check for it. 2021-03-01 16:46:48 -05:00
Isaac Connor
48dcb23af0 small cleanup in logging 2020-12-31 09:14:03 -05:00
Isaac Connor
df783f4835 Merge branch 'master' into zma_to_thread 2020-11-12 12:53:55 -05:00
Isaac Connor
a63600ccef remove dead code 2020-10-30 16:09:24 -04:00
Isaac Connor
a39a656373 Merge branch 'master' into zma_to_thread 2020-09-29 11:02:40 -04:00
Peter Keresztes Schmidt
8f980a1168 Convert NULL/0 to nullptr
The 0 -> nullptr changes should definitely improve readability.
2020-08-26 22:03:40 +02:00
Isaac Connor
4ff341a0f5 Merge branch 'master' into zma_to_thread 2020-05-02 18:03:42 -04:00
Isaac Connor
6d4ed20745 Drop lock around openFile so that we don't hang 2020-03-04 14:14:28 -05:00
Isaac Connor
6da998b0c0 code comments and parenthesis 2020-01-10 16:42:18 -05:00
Isaac Connor
09fcbad666 Merge branch 'master' into zma_to_thread 2019-11-30 14:59:39 -05:00
Isaac Connor
33aa6abf59 Only open log file if we are going to write to it. 2019-09-17 11:36:57 -04:00
Isaac Connor
1a94479751 Cleanup/rework. Handle database connection failure. This can happen if we init logging before config reading. Default terminal log level to warning. Cleanup logInit copying the options in order to populate mLogPath from config. We can handle this in the constructor now. 2019-09-17 11:10:59 -04:00
Isaac Connor
077ad75516 Merge branch 'storageareas' into origin/zma_to_thread 2019-04-25 12:41:48 -04:00
Isaac Connor
293ec20824 Must unlock mutex before destructor as we do some logging in the mutex destructor when we destroy it while locked. 2019-04-15 17:54:17 -04:00
Isaac Connor
7c8b37e08c fix mutex hang on Fatal 2019-04-15 11:21:23 -04:00
Isaac Connor
f726666f54 Merge branch 'master' into h265 2019-01-14 12:36:11 -05:00