summaryrefslogtreecommitdiffstats
path: root/Query.c
diff options
context:
space:
mode:
authorJes Sorensen <jsorensen@fb.com>2017-04-13 17:53:21 +0200
committerJes Sorensen <jsorensen@fb.com>2017-04-13 17:53:21 +0200
commit8d0cd09d73a9a9d57ee73b7a79114e881dad1507 (patch)
treed3da840ec73c8036558ab60f4d7bd9e42049549d /Query.c
parentDetail: Fixup ugly if () foo() abuse (diff)
downloadmdadm-8d0cd09d73a9a9d57ee73b7a79114e881dad1507.tar.xz
mdadm-8d0cd09d73a9a9d57ee73b7a79114e881dad1507.zip
Query: Handle error returned by fstat()
We shouldn't ignore any error returned by fstat() even if open() didn't fail. Signed-off-by: Jes Sorensen <jsorensen@fb.com>
Diffstat (limited to 'Query.c')
-rw-r--r--Query.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/Query.c b/Query.c
index bea273fe..0d18da4e 100644
--- a/Query.c
+++ b/Query.c
@@ -32,22 +32,21 @@ int Query(char *dev)
* whether it is an md device and whether it has
* a superblock
*/
- int fd = open(dev, O_RDONLY);
- int ioctlerr;
+ int fd;
+ int ioctlerr, staterr;
int superror;
struct mdinfo info;
mdu_array_info_t array;
struct supertype *st = NULL;
-
unsigned long long larray_size;
struct stat stb;
char *mddev;
mdu_disk_info_t disc;
char *activity;
+ fd = open(dev, O_RDONLY);
if (fd < 0){
- pr_err("cannot open %s: %s\n",
- dev, strerror(errno));
+ pr_err("cannot open %s: %s\n", dev, strerror(errno));
return 1;
}
@@ -56,9 +55,12 @@ int Query(char *dev)
else
ioctlerr = 0;
- fstat(fd, &stb);
+ if (fstat(fd, &stb) < 0)
+ staterr = errno;
+ else
+ staterr = 0;
- if (!ioctlerr) {
+ if (!ioctlerr && !staterr) {
if (!get_dev_size(fd, NULL, &larray_size))
larray_size = 0;
}
@@ -68,6 +70,9 @@ int Query(char *dev)
else if (ioctlerr)
printf("%s: is an md device, but gives \"%s\" when queried\n",
dev, strerror(ioctlerr));
+ else if (staterr)
+ printf("%s: is not a valid md device, returning %s\n",
+ dev, strerror(ioctlerr));
else {
printf("%s: %s %s %d devices, %d spare%s. Use mdadm --detail for more detail.\n",
dev,