summaryrefslogtreecommitdiff
path: root/init/builtins.cpp
diff options
context:
space:
mode:
authorTom Cherry <tomcherry@google.com>2017-05-04 18:17:33 -0700
committerTom Cherry <tomcherry@google.com>2017-05-05 14:37:12 -0700
commit2cbbe9f7a35efdc94e8e34ef92eb6f70a85887fe (patch)
tree215ecac00aa47fbac652e5e7bc99761176884b84 /init/builtins.cpp
parent517e1f17cfec2143d4d10a64b1496a550acf3ea2 (diff)
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
Diffstat (limited to 'init/builtins.cpp')
-rw-r--r--init/builtins.cpp33
1 files changed, 27 insertions, 6 deletions
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<std::string>& args) {
}
static int do_domainname(const std::vector<std::string>& 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<std::string>& args) {
@@ -174,7 +179,12 @@ 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]) ? 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<std::string>& args) {
@@ -651,15 +661,26 @@ static int do_verity_update_state(const std::vector<std::string>& args) {
}
static int do_write(const std::vector<std::string>& 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<std::string>& 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<std::string>& args) {