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

Diff for /src/usr.bin/cvs/util.c between version 1.143 and 1.144

version 1.143, 2008/03/09 12:52:33 version 1.144, 2008/06/10 01:00:35
Line 849 
Line 849 
         return (ret);          return (ret);
 }  }
   
 void  /*
 cvs_exec(const char *prog)   * cvs_exec()
    *
    * Execute <prog> and send <in> to the STDIN if not NULL.
    * If <needwait> == 1, return the result of <prog>,
    * else, 0 or -1 if an error occur.
    */
   int
   cvs_exec(const char *prog, const char *in, int needwait)
 {  {
         pid_t pid;          pid_t pid;
         char *argp[] = { "sh", "-c", NULL, NULL };          int fds[2], size, st;
           char *argp[4] = { "sh", "-c", prog, NULL };
   
         argp[2] = prog;          if (in != NULL && pipe(fds) < 0) {
                   cvs_log(LP_ERR, "cvs_exec: pipe failed");
                   return (-1);
           }
   
         if ((pid = fork()) == -1) {          if ((pid = fork()) == -1) {
                 cvs_log(LP_ERR, "cvs_exec: fork failed");                  cvs_log(LP_ERR, "cvs_exec: fork failed");
                 return;                  return (-1);
         } else if (pid == 0) {          } else if (pid == 0) {
                   if (in != NULL) {
                           close(fds[1]);
                           dup2(fds[0], STDIN_FILENO);
                   }
   
                   setenv("CVSROOT", current_cvsroot->cr_dir, 1);
                 execv(_PATH_BSHELL, argp);                  execv(_PATH_BSHELL, argp);
                 cvs_log(LP_ERR, "failed to run '%s'", prog);                  cvs_log(LP_ERR, "cvs_exec: failed to run '%s'", prog);
                 _exit(127);                  _exit(127);
         }          }
   
           if (in != NULL) {
                   close(fds[0]);
                   size = strlen(in);
                   if (atomicio(vwrite, fds[1], in, size) != size)
                           cvs_log(LP_ERR, "cvs_exec: failed to write on STDIN");
                   close(fds[1]);
           }
   
           if (needwait == 1) {
                   while (waitpid(pid, &st, 0) == -1)
                           ;
                   if (!WIFEXITED(st)) {
                           errno = EINTR;
                           return (-1);
                   }
                   return (WEXITSTATUS(st));
           }
   
           return (0);
 }  }

Legend:
Removed from v.1.143  
changed lines
  Added in v.1.144