-/* $NetBSD: wump.c,v 1.6 1998/08/30 09:19:41 veego Exp $ */
+/* $NetBSD: wump.c,v 1.12 1999/09/12 09:02:24 jsm Exp $ */
/*
* Copyright (c) 1989, 1993
#if 0
static char sccsid[] = "@(#)wump.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: wump.c,v 1.6 1998/08/30 09:19:41 veego Exp $");
+__RCSID("$NetBSD: wump.c,v 1.12 1999/09/12 09:02:24 jsm Exp $");
#endif
#endif /* not lint */
* would care to remember.
*/
+#include <err.h>
#include <sys/types.h>
#include <sys/file.h>
+#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#include <unistd.h>
#include "pathnames.h"
int shoot __P((char *));
void shoot_self __P((void));
int take_action __P((void));
-void usage __P((void));
+void usage __P((void)) __attribute__((__noreturn__));
void wump_kill __P((void));
int wump_nearby __P((void));
{
int c;
+ /* Revoke setgid privileges */
+ setregid(getgid(), getgid());
+
#ifdef DEBUG
while ((c = getopt(argc, argv, "a:b:hp:r:t:d")) != -1)
#else
int_compare(a, b)
const void *a, *b;
{
- return(*(int *)a < *(int *)b ? -1 : 1);
+ return(*(const int *)a < *(const int *)b ? -1 : 1);
}
void
instructions()
{
- char buf[120], *p;
+ const char *pager;
+ pid_t pid;
+ int status;
+ int fd;
/*
* read the instructions file, if needed, and show the user how to
return;
}
- if (!(p = getenv("PAGER")) ||
- strlen(p) > sizeof(buf) + strlen(_PATH_WUMPINFO) + 5)
- p = _PATH_PAGER;
-
- (void)sprintf(buf, "%s %s", p, _PATH_WUMPINFO);
- (void)system(buf);
+ if (!isatty(STDOUT_FILENO))
+ pager = "cat";
+ else {
+ if (!(pager = getenv("PAGER")) || (*pager == 0))
+ pager = _PATH_PAGER;
+ }
+ switch (pid = fork()) {
+ case 0: /* child */
+ if ((fd = open(_PATH_WUMPINFO, O_RDONLY)) == -1)
+ err(1, "open %s", _PATH_WUMPINFO);
+ if (dup2(fd, STDIN_FILENO) == -1)
+ err(1, "dup2");
+ (void)execl("/bin/sh", "sh", "-c", pager, NULL);
+ err(1, "exec sh -c %s", pager);
+ case -1:
+ err(1, "fork");
+ default:
+ (void)waitpid(pid, &status, 0);
+ break;
+ }
}
void