@@ -201,6 +201,12 @@ static void uv__write_int(int fd, int val) {
201
201
}
202
202
203
203
204
+ static void uv__write_errno (int error_fd ) {
205
+ uv__write_int (error_fd , UV__ERR (errno ));
206
+ _exit (127 );
207
+ }
208
+
209
+
204
210
#if !(defined(__APPLE__ ) && (TARGET_OS_TV || TARGET_OS_WATCH ))
205
211
/* execvp is marked __WATCHOS_PROHIBITED __TVOS_PROHIBITED, so must be
206
212
* avoided. Since this isn't called on those targets, the function
@@ -229,10 +235,8 @@ static void uv__process_child_init(const uv_process_options_t* options,
229
235
if (use_fd < 0 || use_fd >= fd )
230
236
continue ;
231
237
pipes [fd ][1 ] = fcntl (use_fd , F_DUPFD , stdio_count );
232
- if (pipes [fd ][1 ] == -1 ) {
233
- uv__write_int (error_fd , UV__ERR (errno ));
234
- _exit (127 );
235
- }
238
+ if (pipes [fd ][1 ] == -1 )
239
+ uv__write_errno (error_fd );
236
240
}
237
241
238
242
for (fd = 0 ; fd < stdio_count ; fd ++ ) {
@@ -249,10 +253,8 @@ static void uv__process_child_init(const uv_process_options_t* options,
249
253
use_fd = open ("/dev/null" , fd == 0 ? O_RDONLY : O_RDWR );
250
254
close_fd = use_fd ;
251
255
252
- if (use_fd < 0 ) {
253
- uv__write_int (error_fd , UV__ERR (errno ));
254
- _exit (127 );
255
- }
256
+ if (use_fd < 0 )
257
+ uv__write_errno (error_fd );
256
258
}
257
259
}
258
260
@@ -261,10 +263,8 @@ static void uv__process_child_init(const uv_process_options_t* options,
261
263
else
262
264
fd = dup2 (use_fd , fd );
263
265
264
- if (fd == -1 ) {
265
- uv__write_int (error_fd , UV__ERR (errno ));
266
- _exit (127 );
267
- }
266
+ if (fd == -1 )
267
+ uv__write_errno (error_fd );
268
268
269
269
if (fd <= 2 )
270
270
uv__nonblock_fcntl (fd , 0 );
@@ -280,10 +280,8 @@ static void uv__process_child_init(const uv_process_options_t* options,
280
280
uv__close (use_fd );
281
281
}
282
282
283
- if (options -> cwd != NULL && chdir (options -> cwd )) {
284
- uv__write_int (error_fd , UV__ERR (errno ));
285
- _exit (127 );
286
- }
283
+ if (options -> cwd != NULL && chdir (options -> cwd ))
284
+ uv__write_errno (error_fd );
287
285
288
286
if (options -> flags & (UV_PROCESS_SETUID | UV_PROCESS_SETGID )) {
289
287
/* When dropping privileges from root, the `setgroups` call will
@@ -296,15 +294,11 @@ static void uv__process_child_init(const uv_process_options_t* options,
296
294
SAVE_ERRNO (setgroups (0 , NULL ));
297
295
}
298
296
299
- if ((options -> flags & UV_PROCESS_SETGID ) && setgid (options -> gid )) {
300
- uv__write_int (error_fd , UV__ERR (errno ));
301
- _exit (127 );
302
- }
297
+ if ((options -> flags & UV_PROCESS_SETGID ) && setgid (options -> gid ))
298
+ uv__write_errno (error_fd );
303
299
304
- if ((options -> flags & UV_PROCESS_SETUID ) && setuid (options -> uid )) {
305
- uv__write_int (error_fd , UV__ERR (errno ));
306
- _exit (127 );
307
- }
300
+ if ((options -> flags & UV_PROCESS_SETUID ) && setuid (options -> uid ))
301
+ uv__write_errno (error_fd );
308
302
309
303
if (options -> env != NULL ) {
310
304
environ = options -> env ;
@@ -327,26 +321,23 @@ static void uv__process_child_init(const uv_process_options_t* options,
327
321
if (SIG_ERR != signal (n , SIG_DFL ))
328
322
continue ;
329
323
330
- uv__write_int (error_fd , UV__ERR (errno ));
331
- _exit (127 );
324
+ uv__write_errno (error_fd );
332
325
}
333
326
334
327
/* Reset signal mask. */
335
328
sigemptyset (& set );
336
329
err = pthread_sigmask (SIG_SETMASK , & set , NULL );
337
330
338
- if (err != 0 ) {
339
- uv__write_int (error_fd , UV__ERR (err ));
340
- _exit (127 );
341
- }
331
+ if (err != 0 )
332
+ uv__write_errno (error_fd );
342
333
343
334
#ifdef __MVS__
344
335
execvpe (options -> file , options -> args , environ );
345
336
#else
346
337
execvp (options -> file , options -> args );
347
338
#endif
348
- uv__write_int ( error_fd , UV__ERR ( errno ));
349
- _exit ( 127 );
339
+
340
+ uv__write_errno ( error_fd );
350
341
}
351
342
#endif
352
343
0 commit comments