X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;ds=sidebyside;f=src%2Fsystem.c;fp=src%2Fsystem.c;h=003f02994e223ea50ab9952e5843781ef0a84451;hb=af30244849448c775b3e447a84ba8b0249b4b697;hp=c90a40d1217b0441571604ead5f9af839675793c;hpb=be34933b638b75a40513ea2b724c756b1f8e3b85;p=chaz%2Ftar diff --git a/src/system.c b/src/system.c index c90a40d..003f029 100644 --- a/src/system.c +++ b/src/system.c @@ -283,6 +283,29 @@ xdup2 (int from, int into) } } +void wait_for_grandchild (pid_t pid) __attribute__ ((__noreturn__)); + +/* Propagate any failure of the grandchild back to the parent. */ +void +wait_for_grandchild (pid_t pid) +{ + int wait_status; + + while (waitpid (pid, &wait_status, 0) == -1) + if (errno != EINTR) + { + waitpid_error (use_compress_program_option); + break; + } + + if (WIFSIGNALED (wait_status)) + raise (WTERMSIG (wait_status)); + else if (WEXITSTATUS (wait_status) != 0) + exit_status = WEXITSTATUS (wait_status); + + exit (exit_status); +} + /* Set ARCHIVE for writing, then compressing an archive. */ pid_t sys_child_open_for_compress (void) @@ -291,7 +314,6 @@ sys_child_open_for_compress (void) int child_pipe[2]; pid_t grandchild_pid; pid_t child_pid; - int wait_status; xpipe (parent_pipe); child_pid = xfork (); @@ -424,24 +446,7 @@ sys_child_open_for_compress (void) archive_write_error (status); } - /* Propagate any failure of the grandchild back to the parent. */ - - while (waitpid (grandchild_pid, &wait_status, 0) == -1) - if (errno != EINTR) - { - waitpid_error (use_compress_program_option); - break; - } - - if (WIFSIGNALED (wait_status)) - { - kill (child_pid, WTERMSIG (wait_status)); - exit_status = TAREXIT_FAILURE; - } - else if (WEXITSTATUS (wait_status) != 0) - exit_status = WEXITSTATUS (wait_status); - - exit (exit_status); + wait_for_grandchild (grandchild_pid); } /* Set ARCHIVE for uncompressing, then reading an archive. */ @@ -452,7 +457,6 @@ sys_child_open_for_uncompress (void) int child_pipe[2]; pid_t grandchild_pid; pid_t child_pid; - int wait_status; xpipe (parent_pipe); child_pid = xfork (); @@ -562,24 +566,7 @@ sys_child_open_for_uncompress (void) xclose (STDOUT_FILENO); - /* Propagate any failure of the grandchild back to the parent. */ - - while (waitpid (grandchild_pid, &wait_status, 0) == -1) - if (errno != EINTR) - { - waitpid_error (use_compress_program_option); - break; - } - - if (WIFSIGNALED (wait_status)) - { - kill (child_pid, WTERMSIG (wait_status)); - exit_status = TAREXIT_FAILURE; - } - else if (WEXITSTATUS (wait_status) != 0) - exit_status = WEXITSTATUS (wait_status); - - exit (exit_status); + wait_for_grandchild (grandchild_pid); }