-/* $NetBSD: dm.c,v 1.13 1999/09/19 18:13:41 jsm Exp $ */
+/* $NetBSD: dm.c,v 1.21 2004/11/05 21:30:32 dsl Exp $ */
/*
* Copyright (c) 1987, 1993
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
#if 0
static char sccsid[] = "@(#)dm.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: dm.c,v 1.13 1999/09/19 18:13:41 jsm Exp $");
+__RCSID("$NetBSD: dm.c,v 1.21 2004/11/05 21:30:32 dsl Exp $");
#endif
#endif /* not lint */
#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 "utmpentry.h"
#include "pathnames.h"
static time_t now; /* current time value */
static char *game, /* requested game */
*gametty; /* from tty? */
-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 **)) __attribute__((__noreturn__));
-void read_config __P((void));
-int users __P((void));
+void c_day(const char *, const char *, const char *);
+void c_game(const char *, const char *, const char *, const char *);
+void c_tty(const char *);
+const char *hour(int);
+double load(void);
+int main(int, char *[]);
+void nogamefile(void);
+void play(char **) __attribute__((__noreturn__));
+void read_config(void);
+int users(void);
int
main(argc, argv)
- int argc;
+ int argc __attribute__((__unused__));
char *argv[];
{
char *cp;
{
char pbuf[MAXPATHLEN];
- (void)strncpy(pbuf, _PATH_HIDE, sizeof(pbuf) - 1);
- (void)strncpy(pbuf + sizeof(_PATH_HIDE) - 1, game,
- sizeof(pbuf) - sizeof(_PATH_HIDE) - 1);
- pbuf[sizeof(pbuf) - 1] = '\0';
+ snprintf(pbuf, sizeof(pbuf), "%s%s", _PATH_HIDE, game);
if (priority > 0) /* < 0 requires root */
(void)setpriority(PRIO_PROCESS, 0, priority);
execv(pbuf, args);
ct = localtime(&now);
if (strcasecmp(s_day, days[ct->tm_wday]))
return;
- if (!isdigit(*s_start) || !isdigit(*s_stop))
+ if (!isdigit((unsigned char)*s_start) || !isdigit((unsigned char)*s_stop))
return;
start = atoi(s_start);
stop = atoi(s_stop);
if (strcmp(game, s_game) && strcasecmp("default", s_game))
return;
++found;
- if (isdigit(*s_load) && atoi(s_load) < load())
+ if (isdigit((unsigned char)*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())
+ if (isdigit((unsigned char)*s_users) && atoi(s_users) <= users())
errx(0, "Sorry, there are too many users logged on right now.");
- if (isdigit(*s_priority))
+ if (isdigit((unsigned char)*s_priority))
priority = atoi(s_priority);
}
double avenrun[3];
if (getloadavg(avenrun, sizeof(avenrun)/sizeof(avenrun[0])) < 0)
- err(1, "getloadavg() failed.");
+ err(1, "getloadavg() failed");
return (avenrun[2]);
}
int
users()
{
-
- int nusers, utmp;
- struct utmp buf;
-
- 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);
+ static struct utmpentry *ohead = NULL;
+ struct utmpentry *ep;
+ int nusers;
+
+ nusers = getutentries(NULL, &ep);
+ if (ep != ohead) {
+ freeutentries(ep);
+ ohead = ep;
+ }
+ return nusers;
}
void