@@ -647,9 +647,9 @@ static void uv__drain(uv_stream_t* stream) {
647
647
ev_io_stop (EV_DEFAULT_ & stream -> write_watcher );
648
648
649
649
/* Shutdown? */
650
- if (((( uv_handle_t * ) stream ) -> flags & UV_SHUTTING ) &&
651
- !((( uv_handle_t * ) stream ) -> flags & UV_CLOSING ) &&
652
- !((( uv_handle_t * ) stream ) -> flags & UV_SHUT )) {
650
+ if ((stream -> flags & UV_SHUTTING ) &&
651
+ !(stream -> flags & UV_CLOSING ) &&
652
+ !(stream -> flags & UV_SHUT )) {
653
653
assert (stream -> shutdown_req );
654
654
655
655
req = stream -> shutdown_req ;
@@ -2193,6 +2193,9 @@ static void uv__chld(EV_P_ ev_child* watcher, int revents) {
2193
2193
}
2194
2194
}
2195
2195
2196
+ #ifndef SPAWN_WAIT_EXEC
2197
+ # define SPAWN_WAIT_EXEC 1
2198
+ #endif
2196
2199
2197
2200
int uv_spawn (uv_process_t * process , uv_process_options_t options ) {
2198
2201
/*
@@ -2203,8 +2206,10 @@ int uv_spawn(uv_process_t* process, uv_process_options_t options) {
2203
2206
int stdin_pipe [2 ] = { -1 , -1 };
2204
2207
int stdout_pipe [2 ] = { -1 , -1 };
2205
2208
int stderr_pipe [2 ] = { -1 , -1 };
2209
+ #if SPAWN_WAIT_EXEC
2206
2210
int signal_pipe [2 ] = { -1 , -1 };
2207
2211
struct pollfd pfd ;
2212
+ #endif
2208
2213
int status ;
2209
2214
pid_t pid ;
2210
2215
@@ -2222,6 +2227,8 @@ int uv_spawn(uv_process_t* process, uv_process_options_t options) {
2222
2227
if (pipe (stdin_pipe ) < 0 ) {
2223
2228
goto error ;
2224
2229
}
2230
+ uv__cloexec (stdin_pipe [0 ], 1 );
2231
+ uv__cloexec (stdin_pipe [1 ], 1 );
2225
2232
}
2226
2233
2227
2234
if (options .stdout_stream ) {
@@ -2233,6 +2240,8 @@ int uv_spawn(uv_process_t* process, uv_process_options_t options) {
2233
2240
if (pipe (stdout_pipe ) < 0 ) {
2234
2241
goto error ;
2235
2242
}
2243
+ uv__cloexec (stdout_pipe [0 ], 1 );
2244
+ uv__cloexec (stdout_pipe [1 ], 1 );
2236
2245
}
2237
2246
2238
2247
if (options .stderr_stream ) {
@@ -2244,6 +2253,8 @@ int uv_spawn(uv_process_t* process, uv_process_options_t options) {
2244
2253
if (pipe (stderr_pipe ) < 0 ) {
2245
2254
goto error ;
2246
2255
}
2256
+ uv__cloexec (stderr_pipe [0 ], 1 );
2257
+ uv__cloexec (stderr_pipe [1 ], 1 );
2247
2258
}
2248
2259
2249
2260
/* This pipe is used by the parent to wait until
@@ -2266,25 +2277,29 @@ int uv_spawn(uv_process_t* process, uv_process_options_t options) {
2266
2277
* marked close-on-exec. Then, after the call to `fork()`,
2267
2278
* the parent polls the read end until it sees POLLHUP.
2268
2279
*/
2269
- #ifdef HAVE_PIPE2
2280
+ #if SPAWN_WAIT_EXEC
2281
+ # ifdef HAVE_PIPE2
2270
2282
if (pipe2 (signal_pipe , O_CLOEXEC | O_NONBLOCK ) < 0 ) {
2271
2283
goto error ;
2272
2284
}
2273
- #else
2285
+ # else
2274
2286
if (pipe (signal_pipe ) < 0 ) {
2275
2287
goto error ;
2276
2288
}
2277
2289
uv__cloexec (signal_pipe [0 ], 1 );
2278
2290
uv__cloexec (signal_pipe [1 ], 1 );
2279
2291
uv__nonblock (signal_pipe [0 ], 1 );
2280
2292
uv__nonblock (signal_pipe [1 ], 1 );
2293
+ # endif
2281
2294
#endif
2282
2295
2283
2296
pid = fork ();
2284
2297
2285
2298
if (pid == -1 ) {
2299
+ #if SPAWN_WAIT_EXEC
2286
2300
uv__close (signal_pipe [0 ]);
2287
2301
uv__close (signal_pipe [1 ]);
2302
+ #endif
2288
2303
environ = save_our_env ;
2289
2304
goto error ;
2290
2305
}
@@ -2323,6 +2338,7 @@ int uv_spawn(uv_process_t* process, uv_process_options_t options) {
2323
2338
/* Restore environment. */
2324
2339
environ = save_our_env ;
2325
2340
2341
+ #if SPAWN_WAIT_EXEC
2326
2342
/* POLLHUP signals child has exited or execve()'d. */
2327
2343
uv__close (signal_pipe [1 ]);
2328
2344
do {
@@ -2334,11 +2350,13 @@ int uv_spawn(uv_process_t* process, uv_process_options_t options) {
2334
2350
while (status == -1 && (errno == EINTR || errno == ENOMEM ));
2335
2351
2336
2352
uv__close (signal_pipe [0 ]);
2353
+ uv__close (signal_pipe [1 ]);
2337
2354
2338
2355
assert ((status == 1 )
2339
2356
&& "poll() on pipe read end failed" );
2340
2357
assert ((pfd .revents & POLLHUP ) == POLLHUP
2341
2358
&& "no POLLHUP on pipe read end" );
2359
+ #endif
2342
2360
2343
2361
process -> pid = pid ;
2344
2362
0 commit comments