diff options
author | Andy Whitcroft <apw@shadowen.org> | 2007-01-08 15:58:08 +0000 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2007-01-08 15:44:47 -0800 |
commit | 93d26e4cb9cec2eb8abb4f37e6dda2c86fcceeac (patch) | |
tree | 8d3cda91ddd8242531995cb304f37578bfaa7cf0 /ssh-upload.c | |
parent | short i/o: clean up the naming for the write_{in,or}_xxx family (diff) | |
download | tgif-93d26e4cb9cec2eb8abb4f37e6dda2c86fcceeac.tar.xz |
short i/o: fix calls to read to use xread or read_in_full
We have a number of badly checked read() calls. Often we are
expecting read() to read exactly the size we requested or fail, this
fails to handle interrupts or short reads. Add a read_in_full()
providing those semantics. Otherwise we at a minimum need to check
for EINTR and EAGAIN, where this is appropriate use xread().
Signed-off-by: Andy Whitcroft <apw@shadowen.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'ssh-upload.c')
-rw-r--r-- | ssh-upload.c | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/ssh-upload.c b/ssh-upload.c index 901e0366df..86b169bf4f 100644 --- a/ssh-upload.c +++ b/ssh-upload.c @@ -21,17 +21,14 @@ static int serve_object(int fd_in, int fd_out) { ssize_t size; unsigned char sha1[20]; signed char remote; - int posn = 0; - do { - size = read(fd_in, sha1 + posn, 20 - posn); - if (size < 0) { - perror("git-ssh-upload: read "); - return -1; - } - if (!size) - return -1; - posn += size; - } while (posn < 20); + + size = read_in_full(fd_in, sha1, 20); + if (size < 0) { + perror("git-ssh-upload: read "); + return -1; + } + if (!size) + return -1; if (verbose) fprintf(stderr, "Serving %s\n", sha1_to_hex(sha1)); @@ -54,7 +51,7 @@ static int serve_object(int fd_in, int fd_out) { static int serve_version(int fd_in, int fd_out) { - if (read(fd_in, &remote_version, 1) < 1) + if (xread(fd_in, &remote_version, 1) < 1) return -1; write(fd_out, &local_version, 1); return 0; @@ -67,7 +64,7 @@ static int serve_ref(int fd_in, int fd_out) int posn = 0; signed char remote = 0; do { - if (posn >= PATH_MAX || read(fd_in, ref + posn, 1) < 1) + if (posn >= PATH_MAX || xread(fd_in, ref + posn, 1) < 1) return -1; posn++; } while (ref[posn - 1]); @@ -89,7 +86,7 @@ static void service(int fd_in, int fd_out) { char type; int retval; do { - retval = read(fd_in, &type, 1); + retval = xread(fd_in, &type, 1); if (retval < 1) { if (retval < 0) perror("git-ssh-upload: read "); |