]> andersk Git - openssh.git/blobdiff - scp.c
- (tim) [configure.ac] Some platforms need sys/types.h for arpa/nameser.h.
[openssh.git] / scp.c
diff --git a/scp.c b/scp.c
index f69fd05fc66ff418a43f30d366ff7d84ca178b1e..9dc060e26de7434a9e460317b39c93fcc4d5f39a 100644 (file)
--- a/scp.c
+++ b/scp.c
@@ -71,7 +71,7 @@
  */
 
 #include "includes.h"
-RCSID("$OpenBSD: scp.c,v 1.119 2005/01/24 10:22:06 dtucker Exp $");
+RCSID("$OpenBSD: scp.c,v 1.123 2005/05/26 02:08:05 avsm Exp $");
 
 #include "xmalloc.h"
 #include "atomicio.h"
@@ -109,11 +109,13 @@ static void
 killchild(int signo)
 {
        if (do_cmd_pid > 1) {
-               kill(do_cmd_pid, signo);
+               kill(do_cmd_pid, signo ? signo : SIGTERM);
                waitpid(do_cmd_pid, NULL, 0);
        }
 
-       _exit(1);
+       if (signo)
+               _exit(1);
+       exit(1);
 }
 
 /*
@@ -361,20 +363,21 @@ void
 toremote(char *targ, int argc, char **argv)
 {
        int i, len;
-       char *bp, *host, *src, *suser, *thost, *tuser;
+       char *bp, *host, *src, *suser, *thost, *tuser, *arg;
 
        *targ++ = 0;
        if (*targ == 0)
                targ = ".";
 
-       if ((thost = strrchr(argv[argc - 1], '@'))) {
+       arg = xstrdup(argv[argc - 1]);
+       if ((thost = strrchr(arg, '@'))) {
                /* user@host */
                *thost++ = 0;
-               tuser = argv[argc - 1];
+               tuser = arg;
                if (*tuser == '\0')
                        tuser = NULL;
        } else {
-               thost = argv[argc - 1];
+               thost = arg;
                tuser = NULL;
        }
 
@@ -501,7 +504,8 @@ source(int argc, char **argv)
        struct stat stb;
        static BUF buffer;
        BUF *bp;
-       off_t i, amt, result, statbytes;
+       off_t i, amt, statbytes;
+       size_t result;
        int fd, haderr, indx;
        char *last, *name, buf[2048];
        int len;
@@ -577,14 +581,14 @@ next:                     (void) close(fd);
                        if (!haderr) {
                                result = atomicio(read, fd, bp->buf, amt);
                                if (result != amt)
-                                       haderr = result >= 0 ? EIO : errno;
+                                       haderr = errno;
                        }
                        if (haderr)
                                (void) atomicio(vwrite, remout, bp->buf, amt);
                        else {
                                result = atomicio(vwrite, remout, bp->buf, amt);
                                if (result != amt)
-                                       haderr = result >= 0 ? EIO : errno;
+                                       haderr = errno;
                                statbytes += result;
                        }
                        if (limit_rate)
@@ -719,7 +723,8 @@ sink(int argc, char **argv)
                YES, NO, DISPLAYED
        } wrerr;
        BUF *bp;
-       off_t i, j;
+       off_t i;
+       size_t j;
        int amt, count, exists, first, mask, mode, ofd, omode;
        off_t size, statbytes;
        int setimes, targisdir, wrerrno = 0;
@@ -747,7 +752,7 @@ sink(int argc, char **argv)
                targisdir = 1;
        for (first = 1;; first = 0) {
                cp = buf;
-               if (atomicio(read, remin, cp, 1) <= 0)
+               if (atomicio(read, remin, cp, 1) != 1)
                        return;
                if (*cp++ == '\n')
                        SCREWUP("unexpected <newline>");
@@ -901,7 +906,7 @@ bad:                        run_err("%s: %s", np, strerror(errno));
                        count += amt;
                        do {
                                j = atomicio(read, remin, cp, amt);
-                               if (j <= 0) {
+                               if (j == 0) {
                                        run_err("%s", j ? strerror(errno) :
                                            "dropped connection");
                                        exit(1);
@@ -917,10 +922,10 @@ bad:                      run_err("%s: %s", np, strerror(errno));
                        if (count == bp->cnt) {
                                /* Keep reading so we stay sync'd up. */
                                if (wrerr == NO) {
-                                       j = atomicio(vwrite, ofd, bp->buf, count);
-                                       if (j != count) {
+                                       if (atomicio(vwrite, ofd, bp->buf,
+                                           count) != count) {
                                                wrerr = YES;
-                                               wrerrno = j >= 0 ? EIO : errno;
+                                               wrerrno = errno;
                                        }
                                }
                                count = 0;
@@ -930,9 +935,9 @@ bad:                        run_err("%s: %s", np, strerror(errno));
                if (showprogress)
                        stop_progress_meter();
                if (count != 0 && wrerr == NO &&
-                   (j = atomicio(vwrite, ofd, bp->buf, count)) != count) {
+                   atomicio(vwrite, ofd, bp->buf, count) != count) {
                        wrerr = YES;
-                       wrerrno = j >= 0 ? EIO : errno;
+                       wrerrno = errno;
                }
                if (wrerr == NO && ftruncate(ofd, size) != 0) {
                        run_err("%s: truncate: %s", np, strerror(errno));
@@ -1069,7 +1074,7 @@ verifydir(char *cp)
                errno = ENOTDIR;
        }
        run_err("%s: %s", cp, strerror(errno));
-       exit(1);
+       killchild(0);
 }
 
 int
This page took 0.04168 seconds and 4 git commands to generate.