 la_serva: fix memory/descriptor leaks, crashes and a DB-log deadlock
Leaks that grew without bound:
- Dead module connections were never removed (half-open TCP after a
module power loss / network drop): every one kept 3 threads, 8 MB of
socket buffers, a descriptor and a 10 ms DB poll. servaRPCHadnler now
drops a connection that sends nothing for RPC_IDLE_TIMEOUT_S (60 s;
la_mojo sends a status about every second), and accepted sockets get
TCP keepalive (30 s idle, 3 probes of 10 s).
- The client socket was only closed on an I/O error: a handler removed
for any other reason (module disabled / not registered, idle) leaked
its descriptor until accept() failed with EMFILE - which ended the
accept thread for good. ~serverPort now shuts down and closes it;
transient accept() errors (EMFILE, ENFILE, ENOMEM, ECONNABORTED,
EINTR, ...) no longer stop the server. recv() == 0 (peer closed) is
always a disconnect, whatever errno holds.
- servaSessionManager::reopenSession stored the reopened (expired)
session in the per-track map, overwriting the track's ACTIVE session:
its data and open report.db leaked and it was never closed in MySQL.
Reopened sessions are now kept outside the map and released by the
caller (addVideo, getSessionBase).
- servaVideoComposer leaked its session data, an open SQLite connection
and both video queues on every composition; servaKernel leaked a
composer whose compose() failed, never initialised / released the
automatic composer (it ran at most once) and leaked the media info
of every encoded video (processVideoFile success path).
Crashes / corruption:
- vector erase() with the old iterator reused (netServer client
cleanup, encoder / composer pools, 4 ModBus action loops).
- transportSocket::_close wrote the stop byte into the read end of the
pipe (threads only stopped at the 5 s select timeout, blocking the
accept thread on every disconnect) and left closed pipe numbers set
(a second _close could write into another connection's socket).
- Session map used without the lock from RPC, kernel and ModBus
threads: now a recursive mutex held for each public operation.
- Freeze on the first MySQL error with DB logging enabled: Query() logs
while holding the non-recursive DB mutex and the log service wrote
synchronously into the DB (same-thread and two-thread deadlock).
The DB log service now queues lines (max 1000) and writes them with
MySQL_Connector::TrySilentQuery (never blocks, never logs); reconnect
retries per query are bounded (3) instead of looping forever while
holding the mutex. The log line parser also skips the UTC offset.
- basicMutex::try_lock returned true when the lock was NOT taken: an
uncontended try_lock took the mutex and the caller never released it
(basicEngine, serial transport, ...).
- Kernel restart (web commands): the ModBus singleton was deleted but
not reset (next getInstance returned freed memory), the remote client
kept the deleted kernel and refused to start again, and
EXIT_CODE_RELOAD_SERVICES deleted the DB object every surviving
component still used. Now fixed / the DB object is kept.
- Life monitoring overflowed module_id[4] for platforms with > 4
modules; registerServA overflowed a 120-byte stack buffer, closed a
popen() stream with fclose and leaked the config; 9 config strings in
servaBackend were allocated one byte short; video chunk length is now
checked against the packet; "eased" events copied every field from
itself (all 0); networkServer freed libconfig's host string.
Minor: ModBus action list / sessions freed at shutdown, session-start
event payload freed if the event cannot be created, the per-second
"No History Auto Delete!" log line moved to DEBUG_EXTRA.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
44 minutes ago  la_serva: fix memory/descriptor leaks, crashes and a DB-log deadlock
Leaks that grew without bound:
- Dead module connections were never removed (half-open TCP after a
module power loss / network drop): every one kept 3 threads, 8 MB of
socket buffers, a descriptor and a 10 ms DB poll. servaRPCHadnler now
drops a connection that sends nothing for RPC_IDLE_TIMEOUT_S (60 s;
la_mojo sends a status about every second), and accepted sockets get
TCP keepalive (30 s idle, 3 probes of 10 s).
- The client socket was only closed on an I/O error: a handler removed
for any other reason (module disabled / not registered, idle) leaked
its descriptor until accept() failed with EMFILE - which ended the
accept thread for good. ~serverPort now shuts down and closes it;
transient accept() errors (EMFILE, ENFILE, ENOMEM, ECONNABORTED,
EINTR, ...) no longer stop the server. recv() == 0 (peer closed) is
always a disconnect, whatever errno holds.
- servaSessionManager::reopenSession stored the reopened (expired)
session in the per-track map, overwriting the track's ACTIVE session:
its data and open report.db leaked and it was never closed in MySQL.
Reopened sessions are now kept outside the map and released by the
caller (addVideo, getSessionBase).
- servaVideoComposer leaked its session data, an open SQLite connection
and both video queues on every composition; servaKernel leaked a
composer whose compose() failed, never initialised / released the
automatic composer (it ran at most once) and leaked the media info
of every encoded video (processVideoFile success path).
Crashes / corruption:
- vector erase() with the old iterator reused (netServer client
cleanup, encoder / composer pools, 4 ModBus action loops).
- transportSocket::_close wrote the stop byte into the read end of the
pipe (threads only stopped at the 5 s select timeout, blocking the
accept thread on every disconnect) and left closed pipe numbers set
(a second _close could write into another connection's socket).
- Session map used without the lock from RPC, kernel and ModBus
threads: now a recursive mutex held for each public operation.
- Freeze on the first MySQL error with DB logging enabled: Query() logs
while holding the non-recursive DB mutex and the log service wrote
synchronously into the DB (same-thread and two-thread deadlock).
The DB log service now queues lines (max 1000) and writes them with
MySQL_Connector::TrySilentQuery (never blocks, never logs); reconnect
retries per query are bounded (3) instead of looping forever while
holding the mutex. The log line parser also skips the UTC offset.
- basicMutex::try_lock returned true when the lock was NOT taken: an
uncontended try_lock took the mutex and the caller never released it
(basicEngine, serial transport, ...).
- Kernel restart (web commands): the ModBus singleton was deleted but
not reset (next getInstance returned freed memory), the remote client
kept the deleted kernel and refused to start again, and
EXIT_CODE_RELOAD_SERVICES deleted the DB object every surviving
component still used. Now fixed / the DB object is kept.
- Life monitoring overflowed module_id[4] for platforms with > 4
modules; registerServA overflowed a 120-byte stack buffer, closed a
popen() stream with fclose and leaked the config; 9 config strings in
servaBackend were allocated one byte short; video chunk length is now
checked against the packet; "eased" events copied every field from
itself (all 0); networkServer freed libconfig's host string.
Minor: ModBus action list / sessions freed at shutdown, session-start
event payload freed if the event cannot be created, the per-second
"No History Auto Delete!" log line moved to DEBUG_EXTRA.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
44 minutes ago  la_serva: fix memory/descriptor leaks, crashes and a DB-log deadlock
Leaks that grew without bound:
- Dead module connections were never removed (half-open TCP after a
module power loss / network drop): every one kept 3 threads, 8 MB of
socket buffers, a descriptor and a 10 ms DB poll. servaRPCHadnler now
drops a connection that sends nothing for RPC_IDLE_TIMEOUT_S (60 s;
la_mojo sends a status about every second), and accepted sockets get
TCP keepalive (30 s idle, 3 probes of 10 s).
- The client socket was only closed on an I/O error: a handler removed
for any other reason (module disabled / not registered, idle) leaked
its descriptor until accept() failed with EMFILE - which ended the
accept thread for good. ~serverPort now shuts down and closes it;
transient accept() errors (EMFILE, ENFILE, ENOMEM, ECONNABORTED,
EINTR, ...) no longer stop the server. recv() == 0 (peer closed) is
always a disconnect, whatever errno holds.
- servaSessionManager::reopenSession stored the reopened (expired)
session in the per-track map, overwriting the track's ACTIVE session:
its data and open report.db leaked and it was never closed in MySQL.
Reopened sessions are now kept outside the map and released by the
caller (addVideo, getSessionBase).
- servaVideoComposer leaked its session data, an open SQLite connection
and both video queues on every composition; servaKernel leaked a
composer whose compose() failed, never initialised / released the
automatic composer (it ran at most once) and leaked the media info
of every encoded video (processVideoFile success path).
Crashes / corruption:
- vector erase() with the old iterator reused (netServer client
cleanup, encoder / composer pools, 4 ModBus action loops).
- transportSocket::_close wrote the stop byte into the read end of the
pipe (threads only stopped at the 5 s select timeout, blocking the
accept thread on every disconnect) and left closed pipe numbers set
(a second _close could write into another connection's socket).
- Session map used without the lock from RPC, kernel and ModBus
threads: now a recursive mutex held for each public operation.
- Freeze on the first MySQL error with DB logging enabled: Query() logs
while holding the non-recursive DB mutex and the log service wrote
synchronously into the DB (same-thread and two-thread deadlock).
The DB log service now queues lines (max 1000) and writes them with
MySQL_Connector::TrySilentQuery (never blocks, never logs); reconnect
retries per query are bounded (3) instead of looping forever while
holding the mutex. The log line parser also skips the UTC offset.
- basicMutex::try_lock returned true when the lock was NOT taken: an
uncontended try_lock took the mutex and the caller never released it
(basicEngine, serial transport, ...).
- Kernel restart (web commands): the ModBus singleton was deleted but
not reset (next getInstance returned freed memory), the remote client
kept the deleted kernel and refused to start again, and
EXIT_CODE_RELOAD_SERVICES deleted the DB object every surviving
component still used. Now fixed / the DB object is kept.
- Life monitoring overflowed module_id[4] for platforms with > 4
modules; registerServA overflowed a 120-byte stack buffer, closed a
popen() stream with fclose and leaked the config; 9 config strings in
servaBackend were allocated one byte short; video chunk length is now
checked against the packet; "eased" events copied every field from
itself (all 0); networkServer freed libconfig's host string.
Minor: ModBus action list / sessions freed at shutdown, session-start
event payload freed if the event cannot be created, the per-second
"No History Auto Delete!" log line moved to DEBUG_EXTRA.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
44 minutes ago  la_serva: fix memory/descriptor leaks, crashes and a DB-log deadlock
Leaks that grew without bound:
- Dead module connections were never removed (half-open TCP after a
module power loss / network drop): every one kept 3 threads, 8 MB of
socket buffers, a descriptor and a 10 ms DB poll. servaRPCHadnler now
drops a connection that sends nothing for RPC_IDLE_TIMEOUT_S (60 s;
la_mojo sends a status about every second), and accepted sockets get
TCP keepalive (30 s idle, 3 probes of 10 s).
- The client socket was only closed on an I/O error: a handler removed
for any other reason (module disabled / not registered, idle) leaked
its descriptor until accept() failed with EMFILE - which ended the
accept thread for good. ~serverPort now shuts down and closes it;
transient accept() errors (EMFILE, ENFILE, ENOMEM, ECONNABORTED,
EINTR, ...) no longer stop the server. recv() == 0 (peer closed) is
always a disconnect, whatever errno holds.
- servaSessionManager::reopenSession stored the reopened (expired)
session in the per-track map, overwriting the track's ACTIVE session:
its data and open report.db leaked and it was never closed in MySQL.
Reopened sessions are now kept outside the map and released by the
caller (addVideo, getSessionBase).
- servaVideoComposer leaked its session data, an open SQLite connection
and both video queues on every composition; servaKernel leaked a
composer whose compose() failed, never initialised / released the
automatic composer (it ran at most once) and leaked the media info
of every encoded video (processVideoFile success path).
Crashes / corruption:
- vector erase() with the old iterator reused (netServer client
cleanup, encoder / composer pools, 4 ModBus action loops).
- transportSocket::_close wrote the stop byte into the read end of the
pipe (threads only stopped at the 5 s select timeout, blocking the
accept thread on every disconnect) and left closed pipe numbers set
(a second _close could write into another connection's socket).
- Session map used without the lock from RPC, kernel and ModBus
threads: now a recursive mutex held for each public operation.
- Freeze on the first MySQL error with DB logging enabled: Query() logs
while holding the non-recursive DB mutex and the log service wrote
synchronously into the DB (same-thread and two-thread deadlock).
The DB log service now queues lines (max 1000) and writes them with
MySQL_Connector::TrySilentQuery (never blocks, never logs); reconnect
retries per query are bounded (3) instead of looping forever while
holding the mutex. The log line parser also skips the UTC offset.
- basicMutex::try_lock returned true when the lock was NOT taken: an
uncontended try_lock took the mutex and the caller never released it
(basicEngine, serial transport, ...).
- Kernel restart (web commands): the ModBus singleton was deleted but
not reset (next getInstance returned freed memory), the remote client
kept the deleted kernel and refused to start again, and
EXIT_CODE_RELOAD_SERVICES deleted the DB object every surviving
component still used. Now fixed / the DB object is kept.
- Life monitoring overflowed module_id[4] for platforms with > 4
modules; registerServA overflowed a 120-byte stack buffer, closed a
popen() stream with fclose and leaked the config; 9 config strings in
servaBackend were allocated one byte short; video chunk length is now
checked against the packet; "eased" events copied every field from
itself (all 0); networkServer freed libconfig's host string.
Minor: ModBus action list / sessions freed at shutdown, session-start
event payload freed if the event cannot be created, the per-second
"No History Auto Delete!" log line moved to DEBUG_EXTRA.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
44 minutes ago  la_serva: fix memory/descriptor leaks, crashes and a DB-log deadlock
Leaks that grew without bound:
- Dead module connections were never removed (half-open TCP after a
module power loss / network drop): every one kept 3 threads, 8 MB of
socket buffers, a descriptor and a 10 ms DB poll. servaRPCHadnler now
drops a connection that sends nothing for RPC_IDLE_TIMEOUT_S (60 s;
la_mojo sends a status about every second), and accepted sockets get
TCP keepalive (30 s idle, 3 probes of 10 s).
- The client socket was only closed on an I/O error: a handler removed
for any other reason (module disabled / not registered, idle) leaked
its descriptor until accept() failed with EMFILE - which ended the
accept thread for good. ~serverPort now shuts down and closes it;
transient accept() errors (EMFILE, ENFILE, ENOMEM, ECONNABORTED,
EINTR, ...) no longer stop the server. recv() == 0 (peer closed) is
always a disconnect, whatever errno holds.
- servaSessionManager::reopenSession stored the reopened (expired)
session in the per-track map, overwriting the track's ACTIVE session:
its data and open report.db leaked and it was never closed in MySQL.
Reopened sessions are now kept outside the map and released by the
caller (addVideo, getSessionBase).
- servaVideoComposer leaked its session data, an open SQLite connection
and both video queues on every composition; servaKernel leaked a
composer whose compose() failed, never initialised / released the
automatic composer (it ran at most once) and leaked the media info
of every encoded video (processVideoFile success path).
Crashes / corruption:
- vector erase() with the old iterator reused (netServer client
cleanup, encoder / composer pools, 4 ModBus action loops).
- transportSocket::_close wrote the stop byte into the read end of the
pipe (threads only stopped at the 5 s select timeout, blocking the
accept thread on every disconnect) and left closed pipe numbers set
(a second _close could write into another connection's socket).
- Session map used without the lock from RPC, kernel and ModBus
threads: now a recursive mutex held for each public operation.
- Freeze on the first MySQL error with DB logging enabled: Query() logs
while holding the non-recursive DB mutex and the log service wrote
synchronously into the DB (same-thread and two-thread deadlock).
The DB log service now queues lines (max 1000) and writes them with
MySQL_Connector::TrySilentQuery (never blocks, never logs); reconnect
retries per query are bounded (3) instead of looping forever while
holding the mutex. The log line parser also skips the UTC offset.
- basicMutex::try_lock returned true when the lock was NOT taken: an
uncontended try_lock took the mutex and the caller never released it
(basicEngine, serial transport, ...).
- Kernel restart (web commands): the ModBus singleton was deleted but
not reset (next getInstance returned freed memory), the remote client
kept the deleted kernel and refused to start again, and
EXIT_CODE_RELOAD_SERVICES deleted the DB object every surviving
component still used. Now fixed / the DB object is kept.
- Life monitoring overflowed module_id[4] for platforms with > 4
modules; registerServA overflowed a 120-byte stack buffer, closed a
popen() stream with fclose and leaked the config; 9 config strings in
servaBackend were allocated one byte short; video chunk length is now
checked against the packet; "eased" events copied every field from
itself (all 0); networkServer freed libconfig's host string.
Minor: ModBus action list / sessions freed at shutdown, session-start
event payload freed if the event cannot be created, the per-second
"No History Auto Delete!" log line moved to DEBUG_EXTRA.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
44 minutes ago  la_serva: fix memory/descriptor leaks, crashes and a DB-log deadlock
Leaks that grew without bound:
- Dead module connections were never removed (half-open TCP after a
module power loss / network drop): every one kept 3 threads, 8 MB of
socket buffers, a descriptor and a 10 ms DB poll. servaRPCHadnler now
drops a connection that sends nothing for RPC_IDLE_TIMEOUT_S (60 s;
la_mojo sends a status about every second), and accepted sockets get
TCP keepalive (30 s idle, 3 probes of 10 s).
- The client socket was only closed on an I/O error: a handler removed
for any other reason (module disabled / not registered, idle) leaked
its descriptor until accept() failed with EMFILE - which ended the
accept thread for good. ~serverPort now shuts down and closes it;
transient accept() errors (EMFILE, ENFILE, ENOMEM, ECONNABORTED,
EINTR, ...) no longer stop the server. recv() == 0 (peer closed) is
always a disconnect, whatever errno holds.
- servaSessionManager::reopenSession stored the reopened (expired)
session in the per-track map, overwriting the track's ACTIVE session:
its data and open report.db leaked and it was never closed in MySQL.
Reopened sessions are now kept outside the map and released by the
caller (addVideo, getSessionBase).
- servaVideoComposer leaked its session data, an open SQLite connection
and both video queues on every composition; servaKernel leaked a
composer whose compose() failed, never initialised / released the
automatic composer (it ran at most once) and leaked the media info
of every encoded video (processVideoFile success path).
Crashes / corruption:
- vector erase() with the old iterator reused (netServer client
cleanup, encoder / composer pools, 4 ModBus action loops).
- transportSocket::_close wrote the stop byte into the read end of the
pipe (threads only stopped at the 5 s select timeout, blocking the
accept thread on every disconnect) and left closed pipe numbers set
(a second _close could write into another connection's socket).
- Session map used without the lock from RPC, kernel and ModBus
threads: now a recursive mutex held for each public operation.
- Freeze on the first MySQL error with DB logging enabled: Query() logs
while holding the non-recursive DB mutex and the log service wrote
synchronously into the DB (same-thread and two-thread deadlock).
The DB log service now queues lines (max 1000) and writes them with
MySQL_Connector::TrySilentQuery (never blocks, never logs); reconnect
retries per query are bounded (3) instead of looping forever while
holding the mutex. The log line parser also skips the UTC offset.
- basicMutex::try_lock returned true when the lock was NOT taken: an
uncontended try_lock took the mutex and the caller never released it
(basicEngine, serial transport, ...).
- Kernel restart (web commands): the ModBus singleton was deleted but
not reset (next getInstance returned freed memory), the remote client
kept the deleted kernel and refused to start again, and
EXIT_CODE_RELOAD_SERVICES deleted the DB object every surviving
component still used. Now fixed / the DB object is kept.
- Life monitoring overflowed module_id[4] for platforms with > 4
modules; registerServA overflowed a 120-byte stack buffer, closed a
popen() stream with fclose and leaked the config; 9 config strings in
servaBackend were allocated one byte short; video chunk length is now
checked against the packet; "eased" events copied every field from
itself (all 0); networkServer freed libconfig's host string.
Minor: ModBus action list / sessions freed at shutdown, session-start
event payload freed if the event cannot be created, the per-second
"No History Auto Delete!" log line moved to DEBUG_EXTRA.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
44 minutes ago |
|
#include "servaKernel.h"
#include <sys/types.h>
#include <sys/sysinfo.h>
#include <sys/statvfs.h>
#define LOG( X ) kernelPrototype::m_pLog->Log( "KRNL", this, X )
#ifdef DEBUG
#define LOG_ERROR( X ) {\
char _tBfrErrMSG234[256];\ sprintf( _tBfrErrMSG234, "In file %s[%d] in func:%s %s",__FILE__, __LINE__, __func__, X );\ kernelPrototype::m_pLog->Log( "KRNL", this, _LOG_ERROR, _tBfrErrMSG234 );\ }#else
#define LOG_ERROR( X ) kernelPrototype::m_pLog->Log( "KRNL", this, _LOG_ERROR, X );
#endif
bool servaKernel::cleanUpMess(){ LOG("Cleanup"); //Get Not transfered Items
DBC_UINT64_LIST *tList = m_pDBC->listMediaQueueItems( 0 ); if ( tList ) { LOG("1"); for ( DBC_UINT64_LIST::iterator idx = tList->begin(); idx < tList->end(); idx++ ) { LOG("*"); DBC_RPC_MEDIA_INFO_EX *tData = m_pDBC->getRemoteMediaInfoEx( *idx ); if ( tData ) { LOG("2"); CSTR tRB = m_pSM->getReportDir( m_pDBC->getSessionTrackId( tData->session_id ), tData->ts ); if ( tRB ) { LOG("3"); char tName[MAX_PATH]; sprintf( tName, "%s/%s.%s", tRB, tData->uuid, tData->fmt ); LOG( tName ); free( tRB ); unlink( tName ); }; LOG("f"); free( tData ); }; m_pDBC->removeRemoteMediaInfo( *idx ); }; LOG("-"); tList->clear(); delete( tList ); }; LOG("LVL2"); //Get Not Converted Items
tList = m_pDBC->listMediaQueueItems( 2 ); if ( tList ) { LOG("1"); for ( DBC_UINT64_LIST::iterator idx = tList->begin(); idx < tList->end(); idx++ ) { LOG("*"); DBC_RPC_MEDIA_INFO_EX *tData = m_pDBC->getRemoteMediaInfoEx( *idx ); if ( tData ) { LOG("2"); CSTR tRB = m_pSM->getReportDir( m_pDBC->getSessionTrackId( tData->session_id ), tData->ts ); LOG("2a"); if ( tRB ) { LOG("3"); char tName[MAX_PATH]; sprintf( tName, "%s/%s.%s", tRB, tData->uuid, "mp4" ); free( tRB ); LOG( tName ); unlink( tName ); }; LOG("f"); free( tData ); }; m_pDBC->updateEncodeStatus( *idx, 1, 0 ); }; tList->clear(); delete( tList ); }; LOG("Close all Staled Sessions");
LOG("Done"); return true;};
bool servaKernel::registerServA(){ DBC_SERVA_CONFIG *tData = m_pDBC->getServaConfig(); if ( tData ) { memcpy(&m_sServaConfig, tData, sizeof(DBC_SERVA_CONFIG)); free( tData ); // was leaked
} else { memset(&m_sServaConfig, 0, sizeof(DBC_SERVA_CONFIG)); m_sServaConfig.encoderLimit = 1;
};
m_pDBC->setServerStatValue( SERVER_VERSION, _BUILD_STRING_ ); m_pDBC->setSystemProp("version_string", _BUILD_STRING_ );#ifndef NO_EXEC_EXTERNALS
char OS_INFO[128]; // was 120 while fgets() wrote up to 127 bytes and [127] was set: stack overflow
OS_INFO[0] = (char)0; FILE *fd = popen("/bin/uname -s -r -v -m","r"); if( fd!= NULL ) { if ( fgets( OS_INFO, sizeof( OS_INFO ), fd ) == NULL ) OS_INFO[0] = (char)0; OS_INFO[sizeof( OS_INFO ) - 1] = (char)0; trim( OS_INFO ); pclose( fd ); // popen() streams must be closed with pclose() (fclose leaves a zombie process)
fd = NULL; m_pDBC->setServerStatValue( SERVER_OS, OS_INFO ); m_pDBC->setSystemProp("os_info", (CSTR) OS_INFO ); } else { m_pDBC->setServerStatValue( SERVER_OS, "Linux" ); m_pDBC->setSystemProp("os_info", "Linux" ); };#else
FILE *fd = NULL; m_pDBC->setServerStatValue( SERVER_OS, "Linux" ); m_pDBC->setSystemProp("os_info", "Linux" );#endif
char HW_INFO[128]; fd = fopen("/proc/cpuinfo","r"); if ( fd!= NULL ) { char tBB[1024]; bool bARM = false; while( !feof( fd ) ) { fgets( tBB, 1024, fd ); trim( tBB ); if( strcasestr(tBB, "model") != NULL ) { if( strcasestr(tBB, "model name") != NULL ) { if ( !bARM ) { if( strcasestr( tBB, "ARM" ) != NULL){ bARM = true; } else { CArray *tA = explode(':', tBB ); if ( tA ) { strncpy( HW_INFO, tA->at(1), 127 ); delete tA; }; break; }; }; } else { if( bARM ) { CArray *tA = explode(':', tBB); if ( tA ) { strncpy( HW_INFO, tA->at(1), 127 ); delete tA; }; break; }; }; }; }; HW_INFO[127] = (char)0; trim( HW_INFO ); fclose( fd ); fd = NULL; }; m_pDBC->setSystemProp("hw_info", (CSTR) HW_INFO ); m_pDBC->setServerStatValue( SERVER_HW, (CSTR) HW_INFO ); m_pDBC->setServerStatValue( SERVER_START_TS, (uint32_t) time(NULL) ); return true;};
bool servaKernel::updateStatus(){ struct sysinfo SI; struct statvfs DI; DBC_SYS_LOAD_INFO info = { 0 }; info.CPU_CORES = get_nprocs(); info.C_TS = (uint32_t) time(NULL);
if( sysinfo( &SI ) == 0 ){ float f_load = 100.f / (float)( info.CPU_CORES * ( 1 << SI_LOAD_SHIFT ) ); info.cpu1 = SI.loads[0] * f_load; info.cpu5 = SI.loads[1] * f_load; info.cpu15 = SI.loads[2] * f_load; info.T_MEM = SI.totalram; info.C_MEM = SI.totalram - SI.freeram; info.mem = 100.0f * (float)info.C_MEM / (float)info.T_MEM; } else { LOG_ERROR("Error while getting System Info!"); }; //const uint32_t MB = 1 << 10;//(1024 * 1024);// * 1024;
if( statvfs("/", &DI) == 0 ){ info.T_DISK = ( DI.f_blocks * (unsigned long long) DI.f_frsize ) >> 10;// / MB;
//cDISK = ( DI.f_bavail * (unsigned long long) DI.f_bsize ) >> 10;// / MB;
info.C_DISK = info.T_DISK - ( ( DI.f_bfree * (unsigned long long) DI.f_bsize ) >> 10 ); info.disk = 100.0f * (float)info.C_DISK / (float)info.T_DISK; } else { LOG_ERROR("Error while getting Disk Info!"); }; //Check if need to erase some reports
if ( m_sServaConfig.historyAutoDeleteLimit ) {#ifdef DEBUG_EXTRA
LOG("History Auto Delete is set!");#endif
if (m_sServaConfig.historyPreserveFreeSpacePerc || m_sServaConfig.historyPreserveFreeSpaceMB) {#ifdef DEBUG_EXTRA
LOG("History Size is set!");#endif
uint64_t tid = 0; if ( m_sServaConfig.historyPreserveFreeSpacePerc > ( 100.0f - info.disk ) ) { tid = m_pDBC->getSessionOldest( m_sServaConfig.historyAutoDeleteLimit ); } else if ( m_sServaConfig.historyPreserveFreeSpaceMB > ( info.T_DISK - info.C_DISK ) ) { tid = m_pDBC->getSessionOldest( m_sServaConfig.historyAutoDeleteLimit ); }; if ( tid ) {#ifdef DEBUG_EXTRA
LOG("Need to Delete some Sessions!");#endif
m_pSM->eraseSession( tid );#ifdef DEBUG_EXTRA
LOG("Delete Session Done!");#endif
};#ifdef DEBUG_EXTRA
} else { LOG("No History Size is set!");#endif
}; if ( m_sServaConfig.historyDaysLimit ) {#ifdef DEBUG_EXTRA
LOG("History Time is set!");#endif
uint32_t cts = time( NULL ) - (m_sServaConfig.historyDaysLimit * 86400); uint64_t tid = m_pDBC->getSessionOlderThan( cts, m_sServaConfig.historyAutoDeleteLimit ); if ( tid ) {#ifdef DEBUG_EXTRA
LOG("Need to Delete some Sessions!");#endif
m_pSM->eraseSession( tid );#ifdef DEBUG_EXTRA
LOG("Delete Session Done!");#endif
};#ifdef DEBUG_EXTRA
} else { LOG("No History Time Limit is set!");#endif
};#ifdef DEBUG_EXTRA
} else { LOG("No History Auto Delete!"); // every second: ~86400 log lines (and DB log rows) a day in DEBUG builds
#endif
}; //Temperature reading
info.temperature = -1; if( fileExist( "/sys/class/thermal" ) ) { char tB[128]; // Check first 8 zones to find CPU one
for ( uint8_t i = 0; i < 8; i++ ) { sprintf( tB, "/sys/class/thermal/thermal_zone%d", i ); if ( fileExist( tB ) ) { sprintf( tB, "/sys/class/thermal/thermal_zone%d/type", i ); if ( fileExist( tB ) ) { FILE *fd = fopen( tB, "r" ); readLine( fd, tB, 128 ); fclose(fd); if ( strcasestr(tB,"cpu")!=NULL || strcasestr(tB,"x86_pkg")!=NULL || strcasestr(tB,"acpitz")!=NULL ) { sprintf( tB, "/sys/class/thermal/thermal_zone%d/temp", i ); FILE *fd = fopen( tB, "r" ); readLine( fd, tB, 128 ); fclose(fd); info.temperature = ((float) atoll( tB )) / 1000.0f; break; }; } else continue; } else break; }; }; return m_pDBC->updateServerUtilisation( &info );};
#undef LOG
#undef LOG_ERROR
|