Commit 5ee95a9f authored by nextime's avatar nextime

Fix watchdog PID file to store correct background process PID

- Capture PID of background main() process with MAIN_PID=
- Store correct PID in watchdog PID file instead of main() function PID
- Prevent PID file from containing exited process PID
- Fix both wssshd and wssshc watchdogs
- Watchdog PID file now contains PID of actual running process
parent 24611f90
...@@ -198,8 +198,9 @@ main() { ...@@ -198,8 +198,9 @@ main() {
log_message "START validation passed, proceeding with watchdog initialization" log_message "START validation passed, proceeding with watchdog initialization"
# Store watchdog PID # Store watchdog PID (use the background process PID captured by parent)
echo $$ > "$WATCHDOG_PID_FILE" echo $MAIN_PID > "$WATCHDOG_PID_FILE"
log_message "Created PID file with PID: $MAIN_PID"
log_message "Watchdog started for $DAEMON_NAME" log_message "Watchdog started for $DAEMON_NAME"
log_message "Check interval: $CHECK_INTERVAL seconds" log_message "Check interval: $CHECK_INTERVAL seconds"
...@@ -254,8 +255,9 @@ case "$1" in ...@@ -254,8 +255,9 @@ case "$1" in
fi fi
echo "Calling main() function..." echo "Calling main() function..."
# Run main() function in background # Run main() function in background and capture its PID
main & main &
MAIN_PID=$!
# Give it a moment to start # Give it a moment to start
sleep 1 sleep 1
......
...@@ -193,8 +193,9 @@ main() { ...@@ -193,8 +193,9 @@ main() {
log_message "START validation passed, proceeding with watchdog initialization" log_message "START validation passed, proceeding with watchdog initialization"
# Store watchdog PID # Store watchdog PID (use the background process PID captured by parent)
echo $$ > "$WATCHDOG_PID_FILE" echo $MAIN_PID > "$WATCHDOG_PID_FILE"
log_message "Created PID file with PID: $MAIN_PID"
log_message "Watchdog started for $DAEMON_NAME" log_message "Watchdog started for $DAEMON_NAME"
log_message "Check interval: $CHECK_INTERVAL seconds" log_message "Check interval: $CHECK_INTERVAL seconds"
...@@ -249,8 +250,9 @@ case "$1" in ...@@ -249,8 +250,9 @@ case "$1" in
fi fi
echo "Calling main() function..." echo "Calling main() function..."
# Run main() function in background # Run main() function in background and capture its PID
main & main &
MAIN_PID=$!
# Give it a moment to start # Give it a moment to start
sleep 1 sleep 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment