(pre_update_hook): New configuration key.
(update_wait): Implement it. (run_hook): New.
This commit is contained in:
parent
f12649c3da
commit
7d71984932
3 changed files with 38 additions and 2 deletions
|
@ -86,6 +86,8 @@ EMPCFBOTH("hourslop", hourslop, int, NSC_INT, KM_INTERNAL,
|
||||||
"Number of minutes update check can slip to match update_times")
|
"Number of minutes update check can slip to match update_times")
|
||||||
EMPCFBOTH("blitz_time", blitz_time, int, NSC_INT, 0,
|
EMPCFBOTH("blitz_time", blitz_time, int, NSC_INT, 0,
|
||||||
"Number of minutes between updates under policy #2.")
|
"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")
|
EMPCF_COMMENT("\n\n### Demand update policy")
|
||||||
EMPCFBOTH("update_demandpolicy", update_demandpolicy, int, NSC_INT, 0,
|
EMPCFBOTH("update_demandpolicy", update_demandpolicy, int, NSC_INT, 0,
|
||||||
|
|
|
@ -61,6 +61,7 @@ int blitz_time = 10; /* number of minutes between blitz updates */
|
||||||
char *update_demandtimes = ""; /* times demand update is allowed */
|
char *update_demandtimes = ""; /* times demand update is allowed */
|
||||||
char *game_days = ""; /* days game is running */
|
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 max_idle = 15; /* session dies after max_idle minutes idle */
|
||||||
|
|
||||||
int sect_mob_max = 127; /* sector mobility limits */
|
int sect_mob_max = 127; /* sector mobility limits */
|
||||||
|
|
|
@ -32,6 +32,11 @@
|
||||||
* Steve McClure, 1996
|
* Steve McClure, 1996
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#ifndef _WIN32
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#endif
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "empthread.h"
|
#include "empthread.h"
|
||||||
|
@ -40,9 +45,10 @@
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
|
|
||||||
empth_sem_t *update_sem;
|
empth_sem_t *update_sem;
|
||||||
|
time_t update_time;
|
||||||
|
|
||||||
static void update_wait(void *unused);
|
static void update_wait(void *unused);
|
||||||
time_t update_time;
|
static int run_hook(char *cmd, char *name);
|
||||||
|
|
||||||
/*ARGSUSED*/
|
/*ARGSUSED*/
|
||||||
void
|
void
|
||||||
|
@ -119,6 +125,10 @@ update_wait(void *unused)
|
||||||
/* sleep a few, wait for aborts to take effect */
|
/* sleep a few, wait for aborts to take effect */
|
||||||
empth_sleep(now + 2);
|
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
|
* we rely on the fact that update's priority is the highest
|
||||||
* in the land so it can finish before it yields.
|
* in the land so it can finish before it yields.
|
||||||
|
@ -137,3 +147,26 @@ update_wait(void *unused)
|
||||||
}
|
}
|
||||||
/*NOTREACHED*/
|
/*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;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue