From: Sergey Poznyakoff Date: Sat, 5 Feb 2005 22:02:08 +0000 (+0000) Subject: (sys_exec_command): Use xclose, xpipe, xfork, xdup2 and exec_fatal. X-Git-Url: https://git.dogcows.com/gitweb?a=commitdiff_plain;h=35bb3557343bd4c19399ff8b142a999c3dc18cb6;p=chaz%2Ftar (sys_exec_command): Use xclose, xpipe, xfork, xdup2 and exec_fatal. --- diff --git a/src/system.c b/src/system.c index b1783b1..bf8e050 100644 --- a/src/system.c +++ b/src/system.c @@ -714,34 +714,19 @@ sys_exec_command (char *file_name, int typechar, struct tar_stat_info *st) int p[2]; char *argv[4]; - if (pipe (p)) - { - pipe_error (file_name); - return -1; - } - + xpipe (p); pipe_handler = signal (SIGPIPE, SIG_IGN); - pid = fork (); - - if (pid < 0) - { - fork_error (file_name); - close (p[1]); - close (p[0]); - signal (SIGPIPE, pipe_handler); - return -1; - } + pid = xfork (); if (pid != 0) { - close (p[0]); - return p[1]; + xclose (p[PREAD]); + return p[PWRITE]; } /* Child */ - close (0); - dup (p[0]); - close (p[1]); + xdup2 (p[PREAD], STDIN_FILENO); + xclose (p[PWRITE]); stat_to_env (file_name, typechar, st); @@ -752,8 +737,7 @@ sys_exec_command (char *file_name, int typechar, struct tar_stat_info *st) execv ("/bin/sh", argv); - exec_error (file_name); - _exit (127); + exec_fatal (file_name); } void @@ -786,7 +770,7 @@ sys_wait_command (void) } else ERROR ((0, 0, _("%lu: Child terminated on unknown reason"), - (unsigned long) pid, WTERMSIG (status))); + (unsigned long) pid)); pid = -1; }