Skip to content

Commit

Permalink
Added better watchdog handling (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
DerjenigeUberMensch authored Jul 20, 2024
1 parent 9eb1fad commit 8073222
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion include/watchdog.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ WatchDog
pid_t child;
uint8_t restart;
uint8_t fail_count;
uint8_t pad0[2];
uint8_t die;
uint8_t pad0[1];
/* Maybe use poll?, For now just use these to sleep */
pthread_mutex_t mutex;
pthread_cond_t cond;
Expand Down
15 changes: 12 additions & 3 deletions src/watchdog.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ sigsegv(
*/
Debug0("Sigsev");
watchdog->restart = 1;
abort();
watchdog->running = 0;
}

static void
Expand Down Expand Up @@ -170,19 +170,28 @@ WatchDogRun(
.tv_nsec = 0
};
watchdog->running = 1;
while(watchdog->running && !watchdog->restart)
while(watchdog->running)
{
pthread_mutex_lock(&watchdog->mutex);
pthread_cond_timedwait(&watchdog->cond, &watchdog->mutex, &_time);
pthread_mutex_unlock(&watchdog->mutex);
}

int status = 0;
pid_t pid = 0;
if(watchdog->die)
{
do
{ waitpid(watchdog->child, &status, WNOHANG);
} while(!WIFEXITED(status));
}

if(watchdog->restart)
{ Debug0("restarting");
}
else
{ exit(0);
}
signal(SIGSEGV, NULL);
usleep(100);
munmap(watchdog, sizeof(WatchDog));
return 10;
Expand Down

0 comments on commit 8073222

Please sign in to comment.