fence-virtd: Use perror only if the last system call returns an error.

Fix wrong usage of perror. perror is called when data filled
by read system call is shorter than expected. It is not an error
of system call.  In such case perror should not be used.
Similar code can be found in place where write system call is used.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
This commit is contained in:
Masatake YAMATO 2015-02-08 01:27:59 +09:00
parent 59b49215ab
commit 99d6fa5746

@ -260,9 +260,15 @@ sha_challenge(int fd, fence_auth_type_t auth, void *key,
return 0;
}
if (read(fd, response, sizeof(response)) < sizeof(response)) {
ret = read(fd, response, sizeof(response));
if (ret < 0) {
perror("read");
return 0;
} else if (ret < sizeof(response)) {
fprintf(stderr,
"read data from socket is too short(actual: %d, expected: %lu)\n",
ret, sizeof(response));
return 0;
}
ret = !memcmp(response, hash, sizeof(response));
@ -291,6 +297,7 @@ sha_response(int fd, fence_auth_type_t auth, void *key,
HASHContext *h;
HASH_HashType ht;
unsigned int rlen;
int ret;
FD_ZERO(&rfds);
FD_SET(fd, &rfds);
@ -332,9 +339,16 @@ sha_response(int fd, fence_auth_type_t auth, void *key,
HASH_End(h, hash, &rlen, sizeof(hash));
HASH_Destroy(h);
if (write(fd, hash, sizeof(hash)) < sizeof(hash)) {
ret = write(fd, hash, sizeof(hash));
if (ret < 0) {
perror("write");
return 0;
} else if (ret < sizeof(hash)) {
fprintf(stderr,
"Only part of hash is written(actual: %d, expected: %lu)\n",
ret,
sizeof(hash));
return 0;
}
return 1;