Merge "init: Fix leaking fd and error print"

am: e87a826a1d

Change-Id: Ie807fa6321b0d0313221711999fb01897c192419
This commit is contained in:
Tom Cherry 2017-03-21 20:23:47 +00:00 committed by android-build-merger
commit ff6eb509aa
1 changed files with 5 additions and 7 deletions

View File

@ -163,7 +163,7 @@ out_unlink:
bool read_file(const char* path, std::string* content) {
content->clear();
int fd = TEMP_FAILURE_RETRY(open(path, O_RDONLY|O_NOFOLLOW|O_CLOEXEC));
android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(path, O_RDONLY | O_NOFOLLOW | O_CLOEXEC)));
if (fd == -1) {
return false;
}
@ -176,17 +176,16 @@ bool read_file(const char* path, std::string* content) {
return false;
}
if ((sb.st_mode & (S_IWGRP | S_IWOTH)) != 0) {
PLOG(ERROR) << "skipping insecure file '" << path << "'";
LOG(ERROR) << "skipping insecure file '" << path << "'";
return false;
}
bool okay = android::base::ReadFdToString(fd, content);
close(fd);
return okay;
return android::base::ReadFdToString(fd, content);
}
bool write_file(const char* path, const char* content) {
int fd = TEMP_FAILURE_RETRY(open(path, O_WRONLY|O_CREAT|O_NOFOLLOW|O_CLOEXEC, 0600));
android::base::unique_fd fd(
TEMP_FAILURE_RETRY(open(path, O_WRONLY | O_CREAT | O_NOFOLLOW | O_CLOEXEC, 0600)));
if (fd == -1) {
PLOG(ERROR) << "write_file: Unable to open '" << path << "'";
return false;
@ -195,7 +194,6 @@ bool write_file(const char* path, const char* content) {
if (!success) {
PLOG(ERROR) << "write_file: Unable to write to '" << path << "'";
}
close(fd);
return success;
}