diff --git a/include/econfig-spec.h b/include/econfig-spec.h index 45a6f819..cd477615 100644 --- a/include/econfig-spec.h +++ b/include/econfig-spec.h @@ -86,6 +86,8 @@ EMPCFBOTH("hourslop", hourslop, int, NSC_INT, KM_INTERNAL, "Number of minutes update check can slip to match update_times") EMPCFBOTH("blitz_time", blitz_time, int, NSC_INT, 0, "Number of minutes between updates under policy #2.") +EMPCFBOTH("pre_update_hook", pre_update_hook, char *, NSC_STRING, 0, + "Shell command run right before the update.") EMPCF_COMMENT("\n\n### Demand update policy") EMPCFBOTH("update_demandpolicy", update_demandpolicy, int, NSC_INT, 0, diff --git a/src/lib/global/constants.c b/src/lib/global/constants.c index 8e3dccfb..c7610611 100644 --- a/src/lib/global/constants.c +++ b/src/lib/global/constants.c @@ -60,7 +60,8 @@ int update_wantmin = 0; /* number of votes required for demand update */ int blitz_time = 10; /* number of minutes between blitz updates */ char *update_demandtimes = ""; /* times demand update is allowed */ char *game_days = ""; /* days game is running */ -char *game_hours = ""; /* hours game is running */ +char *game_hours = ""; /* hours game is running */ +char *pre_update_hook = ""; int max_idle = 15; /* session dies after max_idle minutes idle */ int sect_mob_max = 127; /* sector mobility limits */ diff --git a/src/server/update.c b/src/server/update.c index 9ba3a344..b8da7160 100644 --- a/src/server/update.c +++ b/src/server/update.c @@ -32,6 +32,11 @@ * Steve McClure, 1996 */ +#include +#include +#ifndef _WIN32 +#include +#endif #include "misc.h" #include "player.h" #include "empthread.h" @@ -40,9 +45,10 @@ #include "server.h" empth_sem_t *update_sem; +time_t update_time; static void update_wait(void *unused); -time_t update_time; +static int run_hook(char *cmd, char *name); /*ARGSUSED*/ void @@ -119,6 +125,10 @@ update_wait(void *unused) /* sleep a few, wait for aborts to take effect */ empth_sleep(now + 2); } + if (*pre_update_hook) { + if (run_hook(pre_update_hook, "pre-update")) + continue; + } /* * we rely on the fact that update's priority is the highest * in the land so it can finish before it yields. @@ -137,3 +147,26 @@ update_wait(void *unused) } /*NOTREACHED*/ } + +static int +run_hook(char *cmd, char *name) +{ + int status = system(cmd); + if (status == 0) + ; /* successful exit */ + else if (status == -1) + logerror("couldn't execute command processor for %s hook (%s)", + name, strerror(errno)); +#ifndef _WIN32 + else if (WIFEXITED(status)) + logerror("%s hook terminated unsuccessfully (exit status %d)", + name, WEXITSTATUS(status)); + else if (WIFSIGNALED(status)) + logerror("%s hook terminated abnormally (signal %d)", + name, WTERMSIG(status)); +#endif + else if (status) + logerror("%s hook terminated strangely (status %d)", + name, status); + return status; +}