]> granicus.if.org Git - mutt/commitdiff
Avoid a hang due to blocking pipe writes in the auto view code.
authorThomas Roessler <roessler@does-not-exist.org>
Mon, 5 Oct 1998 20:37:08 +0000 (20:37 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Mon, 5 Oct 1998 20:37:08 +0000 (20:37 +0000)
handler.c

index b6c48ca0e427647c6ed42f8ee33567ab93e966ef..8e045a4712e790c479fd003ca554e5f97fe88852 100644 (file)
--- 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 ();
   }