diff options
author | ache <ache@FreeBSD.org> | 1997-09-24 02:34:53 +0000 |
---|---|---|
committer | ache <ache@FreeBSD.org> | 1997-09-24 02:34:53 +0000 |
commit | ace16f9a4bb54d69518d6aaddf9ba9d6fe278e7c (patch) | |
tree | 88856652968dab0f036805bb58e022d22da9c837 /games/snake | |
parent | 3f8a1087277f938d1482d273a24d2444bc103e07 (diff) | |
download | FreeBSD-src-ace16f9a4bb54d69518d6aaddf9ba9d6fe278e7c.zip FreeBSD-src-ace16f9a4bb54d69518d6aaddf9ba9d6fe278e7c.tar.gz |
Beforeinstall scores and log file to prevent them owned by
first who run snake
snake.c: cleanup, use srandomdev() now, fix created file permissions
Diffstat (limited to 'games/snake')
-rw-r--r-- | games/snake/snake/Makefile | 6 | ||||
-rw-r--r-- | games/snake/snake/snake.c | 14 |
2 files changed, 13 insertions, 7 deletions
diff --git a/games/snake/snake/Makefile b/games/snake/snake/Makefile index 8b96cfc..a119453 100644 --- a/games/snake/snake/Makefile +++ b/games/snake/snake/Makefile @@ -8,5 +8,11 @@ LDADD= -lm -ltermcap -lcompat HIDEGAME=hidegame MLINKS= snake.6 snscore.6 +beforeinstall: + ${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m 664 /dev/null \ + ${DESTDIR}/var/games/snakerawscores + ${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m 664 /dev/null \ + ${DESTDIR}/var/games/snake.log + .include "../../Makefile.inc" .include <bsd.prog.mk> diff --git a/games/snake/snake/snake.c b/games/snake/snake/snake.c index 7fdf0db..c9c813d 100644 --- a/games/snake/snake/snake.c +++ b/games/snake/snake/snake.c @@ -58,6 +58,8 @@ static char sccsid[] = "@(#)snake.c 8.2 (Berkeley) 1/7/94"; #include <fcntl.h> #include <pwd.h> #include <time.h> +#include <stdlib.h> +#include <unistd.h> #include "snake.h" #include "pathnames.h" @@ -103,18 +105,16 @@ char **argv; extern char *optarg; extern int optind; int ch, i, j, k; - long atol(); void stop(); - rawscores = open(_PATH_RAWSCORES, O_RDWR|O_CREAT, 0644); + rawscores = open(_PATH_RAWSCORES, O_RDWR|O_CREAT, 0664); logfile = fopen(_PATH_LOGFILE, "a"); /* revoke privs */ setegid(getgid()); setgid(getgid()); - (void)time(&tv); - srandom((int)tv); + srandomdev(); while ((ch = getopt(argc, argv, "l:w:")) != EOF) switch((char)ch) { @@ -494,14 +494,14 @@ int iscore, flag; /* Figure out what happened in the past */ read(rawscores, &allbscore, sizeof(short)); read(rawscores, &allbwho, sizeof(short)); - lseek(rawscores, ((long)uid)*sizeof(short), 0); + lseek(rawscores, ((off_t)uid)*sizeof(short), 0); read(rawscores, &oldbest, sizeof(short)); if (!flag) return (score > oldbest ? 1 : 0); /* Update this jokers best */ if (score > oldbest) { - lseek(rawscores, ((long)uid)*sizeof(short), 0); + lseek(rawscores, ((off_t)uid)*sizeof(short), 0); write(rawscores, &score, sizeof(short)); pr("You bettered your previous best of $%d\n", oldbest); } else @@ -510,7 +510,7 @@ int iscore, flag; /* See if we have a new champ */ p = getpwuid(allbwho); if (p == NULL || score > allbscore) { - lseek(rawscores, (long)0, 0); + lseek(rawscores, (off_t)0, 0); write(rawscores, &score, sizeof(short)); write(rawscores, &uid, sizeof(short)); if (allbwho) |