]> git.pond.sub.org Git - empserver/commitdiff
(pre_update_hook): New configuration key.
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 12 Mar 2005 17:24:57 +0000 (17:24 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 12 Mar 2005 17:24:57 +0000 (17:24 +0000)
(update_wait): Implement it.
(run_hook): New.

include/econfig-spec.h
src/lib/global/constants.c
src/server/update.c

index 45a6f819bb76a028fb6d0cdca8f05d01082c016b..cd47761594ca8257a472273c9954a8f88c668314 100644 (file)
@@ -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,
index 8e3dccfbab42933a52cbd992a2c1cec62d5e0d06..c76106114df8e7e23fb1f0346e2328087d569976 100644 (file)
@@ -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 */
index 9ba3a344cb684c8bcd9d0f6b7d357d549a491c45..b8da716031900988bd38566175abf3bfe6e102f8 100644 (file)
  *     Steve McClure, 1996
  */
 
+#include <errno.h>
+#include <stdlib.h>
+#ifndef _WIN32
+#include <sys/wait.h>
+#endif
 #include "misc.h"
 #include "player.h"
 #include "empthread.h"
 #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;
+}