From 2cbbe9f7a35efdc94e8e34ef92eb6f70a85887fe Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Thu, 4 May 2017 18:17:33 -0700 Subject: init: do not log directly from read_file() and write_file() Their callers may be able to add more context, so use an error string to record the error. Bug: 38038887 Test: boot bullhead Test: Init unit tests Change-Id: I46690d1c66e00a4b15cadc6fd0d6b50e990388c3 --- init/builtins.cpp | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'init/builtins.cpp') diff --git a/init/builtins.cpp b/init/builtins.cpp index 848dfdbf9..27b72f96c 100644 --- a/init/builtins.cpp +++ b/init/builtins.cpp @@ -150,7 +150,12 @@ static int do_class_restart(const std::vector& args) { } static int do_domainname(const std::vector& args) { - return write_file("/proc/sys/kernel/domainname", args[1]) ? 0 : 1; + std::string err; + if (!WriteFile("/proc/sys/kernel/domainname", args[1], &err)) { + LOG(ERROR) << err; + return -1; + } + return 0; } static int do_enable(const std::vector& args) { @@ -174,7 +179,12 @@ static int do_export(const std::vector& args) { } static int do_hostname(const std::vector& args) { - return write_file("/proc/sys/kernel/hostname", args[1]) ? 0 : 1; + std::string err; + if (!WriteFile("/proc/sys/kernel/hostname", args[1], &err)) { + LOG(ERROR) << err; + return -1; + } + return 0; } static int do_ifup(const std::vector& args) { @@ -651,15 +661,26 @@ static int do_verity_update_state(const std::vector& args) { } static int do_write(const std::vector& args) { - return write_file(args[1], args[2]) ? 0 : 1; + std::string err; + if (!WriteFile(args[1], args[2], &err)) { + LOG(ERROR) << err; + return -1; + } + return 0; } static int do_copy(const std::vector& args) { std::string data; - if (read_file(args[1], &data)) { - return write_file(args[2], data) ? 0 : 1; + std::string err; + if (!ReadFile(args[1], &data, &err)) { + LOG(ERROR) << err; + return -1; + } + if (!WriteFile(args[2], data, &err)) { + LOG(ERROR) << err; + return -1; } - return 1; + return 0; } static int do_chown(const std::vector& args) { -- cgit v1.2.3