[PATCH] tgtadm: handle a partial response properly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



tgtadm could get partial responses from tgtd so need to handle such
properly. This fixes the following problem:

http://lists.wpkg.org/pipermail/stgt/2008-October/002397.html

Reported-by: Tomasz Chmielewski <mangoo@xxxxxxxx>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@xxxxxxxxxxxxx>
---
 usr/tgtadm.c |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/usr/tgtadm.c b/usr/tgtadm.c
index f7b4fd3..ce7eb24 100644
--- a/usr/tgtadm.c
+++ b/usr/tgtadm.c
@@ -199,10 +199,23 @@ static int ipc_mgmt_rsp(int fd)
 	struct tgtadm_rsp rsp;
 	int err, rest, len;
 
-	err = read(fd, &rsp, sizeof(rsp));
+retry:
+	err = recv(fd, &rsp, sizeof(rsp), MSG_WAITALL);
 	if (err < 0) {
-		eprintf("can't get the response, %m\n");
+		if (errno == EAGAIN)
+			goto retry;
+		else if (errno == EINTR)
+			eprintf("interrupted by a signal\n");
+		else
+			eprintf("can't get the response, %m\n");
+
 		return errno;
+	} else if (err == 0) {
+		eprintf("tgtd closed the socket\n");
+		return 0;
+	} else if (err != sizeof(rsp)) {
+		eprintf("a partial response\n");
+		return 0;
 	}
 
 	if (rsp.err != TGTADM_SUCCESS) {
-- 
1.5.5.GIT

--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux SCSI]     [Linux RAID]     [Linux Clusters]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]

  Powered by Linux