diff options
| author | Elliott Hughes <enh@google.com> | 2016-10-11 17:09:00 -0700 |
|---|---|---|
| committer | Elliott Hughes <enh@google.com> | 2016-10-13 15:34:05 -0700 |
| commit | e9355bf0ac6f8979a89c032ccbd7a72e59a8c56b (patch) | |
| tree | cbe9ba7c2169c4c59d5fe147a896af3343b45c0a /init/builtins.cpp | |
| parent | f827b6069fbfd0ea1839b29d88297956d6c6cba1 (diff) | |
Move off std::sto* function which abort on failure.
Bug: http://b/31403370
Test: builds, boots, libbase tests pass
Change-Id: I89cd7ca3d8f1c8a1bad0ddf3043439449d19a293
Diffstat (limited to 'init/builtins.cpp')
| -rw-r--r-- | init/builtins.cpp | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/init/builtins.cpp b/init/builtins.cpp index f4ba01822d..da4b84ea21 100644 --- a/init/builtins.cpp +++ b/init/builtins.cpp @@ -304,7 +304,7 @@ static int do_mkdir(const std::vector<std::string>& args) { /* mkdir <path> [mode] [owner] [group] */ if (args.size() >= 3) { - mode = std::stoul(args[2], 0, 8); + mode = std::strtoul(args[2].c_str(), 0, 8); } ret = make_dir(args[1].c_str(), mode); @@ -637,10 +637,13 @@ static int do_setprop(const std::vector<std::string>& args) { static int do_setrlimit(const std::vector<std::string>& args) { struct rlimit limit; int resource; - resource = std::stoi(args[1]); - limit.rlim_cur = std::stoi(args[2]); - limit.rlim_max = std::stoi(args[3]); - return setrlimit(resource, &limit); + if (android::base::ParseInt(args[1], &resource) && + android::base::ParseUint(args[2], &limit.rlim_cur) && + android::base::ParseUint(args[3], &limit.rlim_max)) { + return setrlimit(resource, &limit); + } + LOG(WARNING) << "ignoring setrlimit " << args[1] << " " << args[2] << " " << args[3]; + return -1; } static int do_start(const std::vector<std::string>& args) { @@ -709,7 +712,7 @@ static int do_powerctl(const std::vector<std::string>& args) { std::string timeout = property_get("ro.build.shutdown_timeout"); unsigned int delay = 0; - if (android::base::ParseUint(timeout.c_str(), &delay) && delay > 0) { + if (android::base::ParseUint(timeout, &delay) && delay > 0) { Timer t; // Ask all services to terminate. ServiceManager::GetInstance().ForEachService( @@ -764,13 +767,11 @@ static int do_rmdir(const std::vector<std::string>& args) { } static int do_sysclktz(const std::vector<std::string>& args) { - struct timezone tz; - - memset(&tz, 0, sizeof(tz)); - tz.tz_minuteswest = std::stoi(args[1]); - if (settimeofday(NULL, &tz)) - return -1; - return 0; + struct timezone tz = {}; + if (android::base::ParseInt(args[1], &tz.tz_minuteswest) && settimeofday(NULL, &tz) != -1) { + return 0; + } + return -1; } static int do_verity_load_state(const std::vector<std::string>& args) { @@ -914,7 +915,8 @@ static int do_restorecon_recursive(const std::vector<std::string>& args) { static int do_loglevel(const std::vector<std::string>& args) { // TODO: support names instead/as well? - int log_level = std::stoi(args[1]); + int log_level = -1; + android::base::ParseInt(args[1], &log_level); android::base::LogSeverity severity; switch (log_level) { case 7: severity = android::base::DEBUG; break; @@ -947,9 +949,12 @@ static int do_wait(const std::vector<std::string>& args) { if (args.size() == 2) { return wait_for_file(args[1].c_str(), COMMAND_RETRY_TIMEOUT); } else if (args.size() == 3) { - return wait_for_file(args[1].c_str(), std::stoi(args[2])); - } else - return -1; + int timeout; + if (android::base::ParseInt(args[2], &timeout)) { + return wait_for_file(args[1].c_str(), timeout); + } + } + return -1; } /* |
