summaryrefslogtreecommitdiffstats
path: root/snake/snake/snake.c
diff options
context:
space:
mode:
Diffstat (limited to 'snake/snake/snake.c')
-rw-r--r--snake/snake/snake.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/snake/snake/snake.c b/snake/snake/snake.c
index a356a02f..c3a69681 100644
--- a/snake/snake/snake.c
+++ b/snake/snake/snake.c
@@ -1,4 +1,4 @@
-/* $NetBSD: snake.c,v 1.12 1999/09/08 21:57:21 jsm Exp $ */
+/* $NetBSD: snake.c,v 1.13 1999/09/12 09:02:23 jsm Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1993\n\
#if 0
static char sccsid[] = "@(#)snake.c 8.2 (Berkeley) 1/7/94";
#else
-__RCSID("$NetBSD: snake.c,v 1.12 1999/09/08 21:57:21 jsm Exp $");
+__RCSID("$NetBSD: snake.c,v 1.13 1999/09/12 09:02:23 jsm Exp $");
#endif
#endif /* not lint */
@@ -101,6 +101,9 @@ int repeat = 1;
time_t tv;
char *tn;
+int rawscores;
+FILE *logfile;
+
int main __P((int, char **));
int
@@ -112,6 +115,20 @@ main(argc, argv)
extern int optind;
int ch, i;
+ /* Open score files then revoke setgid privileges */
+ rawscores = open(_PATH_RAWSCORES, O_RDWR|O_CREAT, 0664);
+ if (rawscores < 0) {
+ warn("open %s", _PATH_RAWSCORES);
+ sleep(2);
+ } else if (rawscores < 3)
+ exit(1);
+ logfile = fopen(_PATH_LOGFILE, "a");
+ if (logfile == NULL) {
+ warn("fopen %s", _PATH_LOGFILE);
+ sleep(2);
+ }
+ setregid(getgid(), getgid());
+
(void) time(&tv);
srandom((int) tv);
@@ -498,9 +515,8 @@ post(iscore, flag)
pr("No saved scores for uid %d.\n", uid);
return (1);
}
- if ((rawscores = open(_PATH_RAWSCORES, O_RDWR | O_CREAT, 0644)) < 0) {
- pr("No score file %s: %s.\n", _PATH_RAWSCORES,
- strerror(errno));
+ if (rawscores < 0) {
+ /* Error reported earlier */
return (1);
}
/* Figure out what happened in the past */
@@ -532,7 +548,7 @@ post(iscore, flag)
pr("You set a new record!\n");
} else
pr("The highest is %s with $%d\n", p->pw_name, allbscore);
- close(rawscores);
+ lseek(rawscores, 0, SEEK_SET);
return (1);
}
@@ -935,13 +951,12 @@ void
logit(msg)
const char *msg;
{
- FILE *logfile;
time_t t;
- if ((logfile = fopen(_PATH_LOGFILE, "a")) != NULL) {
+ if (logfile != NULL) {
time(&t);
fprintf(logfile, "%s $%d %dx%d %s %s",
getlogin(), cashvalue, lcnt, ccnt, msg, ctime(&t));
- fclose(logfile);
+ fflush(logfile);
}
}