diff --git a/include/watchdog.h b/include/watchdog.h index 799deee..7d5f93f 100644 --- a/include/watchdog.h +++ b/include/watchdog.h @@ -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; diff --git a/src/watchdog.c b/src/watchdog.c index 693370f..977b203 100644 --- a/src/watchdog.c +++ b/src/watchdog.c @@ -51,7 +51,7 @@ sigsegv( */ Debug0("Sigsev"); watchdog->restart = 1; - abort(); + watchdog->running = 0; } static void @@ -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;