summaryrefslogtreecommitdiff
path: root/libexec
diff options
context:
space:
mode:
authortron <tron@NetBSD.org>2000-07-13 06:15:03 +0000
committertron <tron@NetBSD.org>2000-07-13 06:15:03 +0000
commitb238c131cec82e5f17cbc4582d6441ce82fd95c5 (patch)
treeec3e63bccfa5a0abc84db5f3cc7836ba33d4e84d /libexec
parent3eedcb30092583d664356b3981f65629f8fa5a26 (diff)
Optimize invokation of "nroff":
- Redirect standard error to "/dev/null" because "nroff" error messages for temporary files aren't really useful. - Don't let "nroff" open temporary file. Use its file descriptor as standard input.
Diffstat (limited to 'libexec')
-rw-r--r--libexec/makewhatis/makewhatis.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/libexec/makewhatis/makewhatis.c b/libexec/makewhatis/makewhatis.c
index deb1cf61d89..42ec5ab1640 100644
--- a/libexec/makewhatis/makewhatis.c
+++ b/libexec/makewhatis/makewhatis.c
@@ -1,4 +1,4 @@
-/* $NetBSD: makewhatis.c,v 1.9 2000/07/10 08:11:31 tron Exp $ */
+/* $NetBSD: makewhatis.c,v 1.10 2000/07/13 06:15:03 tron Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1999 The NetBSD Foundation, Inc.\n\
#endif /* not lint */
#ifndef lint
-__RCSID("$NetBSD: makewhatis.c,v 1.9 2000/07/10 08:11:31 tron Exp $");
+__RCSID("$NetBSD: makewhatis.c,v 1.10 2000/07/13 06:15:03 tron Exp $");
#endif /* not lint */
#include <sys/types.h>
@@ -54,6 +54,7 @@ __RCSID("$NetBSD: makewhatis.c,v 1.9 2000/07/10 08:11:31 tron Exp $");
#include <ctype.h>
#include <err.h>
#include <errno.h>
+#include <fcntl.h>
#include <fts.h>
#include <locale.h>
#include <paths.h>
@@ -456,6 +457,7 @@ nroff(gzFile *in)
{
char tempname[MAXPATHLEN], buffer[65536], *data;
int tempfd, bytes, pipefd[2], status;
+ static int devnull = -1;
pid_t child;
if (gzrewind(in) < 0) {
@@ -463,6 +465,12 @@ nroff(gzFile *in)
return NULL;
}
+ if ((devnull < 0) &&
+ ((devnull = open(_PATH_DEVNULL, O_WRONLY, 0)) < 0)) {
+ perror(__progname);
+ return NULL;
+ }
+
(void)strcpy(tempname, _PATH_TMP "makewhatis.XXXXXX");
if ((tempfd = mkstemp(tempname)) < 0) {
perror(__progname);
@@ -495,11 +503,19 @@ nroff(gzFile *in)
/* NOTREACHED */
case 0:
(void)close(pipefd[0]);
+ if (tempfd != STDIN_FILENO) {
+ (void)dup2(tempfd, STDIN_FILENO);
+ (void)close(tempfd);
+ }
if (pipefd[1] != STDOUT_FILENO) {
(void)dup2(pipefd[1], STDOUT_FILENO);
(void)close(pipefd[1]);
}
- (void)execlp("nroff", "nroff", "-mandoc", tempname, NULL);
+ if (devnull != STDERR_FILENO) {
+ (void)dup2(devnull, STDERR_FILENO);
+ (void)close(devnull);
+ }
+ (void)execlp("nroff", "nroff", "-mandoc", NULL);
_exit(EXIT_FAILURE);
default:
(void)close(pipefd[1]);