diff --git a/usr.sbin/iscsid/pdu.c b/usr.sbin/iscsid/pdu.c index 4672ecd21516..78aa065acef1 100644 --- a/usr.sbin/iscsid/pdu.c +++ b/usr.sbin/iscsid/pdu.c @@ -34,7 +34,9 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include +#include #include #include "iscsid.h" @@ -177,18 +179,23 @@ pdu_padding(const struct pdu *pdu) } static void -pdu_read(int fd, char *data, size_t len) +pdu_read(const struct connection *conn, char *data, size_t len) { ssize_t ret; while (len > 0) { - ret = read(fd, data, len); + ret = read(conn->conn_socket, data, len); if (ret < 0) { - if (timed_out()) + if (timed_out()) { + fail(conn, "Login Phase timeout"); log_errx(1, "exiting due to timeout"); + } + fail(conn, strerror(errno)); log_err(1, "read"); - } else if (ret == 0) + } else if (ret == 0) { + fail(conn, "connection lost"); log_errx(1, "read: connection lost"); + } len -= ret; data += ret; } @@ -207,7 +214,7 @@ pdu_receive(struct pdu *pdu) assert(pdu->pdu_connection->conn_conf.isc_iser == 0); - pdu_read(pdu->pdu_connection->conn_socket, + pdu_read(pdu->pdu_connection, (char *)pdu->pdu_bhs, sizeof(*pdu->pdu_bhs)); len = pdu_ahs_length(pdu); @@ -227,13 +234,13 @@ pdu_receive(struct pdu *pdu) if (pdu->pdu_data == NULL) log_err(1, "malloc"); - pdu_read(pdu->pdu_connection->conn_socket, + pdu_read(pdu->pdu_connection, (char *)pdu->pdu_data, pdu->pdu_data_len); padding = pdu_padding(pdu); if (padding != 0) { assert(padding < sizeof(dummy)); - pdu_read(pdu->pdu_connection->conn_socket, + pdu_read(pdu->pdu_connection, (char *)dummy, padding); } }