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>
This commit is contained in:

committed by
Junio C Hamano

parent
e08140568a
commit
93d26e4cb9
25
ssh-upload.c
25
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 ");
|
||||
|
Reference in New Issue
Block a user