+
+ status = write_archive_buffer ();
+ if (status != record_size)
+ write_error (status);
+ }
+
+#if 0
+ close_archive ();
+#endif
+ 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;
+
+ if (pipe (parent_pipe) < 0)
+ FATAL_ERROR ((0, errno, _("Cannot open pipe")));
+
+ child_pid = fork ();
+ if (child_pid < 0)
+ FATAL_ERROR ((0, errno, _("Cannot fork")));
+
+ 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 new born child tar is here! */
+
+ program_name = _("tar (child)");
+
+ xdup2 (parent_pipe[PWRITE], STDOUT_FILENO, _("(child) Pipe to stdout"));
+ 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)
+ FATAL_ERROR ((0, errno, _("Cannot open archive %s"),
+ archive_name_array[0]));
+ xdup2 (archive, STDIN_FILENO, _("Archive to stdin"));
+ execlp (use_compress_program_option, use_compress_program_option,
+ "-d", (char *) 0);
+ FATAL_ERROR ((0, errno, _("Cannot exec %s"),
+ use_compress_program_option));
+ }
+
+ /* We do need a grandchild tar. */
+
+ if (pipe (child_pipe) < 0)
+ FATAL_ERROR ((0, errno, _("Cannot open pipe")));
+
+ grandchild_pid = fork ();
+ if (grandchild_pid < 0)
+ FATAL_ERROR ((0, errno, _("Child cannot fork")));
+
+ if (grandchild_pid > 0)
+ {
+ /* The child tar is still here! Launch the uncompressor. */
+
+ xdup2 (child_pipe[PREAD], STDIN_FILENO, _("((child)) Pipe to stdin"));
+ xclose (child_pipe[PWRITE]);
+ execlp (use_compress_program_option, use_compress_program_option,
+ "-d", (char *) 0);
+ FATAL_ERROR ((0, errno, _("Cannot exec %s"),
+ use_compress_program_option));
+ }
+
+ /* The new born grandchild tar is here! */
+
+ program_name = _("tar (grandchild)");
+
+ /* Prepare for unblocking the data from the archive into the uncompressor. */
+
+ xdup2 (child_pipe[PWRITE], STDOUT_FILENO, _("(grandchild) Pipe to stdout"));
+ 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)
+ FATAL_ERROR ((0, errno, _("Cannot open archive %s"),
+ 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)
+ {
+ read_error ();
+ goto error_loop;