Changeset 402:98bc92448192

Show
Ignore:
Timestamp:
1998-10-05 23:07:55 (10 years ago)
Author:
Thomas Roessler <roessler@…>
Branch:
HEAD
Message:

Fix another pipe-related hang in mutt_view_attachment().

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • attach.c

    r300 r402  
    359359                                 tempfile, sizeof (tempfile))) 
    360360    { 
    361       if (fp == NULL) 
     361      if (fp == NULL && strcmp(tempfile, a->filename)) 
    362362      { 
    363363        /* send case: the file is already there */ 
     
    404404  { 
    405405    pid_t thepid = 0; 
    406     FILE *pagerfp = NULL; 
    407     FILE *tempfp = NULL; 
    408     FILE *filter_in; 
    409     FILE *filter_out; 
    410  
     406    int tempfd = -1, pagerfd = -1; 
     407     
    411408    if (!use_pager) 
    412409      endwin (); 
     
    414411    if (use_pager || use_pipe) 
    415412    { 
    416       if (use_pager && ((pagerfp = safe_fopen (pagerfile, "w")) == NULL)) 
    417       { 
    418         mutt_perror ("fopen"); 
     413      if (use_pager && ((pagerfd = safe_open (pagerfile, O_CREAT | O_EXCL | O_WRONLY)) == -1)) 
     414      { 
     415        mutt_perror ("open"); 
    419416        goto return_error; 
    420417      } 
    421       if (use_pipe && ((tempfp = fopen (tempfile, "r")) == NULL)) 
    422       { 
    423         if (pagerfp) 
    424           fclose (pagerfp); 
    425         mutt_perror ("fopen"); 
     418      if (use_pipe && ((tempfd = open (tempfile, 0)) == -1)) 
     419      { 
     420        if(pagerfd != -1) 
     421          close(pagerfd); 
     422        mutt_perror ("open"); 
    426423        goto return_error; 
    427424      } 
    428425 
    429       if ((thepid = mutt_create_filter (command, use_pipe ? &filter_in : NULL, 
    430                                         use_pager ? &filter_out : NULL, NULL)) == -1) 
    431       { 
    432         if (pagerfp) 
    433           fclose (pagerfp); 
    434         if (tempfp) 
    435           fclose (tempfp); 
     426      if ((thepid = mutt_create_filter_fd (command, NULL, NULL, NULL, 
     427                                           use_pipe ? tempfd : -1, use_pager ? pagerfd : -1, -1)) == -1) 
     428      { 
     429        if(pagerfd != -1) 
     430          close(pagerfd); 
     431         
     432        if(tempfd != -1) 
     433          close(tempfd); 
     434 
    436435        mutt_error _("Cannot create filter"); 
    437436        goto return_error; 
    438437      } 
    439438 
    440       if (use_pipe) 
    441       { 
    442         mutt_copy_stream (tempfp, filter_in); 
    443         fclose (tempfp); 
    444         fclose (filter_in); 
    445       } 
    446439      if (use_pager) 
    447440      { 
    448         mutt_copy_stream (filter_out, pagerfp); 
    449         fclose (filter_out); 
    450         fclose (pagerfp); 
    451441        if (a->description) 
    452442          snprintf (descrip, sizeof (descrip), 
     
    461451          option (OPTWAITKEY))) && !use_pager) 
    462452        mutt_any_key_to_continue (NULL); 
     453       
     454      close(tempfd); 
     455      close(pagerfd); 
     456       
    463457    } 
    464458    else