From 77f90040a1c3827dda27c1396d073bf0e16b4854 Mon Sep 17 00:00:00 2001 From: op Date: Sat, 3 Jun 2023 15:19:38 +0000 Subject: [PATCH] drop `uptodate()' check from hack(6) hack(6) scrapes $PATH to find its executable and compare the mtime to the save file and bone file. If the game is newer than those, they're not loaded. Drop this feature. /usr/games is not in the default $PATH anymore, and the format for those file didn't change since the import. Diff from Anton Konyahin (me [at] konyahin [dot] xyz) --- games/hack/hack.bones.c | 14 +++++------- games/hack/hack.h | 3 +-- games/hack/hack.main.c | 15 ++----------- games/hack/hack.unix.c | 49 ++--------------------------------------- 4 files changed, 11 insertions(+), 70 deletions(-) diff --git a/games/hack/hack.bones.c b/games/hack/hack.bones.c index 4abe525065d..20fa34841c1 100644 --- a/games/hack/hack.bones.c +++ b/games/hack/hack.bones.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hack.bones.c,v 1.11 2019/06/28 13:32:52 deraadt Exp $ */ +/* $OpenBSD: hack.bones.c,v 1.12 2023/06/03 15:19:38 op Exp $ */ /* * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica, @@ -139,17 +139,15 @@ savebones(void) int getbones(void) { - int fd,x,y,ok; + int fd,x,y; if(rn2(3)) return(0); /* only once in three times do we find bones */ bones[6] = '0' + dlevel/10; bones[7] = '0' + dlevel%10; if((fd = open(bones, O_RDONLY)) == -1) return(0); - if((ok = uptodate(fd)) != 0){ - getlev(fd, 0, dlevel); - for(x = 0; x < COLNO; x++) for(y = 0; y < ROWNO; y++) - levl[x][y].seen = levl[x][y].new = 0; - } + getlev(fd, 0, dlevel); + for(x = 0; x < COLNO; x++) for(y = 0; y < ROWNO; y++) + levl[x][y].seen = levl[x][y].new = 0; (void) close(fd); #ifdef WIZARD if(!wizard) /* duvel!frans: don't remove bones while debugging */ @@ -158,5 +156,5 @@ getbones(void) pline("Cannot unlink %s .", bones); return(0); } - return(ok); + return(1); } diff --git a/games/hack/hack.h b/games/hack/hack.h index 4fa5eafc297..9e0e9154cd7 100644 --- a/games/hack/hack.h +++ b/games/hack/hack.h @@ -1,4 +1,4 @@ -/* $OpenBSD: hack.h,v 1.13 2016/01/09 18:33:15 mestre Exp $*/ +/* $OpenBSD: hack.h,v 1.14 2023/06/03 15:19:38 op Exp $*/ /* $NetBSD: hack.h,v 1.3 1995/03/23 08:30:21 cgd Exp $*/ /* @@ -681,7 +681,6 @@ int phase_of_the_moon(void); int night(void); int midnight(void); void gethdate(char *); -int uptodate(int); void getlock(void); #ifdef MAIL void getmailstatus(void); diff --git a/games/hack/hack.main.c b/games/hack/hack.main.c index 51a066600db..96382aa2f49 100644 --- a/games/hack/hack.main.c +++ b/games/hack/hack.main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hack.main.c,v 1.24 2019/06/28 13:32:52 deraadt Exp $ */ +/* $OpenBSD: hack.main.c,v 1.25 2023/06/03 15:19:38 op Exp $ */ /* * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica, @@ -103,7 +103,6 @@ static void chdirx(char *, boolean); int main(int argc, char **argv) { - extern char *__progname; int fd; #ifdef CHDIR char *dir; @@ -183,15 +182,6 @@ main(int argc, char **argv) u.ux = FAR; /* prevent nscr() */ (void) signal(SIGHUP, hackhangup); - /* - * Find the creation date of this game, - * so as to avoid restoring outdated savefiles. - */ - gethdate(__progname); - - /* - * We cannot do chdir earlier, otherwise gethdate will fail. - */ #ifdef CHDIR chdirx(dir,1); #endif @@ -298,8 +288,7 @@ main(int argc, char **argv) setftty(); (void) snprintf(SAVEF, sizeof SAVEF, "save/%u%s", getuid(), plname); regularize(SAVEF+5); /* avoid . or / in name */ - if((fd = open(SAVEF, O_RDONLY)) >= 0 && - (uptodate(fd) || unlink(SAVEF) == 666)) { + if((fd = open(SAVEF, O_RDONLY)) >= 0) { (void) signal(SIGINT,done1); pline("Restoring old save file..."); (void) fflush(stdout); diff --git a/games/hack/hack.unix.c b/games/hack/hack.unix.c index 96a9ca84d2f..039ef93c5dc 100644 --- a/games/hack/hack.unix.c +++ b/games/hack/hack.unix.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hack.unix.c,v 1.21 2021/12/15 16:29:29 deraadt Exp $ */ +/* $OpenBSD: hack.unix.c,v 1.22 2023/06/03 15:19:38 op Exp $ */ /* * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica, @@ -154,52 +154,7 @@ midnight(void) return(getlt()->tm_hour == 0); } -struct stat buf, hbuf; - -void -gethdate(char *name) -{ - char *p, *np, *path; - char filename[PATH_MAX]; - - if (strchr(name, '/') != NULL || (p = getenv("PATH")) == NULL) - p = ""; - np = path = strdup(p); /* Make a copy for strsep. */ - if (path == NULL) - err(1, NULL); - - for (;;) { - if ((p = strsep(&np, ":")) == NULL) - break; - if (*p == '\0') /* :: */ - (void) strlcpy(filename, name, sizeof filename); - else - (void) snprintf(filename, sizeof filename, - "%s/%s", p, name); - - if (stat(filename, &hbuf) == 0) { - free(path); - return; - } - } - error("Cannot get status of %s.", - (p = strrchr(name, '/')) ? p+1 : name); - free(path); -} - -int -uptodate(int fd) -{ - if(fstat(fd, &buf)) { - pline("Cannot get status of saved level? "); - return(0); - } - if(buf.st_mtime < hbuf.st_mtime) { - pline("Saved level is out of date. "); - return(0); - } - return(1); -} +struct stat buf; /* see whether we should throw away this xlock file */ static int -- 2.20.1