29758d2 filefrag: exit with error code if an error is hit
introduced a couple errors; in one case it missed returning
a value, and possibly picked up errno from (unchecked) close(),
and in the other used a test where it needed an
assignment. So capture the error, move perror() directly
after the failed call in both cases, and fix the assignment.
Also fix a precedence problem with:
if (fe_flags & mask == 0)
which is equivalent to:
if (fe_flags & (mask == 0))
but we need:
if ((fe_flags & mask) == 0)
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
for (mask = 1; fe_flags != 0 && mask != 0; mask <<= 1) {
char hex[6];
- if (fe_flags & mask == 0)
+ if ((fe_flags & mask) == 0)
continue;
sprintf(hex, "%#04x,", mask);
print_flag(&fe_flags, mask, flags, hex);
#else
if (fstat(fd, &st) < 0) {
#endif
- close(fd);
rc = -errno;
perror("stat");
+ close(fd);
return rc;
}
if (last_device != st.st_dev) {
if (fstatfs(fd, &fsinfo) < 0) {
- close(fd);
+ rc = -errno;
perror("fstatfs");
- return;
+ close(fd);
+ return rc;
}
if (verbose)
printf("Filesystem type is: %lx\n",
int rc2 = frag_report(*cpp);
if (rc2 < 0 && rc == 0)
- rc == rc2;
+ rc = rc2;
}
return rc;