summaryrefslogtreecommitdiffstats
path: root/src/hardware
diff options
context:
space:
mode:
authorPeter Schiffer <pschiffe@redhat.com>2013-12-10 14:56:30 +0100
committerPeter Schiffer <pschiffe@redhat.com>2013-12-10 16:28:51 +0100
commit4d3e9d9f3bda71faf6b46286e1ad78fb0e3696cf (patch)
treefc5fad268b20f36b56841822e0370c15703afeef /src/hardware
parentae2ebe7f2c145b3553a42e016f67edb950ed87b9 (diff)
downloadopenlmi-providers-4d3e9d9f3bda71faf6b46286e1ad78fb0e3696cf.tar.gz
openlmi-providers-4d3e9d9f3bda71faf6b46286e1ad78fb0e3696cf.tar.xz
openlmi-providers-4d3e9d9f3bda71faf6b46286e1ad78fb0e3696cf.zip
Hardware: honour command return code in run_command() function
Diffstat (limited to 'src/hardware')
-rw-r--r--src/hardware/smartctl.c9
-rw-r--r--src/hardware/utils.c9
-rw-r--r--src/hardware/utils.h3
3 files changed, 14 insertions, 7 deletions
diff --git a/src/hardware/smartctl.c b/src/hardware/smartctl.c
index 5648ef0..afa690f 100644
--- a/src/hardware/smartctl.c
+++ b/src/hardware/smartctl.c
@@ -93,6 +93,13 @@ done:
return ret;
}
+/*
+ * Scan available hdd devices in system with "smartctl --scan" command and
+ * create array of SmartctlHdd structures.
+ * @param hdds array of hdds
+ * @param hdds_nb number of hard drives in hdds
+ * @return 0 if success, negative value otherwise
+ */
short scan_smctlhdd_devices(SmartctlHdd **hdds, unsigned *hdds_nb)
{
short ret = -1;
@@ -199,7 +206,7 @@ short smartctl_get_hdds(SmartctlHdd **hdds, unsigned *hdds_nb)
char command[PATH_MAX];
snprintf(command, PATH_MAX, "smartctl -iH --identify=n %s",
(*hdds)[curr_hdd].dev_path);
- if (run_command(command, &buffer, &buffer_size) != 0) {
+ if (run_command(command, &buffer, &buffer_size) < 0) {
continue;
}
diff --git a/src/hardware/utils.c b/src/hardware/utils.c
index 2393d66..305cc1e 100644
--- a/src/hardware/utils.c
+++ b/src/hardware/utils.c
@@ -164,14 +164,13 @@ done:
ret = -1;
}
} else if (ret_code != 0) {
- warn("Command \"%s\" exited unexpectedly.", command);
- if (ret == 0) {
- ret = -1;
- }
+ warn("Command \"%s\" exited unexpectedly with return code: %d",
+ command, ret_code);
+ ret = ret_code;
}
}
- if (ret != 0) {
+ if (ret < 0) {
free_2d_buffer(buffer, buffer_size);
}
diff --git a/src/hardware/utils.h b/src/hardware/utils.h
index abd67d4..f9acc4f 100644
--- a/src/hardware/utils.h
+++ b/src/hardware/utils.h
@@ -61,7 +61,8 @@ void free_2d_buffer(char ***buffer, unsigned *buffer_size);
* @param command to be run
* @param buffer
* @param buffer_size number of lines in buffer
- * @return 0 if success, negative value otherwise
+ * @return negative value if problem occurred. In this case, buffer is freed.
+ * 0 and positive value represent return code of command.
*/
short run_command(const char *command, char ***buffer, unsigned *buffer_size);