test-tool: If SG_IO fails, report why it failed

See also https://github.com/sahlberg/libiscsi/issues/302.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
This commit is contained in:
Bart Van Assche
2019-10-31 12:50:00 -07:00
parent a55f11ee68
commit 2bbf7b5017

View File

@@ -370,10 +370,14 @@ static struct scsi_task *send_scsi_command(struct scsi_device *sdev, struct scsi
io_hdr.timeout = 5000;
if(ioctl(sdev->sgio_fd, SG_IO, &io_hdr) < 0){
int err = errno;
if (sdev->error_str != NULL) {
free(discard_const(sdev->error_str));
}
sdev->error_str = strdup("SG_IO ioctl failed");
if (asprintf(&sdev->error_str, "SG_IO ioctl failed: %s",
strerror(err)) < 0)
sdev->error_str = NULL;
return NULL;
}