summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkstailey <kstailey@cvs.openbsd.org>1997-06-18 18:32:45 +0000
committerkstailey <kstailey@cvs.openbsd.org>1997-06-18 18:32:45 +0000
commit1b65aa0cebe95a4104d13ee5baba98983a4f4805 (patch)
tree0c65e0745d735404fd03c412c288c1f63e9956b2
parentd60a8b61c754f2cff9f1f1a9d9088530ad1775cf (diff)
fix highscore file
-rw-r--r--games/atc/Makefile8
-rw-r--r--games/atc/log.c57
-rw-r--r--games/atc/main.c2
3 files changed, 45 insertions, 22 deletions
diff --git a/games/atc/Makefile b/games/atc/Makefile
index ca4cf6b9721..68b8be94122 100644
--- a/games/atc/Makefile
+++ b/games/atc/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.5 1997/06/18 16:43:46 kstailey Exp $
+# $OpenBSD: Makefile,v 1.6 1997/06/18 18:32:43 kstailey Exp $
# $NetBSD: Makefile,v 1.9 1995/03/21 15:03:38 cgd Exp $
# @(#)Makefile 8.1 (Berkeley) 5/31/93
@@ -27,5 +27,11 @@ beforeinstall:
(cd ${.CURDIR}/games; ${INSTALL} ${INSTALL_COPY} \
-o ${BINOWN} -g ${BINGRP} \
-m 444 ${GAMES} ${DESTDIR}/usr/share/games/atc)
+ @if [ ! -f ${DESTDIR}/var/games/atc_score ]; then \
+ ${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m 664 \
+ /dev/null ${DESTDIR}/var/games/atc_score ; \
+ else \
+ true ; \
+ fi
.include <bsd.prog.mk>
diff --git a/games/atc/log.c b/games/atc/log.c
index 4b84798d46a..53f3590a918 100644
--- a/games/atc/log.c
+++ b/games/atc/log.c
@@ -56,6 +56,8 @@ static char rcsid[] = "$NetBSD: log.c,v 1.3 1995/03/21 15:04:21 cgd Exp $";
#include "include.h"
#include "pathnames.h"
+static FILE *score_fp;
+
compar(a, b)
SCORE *a, *b;
{
@@ -94,20 +96,14 @@ timestr(t)
return (s);
}
-log_score(list_em)
+open_score_file()
{
- register int i, fd, num_scores = 0, good, changed = 0, found = 0;
- struct passwd *pw;
- FILE *fp;
- char *cp;
- SCORE score[100], thisscore;
-#ifdef SYSV
- struct utsname name;
-#endif
+ mode_t old_mode;
+ int score_fd;
- umask(0);
- fd = open(_PATH_SCORE, O_CREAT|O_RDWR, 0644);
- if (fd < 0) {
+ old_mode = umask(0);
+ score_fd = open(_PATH_SCORE, O_CREAT|O_RDWR, 0664);
+ if (score_fd < 0) {
perror(_PATH_SCORE);
return (-1);
}
@@ -115,23 +111,36 @@ log_score(list_em)
* This is done to take advantage of stdio, while still
* allowing a O_CREAT during the open(2) of the log file.
*/
- fp = fdopen(fd, "r+");
- if (fp == NULL) {
+ score_fp = fdopen(score_fd, "r+");
+ if (score_fp == NULL) {
perror(_PATH_SCORE);
return (-1);
}
+ umask(old_mode);
+}
+
+log_score(list_em)
+{
+ int i, num_scores = 0, good, changed = 0, found = 0;
+ struct passwd *pw;
+ char *cp;
+ SCORE score[100], thisscore;
+#ifdef SYSV
+ struct utsname name;
+#endif
+
#ifdef BSD
- if (flock(fileno(fp), LOCK_EX) < 0)
+ if (flock(fileno(score_fp), LOCK_EX) < 0)
#endif
#ifdef SYSV
- while (lockf(fileno(fp), F_LOCK, 1) < 0)
+ while (lockf(fileno(score_fp), F_LOCK, 1) < 0)
#endif
{
perror("flock");
return (-1);
}
for (;;) {
- good = fscanf(fp, "%s %s %s %d %d %d",
+ good = fscanf(score_fp, "%s %s %s %d %d %d",
score[num_scores].name,
score[num_scores].host,
score[num_scores].game,
@@ -215,9 +224,9 @@ log_score(list_em)
else
puts("You made the top players list!");
qsort(score, num_scores, sizeof (*score), compar);
- rewind(fp);
+ rewind(score_fp);
for (i = 0; i < num_scores; i++)
- fprintf(fp, "%s %s %s %d %d %d\n",
+ fprintf(score_fp, "%s %s %s %d %d %d\n",
score[i].name, score[i].host,
score[i].game, score[i].planes,
score[i].time, score[i].real_time);
@@ -230,12 +239,18 @@ log_score(list_em)
putchar('\n');
}
#ifdef BSD
- flock(fileno(fp), LOCK_UN);
+ flock(fileno(score_fp), LOCK_UN);
#endif
#ifdef SYSV
/* lock will evaporate upon close */
#endif
- fclose(fp);
+#if 0
+ fclose(score_fp);
+#else
+ fflush(score_fp);
+ fsync(fileno(score_fp));
+ rewind(score_fp);
+#endif
printf("%2s: %-8s %-8s %-18s %4s %9s %4s\n", "#", "name", "host",
"game", "time", "real time", "planes safe");
puts("-------------------------------------------------------------------------------");
diff --git a/games/atc/main.c b/games/atc/main.c
index cd502e26a63..32d5f8d341a 100644
--- a/games/atc/main.c
+++ b/games/atc/main.c
@@ -77,6 +77,8 @@ main(ac, av)
extern char *default_game(), *okay_game();
extern void log_score(), quit(), update();
+ open_score_file();
+
/* revoke privs */
setegid(getgid());
setgid(getgid());