You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.2 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
watchDogDaemon: line buffer, end on client EOF, handler cleanup; la_mojo sends getpid() watchDogDaemon (kernel.cpp) - Client lines are assembled in a buffer. readLine() on the non-blocking socket dropped the bytes of a line that had only partly arrived. - EOF (client closed or crashed without "-1") ends the monitoring of that client. Before, EOF read as "no data", and after the deadline kill(9) went to a PID that may belong to another process by then. - The handler record is zeroed. "finished" was uninitialized (malloc), so the accept loop could pthread_join() a live handler and block. - Finished handlers are joined, freed and erased correctly. erase() inside the for loop skipped the next one, and the records were never freed. A record whose thread could not be created is freed. pthread_create() returns an error number, not -1. - The bind() result is checked. - The log says which PID is watched or stopped, and for a stall how long ago the last update was ("WD update STALLED! (PID n, last update N ms ago)"). kernelPrototype - Sends getpid() as the PID to kill (was gettid(): the same value only in the main thread). Tested with the rebuilt daemon: the kernel scenarios as before (normal, 6 s step: not killed; hang: killed). A client that closes without "-1": its process isn't killed later. An update split into 3 pieces, 6 times with a 4 s deadline: understood, not killed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0139veDo3XyavMuVhdnHcN16
8 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #ifndef __START_PROC_KERNEL_HEADER__
  2. #define __START_PROC_KERNEL_HEADER__
  3. #include "../../lib/components/base/basicSettingsProvider.h"
  4. #include "../../lib/components/base/basicThread.h"
  5. class SP_KERNEL;
  6. #define SW_DEFAULT_TIMEOUT 180000 // 180 seconds
  7. #define SW_TIMEOUT_PERCISION 100 // 0.1 second
  8. #define INVALID_SOCKET -1
  9. typedef struct S_WATCHDOG_PROC_REC
  10. {
  11. SP_KERNEL * master;
  12. int client_socket;
  13. uint64_t timeout;
  14. volatile bool finished;
  15. pthread_t handler;
  16. } WATCHDOG_PROC_REC;
  17. typedef std::vector<WATCHDOG_PROC_REC *> WATCHDOG_PROCS_VECTOR;
  18. class SP_KERNEL : public basicThread
  19. {
  20. protected:
  21. virtual void m_fThreadProc(void);
  22. public:
  23. static SP_KERNEL * getInstance(bool ColdStart = true);
  24. bool create(void);
  25. int getExitCause()
  26. {
  27. return m_iExitCause;
  28. }
  29. void WaitFinish(bool force);
  30. ~SP_KERNEL();
  31. private:
  32. int m_iServerSocket;
  33. int m_iExitCause;
  34. WATCHDOG_PROCS_VECTOR m_vWPV;
  35. static SP_KERNEL * _instance;
  36. static void * sw_proc(void *);
  37. void wd_shutdown(void);
  38. SP_KERNEL();
  39. basicLogCollection * m_pLog;
  40. config_setting_t * m_pSettings;
  41. char m_pUnixSocketName[PATH_MAX];
  42. };
  43. #endif