Use a more precise error detection when running external programs

This commit is contained in:
Andrea Mazzoleni 2015-01-24 14:10:23 +01:00
parent f974a8378b
commit 88aa107596
2 changed files with 21 additions and 2 deletions

View file

@ -696,9 +696,21 @@ static int devsmart(dev_t device, uint64_t* smart, char* serial)
}
ret = pclose(f);
if (!WIFEXITED(ret) || WEXITSTATUS(ret) != 0) {
if (!WIFEXITED(ret)) {
/* LCOV_EXCL_START */
fprintf(stderr, "Failed to run smartctrl -a on device '%u:%u' (from pclose).\n", major(device), minor(device));
fprintf(stderr, "Failed to run smartctrl -a on device '%u:%u' (not exited).\n", major(device), minor(device));
return -1;
/* LCOV_EXCL_STOP */
}
if (WEXITSTATUS(ret) == 127) {
/* LCOV_EXCL_START */
fprintf(stderr, "Failed to run smartctrl -a on device '%u:%u' (from sh).\n", major(device), minor(device));
return -1;
/* LCOV_EXCL_STOP */
}
if (WEXITSTATUS(ret) != 0) {
/* LCOV_EXCL_START */
fprintf(stderr, "Failed to run smartctrl -a on device '%u:%u' with return code %d.\n", major(device), minor(device), WEXITSTATUS(ret));
return -1;
/* LCOV_EXCL_STOP */
}
@ -724,6 +736,12 @@ static int devdown(dev_t device)
return -1;
/* LCOV_EXCL_STOP */
}
if (!WIFEXITED(ret)) {
/* LCOV_EXCL_START */
fprintf(stderr, "Failed to run hdparm -y on device '%u:%u' (not exited).\n", major(device), minor(device));
return -1;
/* LCOV_EXCL_STOP */
}
if (WEXITSTATUS(ret) == 127) {
/* LCOV_EXCL_START */
fprintf(stderr, "Failed to run hdparm -y on device '%u:%u' (from sh).\n", major(device), minor(device));