Deleted Added
full compact
exec.c (47769) exec.c (47849)
1/*-
2 * Copyright (c) 1999 Brian Somers <brian@Awfulhak.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 1999 Brian Somers <brian@Awfulhak.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $Id: exec.c,v 1.4 1999/06/01 19:08:57 brian Exp $
26 * $Id: exec.c,v 1.5 1999/06/05 21:35:50 brian Exp $
27 */
28
29#include <sys/param.h>
30#include <sys/socket.h>
31#include <netinet/in.h>
32#include <arpa/inet.h>
33#include <netdb.h>
34#include <netinet/in_systm.h>

--- 78 unchanged lines hidden (view full) ---

113 if (p->fd < 0 && *p->name.full == '!') {
114 int fids[2];
115
116 if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, fids) < 0)
117 log_Printf(LogPHASE, "Unable to create pipe for line exec: %s\n",
118 strerror(errno));
119 else {
120 int stat, argc;
27 */
28
29#include <sys/param.h>
30#include <sys/socket.h>
31#include <netinet/in.h>
32#include <arpa/inet.h>
33#include <netdb.h>
34#include <netinet/in_systm.h>

--- 78 unchanged lines hidden (view full) ---

113 if (p->fd < 0 && *p->name.full == '!') {
114 int fids[2];
115
116 if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, fids) < 0)
117 log_Printf(LogPHASE, "Unable to create pipe for line exec: %s\n",
118 strerror(errno));
119 else {
120 int stat, argc;
121 pid_t pid;
121 pid_t pid, realpid;
122 char *argv[MAXARGS];
123
124 stat = fcntl(fids[0], F_GETFL, 0);
125 if (stat > 0) {
126 stat |= O_NONBLOCK;
127 fcntl(fids[0], F_SETFL, stat);
128 }
122 char *argv[MAXARGS];
123
124 stat = fcntl(fids[0], F_GETFL, 0);
125 if (stat > 0) {
126 stat |= O_NONBLOCK;
127 fcntl(fids[0], F_SETFL, stat);
128 }
129 realpid = getpid();
129 switch ((pid = fork())) {
130 case -1:
131 log_Printf(LogPHASE, "Unable to create pipe for line exec: %s\n",
132 strerror(errno));
133 break;
134
135 case 0:
136 close(fids[0]);

--- 14 unchanged lines hidden (view full) ---

151 fids[1] = fcntl(fids[1], F_DUPFD, 3);
152 dup2(fids[1], STDIN_FILENO);
153 dup2(fids[1], STDOUT_FILENO);
154 dup2(fids[1], STDERR_FILENO);
155
156 log_Printf(LogDEBUG, "Exec'ing ``%s''\n", p->name.base);
157 argc = MakeArgs(p->name.base, argv, VECSIZE(argv));
158 command_Expand(argv, argc, (char const *const *)argv,
130 switch ((pid = fork())) {
131 case -1:
132 log_Printf(LogPHASE, "Unable to create pipe for line exec: %s\n",
133 strerror(errno));
134 break;
135
136 case 0:
137 close(fids[0]);

--- 14 unchanged lines hidden (view full) ---

152 fids[1] = fcntl(fids[1], F_DUPFD, 3);
153 dup2(fids[1], STDIN_FILENO);
154 dup2(fids[1], STDOUT_FILENO);
155 dup2(fids[1], STDERR_FILENO);
156
157 log_Printf(LogDEBUG, "Exec'ing ``%s''\n", p->name.base);
158 argc = MakeArgs(p->name.base, argv, VECSIZE(argv));
159 command_Expand(argv, argc, (char const *const *)argv,
159 p->dl->bundle, 0);
160 p->dl->bundle, 0, realpid);
160 execvp(*argv, argv);
161 fprintf(stderr, "execvp failed: %s: %s\r\n", *argv, strerror(errno));
162 _exit(127);
163 break;
164
165 default:
166 close(fids[1]);
167 p->fd = fids[0];
168 waitpid(pid, &stat, 0);
169 log_Printf(LogDEBUG, "Using descriptor %d for child\n", p->fd);
170 physical_SetupStack(p, execdevice.name, PHYSICAL_FORCE_ASYNC);
171 return &execdevice;
172 }
173 }
174 }
175
176 return NULL;
177}
161 execvp(*argv, argv);
162 fprintf(stderr, "execvp failed: %s: %s\r\n", *argv, strerror(errno));
163 _exit(127);
164 break;
165
166 default:
167 close(fids[1]);
168 p->fd = fids[0];
169 waitpid(pid, &stat, 0);
170 log_Printf(LogDEBUG, "Using descriptor %d for child\n", p->fd);
171 physical_SetupStack(p, execdevice.name, PHYSICAL_FORCE_ASYNC);
172 return &execdevice;
173 }
174 }
175 }
176
177 return NULL;
178}