lock -> g.lock

This commit is contained in:
Bart House
2018-12-25 13:05:43 -08:00
parent c67f7e5122
commit 64be5fd35a
7 changed files with 54 additions and 54 deletions
+4 -4
View File
@@ -236,10 +236,10 @@ getlock(void)
{ {
int fd; int fd;
Sprintf(lock, "%d%s", getuid(), g.plname); Sprintf(g.lock, "%d%s", getuid(), g.plname);
regularize(lock); regularize(g.lock);
set_levelfile_name(lock, 0); set_levelfile_name(g.lock, 0);
fd = creat(lock, FCMASK); fd = creat(g.lock, FCMASK);
if (fd == -1) { if (fd == -1) {
error("cannot creat lock file."); error("cannot creat lock file.");
} else { } else {
+5 -5
View File
@@ -24,16 +24,16 @@ getlock(void)
int fd; int fd;
int pid = getpid(); /* Process ID */ int pid = getpid(); /* Process ID */
Sprintf(lock, "%d%s", getuid(), g.plname); Sprintf(g.lock, "%d%s", getuid(), g.plname);
set_levelfile_name(lock, 0); set_levelfile_name(g.lock, 0);
if ((fd = open(lock, O_RDWR | O_EXCL | O_CREAT, LEVL_TYPE)) == -1) { if ((fd = open(g.lock, O_RDWR | O_EXCL | O_CREAT, LEVL_TYPE)) == -1) {
raw_printf("Could not lock the game %s.", lock); raw_printf("Could not lock the game %s.", g.lock);
panic("Another game in progress?"); panic("Another game in progress?");
} }
if (write(fd, (char *) &pid, sizeof(pid)) != sizeof(pid)) { if (write(fd, (char *) &pid, sizeof(pid)) != sizeof(pid)) {
raw_printf("Could not lock the game %s.", lock); raw_printf("Could not lock the game %s.", g.lock);
panic("Disk locked?"); panic("Disk locked?");
} }
close(fd); close(fd);
+7 -7
View File
@@ -421,22 +421,22 @@ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);*/
* overwritten without confirmation when a user starts up * overwritten without confirmation when a user starts up
* another game with the same player name. * another game with the same player name.
*/ */
Strcpy(lock, g.plname); Strcpy(g.lock, g.plname);
regularize(lock); regularize(g.lock);
getlock(); getlock();
#else /* What follows is !PC_LOCKING */ #else /* What follows is !PC_LOCKING */
#ifdef AMIGA /* We'll put the bones & levels in the user specified directory \ #ifdef AMIGA /* We'll put the bones & levels in the user specified directory \
-jhsa */ -jhsa */
Strcat(lock, g.plname); Strcat(g.lock, g.plname);
Strcat(lock, ".99"); Strcat(g.lock, ".99");
#else #else
#ifndef MFLOPPY #ifndef MFLOPPY
/* I'm not sure what, if anything, is left here, but MFLOPPY has /* I'm not sure what, if anything, is left here, but MFLOPPY has
* conflicts with set_lock_and_bones() in files.c. * conflicts with set_lock_and_bones() in files.c.
*/ */
Strcpy(lock, g.plname); Strcpy(g.lock, g.plname);
Strcat(lock, ".99"); Strcat(g.lock, ".99");
regularize(lock); /* is this necessary? */ regularize(g.lock); /* is this necessary? */
/* not compatible with full path a la AMIGA */ /* not compatible with full path a la AMIGA */
#endif #endif
#endif #endif
+7 -7
View File
@@ -85,14 +85,14 @@ eraseoldlocks()
*/ */
for (i = 1; i <= MAXDUNGEON * MAXLEVEL + 1; i++) { for (i = 1; i <= MAXDUNGEON * MAXLEVEL + 1; i++) {
/* try to remove all */ /* try to remove all */
set_levelfile_name(lock, i); set_levelfile_name(g.lock, i);
(void) unlink(fqname(lock, LEVELPREFIX, 0)); (void) unlink(fqname(g.lock, LEVELPREFIX, 0));
} }
set_levelfile_name(lock, 0); set_levelfile_name(g.lock, 0);
#ifdef HOLD_LOCKFILE_OPEN #ifdef HOLD_LOCKFILE_OPEN
really_close(); really_close();
#endif #endif
if (unlink(fqname(lock, LEVELPREFIX, 0))) if (unlink(fqname(g.lock, LEVELPREFIX, 0)))
return 0; /* cannot remove it */ return 0; /* cannot remove it */
return (1); /* success! */ return (1); /* success! */
} }
@@ -117,9 +117,9 @@ getlock()
} }
/* regularize(lock); */ /* already done in pcmain */ /* regularize(lock); */ /* already done in pcmain */
Sprintf(tbuf, "%s", fqname(lock, LEVELPREFIX, 0)); Sprintf(tbuf, "%s", fqname(g.lock, LEVELPREFIX, 0));
set_levelfile_name(lock, 0); set_levelfile_name(g.lock, 0);
fq_lock = fqname(lock, LEVELPREFIX, 1); fq_lock = fqname(g.lock, LEVELPREFIX, 1);
if ((fd = open(fq_lock, 0)) == -1) { if ((fd = open(fq_lock, 0)) == -1) {
if (errno == ENOENT) if (errno == ENOENT)
goto gotlock; /* no such file */ goto gotlock; /* no such file */
+11 -11
View File
@@ -82,11 +82,11 @@ eraseoldlocks()
*/ */
for (i = 1; i <= MAXDUNGEON * MAXLEVEL + 1; i++) { for (i = 1; i <= MAXDUNGEON * MAXLEVEL + 1; i++) {
/* try to remove all */ /* try to remove all */
set_levelfile_name(lock, i); set_levelfile_name(g.lock, i);
(void) unlink(fqname(lock, LEVELPREFIX, 0)); (void) unlink(fqname(g.lock, LEVELPREFIX, 0));
} }
set_levelfile_name(lock, 0); set_levelfile_name(g.lock, 0);
if (unlink(fqname(lock, LEVELPREFIX, 0))) if (unlink(fqname(g.lock, LEVELPREFIX, 0)))
return 0; /* cannot remove it */ return 0; /* cannot remove it */
return 1; /* success! */ return 1; /* success! */
} }
@@ -116,22 +116,22 @@ getlock()
error("%s", ""); error("%s", "");
} }
/* default value of lock[] is "1lock" where '1' gets changed to /* default value of g.lock[] is "1lock" where '1' gets changed to
'a','b',&c below; override the default and use <uid><charname> 'a','b',&c below; override the default and use <uid><charname>
if we aren't restricting the number of simultaneous games */ if we aren't restricting the number of simultaneous games */
if (!g.locknum) if (!g.locknum)
Sprintf(lock, "%u%s", (unsigned) getuid(), g.plname); Sprintf(g.lock, "%u%s", (unsigned) getuid(), g.plname);
regularize(lock); regularize(g.lock);
set_levelfile_name(lock, 0); set_levelfile_name(g.lock, 0);
if (g.locknum) { if (g.locknum) {
if (g.locknum > 25) if (g.locknum > 25)
g.locknum = 25; g.locknum = 25;
do { do {
lock[0] = 'a' + i++; g.lock[0] = 'a' + i++;
fq_lock = fqname(lock, LEVELPREFIX, 0); fq_lock = fqname(g.lock, LEVELPREFIX, 0);
if ((fd = open(fq_lock, 0)) == -1) { if ((fd = open(fq_lock, 0)) == -1) {
if (errno == ENOENT) if (errno == ENOENT)
@@ -150,7 +150,7 @@ getlock()
unlock_file(HLOCK); unlock_file(HLOCK);
error("Too many hacks running now."); error("Too many hacks running now.");
} else { } else {
fq_lock = fqname(lock, LEVELPREFIX, 0); fq_lock = fqname(g.lock, LEVELPREFIX, 0);
if ((fd = open(fq_lock, 0)) == -1) { if ((fd = open(fq_lock, 0)) == -1) {
if (errno == ENOENT) if (errno == ENOENT)
goto gotlock; /* no such file */ goto gotlock; /* no such file */
+13 -13
View File
@@ -77,11 +77,11 @@ int fd;
*/ */
for (i = 1; i <= MAXDUNGEON * MAXLEVEL + 1; i++) { for (i = 1; i <= MAXDUNGEON * MAXLEVEL + 1; i++) {
/* try to remove all */ /* try to remove all */
set_levelfile_name(lock, i); set_levelfile_name(g.lock, i);
(void) delete (lock); (void) delete (g.lock);
} }
set_levelfile_name(lock, 0); set_levelfile_name(g.lock, 0);
if (delete (lock)) if (delete (g.lock))
return 0; /* cannot remove it */ return 0; /* cannot remove it */
return 1; /* success! */ return 1; /* success! */
} }
@@ -106,27 +106,27 @@ getlock()
error("Quitting."); error("Quitting.");
} }
/* default value of lock[] is "1lock" where '1' gets changed to /* default value of g.lock[] is "1lock" where '1' gets changed to
'a','b',&c below; override the default and use <uid><charname> 'a','b',&c below; override the default and use <uid><charname>
if we aren't restricting the number of simultaneous games */ if we aren't restricting the number of simultaneous games */
if (!g.locknum) if (!g.locknum)
Sprintf(lock, "_%u%s", (unsigned) getuid(), plname); Sprintf(g.lock, "_%u%s", (unsigned) getuid(), plname);
regularize(lock); regularize(g.lock);
set_levelfile_name(lock, 0); set_levelfile_name(g.lock, 0);
if (g.locknum > 25) if (g.locknum > 25)
g.locknum = 25; g.locknum = 25;
do { do {
if (g.locknum) if (g.locknum)
lock[0] = 'a' + i++; g.lock[0] = 'a' + i++;
if ((fd = open(lock, 0, 0)) == -1) { if ((fd = open(g.lock, 0, 0)) == -1) {
if (errno == ENOENT) if (errno == ENOENT)
goto gotlock; /* no such file */ goto gotlock; /* no such file */
perror(lock); perror(g.lock);
unlock_file(HLOCK); unlock_file(HLOCK);
error("Cannot open %s", lock); error("Cannot open %s", g.lock);
} }
if (veryold(fd)) /* if true, this closes fd and unlinks lock */ if (veryold(fd)) /* if true, this closes fd and unlinks lock */
@@ -139,7 +139,7 @@ getlock()
: "There is a game in progress under your name."); : "There is a game in progress under your name.");
gotlock: gotlock:
fd = creat(lock, FCMASK); fd = creat(g.lock, FCMASK);
unlock_file(HLOCK); unlock_file(HLOCK);
if (fd == -1) { if (fd == -1) {
error("cannot creat lock file."); error("cannot creat lock file.");
+7 -7
View File
@@ -167,11 +167,11 @@ eraseoldlocks()
*/ */
for (i = 1; i <= MAXDUNGEON * MAXLEVEL + 1; i++) { for (i = 1; i <= MAXDUNGEON * MAXLEVEL + 1; i++) {
/* try to remove all */ /* try to remove all */
set_levelfile_name(lock, i); set_levelfile_name(g.lock, i);
(void) unlink(fqname(lock, LEVELPREFIX, 0)); (void) unlink(fqname(g.lock, LEVELPREFIX, 0));
} }
set_levelfile_name(lock, 0); set_levelfile_name(g.lock, 0);
if (unlink(fqname(lock, LEVELPREFIX, 0))) if (unlink(fqname(g.lock, LEVELPREFIX, 0)))
return 0; /* cannot remove it */ return 0; /* cannot remove it */
return (1); /* success! */ return (1); /* success! */
} }
@@ -187,9 +187,9 @@ getlock()
int choice; int choice;
/* regularize(lock); */ /* already done in pcmain */ /* regularize(lock); */ /* already done in pcmain */
Sprintf(tbuf, "%s", fqname(lock, LEVELPREFIX, 0)); Sprintf(tbuf, "%s", fqname(g.lock, LEVELPREFIX, 0));
set_levelfile_name(lock, 0); set_levelfile_name(g.lock, 0);
fq_lock = fqname(lock, LEVELPREFIX, 1); fq_lock = fqname(g.lock, LEVELPREFIX, 1);
f = CreateFile(NH_A2W(fq_lock, wbuf, BUFSZ), GENERIC_READ, 0, NULL, f = CreateFile(NH_A2W(fq_lock, wbuf, BUFSZ), GENERIC_READ, 0, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);