X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/01f8d1db18471a5d88884cc54ab794ba91fd75ac..283621ee3b4a30d66d08567b6507c0ba1580dbf1:/dm/dm.c diff --git a/dm/dm.c b/dm/dm.c index ebe43652..488110d8 100644 --- a/dm/dm.c +++ b/dm/dm.c @@ -1,4 +1,4 @@ -/* $NetBSD: dm.c,v 1.7 1997/10/10 12:49:49 lukem Exp $ */ +/* $NetBSD: dm.c,v 1.15 1999/09/22 18:54:42 jsm Exp $ */ /* * Copyright (c) 1987, 1993 @@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1987, 1993\n\ #if 0 static char sccsid[] = "@(#)dm.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: dm.c,v 1.7 1997/10/10 12:49:49 lukem Exp $"); +__RCSID("$NetBSD: dm.c,v 1.15 1999/09/22 18:54:42 jsm Exp $"); #endif #endif /* not lint */ @@ -55,7 +55,6 @@ __RCSID("$NetBSD: dm.c,v 1.7 1997/10/10 12:49:49 lukem Exp $"); #include #include #include -#include #include #include #include @@ -71,14 +70,14 @@ static int priority = 0; /* priority game runs at */ static char *game, /* requested game */ *gametty; /* from tty? */ -void c_day __P((char *, char *, char *)); -void c_game __P((char *, char *, char *, char *)); -void c_tty __P((char *)); +void c_day __P((const char *, const char *, const char *)); +void c_game __P((const char *, const char *, const char *, const char *)); +void c_tty __P((const char *)); const char *hour __P((int)); double load __P((void)); int main __P((int, char *[])); void nogamefile __P((void)); -void play __P((char **)); +void play __P((char **)) __attribute__((__noreturn__)); void read_config __P((void)); int users __P((void)); @@ -96,6 +95,7 @@ main(argc, argv) exit(0); gametty = ttyname(0); + unsetenv("TZ"); (void)time(&now); read_config(); #ifdef LOG @@ -103,7 +103,7 @@ main(argc, argv) #endif play(argv); /*NOTREACHED*/ - return(0); + return (0); } /* @@ -122,7 +122,6 @@ play(args) pbuf[sizeof(pbuf) - 1] = '\0'; if (priority > 0) /* < 0 requires root */ (void)setpriority(PRIO_PROCESS, 0, priority); - setgid(getgid()); /* we run setgid kmem; lose it */ execv(pbuf, args); err(1, "%s", pbuf); } @@ -140,7 +139,7 @@ read_config() if (!(cfp = fopen(_PATH_CONFIG, "r"))) return; while (fgets(lbuf, sizeof(lbuf), cfp)) - switch(*lbuf) { + switch (*lbuf) { case 'b': /* badtty */ if (sscanf(lbuf, "%s%s", f1, f2) != 2 || strcasecmp(f1, "badtty")) @@ -168,9 +167,9 @@ read_config() */ void c_day(s_day, s_start, s_stop) - char *s_day, *s_start, *s_stop; + const char *s_day, *s_start, *s_stop; { - static char *days[] = { + static const char *const days[] = { "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", }; @@ -185,9 +184,13 @@ c_day(s_day, s_start, s_stop) return; start = atoi(s_start); stop = atoi(s_stop); - if (ct->tm_hour >= start && ct->tm_hour < stop) - errx(0, "Sorry, games are not available from %s to %s today.", - hour(start), hour(stop)); + if (ct->tm_hour >= start && ct->tm_hour < stop) { + if (start == 0 && stop == 24) + errx(0, "Sorry, games are not available today."); + else + errx(0, "Sorry, games are not available from %s to %s today.", + hour(start), hour(stop)); + } } /* @@ -196,7 +199,7 @@ c_day(s_day, s_start, s_stop) */ void c_tty(tty) - char *tty; + const char *tty; { static int first = 1; static char *p_tty; @@ -216,7 +219,7 @@ c_tty(tty) */ void c_game(s_game, s_load, s_users, s_priority) - char *s_game, *s_load, *s_users, *s_priority; + const char *s_game, *s_load, *s_users, *s_priority; { static int found; @@ -243,8 +246,8 @@ load() double avenrun[3]; if (getloadavg(avenrun, sizeof(avenrun)/sizeof(avenrun[0])) < 0) - err(1, "getloadavg() failed."); - return(avenrun[2]); + err(1, "getloadavg() failed"); + return (avenrun[2]); } /* @@ -265,7 +268,7 @@ users() for (nusers = 0; read(utmp, (char *)&buf, sizeof(struct utmp)) > 0;) if (buf.ut_name[0] != '\0') ++nusers; - return(nusers); + return (nusers); } void @@ -291,16 +294,16 @@ const char * hour(h) int h; { - static char *hours[] = { + static const char *const hours[] = { "midnight", "1am", "2am", "3am", "4am", "5am", "6am", "7am", "8am", "9am", "10am", "11am", "noon", "1pm", "2pm", "3pm", "4pm", "5pm", - "6pm", "7pm", "8pm", "9pm", "10pm", "11pm" }; + "6pm", "7pm", "8pm", "9pm", "10pm", "11pm", "midnight" }; - if (h < 0 || h > 23) - return "BAD TIME"; + if (h < 0 || h > 24) + return ("BAD TIME"); else - return hours[h]; + return (hours[h]); } #ifdef LOG