| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: popen.c,v 1.35 2009/03/15 07:48:36 lukem Exp $ */ | | 1 | /* $NetBSD: popen.c,v 1.36 2009/03/18 02:27:41 lukem Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 1999-2009 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 1999-2009 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Luke Mewburn. | | 8 | * by Luke Mewburn. |
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. |
| @@ -57,27 +57,27 @@ | | | @@ -57,27 +57,27 @@ |
57 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 57 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
58 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 58 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
59 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 59 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
60 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 60 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
61 | * SUCH DAMAGE. | | 61 | * SUCH DAMAGE. |
62 | * | | 62 | * |
63 | */ | | 63 | */ |
64 | | | 64 | |
65 | #include <sys/cdefs.h> | | 65 | #include <sys/cdefs.h> |
66 | #ifndef lint | | 66 | #ifndef lint |
67 | #if 0 | | 67 | #if 0 |
68 | static char sccsid[] = "@(#)popen.c 8.3 (Berkeley) 4/6/94"; | | 68 | static char sccsid[] = "@(#)popen.c 8.3 (Berkeley) 4/6/94"; |
69 | #else | | 69 | #else |
70 | __RCSID("$NetBSD: popen.c,v 1.35 2009/03/15 07:48:36 lukem Exp $"); | | 70 | __RCSID("$NetBSD: popen.c,v 1.36 2009/03/18 02:27:41 lukem Exp $"); |
71 | #endif | | 71 | #endif |
72 | #endif /* not lint */ | | 72 | #endif /* not lint */ |
73 | | | 73 | |
74 | #include <sys/types.h> | | 74 | #include <sys/types.h> |
75 | #include <sys/param.h> | | 75 | #include <sys/param.h> |
76 | #include <sys/wait.h> | | 76 | #include <sys/wait.h> |
77 | | | 77 | |
78 | #include <errno.h> | | 78 | #include <errno.h> |
79 | #include <glob.h> | | 79 | #include <glob.h> |
80 | #include <signal.h> | | 80 | #include <signal.h> |
81 | #include <stdio.h> | | 81 | #include <stdio.h> |
82 | #include <stdlib.h> | | 82 | #include <stdlib.h> |
83 | #include <string.h> | | 83 | #include <string.h> |
| @@ -98,27 +98,28 @@ __RCSID("$NetBSD: popen.c,v 1.35 2009/03 | | | @@ -98,27 +98,28 @@ __RCSID("$NetBSD: popen.c,v 1.35 2009/03 |
98 | * command. | | 98 | * command. |
99 | * If stderrfd != -1, then send stderr of a read command there, | | 99 | * If stderrfd != -1, then send stderr of a read command there, |
100 | * otherwise close stderr. | | 100 | * otherwise close stderr. |
101 | */ | | 101 | */ |
102 | static int *pids; | | 102 | static int *pids; |
103 | static int fds; | | 103 | static int fds; |
104 | | | 104 | |
105 | extern int ls_main(int, char *[]); | | 105 | extern int ls_main(int, char *[]); |
106 | | | 106 | |
107 | FILE * | | 107 | FILE * |
108 | ftpd_popen(const char *argv[], const char *ptype, int stderrfd) | | 108 | ftpd_popen(const char *argv[], const char *ptype, int stderrfd) |
109 | { | | 109 | { |
110 | FILE *iop; | | 110 | FILE *iop; |
111 | int argc, pdes[2], pid, isls; | | 111 | int argc, pdes[2], pid; |
| | | 112 | volatile int isls; |
112 | char **pop; | | 113 | char **pop; |
113 | StringList *sl; | | 114 | StringList *sl; |
114 | | | 115 | |
115 | iop = NULL; | | 116 | iop = NULL; |
116 | isls = 0; | | 117 | isls = 0; |
117 | if ((*ptype != 'r' && *ptype != 'w') || ptype[1]) | | 118 | if ((*ptype != 'r' && *ptype != 'w') || ptype[1]) |
118 | return (NULL); | | 119 | return (NULL); |
119 | | | 120 | |
120 | if (!pids) { | | 121 | if (!pids) { |
121 | if ((fds = getdtablesize()) <= 0) | | 122 | if ((fds = getdtablesize()) <= 0) |
122 | return (NULL); | | 123 | return (NULL); |
123 | if ((pids = (int *)malloc((unsigned int)(fds * sizeof(int)))) == NULL) | | 124 | if ((pids = (int *)malloc((unsigned int)(fds * sizeof(int)))) == NULL) |
124 | return (NULL); | | 125 | return (NULL); |