Stop fdsan complains

This commit is contained in:
topjohnwu 2019-04-29 20:04:39 -04:00
parent 70a3c78ebb
commit a2fa8d8be1

View File

@ -498,20 +498,20 @@ void unlock_blocks() {
struct dirent *entry; struct dirent *entry;
int fd, dev, OFF = 0; int fd, dev, OFF = 0;
if ((dev = xopen("/dev/block", O_RDONLY | O_CLOEXEC)) < 0) if (!(dir = xopendir("/dev/block")))
return; return;
dir = xfdopendir(dev); dev = dirfd(dir);
while((entry = readdir(dir))) { while((entry = readdir(dir))) {
if (entry->d_type == DT_BLK) { if (entry->d_type == DT_BLK) {
if ((fd = openat(dev, entry->d_name, O_RDONLY)) < 0) if ((fd = openat(dev, entry->d_name, O_RDONLY | O_CLOEXEC)) < 0)
continue; continue;
if (ioctl(fd, BLKROSET, &OFF) == -1) if (ioctl(fd, BLKROSET, &OFF) < 0)
PLOGE("unlock %s", entry->d_name); PLOGE("unlock %s", entry->d_name);
close(fd); close(fd);
} }
} }
close(dev); closedir(dir);
} }
static bool log_dump = false; static bool log_dump = false;