diff options
-rw-r--r-- | src/libmdsserver/macros.h | 2 | ||||
-rw-r--r-- | src/mds-respawn.c | 3 | ||||
-rw-r--r-- | src/mds-respawn.h | 16 | ||||
-rw-r--r-- | src/mds.c | 3 | ||||
-rwxr-xr-x | 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 <sys/types.h> +#include <time.h> @@ -53,6 +54,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 */ typedef struct server_state @@ -67,6 +78,11 @@ typedef struct server_state */ int state; + /** + * The time (monotonic) the server started + */ + struct timespec started; + } server_state_t; @@ -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 |