init: Make 'write_file' return bool to match 'read_file'.
The mismatch of return values makes reasoning about the correctness of CLs like https://android-review.googlesource.com/317923 quite hard. Bug: 33941660 Test: Init builds, HiKey boots. Change-Id: Ia4b8a9af420682997b154a594892740181980921
This commit is contained in:
parent
491c3871a0
commit
77f0e9fda8
|
@ -249,7 +249,7 @@ static int do_class_reset(const std::vector<std::string>& args) {
|
|||
}
|
||||
|
||||
static int do_domainname(const std::vector<std::string>& args) {
|
||||
return write_file("/proc/sys/kernel/domainname", args[1].c_str());
|
||||
return write_file("/proc/sys/kernel/domainname", args[1].c_str()) ? 0 : 1;
|
||||
}
|
||||
|
||||
static int do_enable(const std::vector<std::string>& args) {
|
||||
|
@ -277,7 +277,7 @@ static int do_export(const std::vector<std::string>& args) {
|
|||
}
|
||||
|
||||
static int do_hostname(const std::vector<std::string>& args) {
|
||||
return write_file("/proc/sys/kernel/hostname", args[1].c_str());
|
||||
return write_file("/proc/sys/kernel/hostname", args[1].c_str()) ? 0 : 1;
|
||||
}
|
||||
|
||||
static int do_ifup(const std::vector<std::string>& args) {
|
||||
|
@ -814,7 +814,7 @@ static int do_verity_update_state(const std::vector<std::string>& args) {
|
|||
static int do_write(const std::vector<std::string>& args) {
|
||||
const char* path = args[1].c_str();
|
||||
const char* value = args[2].c_str();
|
||||
return write_file(path, value);
|
||||
return write_file(path, value) ? 0 : 1;
|
||||
}
|
||||
|
||||
static int do_copy(const std::vector<std::string>& args) {
|
||||
|
|
|
@ -542,7 +542,7 @@ static void selinux_initialize(bool in_kernel_domain) {
|
|||
}
|
||||
}
|
||||
|
||||
if (write_file("/sys/fs/selinux/checkreqprot", "0") == -1) {
|
||||
if (!write_file("/sys/fs/selinux/checkreqprot", "0")) {
|
||||
security_failure();
|
||||
}
|
||||
|
||||
|
|
|
@ -185,18 +185,18 @@ bool read_file(const char* path, std::string* content) {
|
|||
return okay;
|
||||
}
|
||||
|
||||
int write_file(const char* path, const char* 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));
|
||||
if (fd == -1) {
|
||||
PLOG(ERROR) << "write_file: Unable to open '" << path << "'";
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
int result = android::base::WriteStringToFd(content, fd) ? 0 : -1;
|
||||
if (result == -1) {
|
||||
bool success = android::base::WriteStringToFd(content, fd);
|
||||
if (!success) {
|
||||
PLOG(ERROR) << "write_file: Unable to write to '" << path << "'";
|
||||
}
|
||||
close(fd);
|
||||
return result;
|
||||
return success;
|
||||
}
|
||||
|
||||
boot_clock::time_point boot_clock::now() {
|
||||
|
|
|
@ -33,7 +33,7 @@ int create_socket(const char *name, int type, mode_t perm,
|
|||
uid_t uid, gid_t gid, const char *socketcon);
|
||||
|
||||
bool read_file(const char* path, std::string* content);
|
||||
int write_file(const char* path, const char* content);
|
||||
bool write_file(const char* path, const char* content);
|
||||
|
||||
// A std::chrono clock based on CLOCK_BOOTTIME.
|
||||
class boot_clock {
|
||||
|
|
Loading…
Reference in New Issue