From 936d273c3ae5d1589b5789392b3603bed46af91c Mon Sep 17 00:00:00 2001 From: Tim Kientzle Date: Sun, 15 Jun 2008 10:45:57 +0000 Subject: A number of minor corrections to the support for external compression programs: * Support platforms that have fork() but not vfork() * Don't write(), select(), or poll() against closed file descriptors --- lib/libarchive/archive_read_support_compression_program.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'lib/libarchive/archive_read_support_compression_program.c') diff --git a/lib/libarchive/archive_read_support_compression_program.c b/lib/libarchive/archive_read_support_compression_program.c index 5f6cb463b21c..5d92b909f7fd 100644 --- a/lib/libarchive/archive_read_support_compression_program.c +++ b/lib/libarchive/archive_read_support_compression_program.c @@ -28,7 +28,8 @@ __FBSDID("$FreeBSD$"); /* This capability is only available on POSIX systems. */ -#if !defined(HAVE_PIPE) || !defined(HAVE_VFORK) || !defined(HAVE_FCNTL) +#if !defined(HAVE_PIPE) || !defined(HAVE_FCNTL) || \ + !(defined(HAVE_FORK) || defined(HAVE_VFORK)) /* * On non-Posix systems, allow the program to build, but choke if @@ -177,6 +178,12 @@ restart_read: state->child_in_buf_avail = ret; } + if (state->child_stdin == -1) { + fcntl(state->child_stdout, F_SETFL, 0); + __archive_check_child(state->child_stdin, state->child_stdout); + goto restart_read; + } + do { ret = write(state->child_stdin, state->child_in_buf, state->child_in_buf_avail); @@ -191,7 +198,7 @@ restart_read: goto restart_read; } else if (ret == 0 || (ret == -1 && errno == EPIPE)) { close(state->child_stdin); - state->child_stdout = -1; + state->child_stdin = -1; fcntl(state->child_stdout, F_SETFL, 0); goto restart_read; } else { -- cgit v1.3