diff options
author | Damien Miller <djm@mindrot.org> | 2010-09-24 22:15:11 +1000 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2010-09-24 22:15:11 +1000 |
commit | 65e42f87fe945a2bf30d7e02358554dbaefa8a4c (patch) | |
tree | 102c10a0b5328a40c79dca19d208f0ca0c1671b5 /sftp.c | |
parent | 7fe2b1fec3b364faf952828f3875b8e7eed8feb4 (diff) |
- djm@cvs.openbsd.org 2010/09/22 22:58:51
[atomicio.c atomicio.h misc.c misc.h scp.c sftp-client.c]
[sftp-client.h sftp.1 sftp.c]
add an option per-read/write callback to atomicio
factor out bandwidth limiting code from scp(1) into a generic bandwidth
limiter that can be attached using the atomicio callback mechanism
add a bandwidth limit option to sftp(1) using the above
"very nice" markus@
Diffstat (limited to 'sftp.c')
-rw-r--r-- | sftp.c | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: sftp.c,v 1.125 2010/06/18 00:58:39 djm Exp $ */ | 1 | /* $OpenBSD: sftp.c,v 1.126 2010/09/22 22:58:51 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> | 3 | * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> |
4 | * | 4 | * |
@@ -2073,6 +2073,7 @@ main(int argc, char **argv) | |||
2073 | int debug_level = 0, sshver = 2; | 2073 | int debug_level = 0, sshver = 2; |
2074 | char *file1 = NULL, *sftp_server = NULL; | 2074 | char *file1 = NULL, *sftp_server = NULL; |
2075 | char *ssh_program = _PATH_SSH_PROGRAM, *sftp_direct = NULL; | 2075 | char *ssh_program = _PATH_SSH_PROGRAM, *sftp_direct = NULL; |
2076 | const char *errstr; | ||
2076 | LogLevel ll = SYSLOG_LEVEL_INFO; | 2077 | LogLevel ll = SYSLOG_LEVEL_INFO; |
2077 | arglist args; | 2078 | arglist args; |
2078 | extern int optind; | 2079 | extern int optind; |
@@ -2080,6 +2081,7 @@ main(int argc, char **argv) | |||
2080 | struct sftp_conn *conn; | 2081 | struct sftp_conn *conn; |
2081 | size_t copy_buffer_len = DEFAULT_COPY_BUFLEN; | 2082 | size_t copy_buffer_len = DEFAULT_COPY_BUFLEN; |
2082 | size_t num_requests = DEFAULT_NUM_REQUESTS; | 2083 | size_t num_requests = DEFAULT_NUM_REQUESTS; |
2084 | long long limit_kbps = 0; | ||
2083 | 2085 | ||
2084 | /* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */ | 2086 | /* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */ |
2085 | sanitise_stdfd(); | 2087 | sanitise_stdfd(); |
@@ -2097,7 +2099,7 @@ main(int argc, char **argv) | |||
2097 | infile = stdin; | 2099 | infile = stdin; |
2098 | 2100 | ||
2099 | while ((ch = getopt(argc, argv, | 2101 | while ((ch = getopt(argc, argv, |
2100 | "1246hpqrvCc:D:i:o:s:S:b:B:F:P:R:")) != -1) { | 2102 | "1246hpqrvCc:D:i:l:o:s:S:b:B:F:P:R:")) != -1) { |
2101 | switch (ch) { | 2103 | switch (ch) { |
2102 | /* Passed through to ssh(1) */ | 2104 | /* Passed through to ssh(1) */ |
2103 | case '4': | 2105 | case '4': |
@@ -2158,6 +2160,13 @@ main(int argc, char **argv) | |||
2158 | case 'D': | 2160 | case 'D': |
2159 | sftp_direct = optarg; | 2161 | sftp_direct = optarg; |
2160 | break; | 2162 | break; |
2163 | case 'l': | ||
2164 | limit_kbps = strtonum(optarg, 1, 100 * 1024 * 1024, | ||
2165 | &errstr); | ||
2166 | if (errstr != NULL) | ||
2167 | usage(); | ||
2168 | limit_kbps *= 1024; /* kbps */ | ||
2169 | break; | ||
2161 | case 'r': | 2170 | case 'r': |
2162 | global_rflag = 1; | 2171 | global_rflag = 1; |
2163 | break; | 2172 | break; |
@@ -2235,7 +2244,7 @@ main(int argc, char **argv) | |||
2235 | } | 2244 | } |
2236 | freeargs(&args); | 2245 | freeargs(&args); |
2237 | 2246 | ||
2238 | conn = do_init(in, out, copy_buffer_len, num_requests); | 2247 | conn = do_init(in, out, copy_buffer_len, num_requests, limit_kbps); |
2239 | if (conn == NULL) | 2248 | if (conn == NULL) |
2240 | fatal("Couldn't initialise connection to server"); | 2249 | fatal("Couldn't initialise connection to server"); |
2241 | 2250 | ||