diff options
-rw-r--r-- | dm/dm.8 | 18 | ||||
-rw-r--r-- | dm/dm.c | 113 | ||||
-rw-r--r-- | factor/factor.6 | 14 | ||||
-rw-r--r-- | factor/factor.c | 13 |
4 files changed, 80 insertions, 78 deletions
@@ -1,4 +1,4 @@ -.\" $NetBSD: dm.8,v 1.3 1995/03/21 15:09:04 cgd Exp $ +.\" $NetBSD: dm.8,v 1.4 1997/10/10 12:49:45 lukem Exp $ .\" .\" Copyright (c) 1987, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -43,12 +43,12 @@ .Nm ln .Fl s Cm dm Ar game .Sh DESCRIPTION -.Nm Dm +.Nm is a program used to regulate game playing. -.Nm Dm +.Nm expects to be invoked with the name of a game that a user wishes to play. This is done by creating symbolic links to -.Nm dm , +.Nm "" , in the directory .Pa /usr/games for all of the regulated games. @@ -57,9 +57,9 @@ The actual binaries for these games should be placed in a directory, .Pa /usr/games/hide , that may only be accessed by the -.Nm dm +.Nm program. -.Nm Dm +.Nm determines if the requested game is available and, if so, runs it. The file .Pa /etc/dm.conf @@ -88,7 +88,7 @@ game logging file .Xr dm.conf 5 .Sh BUGS Two problems result from -.Nm dm +.Nm running the games setuid .Dq games . First, all games that allow users to run @@ -96,7 +96,7 @@ First, all games that allow users to run commands should carefully set both the real and effective user id's immediately before executing those commands. Probably more important is that -.Nm dm +.Nm never be setuid anything but .Dq games @@ -106,6 +106,6 @@ had no reason to run setuid and which accessed user files may have to be modified. .Sh HISTORY The -.Nm dm +.Nm command appeared in .Bx 4.3 tahoe . @@ -1,4 +1,4 @@ -/* $NetBSD: dm.c,v 1.6 1997/04/21 11:11:47 mrg Exp $ */ +/* $NetBSD: dm.c,v 1.7 1997/10/10 12:49:49 lukem Exp $ */ /* * Copyright (c) 1987, 1993 @@ -33,17 +33,17 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> #ifndef lint -static char copyright[] = -"@(#) Copyright (c) 1987, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; +__COPYRIGHT("@(#) Copyright (c) 1987, 1993\n\ + The Regents of the University of California. All rights reserved.\n"); #endif /* not lint */ #ifndef lint #if 0 static char sccsid[] = "@(#)dm.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: dm.c,v 1.6 1997/04/21 11:11:47 mrg Exp $"; +__RCSID("$NetBSD: dm.c,v 1.7 1997/10/10 12:49:49 lukem Exp $"); #endif #endif /* not lint */ @@ -52,15 +52,17 @@ static char rcsid[] = "$NetBSD: dm.c,v 1.6 1997/04/21 11:11:47 mrg Exp $"; #include <sys/time.h> #include <sys/resource.h> +#include <err.h> #include <ctype.h> +#include <errno.h> #include <nlist.h> #include <pwd.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <time.h> #include <unistd.h> #include <utmp.h> -#include <errno.h> #include "pathnames.h" @@ -69,6 +71,17 @@ 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 *)); +const char *hour __P((int)); +double load __P((void)); +int main __P((int, char *[])); +void nogamefile __P((void)); +void play __P((char **)); +void read_config __P((void)); +int users __P((void)); + int main(argc, argv) int argc; @@ -77,7 +90,7 @@ main(argc, argv) char *cp; nogamefile(); - game = (cp = rindex(*argv, '/')) ? ++cp : *argv; + game = (cp = strrchr(*argv, '/')) ? ++cp : *argv; if (!strcmp(game, "dm")) exit(0); @@ -90,12 +103,14 @@ main(argc, argv) #endif play(argv); /*NOTREACHED*/ + return(0); } /* * play -- * play the game */ +void play(args) char **args; { @@ -109,14 +124,14 @@ play(args) (void)setpriority(PRIO_PROCESS, 0, priority); setgid(getgid()); /* we run setgid kmem; lose it */ execv(pbuf, args); - (void)fprintf(stderr, "dm: %s: %s\n", pbuf, strerror(errno)); - exit(1); + err(1, "%s", pbuf); } /* * read_config -- * read through config file, looking for key words. */ +void read_config() { FILE *cfp; @@ -151,6 +166,7 @@ read_config() * c_day -- * if day is today, see if okay to play */ +void c_day(s_day, s_start, s_stop) char *s_day, *s_start, *s_stop; { @@ -169,20 +185,16 @@ 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) { - fputs("dm: Sorry, games are not available from ", stderr); - hour(start); - fputs(" to ", stderr); - hour(stop); - fputs(" today.\n", stderr); - exit(0); - } + 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)); } /* * c_tty -- * decide if this tty can be used for games. */ +void c_tty(tty) char *tty; { @@ -190,39 +202,33 @@ c_tty(tty) static char *p_tty; if (first) { - p_tty = rindex(gametty, '/'); + p_tty = strrchr(gametty, '/'); first = 0; } - if (!strcmp(gametty, tty) || p_tty && !strcmp(p_tty, tty)) { - fprintf(stderr, "dm: Sorry, you may not play games on %s.\n", gametty); - exit(0); - } + if (!strcmp(gametty, tty) || (p_tty && !strcmp(p_tty, tty))) + errx(1, "Sorry, you may not play games on %s.", gametty); } /* * c_game -- * see if game can be played now. */ +void c_game(s_game, s_load, s_users, s_priority) char *s_game, *s_load, *s_users, *s_priority; { static int found; - double load(); if (found) return; if (strcmp(game, s_game) && strcasecmp("default", s_game)) return; ++found; - if (isdigit(*s_load) && atoi(s_load) < load()) { - fputs("dm: Sorry, the load average is too high right now.\n", stderr); - exit(0); - } - if (isdigit(*s_users) && atoi(s_users) <= users()) { - fputs("dm: Sorry, there are too many users logged on right now.\n", stderr); - exit(0); - } + if (isdigit(*s_load) && atoi(s_load) < load()) + errx(0, "Sorry, the load average is too high right now."); + if (isdigit(*s_users) && atoi(s_users) <= users()) + errx(0, "Sorry, there are too many users logged on right now."); if (isdigit(*s_priority)) priority = atoi(s_priority); } @@ -236,10 +242,8 @@ load() { double avenrun[3]; - if (getloadavg(avenrun, sizeof(avenrun)/sizeof(avenrun[0])) < 0) { - fputs("dm: getloadavg() failed.\n", stderr); - exit(1); - } + if (getloadavg(avenrun, sizeof(avenrun)/sizeof(avenrun[0])) < 0) + err(1, "getloadavg() failed."); return(avenrun[2]); } @@ -249,26 +253,25 @@ load() * todo: check idle time; if idle more than X minutes, don't * count them. */ +int users() { - register int nusers, utmp; + int nusers, utmp; struct utmp buf; - if ((utmp = open(_PATH_UTMP, O_RDONLY, 0)) < 0) { - (void)fprintf(stderr, "dm: %s: %s\n", - _PATH_UTMP, strerror(errno)); - exit(1); - } + if ((utmp = open(_PATH_UTMP, O_RDONLY, 0)) < 0) + err(1, "%s", _PATH_UTMP); for (nusers = 0; read(utmp, (char *)&buf, sizeof(struct utmp)) > 0;) if (buf.ut_name[0] != '\0') ++nusers; return(nusers); } +void nogamefile() { - register int fd, n; + int fd, n; char buf[BUFSIZ]; if ((fd = open(_PATH_NOGAMES, O_RDONLY, 0)) >= 0) { @@ -284,22 +287,20 @@ nogamefile() * hour -- * print out the hour in human form */ +const char * hour(h) int h; { - switch(h) { - case 0: - fputs("midnight", stderr); - break; - case 12: - fputs("noon", stderr); - break; - default: - if (h > 12) - fprintf(stderr, "%dpm", h - 12); - else - fprintf(stderr, "%dam", h); - } + static char *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" }; + + if (h < 0 || h > 23) + return "BAD TIME"; + else + return hours[h]; } #ifdef LOG @@ -319,7 +320,7 @@ logfile() if (!flock(fileno(lp), LOCK_EX)) break; if (lock_cnt == 4) { - perror("dm: log lock"); + warnx("log lock"); (void)fclose(lp); return; } diff --git a/factor/factor.6 b/factor/factor.6 index d21be552..8740314b 100644 --- a/factor/factor.6 +++ b/factor/factor.6 @@ -1,4 +1,4 @@ -.\" $NetBSD: factor.6,v 1.4 1995/03/23 08:28:05 cgd Exp $ +.\" $NetBSD: factor.6,v 1.5 1997/10/10 12:51:27 lukem Exp $ .\" .\" Copyright (c) 1989, 1993 .\" The Regents of the University of California. All rights reserved. @@ -50,14 +50,14 @@ .Nd factor a number, generate primes .Sh SYNOPSIS -.Nm factor +.Nm .Op Ar number ... .br .Nm primes .Op Ar start Op Ar stop .Sh DESCRIPTION The -.Nm factor +.Nm utility will factor integers between -2147483648 and 2147483647 inclusive. When a number is factored, it is printed, followed by a .Dq \: , @@ -67,14 +67,14 @@ If a factor divides a value more than once, it will be printed more than once. .Pp When -.Nm factor +.Nm is invoked with one or more arguments, each argument will be factored. .Pp When -.Nm factor +.Nm is invoked with no arguments, -.Nm factor +.Nm reads numbers, one per line, from standard input, until end of file or error. Leading white-space and empty lines are ignored. Numbers may be preceded by a single - or +. @@ -118,7 +118,7 @@ Out of range or invalid input results in .Sq ouch being written to standard error. .Sh BUGS -.Nm Factor +.Nm cannot handle the .Dq 10 most wanted factor list, diff --git a/factor/factor.c b/factor/factor.c index 051188ea..a0febe27 100644 --- a/factor/factor.c +++ b/factor/factor.c @@ -1,4 +1,4 @@ -/* $NetBSD: factor.c,v 1.6 1997/01/07 12:05:10 tls Exp $ */ +/* $NetBSD: factor.c,v 1.7 1997/10/10 12:51:32 lukem Exp $ */ /* * Copyright (c) 1989, 1993 @@ -36,17 +36,17 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> #ifndef lint -static char copyright[] = -"@(#) Copyright (c) 1989, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; +__COPYRIGHT("@(#) Copyright (c) 1989, 1993\n\ + The Regents of the University of California. All rights reserved.\n"); #endif /* not lint */ #ifndef lint #if 0 static char sccsid[] = "@(#)factor.c 8.4 (Berkeley) 5/4/95"; #else -static char rcsid[] = "$NetBSD: factor.c,v 1.6 1997/01/07 12:05:10 tls Exp $"; +__RCSID("$NetBSD: factor.c,v 1.7 1997/10/10 12:51:32 lukem Exp $"); #endif #endif /* not lint */ @@ -88,6 +88,7 @@ static char rcsid[] = "$NetBSD: factor.c,v 1.6 1997/01/07 12:05:10 tls Exp $"; extern ubig prime[]; extern ubig *pr_limit; /* largest prime in the prime array */ +int main __P((int, char *[])); void pr_fact __P((ubig)); /* print factors of a value */ void usage __P((void)); @@ -100,7 +101,7 @@ main(argc, argv) int ch; char *p, buf[100]; /* > max number of digits. */ - while ((ch = getopt(argc, argv, "")) != EOF) + while ((ch = getopt(argc, argv, "")) != -1) switch (ch) { case '?': default: |