Resolve e2fsdroid failure in certain cases

* Set proper SELinux context for system-as-root system, AOSP uses "/"
   in fstab while TWRP uses "/system_root" so an exception is necessary.
 * Skip initializing context if the target partition doesn't exist in
   /file_contexts e.g. /usb-otg.

Change-Id: I8f802c34e18fb9f65bf936d11967c83a451b0493
This commit is contained in:
dianlujitao
2019-05-15 15:33:27 +08:00
parent c1ad6c1931
commit 3cf05a569e
+13 -7
View File
@@ -2080,13 +2080,19 @@ bool TWPartition::Wipe_EXTFS(string File_System) {
}
if (TWFunc::Path_Exists("/sbin/e2fsdroid")) {
// Execute e2fsdroid to initialize selinux context
Command = "e2fsdroid -e -S /file_contexts -a " + Mount_Point + " " + Actual_Block_Device;
LOGINFO("e2fsdroid command: %s\n", Command.c_str());
ret = TWFunc::Exec_Cmd(Command);
if (ret) {
gui_msg(Msg(msg::kError, "unable_to_wipe=Unable to wipe {1}.")(Display_Name));
return false;
const string& File_Contexts_Entry = (Mount_Point == "/system_root" ? "/" : Mount_Point);
char *secontext = NULL;
if (!selinux_handle || selabel_lookup(selinux_handle, &secontext, File_Contexts_Entry.c_str(), S_IFDIR) < 0) {
LOGINFO("Cannot lookup security context for '%s'\n", Mount_Point.c_str());
} else {
// Execute e2fsdroid to initialize selinux context
Command = "e2fsdroid -e -S /file_contexts -a " + File_Contexts_Entry + " " + Actual_Block_Device;
LOGINFO("e2fsdroid command: %s\n", Command.c_str());
ret = TWFunc::Exec_Cmd(Command);
if (ret) {
gui_msg(Msg(msg::kError, "unable_to_wipe=Unable to wipe {1}.")(Display_Name));
return false;
}
}
} else {
LOGINFO("e2fsdroid not present\n");