~ubuntu-branches/ubuntu/dapper/openssh/dapper

« back to all changes in this revision

Viewing changes to scp.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2005-10-31 07:46:44 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20051031074644-poik7e4un4723tr4
Tags: 1:4.2p1-5ubuntu1
Resynchronise with Debian.

Show diffs side-by-side

added added

removed removed

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