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.

452 lines
13 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
9 hours ago
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
9 hours ago
​
​
​
​
​
​
​
​
​
​
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
9 hours ago
​
​
​
​
​
​
​
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
9 hours ago
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
9 hours ago
​
​
​
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
9 hours ago
​
​
​
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
9 hours ago
​
​
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
9 hours ago
​
​
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
9 hours ago
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
9 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
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
9 hours ago
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
9 hours ago
​
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
9 hours ago
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
9 hours ago
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
9 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
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
9 hours ago
​
​
​
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
9 hours ago
​
​
​
​
​
​
​
​
​
​
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
9 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
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
9 hours ago
​
​
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
9 hours ago
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
9 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
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
9 hours ago
​
​
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
9 hours ago
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
9 hours ago
​
​
​
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
9 hours ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "kernel.h"
  2. #define LOG(X) m_pLog->Log("KERNEL", this, X)
  3. #define LOG_ERROR(X) m_pLog->Log("KERNEL", this, _LOG_ERROR, X)
  4. SP_KERNEL * SP_KERNEL::_instance = NULL;
  5. SP_KERNEL * SP_KERNEL::getInstance(bool ColdStart)
  6. {
  7. if (_instance == NULL)
  8. {
  9. _instance = new SP_KERNEL();
  10. };
  11. return _instance;
  12. }
  13. SP_KERNEL::SP_KERNEL() :
  14. basicThread()
  15. {
  16. m_pLog = basicLogCollection::getInstance();
  17. m_pSettings = basicSettingsProvider::getInstance()->getSubNode(NULL, (CSTR) "KERNEL");
  18. m_iServerSocket = INVALID_SOCKET;
  19. m_iExitCause = 0;
  20. }
  21. SP_KERNEL::~SP_KERNEL()
  22. {
  23. if (m_iServerSocket != INVALID_SOCKET)
  24. {
  25. shutdown(m_iServerSocket, 2);
  26. close(m_iServerSocket);
  27. if (fileExist(m_pUnixSocketName))
  28. {
  29. unlink(m_pUnixSocketName);
  30. }
  31. };
  32. }
  33. void SP_KERNEL::wd_shutdown(void)
  34. {
  35. m_bThreadStatus = TH_ENDED;
  36. m_iExitCause = 33;
  37. }
  38. // Use Killall prior to kill all instances of mojo
  39. // https://stackoverflow.com/questions/8166415/how-to-get-the-pid-of-a-process-in-linux-in-c
  40. #include <sys/param.h>
  41. #include <sys/user.h>
  42. // #include <sys/sysctl.h>
  43. #include <stdio.h>
  44. #include <stdlib.h>
  45. #include <sys/socket.h>
  46. #include <sys/un.h>
  47. // https://www.educative.io/answers/unix-socket-programming-in-c
  48. /************************************************************************
  49. *
  50. * Returns the pid of the process name which is given as the function
  51. * argument.
  52. * In case no process found with the given name -1 will be returned.
  53. *
  54. ************************************************************************* /
  55. pid_t getProcessId(const char * csProcessName){
  56. struct kinfo_proc * sProcesses = NULL;
  57. struct kinfo_proc * sNewProcesses = NULL;
  58. pid_t iCurrentPid;
  59. int aiNames[4];
  60. size_t iNamesLength;
  61. int i, iRetCode, iNumProcs;
  62. size_t iSize = 0;
  63. aiNames[0] = CTL_KERN;
  64. aiNames[1] = KERN_PROC;
  65. aiNames[2] = KERN_PROC_ALL;
  66. aiNames[3] = 0;
  67. iNamesLength = 3;
  68. iRetCode = sysctl( aiNames, iNamesLength, NULL, &iSize, NULL, 0 );
  69. /*
  70. * Allocate memory and populate info in the processes structure
  71. * /
  72. do {
  73. iSize += iSize / 10;
  74. sNewProcesses = (struct kinfo_proc *) realloc( sProcesses, iSize );
  75. if( sNewProcesses == 0 ){
  76. if( sProcesses ) free(sProcesses);
  77. errx(1, "could not reallocate memory");
  78. };
  79. sProcesses = sNewProcesses;
  80. iRetCode = sysctl(aiNames, iNamesLength, sProcesses, &iSize, NULL, 0);
  81. } while ( iRetCode == -1 && errno == ENOMEM );
  82. iNumProcs = iSize / sizeof(struct kinfo_proc);
  83. /*
  84. * Search for the given process name and return its pid.
  85. * /
  86. for (i = 0; i < iNumProcs; i++) {
  87. iCurrentPid = sProcesses[i].kp_proc.p_pid;
  88. if( strncmp(csProcessName, sProcesses[i].kp_proc.p_comm, MAXCOMLEN) == 0 ) {
  89. free(sProcesses);
  90. return iCurrentPid;
  91. }
  92. }
  93. /*
  94. * Clean up and return -1 because the given proc name was not found
  95. * /
  96. free(sProcesses);
  97. return (-1);
  98. } /* end of getProcessId() * /
  99. int main(int argc, char **argv)
  100. {
  101. int pid = 0;
  102. pid = getProcessId( argv[1] );
  103. if( pid < 0 ){
  104. printf("process [%s] not found in the system\n", argv[1]);
  105. } else {
  106. printf("pid of [%s] is %d\n", argv[1], pid);
  107. }
  108. }
  109. */
  110. bool SP_KERNEL::create(void)
  111. {
  112. char tBuffer[PATH_MAX];
  113. if (m_pSettings != NULL)
  114. {
  115. config_setting_t * pSetting;
  116. int tVal;
  117. const char * tBuf;
  118. LOG("Getting Settings ...");
  119. if (! config_setting_lookup_string(m_pSettings, "SOCKET_PATH", &tBuf))
  120. {
  121. LOG("Socket Path not defined - generating dummy!");
  122. sprintf(m_pUnixSocketName, "/srv/etc/watchdog");
  123. pSetting = config_setting_add(m_pSettings, "SOCKET_PATH", CONFIG_TYPE_STRING);
  124. config_setting_set_string(pSetting, m_pUnixSocketName);
  125. basicSettingsProvider::getInstance()->compromise();
  126. }
  127. else
  128. {
  129. sprintf(m_pUnixSocketName, tBuf);
  130. sprintf(tBuffer, "Socket Path From Settings: %s", tBuf);
  131. LOG(tBuffer);
  132. };
  133. /*
  134. if( !config_setting_lookup_string( m_pSettings, "TARGET_APP_FILE", &tBuf ) ){
  135. LOG("Target Application not defined - generating dummy!");
  136. sprintf( m_pTargetAppFile, "TARGET_APP_NAME" );
  137. pSetting = config_setting_add( m_pSettings, "TARGET_APP_FILE", CONFIG_TYPE_STRING );
  138. config_setting_set_string( pSetting, m_pTargetAppFile );
  139. basicSettingsProvider::getInstance()->compromise();
  140. basicSettingsProvider::getInstance()->validate();
  141. LOG_ERROR("Exiting!");
  142. return false;
  143. } else {
  144. sprintf( m_pTargetAppFile, "%s/%s", m_pTargetEnvPath, tBuf );
  145. sprintf( tBuffer, "Target Application Read From Settings: %s", tBuf );
  146. LOG( tBuffer );
  147. if( !fileExist ( m_pTargetAppFile ) ) {
  148. LOG_ERROR("Target Application File Not Exists!");
  149. LOG_ERROR("Exiting!");
  150. return false;
  151. };
  152. };
  153. if( !config_setting_lookup_string( m_pSettings, "TARGET_PID_FILE", &tBuf ) ){
  154. LOG("Target PID File not defined - generating dummy!");
  155. sprintf( m_pTargetPIDFile, "TARGET_FILE_PATH" );
  156. pSetting = config_setting_add( m_pSettings, "TARGET_PID_FILE", CONFIG_TYPE_STRING );
  157. config_setting_set_string( pSetting, m_pTargetPIDFile );
  158. basicSettingsProvider::getInstance()->compromise();
  159. basicSettingsProvider::getInstance()->validate();
  160. LOG_ERROR("Exiting!");
  161. return false;
  162. } else {
  163. sprintf( m_pTargetPIDFile, tBuf );
  164. sprintf( tBuffer, "Target PID File Read From Settings: %s", tBuf );
  165. LOG( tBuffer );
  166. if( !fileExist ( m_pTargetPIDFile ) ) {
  167. LOG_ERROR("Target PID File Not Exists!");
  168. LOG_ERROR("Starting Target Application!");
  169. if( !startTargetApplication() ){
  170. LOG_ERROR("Can not start application!");
  171. return false;
  172. };
  173. };
  174. };
  175. */
  176. basicSettingsProvider::getInstance()->validate();
  177. }
  178. else
  179. {
  180. LOG_ERROR("Failed Read Config Settings!");
  181. return false;
  182. };
  183. // Remove Dead Process Socket
  184. if (fileExist(m_pUnixSocketName))
  185. {
  186. unlink(m_pUnixSocketName);
  187. };
  188. m_iServerSocket = socket(AF_UNIX, SOCK_STREAM, 0);
  189. struct sockaddr_un server_addr;
  190. server_addr.sun_family = AF_UNIX;
  191. strcpy(server_addr.sun_path, m_pUnixSocketName);
  192. int slen = sizeof(server_addr);
  193. int x = fcntl(m_iServerSocket, F_GETFL, 0);
  194. fcntl(m_iServerSocket, F_SETFL, x | O_NONBLOCK);
  195. if (m_iServerSocket == INVALID_SOCKET || bind(m_iServerSocket, (struct sockaddr *) &server_addr, slen) != 0)
  196. {
  197. LOG_ERROR("Could not bind to the UX socket!"); // the bind() result was not checked
  198. return false;
  199. };
  200. listen(m_iServerSocket, 5);
  201. return init();
  202. }
  203. void SP_KERNEL::WaitFinish(bool force)
  204. {
  205. waitThreadEnd(force);
  206. }
  207. /*
  208. One client: first line = PID to kill, then "N" = next update within N ms, "-1" = stop monitoring.
  209. - Lines are assembled in a buffer: readLine() on the non-blocking socket dropped the bytes of a line
  210. that had only partly arrived.
  211. - EOF (the client closed / crashed without "-1") ends the monitoring: before, EOF read as "no data"
  212. and after the deadline kill(9) went to a PID that may belong to another process by then.
  213. */
  214. void * SP_KERNEL::sw_proc(void * ptr)
  215. {
  216. WATCHDOG_PROC_REC * mR = (WATCHDOG_PROC_REC *) ptr;
  217. pid_t CPID = 0;
  218. char tLine[128];
  219. size_t tHave = 0;
  220. char jB[192];
  221. if (mR)
  222. {
  223. uint64_t tLastUpdate = getMilliseconds();
  224. uint64_t tMS = tLastUpdate + SW_DEFAULT_TIMEOUT;
  225. bool tRun = true;
  226. while (tRun)
  227. {
  228. uint64_t cMS = getMilliseconds();
  229. // read what is there (non-blocking)
  230. for (;;)
  231. {
  232. char tB[64];
  233. ssize_t tN = read(mR->client_socket, tB, sizeof(tB));
  234. if (tN > 0)
  235. {
  236. for (ssize_t k = 0; k < tN; k++)
  237. {
  238. if (tB[k] == '\n' || tB[k] == '\r')
  239. {
  240. if (tHave == 0)
  241. {
  242. continue;
  243. };
  244. tLine[tHave] = 0;
  245. tHave = 0;
  246. if (CPID == 0)
  247. {
  248. CPID = (pid_t) atoll(tLine);
  249. snprintf(jB, sizeof(jB), "Watching PID %d", (int) CPID);
  250. mR->master->m_pLog->Log("K_T", mR->master, jB);
  251. }
  252. else
  253. {
  254. int64_t nMS = atoll(tLine);
  255. if (nMS < 0)
  256. {
  257. snprintf(jB, sizeof(jB), "PID %d: monitoring stopped by the client", (int) CPID);
  258. mR->master->m_pLog->Log("K_T", mR->master, jB);
  259. tRun = false; // Stop WD and exit
  260. break;
  261. };
  262. tMS = cMS + nMS;
  263. tLastUpdate = cMS;
  264. };
  265. }
  266. else if (tHave < sizeof(tLine) - 1)
  267. {
  268. tLine[tHave++] = tB[k];
  269. };
  270. };
  271. if (! tRun)
  272. {
  273. break;
  274. };
  275. continue;
  276. };
  277. if (tN == 0)
  278. {
  279. snprintf(jB, sizeof(jB), "PID %d: peer closed the connection - monitoring ended", (int) CPID);
  280. mR->master->m_pLog->Log("K_T", mR->master, jB);
  281. tRun = false;
  282. }
  283. else if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR)
  284. {
  285. mR->master->m_pLog->Log("K_T", mR->master, "Peer Closes Connection!");
  286. tRun = false;
  287. };
  288. break;
  289. };
  290. if (! tRun)
  291. {
  292. break;
  293. };
  294. if (cMS > tMS)
  295. {
  296. // WD TO EXIT!
  297. snprintf(jB, sizeof(jB), "WD update STALLED! (PID %d, last update %llu ms ago)", (int) CPID, (unsigned long long) (cMS - tLastUpdate));
  298. mR->master->m_pLog->Log("K_T", mR->master, jB);
  299. if (CPID)
  300. {
  301. // Try Kill Client Process;
  302. snprintf(jB, sizeof(jB), "Try Killing Process[%d] By Signal 9!", (int) CPID);
  303. mR->master->m_pLog->Log("K_T", mR->master, jB);
  304. kill(CPID, 9);
  305. }
  306. else
  307. {
  308. mR->master->wd_shutdown();
  309. };
  310. break; //-----> exit thread
  311. };
  312. SLEEP(SW_TIMEOUT_PERCISION);
  313. };
  314. shutdown(mR->client_socket, 2);
  315. close(mR->client_socket);
  316. mR->client_socket = -1;
  317. mR->finished = true;
  318. };
  319. pthread_exit(NULL);
  320. return NULL;
  321. }
  322. void SP_KERNEL::m_fThreadProc(void)
  323. {
  324. struct sockaddr_un client_addr;
  325. unsigned int clen = sizeof(client_addr);
  326. int ClientSocket;
  327. m_bThreadStatus = TH_WORKING;
  328. while (m_bThreadStatus < TH_ENDED)
  329. {
  330. ClientSocket = accept(m_iServerSocket, (struct sockaddr *) &client_addr, &clen);
  331. if (ClientSocket < 0)
  332. {
  333. switch (errno)
  334. {
  335. case EAGAIN:
  336. {
  337. // Checkup client disconnection: join and free finished handlers
  338. // (erase() inside the for loop skipped the next handler; the records were never freed)
  339. for (WATCHDOG_PROCS_VECTOR::iterator index = m_vWPV.begin(); index != m_vWPV.end();)
  340. {
  341. if ((*index)->finished)
  342. {
  343. pthread_join((*index)->handler, NULL);
  344. LOG("WD Procedure Removed");
  345. free(*index);
  346. index = m_vWPV.erase(index);
  347. }
  348. else
  349. {
  350. ++index;
  351. };
  352. };
  353. SLEEP(10);
  354. continue;
  355. };
  356. // case EWOULDBLOCK: me->Log(" The socket is marked non-blocking and no connections are present to be accepted."); break;
  357. case EBADF : LOG_ERROR("The descriptor is invalid."); break;
  358. case ECONNABORTED: LOG_ERROR("A connection has been aborted."); break;
  359. case EINTR : LOG_ERROR("The system call was interrupted by a signal that was caught before a valid connection arrived."); break;
  360. case EINVAL : LOG_ERROR("Socket is not listening for connections, or addrlen is invalid (e.g., is negative)."); break;
  361. case EMFILE : LOG_ERROR("The per-process limit of open file descriptors has been reached."); break;
  362. case ENFILE : LOG_ERROR("The system limit on the total number of open files has been reached."); break;
  363. case ENOTSOCK : LOG_ERROR("The descriptor references a file, not a socket."); break;
  364. case EOPNOTSUPP : LOG_ERROR("The referenced socket is not of type SOCK_STREAM."); break;
  365. case EFAULT : LOG_ERROR("The addr argument is not in a writable part of the user address space."); break;
  366. case ENOBUFS :
  367. case ENOMEM : LOG_ERROR("Not enough free memory. This often means that the memory allocation is limited by the socket buffer limits, not by the system memory."); break;
  368. case EPROTO : LOG_ERROR("Protocol error."); break;
  369. case EPERM : LOG_ERROR("Firewall rules forbid connection."); break;
  370. case ENOSR:
  371. #ifdef __linux__
  372. case ESOCKTNOSUPPORT:
  373. #endif
  374. case EPROTONOSUPPORT:
  375. case ETIMEDOUT : LOG_ERROR(" Unusual error in Kernel (Timeout, No Socket Support in Kernel, Unsupported Protocol)"); break;
  376. // case ERESTARTSYS: me->Log(" Unusual error by Kernel"); break;
  377. default: LOG_ERROR(" Unhandled error in Kernel"); break;
  378. };
  379. m_bThreadStatus = TH_ENDED;
  380. }
  381. else
  382. {
  383. WATCHDOG_PROC_REC * tPRC = (WATCHDOG_PROC_REC *) malloc(sizeof(WATCHDOG_PROC_REC));
  384. if (tPRC)
  385. {
  386. int x = fcntl(ClientSocket, F_GETFL, 0);
  387. fcntl(ClientSocket, F_SETFL, x | O_NONBLOCK);
  388. memset(tPRC, 0, sizeof(WATCHDOG_PROC_REC)); // finished was uninitialized (malloc): a live handler
  389. // could be joined - the accept loop blocked
  390. tPRC->client_socket = ClientSocket;
  391. tPRC->master = this;
  392. tPRC->finished = false;
  393. int RetVal = pthread_create(&tPRC->handler, NULL, sw_proc, (void *) tPRC);
  394. if (RetVal != 0) // pthread_create returns an error number, not -1
  395. {
  396. LOG_ERROR("No Client Thread Created!");
  397. shutdown(ClientSocket, 2);
  398. close(ClientSocket);
  399. free(tPRC);
  400. }
  401. else
  402. {
  403. LOG("New Handler Created");
  404. m_vWPV.push_back(tPRC);
  405. };
  406. }
  407. else
  408. {
  409. LOG_ERROR("No Client Handler Created!");
  410. shutdown(ClientSocket, 2);
  411. close(ClientSocket);
  412. };
  413. };
  414. };
  415. }
  416. #undef LOG_ERROR
  417. #undef LOG