[BACK]Return to edit.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mail

Diff for /src/usr.bin/mail/edit.c between version 1.14 and 1.15

version 1.14, 2006/10/10 21:38:16 version 1.15, 2007/08/31 23:14:21
Line 38 
Line 38 
 #endif  #endif
 #endif /* not lint */  #endif /* not lint */
   
   #include <sys/types.h>
   #include <sys/wait.h>
   
 #include "rcv.h"  #include "rcv.h"
   #include <errno.h>
 #include <fcntl.h>  #include <fcntl.h>
 #include "extern.h"  #include "extern.h"
   
   int editit(const char *, const char *);
   
 /*  /*
  * Mail -- a mail program   * Mail -- a mail program
  *   *
Line 184 
Line 190 
                 goto out;                  goto out;
         }          }
         nf = NULL;          nf = NULL;
         if ((edit = value(type == 'e' ? "EDITOR" : "VISUAL")) == NULL)          if (type == 'e') {
                 edit = type == 'e' ? _PATH_EX : _PATH_VI;                  edit = value("EDITOR");
         if (run_command(edit, 0, 0, -1, tempname, NULL, NULL) < 0) {                  if (edit == NULL || edit[0] == '\0')
                           edit = _PATH_EX;
           } else {
                   edit = value("VISUAL");
                   if (edit == NULL || edit[0] == '\0')
                           edit = _PATH_VI;
           }
           if (editit(edit, tempname) == -1) {
                 (void)rm(tempname);                  (void)rm(tempname);
                 goto out;                  goto out;
         }          }
Line 217 
Line 230 
         (void)rm(tempname);          (void)rm(tempname);
 out:  out:
         return(nf);          return(nf);
   }
   
   /*
    * Execute an editor on the specified pathname, which is interpreted
    * from the shell.  This means flags may be included.
    *
    * Returns -1 on error, or the exit value on success.
    */
   int
   editit(const char *ed, const char *pathname)
   {
           char *argp[] = {"sh", "-c", NULL, NULL}, *p;
           sig_t sighup, sigint, sigquit;
           pid_t pid;
           int saved_errno, st;
   
           if (ed == NULL)
                   ed = getenv("VISUAL");
           if (ed == NULL || ed[0] == '\0')
                   ed = getenv("EDITOR");
           if (ed == NULL || ed[0] == '\0')
                   ed = _PATH_VI;
           if (asprintf(&p, "%s %s", ed, pathname) == -1)
                   return (-1);
           argp[2] = p;
   
           sighup = signal(SIGHUP, SIG_IGN);
           sigint = signal(SIGINT, SIG_IGN);
           sigquit = signal(SIGQUIT, SIG_IGN);
           if ((pid = fork()) == -1)
                   goto fail;
           if (pid == 0) {
                   execv(_PATH_BSHELL, argp);
                   _exit(127);
           }
           while (waitpid(pid, &st, 0) == -1)
                   if (errno != EINTR)
                           goto fail;
           free(p);
           (void)signal(SIGHUP, sighup);
           (void)signal(SIGINT, sigint);
           (void)signal(SIGQUIT, sigquit);
           if (!WIFEXITED(st)) {
                   errno = EINTR;
                   return (-1);
           }
           return (WEXITSTATUS(st));
   
    fail:
           saved_errno = errno;
           (void)signal(SIGHUP, sighup);
           (void)signal(SIGINT, sigint);
           (void)signal(SIGQUIT, sigquit);
           free(p);
           errno = saved_errno;
           return (-1);
 }  }

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.15