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
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
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
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
Isaac Connor
28dafd5931
Merge branch 'storageareas' into zma_to_thread
2018-12-26 12:02:00 -05:00
Isaac Connor
c89bb8bc16
Merge branch 'av_logging' into storageareas
2018-11-23 12:46:27 -05:00
Isaac Connor
4d4666f5e0
add a mutex in logging functions so that multiple threads can log at the same time
2018-11-23 12:45:41 -05:00
Isaac Connor
64ce035129
Merge branch 'av_logging' into storageareas
2018-11-14 17:03:32 -05:00
Isaac Connor
70d9fda758
Implement a logging callback for avcodec to use our logging functions
2018-11-14 17:02:52 -05:00
Isaac Connor
a8329465fb
Merge branch 'master' into h265
2018-10-22 10:30:01 -04:00
Isaac Connor
5ab1126260
Merge branch 'storageareas' into zma_to_thread
2018-10-20 17:31:14 -04:00
Isaac Connor
8f6db1c279
Merge branch 'master' into storageareas
2018-09-25 13:54:44 -04:00
Isaac Connor
b55224be30
fix setting mFlush. Just have it on for DEBUG levels
2018-09-24 14:17:16 -04:00
Isaac Connor
fd2e8a530c
When changing log levels by SIGUSR1 turn on flushing
2018-09-24 09:40:05 -04:00
Isaac Connor
89cd7ceaf8
Whitespace, extra parentheses, google code style
2018-09-23 16:47:06 -04:00
Isaac Connor
6b05515828
fix missing sql
2018-08-31 19:14:18 -04:00
Isaac Connor
672b4affe1
Merge branch 'storageareas' into zma_to_thread
2018-08-31 19:05:22 -04:00