| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: redir.c,v 1.32.2.1 2012/04/17 00:01:38 yamt Exp $ */ | | 1 | /* $NetBSD: redir.c,v 1.32.2.2 2013/06/12 01:08:16 yamt Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1991, 1993 | | 4 | * Copyright (c) 1991, 1993 |
5 | * The Regents of the University of California. All rights reserved. | | 5 | * The Regents of the University of California. All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to Berkeley by | | 7 | * This code is derived from software contributed to Berkeley by |
8 | * Kenneth Almquist. | | 8 | * Kenneth Almquist. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -27,27 +27,27 @@ | | | @@ -27,27 +27,27 @@ |
27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | * SUCH DAMAGE. | | 32 | * SUCH DAMAGE. |
33 | */ | | 33 | */ |
34 | | | 34 | |
35 | #include <sys/cdefs.h> | | 35 | #include <sys/cdefs.h> |
36 | #ifndef lint | | 36 | #ifndef lint |
37 | #if 0 | | 37 | #if 0 |
38 | static char sccsid[] = "@(#)redir.c 8.2 (Berkeley) 5/4/95"; | | 38 | static char sccsid[] = "@(#)redir.c 8.2 (Berkeley) 5/4/95"; |
39 | #else | | 39 | #else |
40 | __RCSID("$NetBSD: redir.c,v 1.32.2.1 2012/04/17 00:01:38 yamt Exp $"); | | 40 | __RCSID("$NetBSD: redir.c,v 1.32.2.2 2013/06/12 01:08:16 yamt Exp $"); |
41 | #endif | | 41 | #endif |
42 | #endif /* not lint */ | | 42 | #endif /* not lint */ |
43 | | | 43 | |
44 | #include <sys/types.h> | | 44 | #include <sys/types.h> |
45 | #include <sys/param.h> /* PIPE_BUF */ | | 45 | #include <sys/param.h> /* PIPE_BUF */ |
46 | #include <signal.h> | | 46 | #include <signal.h> |
47 | #include <string.h> | | 47 | #include <string.h> |
48 | #include <fcntl.h> | | 48 | #include <fcntl.h> |
49 | #include <errno.h> | | 49 | #include <errno.h> |
50 | #include <unistd.h> | | 50 | #include <unistd.h> |
51 | #include <stdlib.h> | | 51 | #include <stdlib.h> |
52 | | | 52 | |
53 | /* | | 53 | /* |
| @@ -81,27 +81,27 @@ struct redirtab { | | | @@ -81,27 +81,27 @@ struct redirtab { |
81 | }; | | 81 | }; |
82 | | | 82 | |
83 | | | 83 | |
84 | MKINIT struct redirtab *redirlist; | | 84 | MKINIT struct redirtab *redirlist; |
85 | | | 85 | |
86 | /* | | 86 | /* |
87 | * We keep track of whether or not fd0 has been redirected. This is for | | 87 | * We keep track of whether or not fd0 has been redirected. This is for |
88 | * background commands, where we want to redirect fd0 to /dev/null only | | 88 | * background commands, where we want to redirect fd0 to /dev/null only |
89 | * if it hasn't already been redirected. | | 89 | * if it hasn't already been redirected. |
90 | */ | | 90 | */ |
91 | int fd0_redirected = 0; | | 91 | int fd0_redirected = 0; |
92 | | | 92 | |
93 | STATIC void openredirect(union node *, char[10], int); | | 93 | STATIC void openredirect(union node *, char[10], int); |
94 | STATIC int openhere(union node *); | | 94 | STATIC int openhere(const union node *); |
95 | | | 95 | |
96 | | | 96 | |
97 | /* | | 97 | /* |
98 | * Process a list of redirection commands. If the REDIR_PUSH flag is set, | | 98 | * Process a list of redirection commands. If the REDIR_PUSH flag is set, |
99 | * old file descriptors are stashed away so that the redirection can be | | 99 | * old file descriptors are stashed away so that the redirection can be |
100 | * undone by calling popredir. If the REDIR_BACKQ flag is set, then the | | 100 | * undone by calling popredir. If the REDIR_BACKQ flag is set, then the |
101 | * standard output, and the standard error if it becomes a duplicate of | | 101 | * standard output, and the standard error if it becomes a duplicate of |
102 | * stdout, is saved in memory. | | 102 | * stdout, is saved in memory. |
103 | */ | | 103 | */ |
104 | | | 104 | |
105 | void | | 105 | void |
106 | redirect(union node *redir, int flags) | | 106 | redirect(union node *redir, int flags) |
107 | { | | 107 | { |
| @@ -246,27 +246,27 @@ ecreate: | | | @@ -246,27 +246,27 @@ ecreate: |
246 | eopen: | | 246 | eopen: |
247 | exerrno = 1; | | 247 | exerrno = 1; |
248 | error("cannot open %s: %s", fname, errmsg(errno, E_OPEN)); | | 248 | error("cannot open %s: %s", fname, errmsg(errno, E_OPEN)); |
249 | } | | 249 | } |
250 | | | 250 | |
251 | | | 251 | |
252 | /* | | 252 | /* |
253 | * Handle here documents. Normally we fork off a process to write the | | 253 | * Handle here documents. Normally we fork off a process to write the |
254 | * data to a pipe. If the document is short, we can stuff the data in | | 254 | * data to a pipe. If the document is short, we can stuff the data in |
255 | * the pipe without forking. | | 255 | * the pipe without forking. |
256 | */ | | 256 | */ |
257 | | | 257 | |
258 | STATIC int | | 258 | STATIC int |
259 | openhere(union node *redir) | | 259 | openhere(const union node *redir) |
260 | { | | 260 | { |
261 | int pip[2]; | | 261 | int pip[2]; |
262 | int len = 0; | | 262 | int len = 0; |
263 | | | 263 | |
264 | if (pipe(pip) < 0) | | 264 | if (pipe(pip) < 0) |
265 | error("Pipe call failed"); | | 265 | error("Pipe call failed"); |
266 | if (redir->type == NHERE) { | | 266 | if (redir->type == NHERE) { |
267 | len = strlen(redir->nhere.doc->narg.text); | | 267 | len = strlen(redir->nhere.doc->narg.text); |
268 | if (len <= PIPESIZE) { | | 268 | if (len <= PIPESIZE) { |
269 | xwrite(pip[1], redir->nhere.doc->narg.text, len); | | 269 | xwrite(pip[1], redir->nhere.doc->narg.text, len); |
270 | goto out; | | 270 | goto out; |
271 | } | | 271 | } |
272 | } | | 272 | } |