From f974a8378b7bd8152279fc305c7745b82058b796 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Fri, 23 Jan 2015 22:59:29 +0100 Subject: [PATCH] Add error control at the smart command --- Makefile.am | 1 + cmdline/device.c | 18 +++++++++--------- cmdline/unix.c | 11 +++++++++-- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Makefile.am b/Makefile.am index 0a4c5083..e64e8ec7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/cmdline/device.c b/cmdline/device.c index 787e4c6a..8faa81a8 100644 --- a/cmdline/device.c +++ b/cmdline/device.c @@ -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); diff --git a/cmdline/unix.c b/cmdline/unix.c index 291c1125..846935cb 100644 --- a/cmdline/unix.c +++ b/cmdline/unix.c @@ -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; }