Having had a drink and another look over my previous changes, I saw how I could and should clean this up. Here's a patch on top of the previous one for sarge; it should apply at an offset on the sid version as well. It also adds the minimal documentation of an entry in the list of commands that is available by typing "help".
Ben. -- Ben Hutchings The two most common things in the universe are hydrogen and stupidity.
diff -ur openssh-3.8.1p1-last/sftp.c openssh-3.8.1p1/sftp.c --- openssh-3.8.1p1-last/sftp.c 2005-12-29 23:54:44.000000000 +0000 +++ openssh-3.8.1p1/sftp.c 2005-12-29 23:52:06.000000000 +0000 @@ -136,33 +136,34 @@ help(void) { printf("Available commands:\n"); - printf("cd path Change remote directory to 'path'\n"); - printf("lcd path Change local directory to 'path'\n"); - printf("chgrp grp path Change group of file 'path' to 'grp'\n"); - printf("chmod mode path Change permissions of file 'path' to 'mode'\n"); - printf("chown own path Change owner of file 'path' to 'own'\n"); - printf("help Display this help text\n"); - printf("get remote-path [local-path] Download file\n"); - printf("lls [ls-options [path]] Display local directory listing\n"); - printf("ln oldpath newpath Symlink remote file\n"); - printf("lmkdir path Create local directory\n"); - printf("lpwd Print local working directory\n"); - printf("ls [path] Display remote directory listing\n"); - printf("lumask umask Set local umask to 'umask'\n"); - printf("mkdir path Create remote directory\n"); - printf("progress Toggle display of progress meter\n"); - printf("put local-path [remote-path] Upload file\n"); - printf("pwd Display remote working directory\n"); - printf("exit Quit sftp\n"); - printf("quit Quit sftp\n"); - printf("rename oldpath newpath Rename remote file\n"); - printf("rmdir path Remove remote directory\n"); - printf("rm path Delete remote file\n"); - printf("symlink oldpath newpath Symlink remote file\n"); - printf("version Show SFTP version\n"); - printf("!command Execute 'command' in local shell\n"); - printf("! Escape to local shell\n"); - printf("? Synonym for help\n"); + printf("cd path Change remote directory to 'path'\n"); + printf("lcd path Change local directory to 'path'\n"); + printf("chgrp grp path Change group of file 'path' to 'grp'\n"); + printf("chmod mode path Change permissions of file 'path' to 'mode'\n"); + printf("chown own path Change owner of file 'path' to 'own'\n"); + printf("help Display this help text\n"); + printf("get remote-path [local-path] Download file\n"); + printf("reget remote-path [local-path] Resume download of file\n"); + printf("lls [ls-options [path]] Display local directory listing\n"); + printf("ln oldpath newpath Symlink remote file\n"); + printf("lmkdir path Create local directory\n"); + printf("lpwd Print local working directory\n"); + printf("ls [path] Display remote directory listing\n"); + printf("lumask umask Set local umask to 'umask'\n"); + printf("mkdir path Create remote directory\n"); + printf("progress Toggle display of progress meter\n"); + printf("put local-path [remote-path] Upload file\n"); + printf("pwd Display remote working directory\n"); + printf("exit Quit sftp\n"); + printf("quit Quit sftp\n"); + printf("rename oldpath newpath Rename remote file\n"); + printf("rmdir path Remove remote directory\n"); + printf("rm path Delete remote file\n"); + printf("symlink oldpath newpath Symlink remote file\n"); + printf("version Show SFTP version\n"); + printf("!command Execute 'command' in local shell\n"); + printf("! Escape to local shell\n"); + printf("? Synonym for help\n"); } static void @@ -1213,14 +1214,25 @@ } static void -killchild(int signo) +signal_exit(int signo) { + abort_download(); if (sshpid > 1) kill(sshpid, signo); _exit(1); } +void +cleanup_exit(int i) +{ + abort_download(); + if (sshpid > 1) + kill(sshpid, SIGINT); + + _exit(i); +} + static void connect_to_server(char *path, char **args, int *in, int *out) { @@ -1261,9 +1273,9 @@ exit(1); } - signal(SIGTERM, killchild); - signal(SIGINT, killchild); - signal(SIGHUP, killchild); + signal(SIGTERM, signal_exit); + signal(SIGINT, signal_exit); + signal(SIGHUP, signal_exit); close(c_in); close(c_out); } diff -ur openssh-3.8.1p1-last/sftp-client.c openssh-3.8.1p1/sftp-client.c --- openssh-3.8.1p1-last/sftp-client.c 2005-12-29 23:54:44.000000000 +0000 +++ openssh-3.8.1p1/sftp-client.c 2005-12-29 23:47:13.000000000 +0000 @@ -831,9 +831,6 @@ truncate_len_lower = contig_len; truncate_len_upper = contig_len >> 32; truncate_fd = local_fd; - signal(SIGTERM, cleanup_exit); - signal(SIGINT, cleanup_exit); - signal(SIGHUP, cleanup_exit); if (showprogress && size != 0) start_progress_meter(remote_path, size, &progress_counter); @@ -1226,11 +1223,12 @@ } void -cleanup_exit(int i) +abort_download(void) { // XXX: error reporting? - ftruncate(truncate_fd, - ((u_int64_t)truncate_len_upper << 32) | truncate_len_lower); - - _exit(i); + if (truncate_fd >= 0) { + ftruncate(truncate_fd, + ((u_int64_t)truncate_len_upper << 32) + | truncate_len_lower); + } } diff -ur openssh-3.8.1p1-last/sftp-client.h openssh-3.8.1p1/sftp-client.h --- openssh-3.8.1p1-last/sftp-client.h 2005-12-29 23:54:44.000000000 +0000 +++ openssh-3.8.1p1/sftp-client.h 2005-12-29 23:47:08.000000000 +0000 @@ -91,6 +91,9 @@ */ int do_download(struct sftp_conn *, char *, char *, int, int); +/* This should be called if and when the program is aborted */ +void abort_download(void); + /* * Upload 'local_path' to 'remote_path'. Preserve permissions and times * if 'pflag' is set
signature.asc
Description: This is a digitally signed message part