scp problems
Damien Miller
djm at mindrot.org
Sun Apr 30 00:22:36 EST 2000
On Fri, 28 Apr 2000, Ishikawa wrote:
> I am curious about this thread:
>
> Why don't relevant references to read/write use atomicio() in
> atomicio.c?
I agree.
Anyone who has been experiencing problems with scp, please try the
attached patch. It replaces all plain read() and write() calls with
atomicio() reads and writes().
Regards,
Damien Miller
--
| "Bombay is 250ms from New York in the new world order" - Alan Cox
| Damien Miller - http://www.mindrot.org/
| Email: djm at mindrot.org (home) -or- djm at ibs.com.au (work)
-------------- next part --------------
Index: scp.c
===================================================================
RCS file: /var/cvs/openssh/scp.c,v
retrieving revision 1.20
diff -u -r1.20 scp.c
--- scp.c 2000/04/19 06:26:14 1.20
+++ scp.c 2000/04/29 14:19:33
@@ -543,7 +543,7 @@
(void) sprintf(buf, "T%lu 0 %lu 0\n",
(unsigned long) stb.st_mtime,
(unsigned long) stb.st_atime);
- (void) write(remout, buf, strlen(buf));
+ (void) atomicio(write, remout, buf, strlen(buf));
if (response() < 0)
goto next;
}
@@ -556,7 +556,7 @@
fprintf(stderr, "Sending file modes: %s", buf);
fflush(stderr);
}
- (void) write(remout, buf, strlen(buf));
+ (void) atomicio(write, remout, buf, strlen(buf));
if (response() < 0)
goto next;
if ((bp = allocbuf(&buffer, fd, 2048)) == NULL) {
@@ -573,12 +573,12 @@
if (i + amt > stb.st_size)
amt = stb.st_size - i;
if (!haderr) {
- result = read(fd, bp->buf, amt);
+ result = atomicio(read, fd, bp->buf, amt);
if (result != amt)
haderr = result >= 0 ? EIO : errno;
}
if (haderr)
- (void) write(remout, bp->buf, amt);
+ (void) atomicio(write, remout, bp->buf, amt);
else {
result = atomicio(write, remout, bp->buf, amt);
if (result != amt)
@@ -592,7 +592,7 @@
if (close(fd) < 0 && !haderr)
haderr = errno;
if (!haderr)
- (void) write(remout, "", 1);
+ (void) atomicio(write, remout, "", 1);
else
run_err("%s: %s", name, strerror(haderr));
(void) response();
@@ -621,7 +621,7 @@
(void) sprintf(path, "T%lu 0 %lu 0\n",
(unsigned long) statp->st_mtime,
(unsigned long) statp->st_atime);
- (void) write(remout, path, strlen(path));
+ (void) atomicio(write, remout, path, strlen(path));
if (response() < 0) {
closedir(dirp);
return;
@@ -632,7 +632,7 @@
0, last);
if (verbose_mode)
fprintf(stderr, "Entering directory: %s", path);
- (void) write(remout, path, strlen(path));
+ (void) atomicio(write, remout, path, strlen(path));
if (response() < 0) {
closedir(dirp);
return;
@@ -651,7 +651,7 @@
source(1, vect);
}
(void) closedir(dirp);
- (void) write(remout, "E\n", 2);
+ (void) atomicio(write, remout, "E\n", 2);
(void) response();
}
@@ -687,17 +687,17 @@
if (targetshouldbedirectory)
verifydir(targ);
- (void) write(remout, "", 1);
+ (void) atomicio(write, remout, "", 1);
if (stat(targ, &stb) == 0 && S_ISDIR(stb.st_mode))
targisdir = 1;
for (first = 1;; first = 0) {
cp = buf;
- if (read(remin, cp, 1) <= 0)
+ if (atomicio(read, remin, cp, 1) <= 0)
return;
if (*cp++ == '\n')
SCREWUP("unexpected <newline>");
do {
- if (read(remin, &ch, sizeof(ch)) != sizeof(ch))
+ if (atomicio(read, remin, &ch, sizeof(ch)) != sizeof(ch))
SCREWUP("lost connection");
*cp++ = ch;
} while (cp < &buf[sizeof(buf) - 1] && ch != '\n');
@@ -705,7 +705,7 @@
if (buf[0] == '\01' || buf[0] == '\02') {
if (iamremote == 0)
- (void) write(STDERR_FILENO,
+ (void) atomicio(write, STDERR_FILENO,
buf + 1, strlen(buf + 1));
if (buf[0] == '\02')
exit(1);
@@ -713,7 +713,7 @@
continue;
}
if (buf[0] == 'E') {
- (void) write(remout, "", 1);
+ (void) atomicio(write, remout, "", 1);
return;
}
if (ch == '\n')
@@ -737,7 +737,7 @@
getnum(dummy_usec);
if (*cp++ != '\0')
SCREWUP("atime.usec not delimited");
- (void) write(remout, "", 1);
+ (void) atomicio(write, remout, "", 1);
continue;
}
if (*cp != 'C' && *cp != 'D') {
@@ -816,7 +816,7 @@
bad: run_err("%s: %s", np, strerror(errno));
continue;
}
- (void) write(remout, "", 1);
+ (void) atomicio(write, remout, "", 1);
if ((bp = allocbuf(&buffer, ofd, 4096)) == NULL) {
(void) close(ofd);
continue;
@@ -835,7 +835,7 @@
amt = size - i;
count += amt;
do {
- j = read(remin, cp, amt);
+ j = atomicio(read, remin, cp, amt);
if (j <= 0) {
run_err("%s", j ? strerror(errno) :
"dropped connection");
@@ -848,7 +848,7 @@
if (count == bp->cnt) {
/* Keep reading so we stay sync'd up. */
if (wrerr == NO) {
- j = write(ofd, bp->buf, count);
+ j = atomicio(write, ofd, bp->buf, count);
if (j != count) {
wrerr = YES;
wrerrno = j >= 0 ? EIO : errno;
@@ -861,7 +861,7 @@
if (showprogress)
progressmeter(1);
if (count != 0 && wrerr == NO &&
- (j = write(ofd, bp->buf, count)) != count) {
+ (j = atomicio(write, ofd, bp->buf, count)) != count) {
wrerr = YES;
wrerrno = j >= 0 ? EIO : errno;
}
@@ -897,7 +897,7 @@
run_err("%s: %s", np, strerror(wrerrno));
break;
case NO:
- (void) write(remout, "", 1);
+ (void) atomicio(write, remout, "", 1);
break;
case DISPLAYED:
break;
@@ -913,7 +913,7 @@
{
char ch, *cp, resp, rbuf[2048];
- if (read(remin, &resp, sizeof(resp)) != sizeof(resp))
+ if (atomicio(read, remin, &resp, sizeof(resp)) != sizeof(resp))
lostconn(0);
cp = rbuf;
@@ -926,13 +926,13 @@
case 1: /* error, followed by error msg */
case 2: /* fatal error, "" */
do {
- if (read(remin, &ch, sizeof(ch)) != sizeof(ch))
+ if (atomicio(read, remin, &ch, sizeof(ch)) != sizeof(ch))
lostconn(0);
*cp++ = ch;
} while (cp < &rbuf[sizeof(rbuf) - 1] && ch != '\n');
if (!iamremote)
- (void) write(STDERR_FILENO, rbuf, cp - rbuf);
+ (void) atomicio(write, STDERR_FILENO, rbuf, cp - rbuf);
++errs;
if (resp == 1)
return (-1);
@@ -1240,7 +1240,7 @@
alarmtimer(1);
} else if (flag == 1) {
alarmtimer(0);
- write(fileno(stdout), "\n", 1);
+ atomicio(write, fileno(stdout), "\n", 1);
statbytes = 0;
}
}
More information about the openssh-unix-dev
mailing list