summaryrefslogtreecommitdiff
path: root/scp.c
diff options
context:
space:
mode:
Diffstat (limited to 'scp.c')
-rw-r--r--scp.c41
1 files changed, 23 insertions, 18 deletions
diff --git a/scp.c b/scp.c
index 1daa2ccf7..ef9eaa1a4 100644
--- a/scp.c
+++ b/scp.c
@@ -71,7 +71,7 @@
71 */ 71 */
72 72
73#include "includes.h" 73#include "includes.h"
74RCSID("$OpenBSD: scp.c,v 1.113 2003/11/23 23:21:21 djm Exp $"); 74RCSID("$OpenBSD: scp.c,v 1.117 2004/08/11 21:44:32 avsm Exp $");
75 75
76#include "xmalloc.h" 76#include "xmalloc.h"
77#include "atomicio.h" 77#include "atomicio.h"
@@ -80,11 +80,7 @@ RCSID("$OpenBSD: scp.c,v 1.113 2003/11/23 23:21:21 djm Exp $");
80#include "misc.h" 80#include "misc.h"
81#include "progressmeter.h" 81#include "progressmeter.h"
82 82
83#ifdef HAVE___PROGNAME
84extern char *__progname; 83extern char *__progname;
85#else
86char *__progname;
87#endif
88 84
89void bwlimit(int); 85void bwlimit(int);
90 86
@@ -663,7 +659,7 @@ bwlimit(int amount)
663{ 659{
664 static struct timeval bwstart, bwend; 660 static struct timeval bwstart, bwend;
665 static int lamt, thresh = 16384; 661 static int lamt, thresh = 16384;
666 u_int64_t wait; 662 u_int64_t waitlen;
667 struct timespec ts, rm; 663 struct timespec ts, rm;
668 664
669 if (!timerisset(&bwstart)) { 665 if (!timerisset(&bwstart)) {
@@ -681,10 +677,10 @@ bwlimit(int amount)
681 return; 677 return;
682 678
683 lamt *= 8; 679 lamt *= 8;
684 wait = (double)1000000L * lamt / limit_rate; 680 waitlen = (double)1000000L * lamt / limit_rate;
685 681
686 bwstart.tv_sec = wait / 1000000L; 682 bwstart.tv_sec = waitlen / 1000000L;
687 bwstart.tv_usec = wait % 1000000L; 683 bwstart.tv_usec = waitlen % 1000000L;
688 684
689 if (timercmp(&bwstart, &bwend, >)) { 685 if (timercmp(&bwstart, &bwend, >)) {
690 timersub(&bwstart, &bwend, &bwend); 686 timersub(&bwstart, &bwend, &bwend);
@@ -759,6 +755,8 @@ sink(int argc, char **argv)
759 *cp++ = ch; 755 *cp++ = ch;
760 } while (cp < &buf[sizeof(buf) - 1] && ch != '\n'); 756 } while (cp < &buf[sizeof(buf) - 1] && ch != '\n');
761 *cp = 0; 757 *cp = 0;
758 if (verbose_mode)
759 fprintf(stderr, "Sink: %s", buf);
762 760
763 if (buf[0] == '\01' || buf[0] == '\02') { 761 if (buf[0] == '\01' || buf[0] == '\02') {
764 if (iamremote == 0) 762 if (iamremote == 0)
@@ -822,6 +820,10 @@ sink(int argc, char **argv)
822 size = size * 10 + (*cp++ - '0'); 820 size = size * 10 + (*cp++ - '0');
823 if (*cp++ != ' ') 821 if (*cp++ != ' ')
824 SCREWUP("size not delimited"); 822 SCREWUP("size not delimited");
823 if ((strchr(cp, '/') != NULL) || (strcmp(cp, "..") == 0)) {
824 run_err("error: unexpected filename: %s", cp);
825 exit(1);
826 }
825 if (targisdir) { 827 if (targisdir) {
826 static char *namebuf; 828 static char *namebuf;
827 static int cursize; 829 static int cursize;
@@ -843,6 +845,8 @@ sink(int argc, char **argv)
843 exists = stat(np, &stb) == 0; 845 exists = stat(np, &stb) == 0;
844 if (buf[0] == 'D') { 846 if (buf[0] == 'D') {
845 int mod_flag = pflag; 847 int mod_flag = pflag;
848 if (!iamrecursive)
849 SCREWUP("received directory without -r");
846 if (exists) { 850 if (exists) {
847 if (!S_ISDIR(stb.st_mode)) { 851 if (!S_ISDIR(stb.st_mode)) {
848 errno = ENOTDIR; 852 errno = ENOTDIR;
@@ -894,11 +898,8 @@ bad: run_err("%s: %s", np, strerror(errno));
894 amt = size - i; 898 amt = size - i;
895 count += amt; 899 count += amt;
896 do { 900 do {
897 j = read(remin, cp, amt); 901 j = atomicio(read, remin, cp, amt);
898 if (j == -1 && (errno == EINTR || 902 if (j <= 0) {
899 errno == EAGAIN)) {
900 continue;
901 } else if (j <= 0) {
902 run_err("%s", j ? strerror(errno) : 903 run_err("%s", j ? strerror(errno) :
903 "dropped connection"); 904 "dropped connection");
904 exit(1); 905 exit(1);
@@ -938,21 +939,25 @@ bad: run_err("%s: %s", np, strerror(errno));
938 if (pflag) { 939 if (pflag) {
939 if (exists || omode != mode) 940 if (exists || omode != mode)
940#ifdef HAVE_FCHMOD 941#ifdef HAVE_FCHMOD
941 if (fchmod(ofd, omode)) 942 if (fchmod(ofd, omode)) {
942#else /* HAVE_FCHMOD */ 943#else /* HAVE_FCHMOD */
943 if (chmod(np, omode)) 944 if (chmod(np, omode)) {
944#endif /* HAVE_FCHMOD */ 945#endif /* HAVE_FCHMOD */
945 run_err("%s: set mode: %s", 946 run_err("%s: set mode: %s",
946 np, strerror(errno)); 947 np, strerror(errno));
948 wrerr = DISPLAYED;
949 }
947 } else { 950 } else {
948 if (!exists && omode != mode) 951 if (!exists && omode != mode)
949#ifdef HAVE_FCHMOD 952#ifdef HAVE_FCHMOD
950 if (fchmod(ofd, omode & ~mask)) 953 if (fchmod(ofd, omode & ~mask)) {
951#else /* HAVE_FCHMOD */ 954#else /* HAVE_FCHMOD */
952 if (chmod(np, omode & ~mask)) 955 if (chmod(np, omode & ~mask)) {
953#endif /* HAVE_FCHMOD */ 956#endif /* HAVE_FCHMOD */
954 run_err("%s: set mode: %s", 957 run_err("%s: set mode: %s",
955 np, strerror(errno)); 958 np, strerror(errno));
959 wrerr = DISPLAYED;
960 }
956 } 961 }
957 if (close(ofd) == -1) { 962 if (close(ofd) == -1) {
958 wrerr = YES; 963 wrerr = YES;