From 80d3abcf00a4d521f9c02a39860cd2aa7a2f9374 Mon Sep 17 00:00:00 2001 From: PatR Date: Sun, 6 Oct 2019 17:30:18 -0700 Subject: [PATCH] fix github pull request #26 - validating #explore Fixes #26 Report stated that the attempt to look up the player's username (on Unix) failed (reason unknown) and nethack refused to allow the player to execute the #explore command even though sysconf was set to use character names (CHECK_PLNAME=1) instead of user names. Setting EXPLORERS to "*" overcomes this glitch, but the fix moves a bit of code around to honor CHECK_PLNAME before fetching username so that that isn't necessary. I ended up doing some formattng clean up (replace tabs with spaces, whitespace cleanup in 'port_insert_pastebuf()'). The actual change to fix #26 is only a few lines. --- doc/fixes36.3 | 4 +++- sys/unix/unixmain.c | 49 +++++++++++++++++++++++---------------------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/doc/fixes36.3 b/doc/fixes36.3 index 0ca806da6..f9781a9a8 100644 --- a/doc/fixes36.3 +++ b/doc/fixes36.3 @@ -1,4 +1,4 @@ -$NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.125 $ $NHDT-Date: 1570318925 2019/10/05 23:42:05 $ +$NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.126 $ $NHDT-Date: 1570408209 2019/10/07 00:30:09 $ This fixes36.3 file is here to capture information about updates in the 3.6.x lineage following the release of 3.6.2 in May 2019. Please note, however, @@ -209,6 +209,8 @@ tty: revert the attempt to fix "message line anomaly: if autodecribe feedback wrapped to second line, the wrapped portion wasn't erased when a shorter line was shown or getpos was dismissed" because it disrupted prompts that spanned more than one line, a more significant issue +unix: sysconf CHECK_PLNAME=1 wouldn't work if attempt to obtain unix username + failed even though it didn't need that username Platform- and/or Interface-Specific Fixes or Features diff --git a/sys/unix/unixmain.c b/sys/unix/unixmain.c index 50610d43c..92cf02863 100644 --- a/sys/unix/unixmain.c +++ b/sys/unix/unixmain.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 unixmain.c $NHDT-Date: 1432512788 2015/05/25 00:13:08 $ $NHDT-Branch: master $:$NHDT-Revision: 1.52 $ */ +/* NetHack 3.6 unixmain.c $NHDT-Date: 1570408210 2019/10/07 00:30:10 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.70 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Robert Patrick Rankin, 2011. */ /* NetHack may be freely redistributed. See license for details. */ @@ -117,7 +117,7 @@ char *argv[]; if (argcheck(argc, argv, ARG_DEBUG) == 1) { argc--; argv++; - } + } if (argc > 1 && !strncmp(argv[1], "-d", 2) && argv[1][2] != 'e') { /* avoid matching "-dec" for DECgraphics; since the man page @@ -262,7 +262,7 @@ char *argv[]; * First, try to find and restore a save file for specified character. * We'll return here if new game player_selection() renames the hero. */ -attempt_restore: + attempt_restore: /* * getlock() complains and quits if there is already a game @@ -531,8 +531,8 @@ whoami() { /* * Who am i? Algorithm: 1. Use name as specified in NETHACKOPTIONS - * 2. Use $USER or $LOGNAME (if 1. fails) - * 3. Use getlogin() (if 2. fails) + * 2. Use $USER or $LOGNAME (if 1. fails) + * 3. Use getlogin() (if 2. fails) * The resulting name is overridden by command line options. * If everything fails, or if the resulting name is some generic * account like "games", "play", "player", "hack" then eventually @@ -654,17 +654,17 @@ char *optstr; struct passwd *pw = get_unix_pw(); int pwlen; char *eop, *w; - char *pwname; + char *pwname = 0; if (optstr[0] == '*') return TRUE; /* allow any user */ - if (!pw) - return FALSE; if (sysopt.check_plname) pwname = plname; - else + else if ((pw = get_unix_pw()) != 0) pwname = pw->pw_name; - pwlen = strlen(pwname); + if (!pwname || !*pwname) + return FALSE; + pwlen = (int) strlen(pwname); eop = eos(optstr); w = optstr; while (w + pwlen <= eop) { @@ -722,7 +722,6 @@ get_login_name() struct passwd *pw = get_unix_pw(); buf[0] = '\0'; - if (pw) (void)strcpy(buf, pw->pw_name); @@ -739,31 +738,33 @@ char *buf; /* This should be replaced when there is a Cocoa port. */ const char *errfmt; size_t len; - FILE *PB = popen("/usr/bin/pbcopy","w"); - if(!PB){ - errfmt = "Unable to start pbcopy (%d)\n"; - goto error; + FILE *PB = popen("/usr/bin/pbcopy", "w"); + + if (!PB) { + errfmt = "Unable to start pbcopy (%d)\n"; + goto error; } len = strlen(buf); /* Remove the trailing \n, carefully. */ - if(buf[len-1] == '\n') len--; + if (buf[len - 1] == '\n') + len--; /* XXX Sorry, I'm too lazy to write a loop for output this short. */ - if(len!=fwrite(buf,1,len,PB)){ - errfmt = "Error sending data to pbcopy (%d)\n"; - goto error; + if (len != fwrite(buf, 1, len, PB)) { + errfmt = "Error sending data to pbcopy (%d)\n"; + goto error; } - if(pclose(PB)!=-1){ - return; + if (pclose(PB) != -1) { + return; } errfmt = "Error finishing pbcopy (%d)\n"; -error: - raw_printf(errfmt,strerror(errno)); + error: + raw_printf(errfmt, strerror(errno)); } -#endif +#endif /* __APPLE__ */ unsigned long sys_random_seed()