summaryrefslogtreecommitdiff
path: root/scp.c
diff options
context:
space:
mode:
Diffstat (limited to 'scp.c')
-rw-r--r--scp.c42
1 files changed, 23 insertions, 19 deletions
diff --git a/scp.c b/scp.c
index 1d34cc639..1407aa71d 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.121 2005/04/02 12:41:16 djm Exp $"); 74RCSID("$OpenBSD: scp.c,v 1.125 2005/07/27 10:39:03 dtucker Exp $");
75 75
76#include "xmalloc.h" 76#include "xmalloc.h"
77#include "atomicio.h" 77#include "atomicio.h"
@@ -109,11 +109,13 @@ static void
109killchild(int signo) 109killchild(int signo)
110{ 110{
111 if (do_cmd_pid > 1) { 111 if (do_cmd_pid > 1) {
112 kill(do_cmd_pid, signo); 112 kill(do_cmd_pid, signo ? signo : SIGTERM);
113 waitpid(do_cmd_pid, NULL, 0); 113 waitpid(do_cmd_pid, NULL, 0);
114 } 114 }
115 115
116 _exit(1); 116 if (signo)
117 _exit(1);
118 exit(1);
117} 119}
118 120
119/* 121/*
@@ -184,7 +186,7 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout, int argc)
184} 186}
185 187
186typedef struct { 188typedef struct {
187 int cnt; 189 size_t cnt;
188 char *buf; 190 char *buf;
189} BUF; 191} BUF;
190 192
@@ -502,8 +504,9 @@ source(int argc, char **argv)
502 struct stat stb; 504 struct stat stb;
503 static BUF buffer; 505 static BUF buffer;
504 BUF *bp; 506 BUF *bp;
505 off_t i, amt, result, statbytes; 507 off_t i, amt, statbytes;
506 int fd, haderr, indx; 508 size_t result;
509 int fd = -1, haderr, indx;
507 char *last, *name, buf[2048]; 510 char *last, *name, buf[2048];
508 int len; 511 int len;
509 512
@@ -578,14 +581,14 @@ next: (void) close(fd);
578 if (!haderr) { 581 if (!haderr) {
579 result = atomicio(read, fd, bp->buf, amt); 582 result = atomicio(read, fd, bp->buf, amt);
580 if (result != amt) 583 if (result != amt)
581 haderr = result >= 0 ? EIO : errno; 584 haderr = errno;
582 } 585 }
583 if (haderr) 586 if (haderr)
584 (void) atomicio(vwrite, remout, bp->buf, amt); 587 (void) atomicio(vwrite, remout, bp->buf, amt);
585 else { 588 else {
586 result = atomicio(vwrite, remout, bp->buf, amt); 589 result = atomicio(vwrite, remout, bp->buf, amt);
587 if (result != amt) 590 if (result != amt)
588 haderr = result >= 0 ? EIO : errno; 591 haderr = errno;
589 statbytes += result; 592 statbytes += result;
590 } 593 }
591 if (limit_rate) 594 if (limit_rate)
@@ -720,8 +723,9 @@ sink(int argc, char **argv)
720 YES, NO, DISPLAYED 723 YES, NO, DISPLAYED
721 } wrerr; 724 } wrerr;
722 BUF *bp; 725 BUF *bp;
723 off_t i, j; 726 off_t i;
724 int amt, count, exists, first, mask, mode, ofd, omode; 727 size_t j, count;
728 int amt, exists, first, mask, mode, ofd, omode;
725 off_t size, statbytes; 729 off_t size, statbytes;
726 int setimes, targisdir, wrerrno = 0; 730 int setimes, targisdir, wrerrno = 0;
727 char ch, *cp, *np, *targ, *why, *vect[1], buf[2048]; 731 char ch, *cp, *np, *targ, *why, *vect[1], buf[2048];
@@ -748,7 +752,7 @@ sink(int argc, char **argv)
748 targisdir = 1; 752 targisdir = 1;
749 for (first = 1;; first = 0) { 753 for (first = 1;; first = 0) {
750 cp = buf; 754 cp = buf;
751 if (atomicio(read, remin, cp, 1) <= 0) 755 if (atomicio(read, remin, cp, 1) != 1)
752 return; 756 return;
753 if (*cp++ == '\n') 757 if (*cp++ == '\n')
754 SCREWUP("unexpected <newline>"); 758 SCREWUP("unexpected <newline>");
@@ -829,7 +833,7 @@ sink(int argc, char **argv)
829 } 833 }
830 if (targisdir) { 834 if (targisdir) {
831 static char *namebuf; 835 static char *namebuf;
832 static int cursize; 836 static size_t cursize;
833 size_t need; 837 size_t need;
834 838
835 need = strlen(targ) + strlen(cp) + 250; 839 need = strlen(targ) + strlen(cp) + 250;
@@ -902,7 +906,7 @@ bad: run_err("%s: %s", np, strerror(errno));
902 count += amt; 906 count += amt;
903 do { 907 do {
904 j = atomicio(read, remin, cp, amt); 908 j = atomicio(read, remin, cp, amt);
905 if (j <= 0) { 909 if (j == 0) {
906 run_err("%s", j ? strerror(errno) : 910 run_err("%s", j ? strerror(errno) :
907 "dropped connection"); 911 "dropped connection");
908 exit(1); 912 exit(1);
@@ -918,10 +922,10 @@ bad: run_err("%s: %s", np, strerror(errno));
918 if (count == bp->cnt) { 922 if (count == bp->cnt) {
919 /* Keep reading so we stay sync'd up. */ 923 /* Keep reading so we stay sync'd up. */
920 if (wrerr == NO) { 924 if (wrerr == NO) {
921 j = atomicio(vwrite, ofd, bp->buf, count); 925 if (atomicio(vwrite, ofd, bp->buf,
922 if (j != count) { 926 count) != count) {
923 wrerr = YES; 927 wrerr = YES;
924 wrerrno = j >= 0 ? EIO : errno; 928 wrerrno = errno;
925 } 929 }
926 } 930 }
927 count = 0; 931 count = 0;
@@ -931,9 +935,9 @@ bad: run_err("%s: %s", np, strerror(errno));
931 if (showprogress) 935 if (showprogress)
932 stop_progress_meter(); 936 stop_progress_meter();
933 if (count != 0 && wrerr == NO && 937 if (count != 0 && wrerr == NO &&
934 (j = atomicio(vwrite, ofd, bp->buf, count)) != count) { 938 atomicio(vwrite, ofd, bp->buf, count) != count) {
935 wrerr = YES; 939 wrerr = YES;
936 wrerrno = j >= 0 ? EIO : errno; 940 wrerrno = errno;
937 } 941 }
938 if (wrerr == NO && ftruncate(ofd, size) != 0) { 942 if (wrerr == NO && ftruncate(ofd, size) != 0) {
939 run_err("%s: truncate: %s", np, strerror(errno)); 943 run_err("%s: truncate: %s", np, strerror(errno));
@@ -1070,7 +1074,7 @@ verifydir(char *cp)
1070 errno = ENOTDIR; 1074 errno = ENOTDIR;
1071 } 1075 }
1072 run_err("%s: %s", cp, strerror(errno)); 1076 run_err("%s: %s", cp, strerror(errno));
1073 exit(1); 1077 killchild(0);
1074} 1078}
1075 1079
1076int 1080int