From f934a2908efa99e2d39ad1c3ba01137204baddaf Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 7 Jun 2014 21:46:59 +0200 Subject: test and fix mds-respawn + add missed staging: monotonic clock should be raw MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/libmdsserver/macros.h | 2 +- src/mds-respawn.c | 3 ++- src/mds-respawn.h | 16 ++++++++++++++++ src/mds.c | 3 ++- test.d/mdsinitrc | 4 ++++ 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/libmdsserver/macros.h b/src/libmdsserver/macros.h index f67c371..59537ff 100644 --- a/src/libmdsserver/macros.h +++ b/src/libmdsserver/macros.h @@ -245,7 +245,7 @@ * @return :int Zero on sucess, -1 on error */ #define monotone(time_slot) \ - clock_gettime(CLOCK_MONOTONIC, time_slot) + clock_gettime(CLOCK_MONOTONIC_RAW, time_slot) /** diff --git a/src/mds-respawn.c b/src/mds-respawn.c index 8d5fb0a..84c4b26 100644 --- a/src/mds-respawn.c +++ b/src/mds-respawn.c @@ -182,6 +182,7 @@ static void spawn_server(size_t index) { states[index].pid = pid; states[index].state = ALIVE; + live_count++; return; } @@ -442,7 +443,7 @@ static void joined_with_server(pid_t pid, int status) return; } - if (ended.tv_sec - states[i].started.tv_sec < RESPAWN_TIME_LIMIT_SECONDS) + if (ended.tv_sec - states[i].started.tv_sec < interval) { eprintf("%s died abnormally, burying because it died too fast.", commands[i][0]); states[i].state = DEAD_AND_BURIED; diff --git a/src/mds-respawn.h b/src/mds-respawn.h index 8c25a4a..65557ba 100644 --- a/src/mds-respawn.h +++ b/src/mds-respawn.h @@ -22,6 +22,7 @@ #include "mds-base.h" #include +#include @@ -52,6 +53,16 @@ +/** + * Check that a state is a value state + * + * @param VALUE:int The state + * @return :int Whether the state is value + */ +#define validate_state(VALUE) ((UNBORN <= VALUE) && (VALUE <= CREMATED)) + + + /** * The state and identifier of a server */ @@ -67,6 +78,11 @@ typedef struct server_state */ int state; + /** + * The time (monotonic) the server started + */ + struct timespec started; + } server_state_t; diff --git a/src/mds.c b/src/mds.c index c86b08a..ffe7023 100644 --- a/src/mds.c +++ b/src/mds.c @@ -340,7 +340,8 @@ int spawn_and_respawn_server(int fd) goto pfail; /* If the server exited normally or SIGTERM, do not respawn. */ - if (WIFEXITED(status) || (WEXITSTATUS(status) && WTERMSIG(status))) + if (WIFEXITED(status) ? (WEXITSTATUS(status) == 0) : + ((WTERMSIG(status) == SIGTERM) || (WTERMSIG(status) == SIGINT))) goto done; /* Child exited normally, stop. */ /* Get the current time. (End of child process.) */ diff --git a/test.d/mdsinitrc b/test.d/mdsinitrc index c27cdc0..978dbb6 100755 --- a/test.d/mdsinitrc +++ b/test.d/mdsinitrc @@ -19,12 +19,16 @@ echo "Successfully spawned mdsinitrc. " +export PATH="$(realpath bin):${PATH}" cd test.d export XDG_CONFIG_HOME="${OLD_XDG_CONFIG_HOME}" unset OLD_XDG_CONFIG_HOME if [ -z "${XDG_CONFIG_HOME}" ]; then unset XDG_CONFIG_HOME fi +mds-respawn --interval=10 \ + { sleep 4s } \ + { sleep 1m } & if which terminator 2>/dev/null >&2; then exec terminator else -- cgit v1.2.3-70-g09d2