From 573d3fe87059dace7cfbbf9c60ac71243adf2c44 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 30 Apr 2011 07:35:14 +0200 Subject: [PATCH] Fix xdump updates not to dump bogus extra updates "xdump updates" believes there are always 15 (UPDATE_TIME_LEN - 1) scheduled updates. When fewer than 15 updates are scheduled, it shows whatever crap update time happens to be in the unused part of update_time[]: the initial zero or a previously scheduled update. Root cause is that table EF_UPDATES has always UPDATE_TIME_LEN - 1 entries, which is incorrect when fewer updates are scheduled. Only xdump is affected, as the other users ignore the length and stop at the sentinel. Fix update_get_schedule() to resize table EF_UPDATES. --- src/lib/common/filetable.c | 2 +- src/server/update.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/lib/common/filetable.c b/src/lib/common/filetable.c index feed7c5f0..70a049f52 100644 --- a/src/lib/common/filetable.c +++ b/src/lib/common/filetable.c @@ -186,7 +186,7 @@ struct empfile empfile[] = { * Update schedule table. Use read_schedule() to fill. */ {EF_UPDATES, "updates", NULL, update_ca, - ARRAY_TABLE(update_time, EFF_CFG)}, + ARRAY_CACHE(update_time, EFF_CFG)}, /* * Special tables. EF_META gets bogus size, cids and fids here. * Fixed up by empfile_init(). EF_VERSION's cadef is set by diff --git a/src/server/update.c b/src/server/update.c index 20e31a7ac..dd6f2acb3 100644 --- a/src/server/update.c +++ b/src/server/update.c @@ -41,6 +41,7 @@ #endif #include #include "empthread.h" +#include "file.h" #include "game.h" #include "misc.h" #include "optlist.h" @@ -97,15 +98,20 @@ static int update_get_schedule(void) { time_t now = time(NULL); + int n = sizeof(update_time) / sizeof(*update_time); + int i; - if (read_schedule(schedulefil, update_time, - sizeof(update_time) / sizeof(*update_time), + ef_truncate(EF_UPDATES, 0); + ef_extend(EF_UPDATES, n - 1); + if (read_schedule(schedulefil, update_time, n, now + 30, update_schedule_anchor) < 0) { logerror("No update schedule!"); - update_time[0] = 0; + ef_truncate(EF_UPDATES, 0); return -1; } logerror("Update schedule read"); + for (i = 0; update_time[i]; i++) ; + ef_truncate(EF_UPDATES, i); return 0; } -- 2.43.0