diff options
author | Moritz Jodeit <moritz@cvs.openbsd.org> | 2005-02-26 17:35:06 +0000 |
---|---|---|
committer | Moritz Jodeit <moritz@cvs.openbsd.org> | 2005-02-26 17:35:06 +0000 |
commit | 5885b4493a67eeef9bf0f5bff4f0ff2525ff12aa (patch) | |
tree | 818ca39db1f4f88ae61dee7f1259ee06a684924a /libexec/ftpd | |
parent | df67fd5e181e11dce58145672edda3d4885a5f0f (diff) |
fix {send,recv}data so they don't add -1 to pos in the
EINTR/EAGAIN case as found by otto@.
also make them more quiet as requested by deraadt@.
ok millert@ otto@ henning@
Diffstat (limited to 'libexec/ftpd')
-rw-r--r-- | libexec/ftpd/monitor.c | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/libexec/ftpd/monitor.c b/libexec/ftpd/monitor.c index 486173bd32c..4a3d4e500c8 100644 --- a/libexec/ftpd/monitor.c +++ b/libexec/ftpd/monitor.c @@ -1,4 +1,4 @@ -/* $OpenBSD: monitor.c,v 1.7 2004/12/20 14:58:57 moritz Exp $ */ +/* $OpenBSD: monitor.c,v 1.8 2005/02/26 17:35:05 moritz Exp $ */ /* * Copyright (c) 2004 Moritz Jodeit <moritz@openbsd.org> @@ -77,17 +77,22 @@ void send_data(int sock, void *buf, size_t len) { ssize_t n; - size_t pos; + size_t pos = 0; char *ptr = buf; - for (pos = 0; len > pos; pos += n) { - n = write(sock, ptr + pos, len - pos); - - if (n == -1 && !(errno == EINTR || errno == EAGAIN)) - fatalx("send_data: %m"); - - if (n == 0) - fatalx("send_data: connection closed"); + while (len > pos) { + switch (n = write(sock, ptr + pos, len - pos)) { + case 0: + kill_slave(); + _exit(0); + /* NOTREACHED */ + case -1: + if (errno != EINTR && errno != EAGAIN) + fatalx("send_data: %m"); + break; + default: + pos += n; + } } } @@ -98,17 +103,22 @@ void recv_data(int sock, void *buf, size_t len) { ssize_t n; - size_t pos; + size_t pos = 0; char *ptr = buf; - for (pos = 0; len > pos; pos += n) { - n = read(sock, ptr + pos, len - pos); - - if (n == -1 && !(errno == EINTR || errno == EAGAIN)) - fatalx("recv_data: %m"); - - if (n == 0) - fatalx("recv_data: connection closed"); + while (len > pos) { + switch (n = read(sock, ptr + pos, len - pos)) { + case 0: + kill_slave(); + _exit(0); + /* NOTREACHED */ + case -1: + if (errno != EINTR && errno != EAGAIN) + fatalx("recv_data: %m"); + break; + default: + pos += n; + } } } |