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

Diff for /src/usr.bin/ssh/readpass.c between version 1.47 and 1.48

version 1.47, 2006/08/03 03:34:42 version 1.48, 2010/12/15 00:49:27
Line 30 
Line 30 
 #include <fcntl.h>  #include <fcntl.h>
 #include <paths.h>  #include <paths.h>
 #include <readpassphrase.h>  #include <readpassphrase.h>
   #include <signal.h>
 #include <stdarg.h>  #include <stdarg.h>
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
Line 46 
Line 47 
 static char *  static char *
 ssh_askpass(char *askpass, const char *msg)  ssh_askpass(char *askpass, const char *msg)
 {  {
         pid_t pid;          pid_t pid, ret;
         size_t len;          size_t len;
         char *pass;          char *pass;
         int p[2], status, ret;          int p[2], status;
         char buf[1024];          char buf[1024];
           void (*osigchld)(int);
   
         if (fflush(stdout) != 0)          if (fflush(stdout) != 0)
                 error("ssh_askpass: fflush: %s", strerror(errno));                  error("ssh_askpass: fflush: %s", strerror(errno));
Line 60 
Line 62 
                 error("ssh_askpass: pipe: %s", strerror(errno));                  error("ssh_askpass: pipe: %s", strerror(errno));
                 return NULL;                  return NULL;
         }          }
           osigchld = signal(SIGCHLD, SIG_DFL);
         if ((pid = fork()) < 0) {          if ((pid = fork()) < 0) {
                 error("ssh_askpass: fork: %s", strerror(errno));                  error("ssh_askpass: fork: %s", strerror(errno));
                   signal(SIGCHLD, osigchld);
                 return NULL;                  return NULL;
         }          }
         if (pid == 0) {          if (pid == 0) {
Line 74 
Line 78 
         }          }
         close(p[1]);          close(p[1]);
   
         len = ret = 0;          len = 0;
         do {          do {
                 ret = read(p[0], buf + len, sizeof(buf) - 1 - len);                  ssize_t r = read(p[0], buf + len, sizeof(buf) - 1 - len);
                 if (ret == -1 && errno == EINTR)  
                   if (r == -1 && errno == EINTR)
                         continue;                          continue;
                 if (ret <= 0)                  if (r <= 0)
                         break;                          break;
                 len += ret;                  len += r;
         } while (sizeof(buf) - 1 - len > 0);          } while (sizeof(buf) - 1 - len > 0);
         buf[len] = '\0';          buf[len] = '\0';
   
         close(p[0]);          close(p[0]);
         while (waitpid(pid, &status, 0) < 0)          while ((ret = waitpid(pid, &status, 0)) < 0)
                 if (errno != EINTR)                  if (errno != EINTR)
                         break;                          break;
           signal(SIGCHLD, osigchld);
         if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {          if (ret == -1 || !WIFEXITED(status) || WEXITSTATUS(status) != 0) {
                 memset(buf, 0, sizeof(buf));                  memset(buf, 0, sizeof(buf));
                 return NULL;                  return NULL;
         }          }

Legend:
Removed from v.1.47  
changed lines
  Added in v.1.48