diff options
author | Tom Cherry <tomcherry@google.com> | 2017-05-08 16:21:15 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2017-05-08 16:21:15 +0000 |
commit | 756ee8ded900b1ebda173e5348999d17076ebdfc (patch) | |
tree | 6cb379aa2336033a1dffa29f4809453c47899528 /init/builtins.cpp | |
parent | 18e92c342ac84344a10a975d83bfcffc2e164f9b (diff) | |
parent | 3f9ba91d8ff31fb23f00c0ed695feb2310ba20be (diff) |
Merge changes I46690d1c,I84c11aa5 am: 0dda322d4a am: 18b23afa4b
am: 3f9ba91d8f
Change-Id: Ied40226f25303091aad079cf4e8ea1f9ca0379a7
Diffstat (limited to 'init/builtins.cpp')
-rw-r--r-- | init/builtins.cpp | 72 |
1 files changed, 55 insertions, 17 deletions
diff --git a/init/builtins.cpp b/init/builtins.cpp index 3dadfd7dc..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) { @@ -215,11 +225,19 @@ static int do_mkdir(const std::vector<std::string>& args) { } if (args.size() >= 4) { - uid_t uid = decode_uid(args[3].c_str()); + uid_t uid; + std::string decode_uid_err; + if (!DecodeUid(args[3], &uid, &decode_uid_err)) { + LOG(ERROR) << "Unable to find UID for '" << args[3] << "': " << decode_uid_err; + return -1; + } gid_t gid = -1; if (args.size() == 5) { - gid = decode_uid(args[4].c_str()); + if (!DecodeUid(args[4], &gid, &decode_uid_err)) { + LOG(ERROR) << "Unable to find GID for '" << args[3] << "': " << decode_uid_err; + return -1; + } } if (lchown(args[1].c_str(), uid, gid) == -1) { @@ -643,29 +661,49 @@ 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) { - /* GID is optional. */ - if (args.size() == 3) { - if (lchown(args[2].c_str(), decode_uid(args[1].c_str()), -1) == -1) - return -errno; - } else if (args.size() == 4) { - if (lchown(args[3].c_str(), decode_uid(args[1].c_str()), - decode_uid(args[2].c_str())) == -1) - return -errno; - } else { + uid_t uid; + std::string decode_uid_err; + if (!DecodeUid(args[1], &uid, &decode_uid_err)) { + LOG(ERROR) << "Unable to find UID for '" << args[1] << "': " << decode_uid_err; return -1; } + + // GID is optional and pushes the index of path out by one if specified. + const std::string& path = (args.size() == 4) ? args[3] : args[2]; + gid_t gid = -1; + + if (args.size() == 4) { + if (!DecodeUid(args[2], &gid, &decode_uid_err)) { + LOG(ERROR) << "Unable to find GID for '" << args[2] << "': " << decode_uid_err; + return -1; + } + } + + if (lchown(path.c_str(), uid, gid) == -1) return -errno; + return 0; } |