Add error control at the smart command

This commit is contained in:
Andrea Mazzoleni 2015-01-23 22:59:29 +01:00
parent e0601593bd
commit f974a8378b
3 changed files with 19 additions and 11 deletions

View file

@ -205,6 +205,7 @@ endif
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) up
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) down
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) test-devices
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(CONF) smart
if HAVE_SYMLINK
$(TESTENV) ./snapraid$(EXEEXT) $(CHECKFLAGS) -c $(PAR1) pool
endif

View file

@ -515,21 +515,21 @@ void state_device(struct snapraid_state* state, int operation)
case DEVICE_SMART : fprintf(stderr, "SMART"); break;
}
fprintf(stderr, " unsupported in this platform.\n");
}
} else {
#ifndef _WIN32
if (operation == DEVICE_LIST) {
for (i = tommy_list_head(&low); i != 0; i = i->next) {
devinfo_t* devinfo = i->data;
devinfo_t* parent = devinfo->parent;
if (operation == DEVICE_LIST) {
for (i = tommy_list_head(&low); i != 0; i = i->next) {
devinfo_t* devinfo = i->data;
devinfo_t* parent = devinfo->parent;
printf("%u:%u\t%s\t%u:%u\t%s\t%s\n", major(devinfo->device), minor(devinfo->device), devinfo->file, major(parent->device), minor(parent->device), parent->file, parent->name);
printf("%u:%u\t%s\t%u:%u\t%s\t%s\n", major(devinfo->device), minor(devinfo->device), devinfo->file, major(parent->device), minor(parent->device), parent->file, parent->name);
}
}
}
#endif
if (operation == DEVICE_SMART) {
state_smart(state->level + tommy_list_count(&state->disklist), &low);
if (operation == DEVICE_SMART)
state_smart(state->level + tommy_list_count(&state->disklist), &low);
}
tommy_list_foreach(&high, free);

View file

@ -625,6 +625,7 @@ static int devsmart(dev_t device, uint64_t* smart, char* serial)
FILE* f;
int inside;
unsigned i;
int ret;
*serial = 0;
for (i = 0; i < SMART_COUNT; ++i)
@ -636,7 +637,7 @@ static int devsmart(dev_t device, uint64_t* smart, char* serial)
f = popen(cmd, "r");
if (!f) {
/* LCOV_EXCL_START */
fprintf(stderr, "Failed to run smartctrl -a on device '%u:%u'.\n", major(device), minor(device));
fprintf(stderr, "Failed to run smartctrl -a on device '%u:%u' (from open).\n", major(device), minor(device));
return -1;
/* LCOV_EXCL_STOP */
}
@ -694,7 +695,13 @@ static int devsmart(dev_t device, uint64_t* smart, char* serial)
}
}
pclose(f);
ret = pclose(f);
if (!WIFEXITED(ret) || WEXITSTATUS(ret) != 0) {
/* LCOV_EXCL_START */
fprintf(stderr, "Failed to run smartctrl -a on device '%u:%u' (from pclose).\n", major(device), minor(device));
return -1;
/* LCOV_EXCL_STOP */
}
return 0;
}