src/main.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
New commits:
commit da94fe800c843b467f926420ccbe9961e8289f46
Author: David Teigland <teigland(a)redhat.com>
Date: Thu Oct 4 16:26:54 2012 -0500
sanlock: fix aborted command clearing
When clearing the remainder of an aborted
command, non-blocking recv is used to avoid
blocking the main thread, but this means it
needs to do a minimal amount of retrying when
EAGAIN is returned. It wasn't retrying at all,
so the remainder of the message was handled as
a new command, which caused errors when the
fragment was found to have a bad magic number.
Signed-off-by: David Teigland <teigland(a)redhat.com>
diff --git a/src/main.c b/src/main.c
index 522ae6a..a0b5145 100644
--- a/src/main.c
+++ b/src/main.c
@@ -396,13 +396,22 @@ void client_recv_all(int ci, struct sm_header *h_recv, int pos)
{
char trash[64];
int rem = h_recv->length - sizeof(struct sm_header) - pos;
- int rv, error = 0, total = 0;
+ int rv, error = 0, total = 0, retries = 0;
if (!rem)
return;
while (1) {
rv = recv(client[ci].fd, trash, sizeof(trash), MSG_DONTWAIT);
+
+ if (rv == -1 && errno == EAGAIN) {
+ usleep(1000);
+ if (retries < 20) {
+ retries++;
+ continue;
+ }
+ }
+
if (rv == -1)
error = errno;
if (rv <= 0)
@@ -413,8 +422,8 @@ void client_recv_all(int ci, struct sm_header *h_recv, int pos)
break;
}
- log_debug("recv_all %d,%d,%d pos %d rv %d error %d rem %d total %d",
- ci, client[ci].fd, client[ci].pid, pos, rv, error, rem, total);
+ log_debug("recv_all %d,%d,%d pos %d rv %d error %d retries %d rem %d total
%d",
+ ci, client[ci].fd, client[ci].pid, pos, rv, error, retries, rem, total);
}
void send_result(int fd, struct sm_header *h_recv, int result);
@@ -998,6 +1007,8 @@ static void process_cmd_thread_registered(int ci_in, struct sm_header
*h_recv)
break;
}
if (ci_target < 0) {
+ log_error("cmd %d target pid %d not found",
+ h_recv->cmd, h_recv->data2);
result = -ESRCH;
goto fail;
}