diff options
Diffstat (limited to 'init/init.cpp')
-rw-r--r-- | init/init.cpp | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/init/init.cpp b/init/init.cpp index 9652efafd..55d5fa826 100644 --- a/init/init.cpp +++ b/init/init.cpp | |||
@@ -42,14 +42,12 @@ | |||
42 | #include <android-base/file.h> | 42 | #include <android-base/file.h> |
43 | #include <android-base/logging.h> | 43 | #include <android-base/logging.h> |
44 | #include <android-base/properties.h> | 44 | #include <android-base/properties.h> |
45 | #include <android-base/stringprintf.h> | ||
46 | #include <android-base/strings.h> | 45 | #include <android-base/strings.h> |
47 | #include <android-base/unique_fd.h> | 46 | #include <android-base/unique_fd.h> |
48 | #include <keyutils.h> | 47 | #include <keyutils.h> |
49 | #include <libavb/libavb.h> | 48 | #include <libavb/libavb.h> |
50 | #include <private/android_filesystem_config.h> | 49 | #include <private/android_filesystem_config.h> |
51 | #include <selinux/android.h> | 50 | #include <selinux/android.h> |
52 | #include <selinux/label.h> | ||
53 | #include <selinux/selinux.h> | 51 | #include <selinux/selinux.h> |
54 | 52 | ||
55 | #include <fstream> | 53 | #include <fstream> |
@@ -71,9 +69,14 @@ | |||
71 | #include "util.h" | 69 | #include "util.h" |
72 | #include "watchdogd.h" | 70 | #include "watchdogd.h" |
73 | 71 | ||
72 | using namespace std::string_literals; | ||
73 | |||
74 | using android::base::boot_clock; | 74 | using android::base::boot_clock; |
75 | using android::base::GetProperty; | 75 | using android::base::GetProperty; |
76 | using android::base::StringPrintf; | 76 | using android::base::Timer; |
77 | |||
78 | namespace android { | ||
79 | namespace init { | ||
77 | 80 | ||
78 | struct selabel_handle *sehandle; | 81 | struct selabel_handle *sehandle; |
79 | struct selabel_handle *sehandle_prop; | 82 | struct selabel_handle *sehandle_prop; |
@@ -230,7 +233,7 @@ static int wait_for_coldboot_done_action(const std::vector<std::string>& args) { | |||
230 | panic(); | 233 | panic(); |
231 | } | 234 | } |
232 | 235 | ||
233 | property_set("ro.boottime.init.cold_boot_wait", std::to_string(t.duration_ms()).c_str()); | 236 | property_set("ro.boottime.init.cold_boot_wait", std::to_string(t.duration().count())); |
234 | return 0; | 237 | return 0; |
235 | } | 238 | } |
236 | 239 | ||
@@ -388,7 +391,10 @@ static int set_mmap_rnd_bits_action(const std::vector<std::string>& args) | |||
388 | int ret = -1; | 391 | int ret = -1; |
389 | 392 | ||
390 | /* values are arch-dependent */ | 393 | /* values are arch-dependent */ |
391 | #if defined(__aarch64__) | 394 | #if defined(USER_MODE_LINUX) |
395 | /* uml does not support mmap_rnd_bits */ | ||
396 | ret = 0; | ||
397 | #elif defined(__aarch64__) | ||
392 | /* arm64 supports 18 - 33 bits depending on pagesize and VA_SIZE */ | 398 | /* arm64 supports 18 - 33 bits depending on pagesize and VA_SIZE */ |
393 | if (set_mmap_rnd_bits_min(33, 24, false) | 399 | if (set_mmap_rnd_bits_min(33, 24, false) |
394 | && set_mmap_rnd_bits_min(16, 16, true)) { | 400 | && set_mmap_rnd_bits_min(16, 16, true)) { |
@@ -460,14 +466,14 @@ static void import_kernel_nv(const std::string& key, const std::string& value, b | |||
460 | 466 | ||
461 | if (for_emulator) { | 467 | if (for_emulator) { |
462 | // In the emulator, export any kernel option with the "ro.kernel." prefix. | 468 | // In the emulator, export any kernel option with the "ro.kernel." prefix. |
463 | property_set(StringPrintf("ro.kernel.%s", key.c_str()).c_str(), value.c_str()); | 469 | property_set("ro.kernel." + key, value); |
464 | return; | 470 | return; |
465 | } | 471 | } |
466 | 472 | ||
467 | if (key == "qemu") { | 473 | if (key == "qemu") { |
468 | strlcpy(qemu, value.c_str(), sizeof(qemu)); | 474 | strlcpy(qemu, value.c_str(), sizeof(qemu)); |
469 | } else if (android::base::StartsWith(key, "androidboot.")) { | 475 | } else if (android::base::StartsWith(key, "androidboot.")) { |
470 | property_set(StringPrintf("ro.boot.%s", key.c_str() + 12).c_str(), value.c_str()); | 476 | property_set("ro.boot." + key.substr(12), value); |
471 | } | 477 | } |
472 | } | 478 | } |
473 | 479 | ||
@@ -498,7 +504,7 @@ static void export_kernel_boot_props() { | |||
498 | }; | 504 | }; |
499 | for (size_t i = 0; i < arraysize(prop_map); i++) { | 505 | for (size_t i = 0; i < arraysize(prop_map); i++) { |
500 | std::string value = GetProperty(prop_map[i].src_prop, ""); | 506 | std::string value = GetProperty(prop_map[i].src_prop, ""); |
501 | property_set(prop_map[i].dst_prop, (!value.empty()) ? value.c_str() : prop_map[i].default_value); | 507 | property_set(prop_map[i].dst_prop, (!value.empty()) ? value : prop_map[i].default_value); |
502 | } | 508 | } |
503 | } | 509 | } |
504 | 510 | ||
@@ -522,8 +528,7 @@ static void process_kernel_dt() { | |||
522 | android::base::ReadFileToString(file_name, &dt_file); | 528 | android::base::ReadFileToString(file_name, &dt_file); |
523 | std::replace(dt_file.begin(), dt_file.end(), ',', '.'); | 529 | std::replace(dt_file.begin(), dt_file.end(), ',', '.'); |
524 | 530 | ||
525 | std::string property_name = StringPrintf("ro.boot.%s", dp->d_name); | 531 | property_set("ro.boot."s + dp->d_name, dt_file); |
526 | property_set(property_name.c_str(), dt_file.c_str()); | ||
527 | } | 532 | } |
528 | } | 533 | } |
529 | 534 | ||
@@ -887,7 +892,7 @@ static void selinux_initialize(bool in_kernel_domain) { | |||
887 | } | 892 | } |
888 | 893 | ||
889 | // init's first stage can't set properties, so pass the time to the second stage. | 894 | // init's first stage can't set properties, so pass the time to the second stage. |
890 | setenv("INIT_SELINUX_TOOK", std::to_string(t.duration_ms()).c_str(), 1); | 895 | setenv("INIT_SELINUX_TOOK", std::to_string(t.duration().count()).c_str(), 1); |
891 | } else { | 896 | } else { |
892 | selinux_init_all_handles(); | 897 | selinux_init_all_handles(); |
893 | } | 898 | } |
@@ -905,7 +910,6 @@ static void selinux_restore_context() { | |||
905 | selinux_android_restorecon("/dev/urandom", 0); | 910 | selinux_android_restorecon("/dev/urandom", 0); |
906 | selinux_android_restorecon("/dev/__properties__", 0); | 911 | selinux_android_restorecon("/dev/__properties__", 0); |
907 | 912 | ||
908 | selinux_android_restorecon("/file_contexts.bin", 0); | ||
909 | selinux_android_restorecon("/plat_file_contexts", 0); | 913 | selinux_android_restorecon("/plat_file_contexts", 0); |
910 | selinux_android_restorecon("/nonplat_file_contexts", 0); | 914 | selinux_android_restorecon("/nonplat_file_contexts", 0); |
911 | selinux_android_restorecon("/plat_property_contexts", 0); | 915 | selinux_android_restorecon("/plat_property_contexts", 0); |
@@ -919,7 +923,6 @@ static void selinux_restore_context() { | |||
919 | selinux_android_restorecon("/sepolicy", 0); | 923 | selinux_android_restorecon("/sepolicy", 0); |
920 | selinux_android_restorecon("/vndservice_contexts", 0); | 924 | selinux_android_restorecon("/vndservice_contexts", 0); |
921 | 925 | ||
922 | selinux_android_restorecon("/sys", SELINUX_ANDROID_RESTORECON_RECURSE); | ||
923 | selinux_android_restorecon("/dev/block", SELINUX_ANDROID_RESTORECON_RECURSE); | 926 | selinux_android_restorecon("/dev/block", SELINUX_ANDROID_RESTORECON_RECURSE); |
924 | selinux_android_restorecon("/dev/device-mapper", 0); | 927 | selinux_android_restorecon("/dev/device-mapper", 0); |
925 | 928 | ||
@@ -1036,7 +1039,7 @@ int main(int argc, char** argv) { | |||
1036 | 1039 | ||
1037 | static constexpr uint32_t kNanosecondsPerMillisecond = 1e6; | 1040 | static constexpr uint32_t kNanosecondsPerMillisecond = 1e6; |
1038 | uint64_t start_ms = start_time.time_since_epoch().count() / kNanosecondsPerMillisecond; | 1041 | uint64_t start_ms = start_time.time_since_epoch().count() / kNanosecondsPerMillisecond; |
1039 | setenv("INIT_STARTED_AT", StringPrintf("%" PRIu64, start_ms).c_str(), 1); | 1042 | setenv("INIT_STARTED_AT", std::to_string(start_ms).c_str(), 1); |
1040 | 1043 | ||
1041 | char* path = argv[0]; | 1044 | char* path = argv[0]; |
1042 | char* args[] = { path, nullptr }; | 1045 | char* args[] = { path, nullptr }; |
@@ -1191,3 +1194,10 @@ int main(int argc, char** argv) { | |||
1191 | 1194 | ||
1192 | return 0; | 1195 | return 0; |
1193 | } | 1196 | } |
1197 | |||
1198 | } // namespace init | ||
1199 | } // namespace android | ||
1200 | |||
1201 | int main(int argc, char** argv) { | ||
1202 | android::init::main(argc, argv); | ||
1203 | } | ||