- if(f_multivol) {
- ptr=malloc(strlen(f_volhdr)+20);
- sprintf(ptr,"%s Volume %d",f_volhdr,1);
- } else
- ptr=f_volhdr;
-#endif
- head=findrec();
- if(!head) {
- msg("Archive not labelled to match %s",f_volhdr);
- exit(EX_BADVOL);
- }
- if (re_match (label_pattern, head->header.name,
- strlen (head->header.name), 0, 0) < 0) {
- msg ("Volume mismatch! %s!=%s", f_volhdr,
- head->header.name);
- exit (EX_BADVOL);
- }
-#if 0
- if(strcmp(ptr,head->header.name)) {
- msg("Volume mismatch! %s!=%s",ptr,head->header.name);
- exit(EX_BADVOL);
- }
- if(ptr!=f_volhdr)
- free(ptr);
-#endif
- }
- } else if(f_volhdr) {
- bzero((void *)ar_block,RECORDSIZE);
- if(f_multivol)
- sprintf(ar_block->header.name,"%s Volume 1",f_volhdr);
- else
- strcpy(ar_block->header.name,f_volhdr);
- ar_block->header.linkflag = LF_VOLHDR;
- to_oct(time(0), 1+12, ar_block->header.mtime);
- finish_header(ar_block);
- /* ar_record++; */
+ 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);
+}
+
+/* Set ARCHIVE for uncompressing, then reading an archive. */
+static void
+child_open_for_uncompress (void)
+{
+ int parent_pipe[2];
+ int child_pipe[2];
+ pid_t grandchild_pid;
+ int wait_status;
+
+ xpipe (parent_pipe);
+ child_pid = xfork ();
+
+ if (child_pid > 0)
+ {
+ /* The parent tar is still here! Just clean up. */
+
+ read_full_records_option = 1;
+ archive = parent_pipe[PREAD];
+ xclose (parent_pipe[PWRITE]);
+ return;
+ }
+
+ /* The newborn child tar is here! */
+
+ program_name = _("tar (child)");
+
+ xdup2 (parent_pipe[PWRITE], STDOUT_FILENO);
+ xclose (parent_pipe[PREAD]);
+
+ /* Check if we need a grandchild tar. This happens only if either:
+ a) we're reading stdin: to force unblocking;
+ b) the file is to be accessed by rmt: compressor doesn't know how;
+ c) the file is not a plain file. */
+
+ if (strcmp (archive_name_array[0], "-") != 0
+ && !_remdev (archive_name_array[0])
+ && is_regular_file (archive_name_array[0]))
+ {
+ /* We don't need a grandchild tar. Open the archive and lauch the
+ uncompressor. */
+
+ archive = open (archive_name_array[0], O_RDONLY | O_BINARY, MODE_RW);
+ if (archive < 0)
+ open_fatal (archive_name_array[0]);
+ xdup2 (archive, STDIN_FILENO);
+ execlp (use_compress_program_option, use_compress_program_option,
+ "-d", (char *) 0);
+ exec_fatal (use_compress_program_option);
+ }
+
+ /* We do need a grandchild tar. */
+
+ xpipe (child_pipe);
+ grandchild_pid = xfork ();
+
+ if (grandchild_pid == 0)
+ {
+ /* The newborn grandchild tar is here! Launch the uncompressor. */
+
+ program_name = _("tar (grandchild)");
+
+ xdup2 (child_pipe[PREAD], STDIN_FILENO);
+ xclose (child_pipe[PWRITE]);
+ execlp (use_compress_program_option, use_compress_program_option,
+ "-d", (char *) 0);
+ exec_fatal (use_compress_program_option);
+ }
+
+ /* The child tar is still here! */
+
+ /* Prepare for unblocking the data from the archive into the
+ uncompressor. */
+
+ xdup2 (child_pipe[PWRITE], STDOUT_FILENO);
+ xclose (child_pipe[PREAD]);
+
+ if (strcmp (archive_name_array[0], "-") == 0)
+ archive = STDIN_FILENO;
+ else
+ archive = rmtopen (archive_name_array[0], O_RDONLY | O_BINARY,
+ MODE_RW, rsh_command_option);
+ if (archive < 0)
+ open_fatal (archive_name_array[0]);
+
+ /* Let's read the archive and pipe it into stdout. */
+
+ while (1)
+ {
+ char *cursor;
+ size_t maximum;
+ size_t count;
+ ssize_t status;
+
+ read_error_count = 0;
+
+ error_loop:
+ status = rmtread (archive, record_start->buffer, record_size);
+ if (status < 0)
+ {
+ archive_read_error ();
+ goto error_loop;