From: Thomas Roessler Date: Mon, 5 Oct 1998 20:37:08 +0000 (+0000) Subject: Avoid a hang due to blocking pipe writes in the auto view code. X-Git-Tag: mutt-0-94-13-rel~62 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=19fbdcf0bff0e1a81debe644c8a23576222eb9d1;p=mutt Avoid a hang due to blocking pipe writes in the auto view code. --- diff --git a/handler.c b/handler.c index b6c48ca0..8e045a47 100644 --- a/handler.c +++ b/handler.c @@ -1078,25 +1078,29 @@ void autoview_handler (BODY *a, STATE *s) mutt_message(_("Invoking autoview command: %s"),command); } - if (piped) + if ((fpin = safe_fopen (tempfile, "w+")) == NULL) { - thepid = mutt_create_filter (command, &fpin, &fpout, &fperr); - mutt_copy_bytes (s->fpin, fpin, a->length); - fclose (fpin); + mutt_perror ("fopen"); + rfc1524_free_entry (&entry); + return; } - else - { - if ((fpin = safe_fopen (tempfile, "w")) == NULL) - { - mutt_perror ("fopen"); - rfc1524_free_entry (&entry); - return; - } + + mutt_copy_bytes (s->fpin, fpin, a->length); - mutt_copy_bytes (s->fpin, fpin, a->length); + if(!piped) + { fclose (fpin); thepid = mutt_create_filter (command, NULL, &fpout, &fperr); } + else + { + unlink(tempfile); + fflush(fpin); + rewind(fpin); + thepid = mutt_create_filter_fd (command, NULL, &fpout, &fperr, + dup(fileno(fpin)), -1, -1); + fclose(fpin); + } if (s->prefix) { @@ -1147,7 +1151,9 @@ void autoview_handler (BODY *a, STATE *s) fclose (fpout); fclose (fperr); mutt_wait_filter (thepid); - mutt_unlink (tempfile); + if(!piped) + mutt_unlink (tempfile); + if (s->flags & M_DISPLAY) mutt_clear_error (); }