From 2bbf7b5017c3549c64d8805ea2e3944f2648da70 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Thu, 31 Oct 2019 12:50:00 -0700 Subject: [PATCH] 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 --- test-tool/iscsi-support.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test-tool/iscsi-support.c b/test-tool/iscsi-support.c index 169d2b0..9bec9e1 100644 --- a/test-tool/iscsi-support.c +++ b/test-tool/iscsi-support.c @@ -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; }