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

Diff for /src/usr.bin/ssh/sftp.c between version 1.45 and 1.46

version 1.45, 2004/03/03 09:31:20 version 1.46, 2004/05/19 12:17:33
Line 48 
Line 48 
 /* This is set to 0 if the progressmeter is not desired. */  /* This is set to 0 if the progressmeter is not desired. */
 int showprogress = 1;  int showprogress = 1;
   
   /* SIGINT received during command processing */
   volatile sig_atomic_t interrupted = 0;
   
 int remote_glob(struct sftp_conn *, const char *, int,  int remote_glob(struct sftp_conn *, const char *, int,
     int (*)(const char *, int), glob_t *); /* proto for sftp-glob.c */      int (*)(const char *, int), glob_t *); /* proto for sftp-glob.c */
   
Line 127 
Line 130 
 int interactive_loop(int fd_in, int fd_out, char *file1, char *file2);  int interactive_loop(int fd_in, int fd_out, char *file1, char *file2);
   
 static void  static void
   killchild(int signo)
   {
           if (sshpid > 1)
                   kill(sshpid, SIGTERM);
   
           _exit(1);
   }
   
   static void
   cmd_interrupt(int signo)
   {
           const char msg[] = "\rInterrupt  \n";
   
           write(STDERR_FILENO, msg, sizeof(msg) - 1);
           interrupted = 1;
   }
   
   static void
 help(void)  help(void)
 {  {
         printf("Available commands:\n");          printf("Available commands:\n");
Line 461 
Line 482 
                 goto out;                  goto out;
         }          }
   
         for (i = 0; g.gl_pathv[i]; i++) {          for (i = 0; g.gl_pathv[i] && !interrupted; i++) {
                 if (infer_path(g.gl_pathv[i], &tmp)) {                  if (infer_path(g.gl_pathv[i], &tmp)) {
                         err = -1;                          err = -1;
                         goto out;                          goto out;
Line 530 
Line 551 
                 goto out;                  goto out;
         }          }
   
         for (i = 0; g.gl_pathv[i]; i++) {          for (i = 0; g.gl_pathv[i] && !interrupted; i++) {
                 if (!is_reg(g.gl_pathv[i])) {                  if (!is_reg(g.gl_pathv[i])) {
                         error("skipping non-regular file %s",                          error("skipping non-regular file %s",
                             g.gl_pathv[i]);                              g.gl_pathv[i]);
Line 617 
Line 638 
   
         qsort(d, n, sizeof(*d), sdirent_comp);          qsort(d, n, sizeof(*d), sdirent_comp);
   
         for (n = 0; d[n] != NULL; n++) {          for (n = 0; d[n] != NULL && !interrupted; n++) {
                 char *tmp, *fname;                  char *tmp, *fname;
   
                 tmp = path_append(path, d[n]->filename);                  tmp = path_append(path, d[n]->filename);
Line 669 
Line 690 
                 return (-1);                  return (-1);
         }          }
   
           if (interrupted)
                   goto out;
   
         /*          /*
          * If the glob returns a single match, which is the same as the           * If the glob returns a single match, which is the same as the
          * input glob, and it is a directory, then just list its contents           * input glob, and it is a directory, then just list its contents
Line 702 
Line 726 
                 colspace = width / columns;                  colspace = width / columns;
         }          }
   
         for (i = 0; g.gl_pathv[i]; i++) {          for (i = 0; g.gl_pathv[i] && !interrupted; i++) {
                 char *fname;                  char *fname;
   
                 fname = path_strip(g.gl_pathv[i], strip_path);                  fname = path_strip(g.gl_pathv[i], strip_path);
Line 739 
Line 763 
         if (!(lflag & LONG_VIEW) && (c != 1))          if (!(lflag & LONG_VIEW) && (c != 1))
                 printf("\n");                  printf("\n");
   
    out:
         if (g.gl_pathc)          if (g.gl_pathc)
                 globfree(&g);                  globfree(&g);
   
Line 948 
Line 973 
         case I_RM:          case I_RM:
                 path1 = make_absolute(path1, *pwd);                  path1 = make_absolute(path1, *pwd);
                 remote_glob(conn, path1, GLOB_NOCHECK, NULL, &g);                  remote_glob(conn, path1, GLOB_NOCHECK, NULL, &g);
                 for (i = 0; g.gl_pathv[i]; i++) {                  for (i = 0; g.gl_pathv[i] && !interrupted; i++) {
                         printf("Removing %s\n", g.gl_pathv[i]);                          printf("Removing %s\n", g.gl_pathv[i]);
                         err = do_rm(conn, g.gl_pathv[i]);                          err = do_rm(conn, g.gl_pathv[i]);
                         if (err != 0 && err_abort)                          if (err != 0 && err_abort)
Line 1037 
Line 1062 
                 a.flags |= SSH2_FILEXFER_ATTR_PERMISSIONS;                  a.flags |= SSH2_FILEXFER_ATTR_PERMISSIONS;
                 a.perm = n_arg;                  a.perm = n_arg;
                 remote_glob(conn, path1, GLOB_NOCHECK, NULL, &g);                  remote_glob(conn, path1, GLOB_NOCHECK, NULL, &g);
                 for (i = 0; g.gl_pathv[i]; i++) {                  for (i = 0; g.gl_pathv[i] && !interrupted; i++) {
                         printf("Changing mode on %s\n", g.gl_pathv[i]);                          printf("Changing mode on %s\n", g.gl_pathv[i]);
                         err = do_setstat(conn, g.gl_pathv[i], &a);                          err = do_setstat(conn, g.gl_pathv[i], &a);
                         if (err != 0 && err_abort)                          if (err != 0 && err_abort)
Line 1048 
Line 1073 
         case I_CHGRP:          case I_CHGRP:
                 path1 = make_absolute(path1, *pwd);                  path1 = make_absolute(path1, *pwd);
                 remote_glob(conn, path1, GLOB_NOCHECK, NULL, &g);                  remote_glob(conn, path1, GLOB_NOCHECK, NULL, &g);
                 for (i = 0; g.gl_pathv[i]; i++) {                  for (i = 0; g.gl_pathv[i] && !interrupted; i++) {
                         if (!(aa = do_stat(conn, g.gl_pathv[i], 0))) {                          if (!(aa = do_stat(conn, g.gl_pathv[i], 0))) {
                                 if (err != 0 && err_abort)                                  if (err != 0 && err_abort)
                                         break;                                          break;
Line 1171 
Line 1196 
         for (;;) {          for (;;) {
                 char *cp;                  char *cp;
   
                   signal(SIGINT, SIG_IGN);
   
                 printf("sftp> ");                  printf("sftp> ");
   
                 /* XXX: use libedit */                  /* XXX: use libedit */
Line 1186 
Line 1213 
                 if (cp)                  if (cp)
                         *cp = '\0';                          *cp = '\0';
   
                   /* Handle user interrupts gracefully during commands */
                   interrupted = 0;
                   signal(SIGINT, cmd_interrupt);
   
                 err = parse_dispatch_command(conn, cmd, &pwd, batchmode);                  err = parse_dispatch_command(conn, cmd, &pwd, batchmode);
                 if (err != 0)                  if (err != 0)
                         break;                          break;
Line 1197 
Line 1228 
 }  }
   
 static void  static void
 killchild(int signo)  
 {  
         if (sshpid > 1)  
                 kill(sshpid, signo);  
   
         _exit(1);  
 }  
   
 static void  
 connect_to_server(char *path, char **args, int *in, int *out)  connect_to_server(char *path, char **args, int *in, int *out)
 {  {
         int c_in, c_out;          int c_in, c_out;
Line 1240 
Line 1262 
                 close(*out);                  close(*out);
                 close(c_in);                  close(c_in);
                 close(c_out);                  close(c_out);
   
                   /*
                    * The underlying ssh is in the same process group, so we must
                    * ignore SIGINT if we want to gracefully abort commands,
                    * otherwise the signal will make it to the ssh process and
                    * kill it too
                    */
                   signal(SIGINT, SIG_IGN);
                 execv(path, args);                  execv(path, args);
                 fprintf(stderr, "exec: %s: %s\n", path, strerror(errno));                  fprintf(stderr, "exec: %s: %s\n", path, strerror(errno));
                 exit(1);                  exit(1);

Legend:
Removed from v.1.45  
changed lines
  Added in v.1.46