Merge "init: add a copy_per_line built-in command"
diff --git a/fs_mgr/libsnapshot/android/snapshot/snapshot.proto b/fs_mgr/libsnapshot/android/snapshot/snapshot.proto
index 0328132..acb75d0 100644
--- a/fs_mgr/libsnapshot/android/snapshot/snapshot.proto
+++ b/fs_mgr/libsnapshot/android/snapshot/snapshot.proto
@@ -34,7 +34,7 @@
MERGE_COMPLETED = 3;
}
-// Next: 9
+// Next: 10
message SnapshotStatus {
// Name of the snapshot. This is usually the name of the snapshotted
// logical partition; for example, "system_b".
@@ -84,6 +84,9 @@
// the merge process.
// This is non-zero when |state| == MERGING or MERGE_COMPLETED.
uint64 metadata_sectors = 8;
+
+ // True if compression is enabled, false otherwise.
+ bool compression_enabled = 9;
}
// Next: 8
diff --git a/fs_mgr/libsnapshot/snapshot.cpp b/fs_mgr/libsnapshot/snapshot.cpp
index 6595707..10c707a 100644
--- a/fs_mgr/libsnapshot/snapshot.cpp
+++ b/fs_mgr/libsnapshot/snapshot.cpp
@@ -280,7 +280,7 @@
return false;
}
- if (!IsCompressionEnabled() && !EnsureNoOverflowSnapshot(lock.get())) {
+ if (!EnsureNoOverflowSnapshot(lock.get())) {
LOG(ERROR) << "Cannot ensure there are no overflow snapshots.";
return false;
}
@@ -349,6 +349,7 @@
status->set_state(SnapshotState::CREATED);
status->set_sectors_allocated(0);
status->set_metadata_sectors(0);
+ status->set_compression_enabled(IsCompressionEnabled());
if (!WriteSnapshotStatus(lock, *status)) {
PLOG(ERROR) << "Could not write snapshot status: " << status->name();
@@ -1914,13 +1915,13 @@
remaining_time = GetRemainingTime(params.timeout_ms, begin);
if (remaining_time.count() < 0) return false;
- if (context == SnapshotContext::Update && IsCompressionEnabled()) {
+ if (context == SnapshotContext::Update && live_snapshot_status->compression_enabled()) {
// Stop here, we can't run dm-user yet, the COW isn't built.
created_devices.Release();
return true;
}
- if (IsCompressionEnabled()) {
+ if (live_snapshot_status->compression_enabled()) {
auto name = GetDmUserCowName(params.GetPartitionName());
// :TODO: need to force init to process uevents for these in first-stage.
@@ -2750,7 +2751,7 @@
return Return::Error();
}
- if (IsCompressionEnabled()) {
+ if (it->second.compression_enabled()) {
unique_fd fd(open(cow_path.c_str(), O_RDWR | O_CLOEXEC));
if (fd < 0) {
PLOG(ERROR) << "open " << cow_path << " failed for snapshot "
@@ -3169,6 +3170,14 @@
auto& dm = DeviceMapper::Instance();
for (const auto& snapshot : snapshots) {
+ SnapshotStatus status;
+ if (!ReadSnapshotStatus(lock, snapshot, &status)) {
+ return false;
+ }
+ if (status.compression_enabled()) {
+ continue;
+ }
+
std::vector<DeviceMapper::TargetInfo> targets;
if (!dm.GetTableStatus(snapshot, &targets)) {
LOG(ERROR) << "Could not read snapshot device table: " << snapshot;
diff --git a/fs_mgr/tools/dmuserd.cpp b/fs_mgr/tools/dmuserd.cpp
index 92f5878..e50a4a2 100644
--- a/fs_mgr/tools/dmuserd.cpp
+++ b/fs_mgr/tools/dmuserd.cpp
@@ -76,7 +76,7 @@
static bool verbose = false;
-size_t write_all(int fd, void* buf, size_t len) {
+ssize_t write_all(int fd, void* buf, size_t len) {
char* buf_c = (char*)buf;
ssize_t total = 0;
ssize_t once;
@@ -94,7 +94,7 @@
return total;
}
-size_t read_all(int fd, void* buf, size_t len) {
+ssize_t read_all(int fd, void* buf, size_t len) {
char* buf_c = (char*)buf;
ssize_t total = 0;
ssize_t once;
diff --git a/init/first_stage_init.cpp b/init/first_stage_init.cpp
index 91aaffd..83a32e7 100644
--- a/init/first_stage_init.cpp
+++ b/init/first_stage_init.cpp
@@ -117,7 +117,7 @@
auto dst_dir = android::base::Dirname(dst);
std::error_code ec;
- if (!fs::create_directories(dst_dir, ec)) {
+ if (!fs::create_directories(dst_dir, ec) && !!ec) {
LOG(FATAL) << "Cannot create " << dst_dir << ": " << ec.message();
}
if (rename(src, dst) != 0) {
@@ -315,7 +315,7 @@
std::string dest = GetRamdiskPropForSecondStage();
std::string dir = android::base::Dirname(dest);
std::error_code ec;
- if (!fs::create_directories(dir, ec)) {
+ if (!fs::create_directories(dir, ec) && !!ec) {
LOG(FATAL) << "Can't mkdir " << dir << ": " << ec.message();
}
if (!fs::copy_file(kBootImageRamdiskProp, dest, ec)) {
diff --git a/init/host_init_verifier.cpp b/init/host_init_verifier.cpp
index ef9a451..db127d3 100644
--- a/init/host_init_verifier.cpp
+++ b/init/host_init_verifier.cpp
@@ -25,6 +25,8 @@
#include <fstream>
#include <iostream>
#include <iterator>
+#include <map>
+#include <set>
#include <string>
#include <vector>
@@ -51,6 +53,7 @@
using namespace std::literals;
+using android::base::EndsWith;
using android::base::ParseInt;
using android::base::ReadFileToString;
using android::base::Split;
@@ -61,6 +64,10 @@
static std::vector<std::string> passwd_files;
+// NOTE: Keep this in sync with the order used by init.cpp LoadBootScripts()
+static const std::vector<std::string> partition_search_order =
+ std::vector<std::string>({"system", "system_ext", "odm", "vendor", "product"});
+
static std::vector<std::pair<std::string, int>> GetVendorPasswd(const std::string& passwd_file) {
std::string passwd;
if (!ReadFileToString(passwd_file, &passwd)) {
@@ -148,13 +155,24 @@
#include "generated_stub_builtin_function_map.h"
void PrintUsage() {
- std::cout << "usage: host_init_verifier [options] <init rc file>\n"
- "\n"
- "Tests an init script for correctness\n"
- "\n"
- "-p FILE\tSearch this passwd file for users and groups\n"
- "--property_contexts=FILE\t Use this file for property_contexts\n"
- << std::endl;
+ fprintf(stdout, R"(usage: host_init_verifier [options]
+
+Tests init script(s) for correctness.
+
+Generic options:
+ -p FILE Search this passwd file for users and groups.
+ --property_contexts=FILE Use this file for property_contexts.
+
+Single script mode options:
+ [init rc file] Positional argument; test this init script.
+
+Multiple script mode options:
+ --out_system=DIR Path to the output product directory for the system partition.
+ --out_system_ext=DIR Path to the output product directory for the system_ext partition.
+ --out_odm=DIR Path to the output product directory for the odm partition.
+ --out_vendor=DIR Path to the output product directory for the vendor partition.
+ --out_product=DIR Path to the output product directory for the product partition.
+)");
}
Result<InterfaceInheritanceHierarchyMap> ReadInterfaceInheritanceHierarchy() {
@@ -203,12 +221,18 @@
android::base::SetMinimumLogSeverity(android::base::ERROR);
auto property_infos = std::vector<PropertyInfoEntry>();
+ std::map<std::string, std::string> partition_map;
while (true) {
static const char kPropertyContexts[] = "property-contexts=";
static const struct option long_options[] = {
{"help", no_argument, nullptr, 'h'},
{kPropertyContexts, required_argument, nullptr, 0},
+ {"out_system", required_argument, nullptr, 0},
+ {"out_system_ext", required_argument, nullptr, 0},
+ {"out_odm", required_argument, nullptr, 0},
+ {"out_vendor", required_argument, nullptr, 0},
+ {"out_product", required_argument, nullptr, 0},
{nullptr, 0, nullptr, 0},
};
@@ -224,6 +248,16 @@
if (long_options[option_index].name == kPropertyContexts) {
HandlePropertyContexts(optarg, &property_infos);
}
+ for (const auto& p : partition_search_order) {
+ if (long_options[option_index].name == "out_" + p) {
+ if (partition_map.find(p) != partition_map.end()) {
+ PrintUsage();
+ return EXIT_FAILURE;
+ }
+ partition_map[p] =
+ EndsWith(optarg, "/") ? optarg : std::string(optarg) + "/";
+ }
+ }
break;
case 'h':
PrintUsage();
@@ -240,7 +274,9 @@
argc -= optind;
argv += optind;
- if (argc != 1) {
+ // If provided, use the partition map to check multiple init rc files.
+ // Otherwise, check a single init rc file.
+ if ((!partition_map.empty() && argc != 0) || (partition_map.empty() && argc != 1)) {
PrintUsage();
return EXIT_FAILURE;
}
@@ -262,24 +298,42 @@
property_info_area = reinterpret_cast<const PropertyInfoArea*>(serialized_contexts.c_str());
+ if (!partition_map.empty()) {
+ std::vector<std::string> vendor_prefixes;
+ for (const auto& partition : {"vendor", "odm"}) {
+ if (partition_map.find(partition) != partition_map.end()) {
+ vendor_prefixes.push_back(partition_map.at(partition));
+ }
+ }
+ InitializeHostSubcontext(vendor_prefixes);
+ }
+
const BuiltinFunctionMap& function_map = GetBuiltinFunctionMap();
Action::set_function_map(&function_map);
ActionManager& am = ActionManager::GetInstance();
ServiceList& sl = ServiceList::GetInstance();
Parser parser;
- parser.AddSectionParser("service", std::make_unique<ServiceParser>(
- &sl, nullptr, *interface_inheritance_hierarchy_map));
- parser.AddSectionParser("on", std::make_unique<ActionParser>(&am, nullptr));
+ parser.AddSectionParser("service",
+ std::make_unique<ServiceParser>(&sl, GetSubcontext(),
+ *interface_inheritance_hierarchy_map));
+ parser.AddSectionParser("on", std::make_unique<ActionParser>(&am, GetSubcontext()));
parser.AddSectionParser("import", std::make_unique<HostImportParser>());
- if (!parser.ParseConfigFileInsecure(*argv)) {
- LOG(ERROR) << "Failed to open init rc script '" << *argv << "'";
- return EXIT_FAILURE;
+ if (!partition_map.empty()) {
+ for (const auto& p : partition_search_order) {
+ if (partition_map.find(p) != partition_map.end()) {
+ parser.ParseConfig(partition_map.at(p) + "etc/init");
+ }
+ }
+ } else {
+ if (!parser.ParseConfigFileInsecure(*argv)) {
+ LOG(ERROR) << "Failed to open init rc script '" << *argv << "'";
+ return EXIT_FAILURE;
+ }
}
size_t failures = parser.parse_error_count() + am.CheckAllCommands() + sl.CheckAllCommands();
if (failures > 0) {
- LOG(ERROR) << "Failed to parse init script '" << *argv << "' with " << failures
- << " errors";
+ LOG(ERROR) << "Failed to parse init scripts with " << failures << " error(s).";
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
diff --git a/init/service.cpp b/init/service.cpp
index 7b98392..766eb5d 100644
--- a/init/service.cpp
+++ b/init/service.cpp
@@ -154,6 +154,7 @@
.priority = 0},
namespaces_{.flags = namespace_flags},
seclabel_(seclabel),
+ subcontext_(subcontext_for_restart_commands),
onrestart_(false, subcontext_for_restart_commands, "<Service '" + name + "' onrestart>", 0,
"onrestart", {}),
oom_score_adjust_(DEFAULT_OOM_SCORE_ADJUST),
diff --git a/init/service.h b/init/service.h
index bc5c90f..aee1e5d 100644
--- a/init/service.h
+++ b/init/service.h
@@ -137,6 +137,7 @@
flags_ &= ~SVC_ONESHOT;
}
}
+ Subcontext* subcontext() const { return subcontext_; }
private:
void NotifyStateChange(const std::string& new_state) const;
@@ -168,6 +169,7 @@
std::vector<FileDescriptor> files_;
std::vector<std::pair<std::string, std::string>> environment_vars_;
+ Subcontext* subcontext_;
Action onrestart_; // Commands to execute on restart.
std::vector<std::string> writepid_files_;
diff --git a/init/service_parser.cpp b/init/service_parser.cpp
index 97621da..57c311a 100644
--- a/init/service_parser.cpp
+++ b/init/service_parser.cpp
@@ -657,6 +657,14 @@
<< "' with a config in APEX";
}
+ std::string context = service_->subcontext() ? service_->subcontext()->context() : "";
+ std::string old_context =
+ old_service->subcontext() ? old_service->subcontext()->context() : "";
+ if (context != old_context) {
+ return Error() << "service '" << service_->name() << "' overrides another service "
+ << "across the treble boundary.";
+ }
+
service_list_->RemoveService(*old_service);
old_service = nullptr;
}
diff --git a/init/subcontext.cpp b/init/subcontext.cpp
index dc2455e..f1fbffe 100644
--- a/init/subcontext.cpp
+++ b/init/subcontext.cpp
@@ -342,6 +342,9 @@
new Subcontext(std::vector<std::string>{"/vendor", "/odm"}, kVendorContext));
}
}
+void InitializeHostSubcontext(std::vector<std::string> vendor_prefixes) {
+ subcontext.reset(new Subcontext(vendor_prefixes, kVendorContext, /*host=*/true));
+}
Subcontext* GetSubcontext() {
return subcontext.get();
diff --git a/init/subcontext.h b/init/subcontext.h
index 788d3be..cb4138e 100644
--- a/init/subcontext.h
+++ b/init/subcontext.h
@@ -36,9 +36,11 @@
class Subcontext {
public:
- Subcontext(std::vector<std::string> path_prefixes, std::string context)
+ Subcontext(std::vector<std::string> path_prefixes, std::string context, bool host = false)
: path_prefixes_(std::move(path_prefixes)), context_(std::move(context)), pid_(0) {
- Fork();
+ if (!host) {
+ Fork();
+ }
}
Result<void> Execute(const std::vector<std::string>& args);
@@ -61,6 +63,7 @@
int SubcontextMain(int argc, char** argv, const BuiltinFunctionMap* function_map);
void InitializeSubcontext();
+void InitializeHostSubcontext(std::vector<std::string> vendor_prefixes);
Subcontext* GetSubcontext();
bool SubcontextChildReap(pid_t pid);
void SubcontextTerminate();
diff --git a/libcutils/fs_config.cpp b/libcutils/fs_config.cpp
index 31e1679..79c3abc 100644
--- a/libcutils/fs_config.cpp
+++ b/libcutils/fs_config.cpp
@@ -203,9 +203,14 @@
CAP_MASK_LONG(CAP_SETGID),
"system/bin/simpleperf_app_runner" },
{ 00755, AID_ROOT, AID_ROOT, 0, "first_stage_ramdisk/system/bin/e2fsck" },
- { 00755, AID_ROOT, AID_ROOT, 0, "first_stage_ramdisk/system/bin/tune2fs" },
+#ifdef __LP64__
+ { 00755, AID_ROOT, AID_ROOT, 0, "first_stage_ramdisk/system/bin/linker64" },
+#else
+ { 00755, AID_ROOT, AID_ROOT, 0, "first_stage_ramdisk/system/bin/linker" },
+#endif
{ 00755, AID_ROOT, AID_ROOT, 0, "first_stage_ramdisk/system/bin/resize2fs" },
{ 00755, AID_ROOT, AID_ROOT, 0, "first_stage_ramdisk/system/bin/snapuserd" },
+ { 00755, AID_ROOT, AID_ROOT, 0, "first_stage_ramdisk/system/bin/tune2fs" },
// generic defaults
{ 00755, AID_ROOT, AID_ROOT, 0, "bin/*" },
{ 00640, AID_ROOT, AID_SHELL, 0, "fstab.*" },
diff --git a/libsparse/Android.bp b/libsparse/Android.bp
index bf06bbc..860b9ae 100644
--- a/libsparse/Android.bp
+++ b/libsparse/Android.bp
@@ -4,6 +4,7 @@
name: "libsparse",
host_supported: true,
ramdisk_available: true,
+ vendor_ramdisk_available: true,
recovery_available: true,
unique_host_soname: true,
vendor_available: true,
diff --git a/trusty/trusty-test.mk b/trusty/trusty-test.mk
index dc4c962..74106ec 100644
--- a/trusty/trusty-test.mk
+++ b/trusty/trusty-test.mk
@@ -15,4 +15,5 @@
PRODUCT_PACKAGES += \
spiproxyd \
trusty_keymaster_set_attestation_key \
- keymaster_soft_attestation_keys.xml \
\ No newline at end of file
+ keymaster_soft_attestation_keys.xml \
+