diff mbox

[ndctl,2/3] ndctl, inject-smart: fix usage of strerror(errno)

Message ID 20180329231836.29453-2-vishal.l.verma@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Verma, Vishal L March 29, 2018, 11:18 p.m. UTC
We were incorrectly using strerror(errno) for a number of libndctl
calls, which is incorrect, as libndctl doesn't set errno.
Instead, use the return code from the API to print the error.

Cc: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
---
 ndctl/inject-smart.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

Comments

Dan Williams March 29, 2018, 11:28 p.m. UTC | #1
On Thu, Mar 29, 2018 at 4:18 PM, Vishal Verma <vishal.l.verma@intel.com> wrote:
> We were incorrectly using strerror(errno) for a number of libndctl
> calls, which is incorrect, as libndctl doesn't set errno.
> Instead, use the return code from the API to print the error.
>
> Cc: Dan Williams <dan.j.williams@intel.com>
> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>

Looks good.

Reviewed-by: Dan Williams <dan.j.williams@intel.com>
diff mbox

Patch

diff --git a/ndctl/inject-smart.c b/ndctl/inject-smart.c
index 45dbc8d..60de9fe 100644
--- a/ndctl/inject-smart.c
+++ b/ndctl/inject-smart.c
@@ -232,8 +232,8 @@  static int smart_set_thresh(struct ndctl_dimm *dimm)
 
 	rc = ndctl_cmd_submit(st_cmd);
 	if (rc) {
-		error("%s: smart threshold command failed: %s\n",
-			name, strerror(errno));
+		error("%s: smart threshold command failed: %s (%d)\n",
+			name, strerror(abs(rc)), rc);
 		goto out;
 	}
 
@@ -272,8 +272,8 @@  static int smart_set_thresh(struct ndctl_dimm *dimm)
 
 	rc = ndctl_cmd_submit(sst_cmd);
 	if (rc)
-		error("%s: smart set threshold command failed: %s\n",
-			name, strerror(errno));
+		error("%s: smart set threshold command failed: %s (%d)\n",
+			name, strerror(abs(rc)), rc);
 
 out:
 	ndctl_cmd_unref(sst_cmd);
@@ -291,14 +291,14 @@  out:
 		} \
 		rc = ndctl_cmd_smart_inject_##arg(si_cmd, true, sctx.arg); \
 		if (rc) { \
-			error("%s: smart inject %s cmd invalid: %s\n", \
-				name, #arg, strerror(errno)); \
+			error("%s: smart inject %s cmd invalid: %s (%d)\n", \
+				name, #arg, strerror(abs(rc)), rc); \
 			goto out; \
 		} \
 		rc = ndctl_cmd_submit(si_cmd); \
 		if (rc) { \
-			error("%s: smart inject %s command failed: %s\n", \
-				name, #arg, strerror(errno)); \
+			error("%s: smart inject %s command failed: %s (%d)\n", \
+				name, #arg, strerror(abs(rc)), rc); \
 			goto out; \
 		} \
 		ndctl_cmd_unref(si_cmd); \
@@ -315,14 +315,14 @@  out:
 		} \
 		rc = ndctl_cmd_smart_inject_##arg(si_cmd, true); \
 		if (rc) { \
-			error("%s: smart inject %s cmd invalid: %s\n", \
-				name, #arg, strerror(errno)); \
+			error("%s: smart inject %s cmd invalid: %s (%d)\n", \
+				name, #arg, strerror(abs(rc)), rc); \
 			goto out; \
 		} \
 		rc = ndctl_cmd_submit(si_cmd); \
 		if (rc) { \
-			error("%s: smart inject %s command failed: %s\n", \
-				name, #arg, strerror(errno)); \
+			error("%s: smart inject %s command failed: %s (%d)\n", \
+				name, #arg, strerror(abs(rc)), rc); \
 			goto out; \
 		} \
 		ndctl_cmd_unref(si_cmd); \