diff options
-rw-r--r-- | src/hardware/smartctl.c | 9 | ||||
-rw-r--r-- | src/hardware/utils.c | 9 | ||||
-rw-r--r-- | src/hardware/utils.h | 3 |
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); |