=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ssh/sftp.c,v retrieving revision 1.31.2.2 retrieving revision 1.32 diff -u -r1.31.2.2 -r1.32 --- src/usr.bin/ssh/sftp.c 2003/09/16 21:20:27 1.31.2.2 +++ src/usr.bin/ssh/sftp.c 2002/11/27 17:53:35 1.32 @@ -24,8 +24,10 @@ #include "includes.h" -RCSID("$OpenBSD: sftp.c,v 1.31.2.2 2003/09/16 21:20:27 brad Exp $"); +RCSID("$OpenBSD: sftp.c,v 1.32 2002/11/27 17:53:35 markus Exp $"); +/* XXX: short-form remote directory listings (like 'ls -C') */ + #include "buffer.h" #include "xmalloc.h" #include "log.h" @@ -40,22 +42,10 @@ FILE* infile; size_t copy_buffer_len = 32768; size_t num_requests = 16; -static pid_t sshpid = -1; -extern int showprogress; - static void -killchild(int signo) +connect_to_server(char *path, char **args, int *in, int *out, pid_t *sshpid) { - if (sshpid > 1) - kill(sshpid, signo); - - _exit(1); -} - -static void -connect_to_server(char *path, char **args, int *in, int *out) -{ int c_in, c_out; #ifdef USE_PIPES @@ -76,9 +66,9 @@ c_in = c_out = inout[1]; #endif /* USE_PIPES */ - if ((sshpid = fork()) == -1) + if ((*sshpid = fork()) == -1) fatal("fork: %s", strerror(errno)); - else if (sshpid == 0) { + else if (*sshpid == 0) { if ((dup2(c_in, STDIN_FILENO) == -1) || (dup2(c_out, STDOUT_FILENO) == -1)) { fprintf(stderr, "dup2: %s\n", strerror(errno)); @@ -93,9 +83,6 @@ exit(1); } - signal(SIGTERM, killchild); - signal(SIGINT, killchild); - signal(SIGHUP, killchild); close(c_in); close(c_out); } @@ -106,9 +93,8 @@ extern char *__progname; fprintf(stderr, - "usage: %s [-vC1] [-b batchfile] [-o ssh_option] [-s subsystem | sftp_server]\n" - " [-B buffer_size] [-F ssh_config] [-P sftp_server path]\n" - " [-R num_requests] [-S program]\n" + "usage: %s [-vC1] [-b batchfile] [-o option] [-s subsystem|path] [-B buffer_size]\n" + " [-F config] [-P direct server path] [-S program]\n" " [user@]host[:file [file]]\n", __progname); exit(1); } @@ -116,7 +102,8 @@ int main(int argc, char **argv) { - int in, out, ch, err; + int in, out, ch; + pid_t sshpid; char *host, *userhost, *cp, *file2; int debug_level = 0, sshver = 2; char *file1 = NULL, *sftp_server = NULL; @@ -168,7 +155,6 @@ fatal("%s (%s).", strerror(errno), optarg); } else fatal("Filename already specified."); - showprogress = 0; break; case 'P': sftp_direct = optarg; @@ -233,16 +219,18 @@ args.list[0] = ssh_program; fprintf(stderr, "Connecting to %s...\n", host); - connect_to_server(ssh_program, args.list, &in, &out); + connect_to_server(ssh_program, args.list, &in, &out, + &sshpid); } else { args.list = NULL; addargs(&args, "sftp-server"); fprintf(stderr, "Attaching to %s...\n", sftp_direct); - connect_to_server(sftp_direct, args.list, &in, &out); + connect_to_server(sftp_direct, args.list, &in, &out, + &sshpid); } - err = interactive_loop(in, out, file1, file2); + interactive_loop(in, out, file1, file2); close(in); close(out); @@ -254,5 +242,5 @@ fatal("Couldn't wait for ssh process: %s", strerror(errno)); - exit(err == 0 ? 0 : 1); + exit(0); }