Merge "init: cleanup some string usage"
am: 84c2eebbdd
Change-Id: Ic42cb28916c0e8d03db302985f66cb02a801af97
This commit is contained in:
commit
77382acf42
8 changed files with 27 additions and 40 deletions
|
@ -18,13 +18,11 @@
|
|||
|
||||
#include <android-base/logging.h>
|
||||
#include <android-base/properties.h>
|
||||
#include <android-base/stringprintf.h>
|
||||
#include <android-base/strings.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
using android::base::Join;
|
||||
using android::base::StringPrintf;
|
||||
|
||||
Command::Command(BuiltinFunction f, const std::vector<std::string>& args, int line)
|
||||
: func_(f), args_(args), line_(line) {}
|
||||
|
@ -98,10 +96,10 @@ void Action::ExecuteCommand(const Command& command) const {
|
|||
android::base::GetMinimumLogSeverity() <= android::base::DEBUG) {
|
||||
std::string trigger_name = BuildTriggersString();
|
||||
std::string cmd_str = command.BuildCommandString();
|
||||
std::string source = StringPrintf(" (%s:%d)", filename_.c_str(), command.line());
|
||||
|
||||
LOG(INFO) << "Command '" << cmd_str << "' action=" << trigger_name << source
|
||||
<< " returned " << result << " took " << duration_ms << "ms.";
|
||||
LOG(INFO) << "Command '" << cmd_str << "' action=" << trigger_name << " (" << filename_
|
||||
<< ":" << command.line() << ") returned " << result << " took " << duration_ms
|
||||
<< "ms.";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,6 @@
|
|||
#include <android-base/logging.h>
|
||||
#include <android-base/parseint.h>
|
||||
#include <android-base/properties.h>
|
||||
#include <android-base/stringprintf.h>
|
||||
#include <android-base/strings.h>
|
||||
#include <bootloader_message/bootloader_message.h>
|
||||
#include <cutils/android_reboot.h>
|
||||
|
@ -535,11 +534,10 @@ static int do_mount_all(const std::vector<std::string>& args) {
|
|||
}
|
||||
}
|
||||
|
||||
std::string prop_name = android::base::StringPrintf("ro.boottime.init.mount_all.%s",
|
||||
prop_post_fix);
|
||||
std::string prop_name = "ro.boottime.init.mount_all."s + prop_post_fix;
|
||||
Timer t;
|
||||
int ret = mount_fstab(fstabfile, mount_mode);
|
||||
property_set(prop_name.c_str(), std::to_string(t.duration_ms()).c_str());
|
||||
property_set(prop_name, std::to_string(t.duration_ms()));
|
||||
|
||||
if (import_rc) {
|
||||
/* Paths of .rc files are specified at the 2nd argument and beyond */
|
||||
|
@ -567,9 +565,7 @@ static int do_swapon_all(const std::vector<std::string>& args) {
|
|||
}
|
||||
|
||||
static int do_setprop(const std::vector<std::string>& args) {
|
||||
const char* name = args[1].c_str();
|
||||
const char* value = args[2].c_str();
|
||||
property_set(name, value);
|
||||
property_set(args[1], args[2]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -652,8 +648,7 @@ static int do_verity_load_state(const std::vector<std::string>& args) {
|
|||
|
||||
static void verity_update_property(fstab_rec *fstab, const char *mount_point,
|
||||
int mode, int status) {
|
||||
property_set(android::base::StringPrintf("partition.%s.verified", mount_point).c_str(),
|
||||
android::base::StringPrintf("%d", mode).c_str());
|
||||
property_set("partition."s + mount_point + ".verified", std::to_string(mode));
|
||||
}
|
||||
|
||||
static int do_verity_update_state(const std::vector<std::string>& args) {
|
||||
|
|
|
@ -58,7 +58,7 @@ void DescriptorInfo::CreateAndPublish(const std::string& globalContext) const {
|
|||
std::for_each(publishedName.begin(), publishedName.end(),
|
||||
[] (char& c) { c = isalnum(c) ? c : '_'; });
|
||||
|
||||
std::string val = android::base::StringPrintf("%d", fd);
|
||||
std::string val = std::to_string(fd);
|
||||
add_environment(publishedName.c_str(), val.c_str());
|
||||
|
||||
// make sure we don't close on exec
|
||||
|
@ -74,7 +74,8 @@ SocketInfo::SocketInfo(const std::string& name, const std::string& type, uid_t u
|
|||
}
|
||||
|
||||
void SocketInfo::Clean() const {
|
||||
unlink(android::base::StringPrintf(ANDROID_SOCKET_DIR "/%s", name().c_str()).c_str());
|
||||
std::string path = android::base::StringPrintf("%s/%s", ANDROID_SOCKET_DIR, name().c_str());
|
||||
unlink(path.c_str());
|
||||
}
|
||||
|
||||
int SocketInfo::Create(const std::string& context) const {
|
||||
|
|
|
@ -42,7 +42,6 @@
|
|||
#include <android-base/file.h>
|
||||
#include <android-base/logging.h>
|
||||
#include <android-base/properties.h>
|
||||
#include <android-base/stringprintf.h>
|
||||
#include <android-base/strings.h>
|
||||
#include <android-base/unique_fd.h>
|
||||
#include <keyutils.h>
|
||||
|
@ -71,9 +70,10 @@
|
|||
#include "util.h"
|
||||
#include "watchdogd.h"
|
||||
|
||||
using namespace std::string_literals;
|
||||
|
||||
using android::base::boot_clock;
|
||||
using android::base::GetProperty;
|
||||
using android::base::StringPrintf;
|
||||
|
||||
struct selabel_handle *sehandle;
|
||||
struct selabel_handle *sehandle_prop;
|
||||
|
@ -219,7 +219,7 @@ static int wait_for_coldboot_done_action(const std::vector<std::string>& args) {
|
|||
panic();
|
||||
}
|
||||
|
||||
property_set("ro.boottime.init.cold_boot_wait", std::to_string(t.duration_ms()).c_str());
|
||||
property_set("ro.boottime.init.cold_boot_wait", std::to_string(t.duration_ms()));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -449,14 +449,14 @@ static void import_kernel_nv(const std::string& key, const std::string& value, b
|
|||
|
||||
if (for_emulator) {
|
||||
// In the emulator, export any kernel option with the "ro.kernel." prefix.
|
||||
property_set(StringPrintf("ro.kernel.%s", key.c_str()).c_str(), value.c_str());
|
||||
property_set("ro.kernel." + key, value);
|
||||
return;
|
||||
}
|
||||
|
||||
if (key == "qemu") {
|
||||
strlcpy(qemu, value.c_str(), sizeof(qemu));
|
||||
} else if (android::base::StartsWith(key, "androidboot.")) {
|
||||
property_set(StringPrintf("ro.boot.%s", key.c_str() + 12).c_str(), value.c_str());
|
||||
property_set("ro.boot." + key.substr(12), value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -487,7 +487,7 @@ static void export_kernel_boot_props() {
|
|||
};
|
||||
for (size_t i = 0; i < arraysize(prop_map); i++) {
|
||||
std::string value = GetProperty(prop_map[i].src_prop, "");
|
||||
property_set(prop_map[i].dst_prop, (!value.empty()) ? value.c_str() : prop_map[i].default_value);
|
||||
property_set(prop_map[i].dst_prop, (!value.empty()) ? value : prop_map[i].default_value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -511,8 +511,7 @@ static void process_kernel_dt() {
|
|||
android::base::ReadFileToString(file_name, &dt_file);
|
||||
std::replace(dt_file.begin(), dt_file.end(), ',', '.');
|
||||
|
||||
std::string property_name = StringPrintf("ro.boot.%s", dp->d_name);
|
||||
property_set(property_name.c_str(), dt_file.c_str());
|
||||
property_set("ro.boot."s + dp->d_name, dt_file);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1002,7 +1001,7 @@ int main(int argc, char** argv) {
|
|||
|
||||
static constexpr uint32_t kNanosecondsPerMillisecond = 1e6;
|
||||
uint64_t start_ms = start_time.time_since_epoch().count() / kNanosecondsPerMillisecond;
|
||||
setenv("INIT_STARTED_AT", StringPrintf("%" PRIu64, start_ms).c_str(), 1);
|
||||
setenv("INIT_STARTED_AT", std::to_string(start_ms).c_str(), 1);
|
||||
|
||||
char* path = argv[0];
|
||||
char* args[] = { path, nullptr };
|
||||
|
|
|
@ -45,7 +45,6 @@
|
|||
#include <android-base/file.h>
|
||||
#include <android-base/logging.h>
|
||||
#include <android-base/properties.h>
|
||||
#include <android-base/stringprintf.h>
|
||||
#include <android-base/strings.h>
|
||||
#include <bootimg.h>
|
||||
#include <fs_mgr.h>
|
||||
|
@ -56,8 +55,6 @@
|
|||
#include "init.h"
|
||||
#include "util.h"
|
||||
|
||||
using android::base::StringPrintf;
|
||||
|
||||
#define PERSISTENT_PROPERTY_DIR "/data/property"
|
||||
#define RECOVERY_MOUNT_POINT "/recovery"
|
||||
|
||||
|
@ -714,7 +711,7 @@ void load_recovery_id_prop() {
|
|||
boot_img_hdr hdr;
|
||||
if (android::base::ReadFully(fd, &hdr, sizeof(hdr))) {
|
||||
std::string hex = bytes_to_hex(reinterpret_cast<uint8_t*>(hdr.id), sizeof(hdr.id));
|
||||
property_set("ro.recovery_id", hex.c_str());
|
||||
property_set("ro.recovery_id", hex);
|
||||
} else {
|
||||
PLOG(ERROR) << "error reading /recovery";
|
||||
}
|
||||
|
|
|
@ -198,13 +198,12 @@ void Service::NotifyStateChange(const std::string& new_state) const {
|
|||
return;
|
||||
}
|
||||
|
||||
std::string prop_name = StringPrintf("init.svc.%s", name_.c_str());
|
||||
property_set(prop_name.c_str(), new_state.c_str());
|
||||
std::string prop_name = "init.svc." + name_;
|
||||
property_set(prop_name, new_state);
|
||||
|
||||
if (new_state == "running") {
|
||||
uint64_t start_ns = time_started_.time_since_epoch().count();
|
||||
property_set(StringPrintf("ro.boottime.%s", name_.c_str()).c_str(),
|
||||
StringPrintf("%" PRIu64, start_ns).c_str());
|
||||
property_set("ro.boottime." + name_, std::to_string(start_ns));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -716,7 +715,7 @@ bool Service::Start() {
|
|||
StringPrintf("/dev/cpuset%stasks", default_cpuset.c_str()));
|
||||
}
|
||||
}
|
||||
std::string pid_str = StringPrintf("%d", getpid());
|
||||
std::string pid_str = std::to_string(getpid());
|
||||
for (const auto& file : writepid_files_) {
|
||||
if (!WriteStringToFile(pid_str, file)) {
|
||||
PLOG(ERROR) << "couldn't write " << pid_str << " to " << file;
|
||||
|
@ -757,7 +756,7 @@ bool Service::Start() {
|
|||
}
|
||||
|
||||
if (oom_score_adjust_ != -1000) {
|
||||
std::string oom_str = StringPrintf("%d", oom_score_adjust_);
|
||||
std::string oom_str = std::to_string(oom_score_adjust_);
|
||||
std::string oom_file = StringPrintf("/proc/%d/oom_score_adj", pid);
|
||||
if (!WriteStringToFile(oom_str, oom_file)) {
|
||||
PLOG(ERROR) << "couldn't write oom_score_adj: " << strerror(errno);
|
||||
|
@ -776,9 +775,9 @@ bool Service::Start() {
|
|||
}
|
||||
|
||||
if ((flags_ & SVC_EXEC) != 0) {
|
||||
LOG(INFO) << android::base::StringPrintf(
|
||||
"SVC_EXEC pid %d (uid %d gid %d+%zu context %s) started; waiting...", pid_, uid_, gid_,
|
||||
supp_gids_.size(), !seclabel_.empty() ? seclabel_.c_str() : "default");
|
||||
LOG(INFO) << "SVC_EXEC pid " << pid_ << " (uid " << uid_ << " gid " << gid_ << "+"
|
||||
<< supp_gids_.size() << " context "
|
||||
<< (!seclabel_.empty() ? seclabel_ : "default") << ") started; waiting...";
|
||||
}
|
||||
|
||||
NotifyStateChange("running");
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#include <android-base/logging.h>
|
||||
#include <android-base/stringprintf.h>
|
||||
|
||||
#include "init.h"
|
||||
#include "service.h"
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
|
||||
#include <android-base/logging.h>
|
||||
#include <android-base/properties.h>
|
||||
#include <android-base/stringprintf.h>
|
||||
#include <selinux/android.h>
|
||||
#include <selinux/selinux.h>
|
||||
|
||||
|
|
Loading…
Reference in a new issue