I can suggest another (much less) patch, which still allows users to
play hack without path modification. But all this stuff with checking
saves creating time doesn't looks actual for me, so I keep original
patch below.
Index: hack.unix.c
===================================================================
RCS file: /cvs/src/games/hack/hack.unix.c,v
retrieving revision 1.21
diff -u -p -u -p -r1.21 hack.unix.c
--- hack.unix.c 15 Dec 2021 16:29:29 -0000 1.21
+++ hack.unix.c 29 May 2023 05:44:35 -0000
@@ -182,8 +182,9 @@ gethdate(char *name)
return;
}
}
- error("Cannot get status of %s.",
- (p = strrchr(name, '/')) ? p+1 : name);
+
+ /* can't find hack in path, use old good time as default */
+ hbuf.st_mtime = 0;
free(path);
}
On 21/05, Anton Konyahin wrote:
Hello.
After removing /usr/games from PATH, hack failing with error:
Cannot get status of hack.
Hack tries to get information about st_mtime of execuatble, so it
search for hack in all directories from path. Game wants to compare
modification time of hack and saves, so saves from previous version
won't be load.
I think hack is mature enough and has stable format of saves, we can
remove this check and bring back ability to run it without path's
modification.
Old patch:
Index: hack.bones.c
===================================================================
RCS file: /cvs/src/games/hack/hack.bones.c,v
retrieving revision 1.11
diff -u -p -u -p -r1.11 hack.bones.c
--- hack.bones.c 28 Jun 2019 13:32:52 -0000 1.11
+++ hack.bones.c 21 May 2023 12:18:07 -0000
@@ -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);
}
Index: hack.h
===================================================================
RCS file: /cvs/src/games/hack/hack.h,v
retrieving revision 1.13
diff -u -p -u -p -r1.13 hack.h
--- hack.h 9 Jan 2016 18:33:15 -0000 1.13
+++ hack.h 21 May 2023 12:18:07 -0000
@@ -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);
Index: hack.main.c
===================================================================
RCS file: /cvs/src/games/hack/hack.main.c,v
retrieving revision 1.24
diff -u -p -u -p -r1.24 hack.main.c
--- hack.main.c 28 Jun 2019 13:32:52 -0000 1.24
+++ hack.main.c 21 May 2023 12:18:08 -0000
@@ -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);
Index: hack.unix.c
===================================================================
RCS file: /cvs/src/games/hack/hack.unix.c,v
retrieving revision 1.21
diff -u -p -u -p -r1.21 hack.unix.c
--- hack.unix.c 15 Dec 2021 16:29:29 -0000 1.21
+++ hack.unix.c 21 May 2023 12:18:08 -0000
@@ -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