Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-1-5]: src/libexec/makewhatis Sync with netbsd-current, approved b...
details: https://anonhg.NetBSD.org/src/rev/e8091a8a6e2c
branches: netbsd-1-5
changeset: 488494:e8091a8a6e2c
user: tron <tron%NetBSD.org@localhost>
date: Thu Jul 13 16:42:34 2000 +0000
description:
Sync with netbsd-current, approved by releng-1-5:
- 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.
- Kill "nroff" process and wait for its terminiation if we can't setup
the "libz" file handle.
- Invoke "nroff" with "-S" (safer mode) option because "makewhatis" is
usually invoked by "root".
diffstat:
libexec/makewhatis/makewhatis.c | 27 +++++++++++++++++++++++----
1 files changed, 23 insertions(+), 4 deletions(-)
diffs (83 lines):
diff -r c26048a6c0c5 -r e8091a8a6e2c libexec/makewhatis/makewhatis.c
--- a/libexec/makewhatis/makewhatis.c Thu Jul 13 14:59:50 2000 +0000
+++ b/libexec/makewhatis/makewhatis.c Thu Jul 13 16:42:34 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: makewhatis.c,v 1.7.4.1 2000/07/12 20:18:55 tron Exp $ */
+/* $NetBSD: makewhatis.c,v 1.7.4.2 2000/07/13 16:42:34 tron Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -43,7 +43,7 @@
#endif /* not lint */
#ifndef lint
-__RCSID("$NetBSD: makewhatis.c,v 1.7.4.1 2000/07/12 20:18:55 tron Exp $");
+__RCSID("$NetBSD: makewhatis.c,v 1.7.4.2 2000/07/13 16:42:34 tron Exp $");
#endif /* not lint */
#include <sys/types.h>
@@ -54,9 +54,11 @@
#include <ctype.h>
#include <err.h>
#include <errno.h>
+#include <fcntl.h>
#include <fts.h>
#include <locale.h>
#include <paths.h>
+#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -456,6 +458,7 @@
{
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 +466,12 @@
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 +504,19 @@
/* 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", "-S", "-man", NULL);
_exit(EXIT_FAILURE);
default:
(void)close(pipefd[1]);
@@ -511,7 +528,9 @@
if (errno == 0)
errno = ENOMEM;
perror(__progname);
- (void)close(pipefd[0]); /* Child will be killed by SIGPIPE. */
+ (void)close(pipefd[0]);
+ (void)kill(child, SIGTERM);
+ while (waitpid(child, NULL, 0) != child);
(void)unlink(tempname);
return NULL;
}
Home |
Main Index |
Thread Index |
Old Index