Respect ro.boot.fstab_suffix in swapon_all am: afaa5fbccc

Original change: https://googleplex-android-review.googlesource.com/c/platform/system/core/+/11796125

Change-Id: Icd1bcf684388f584ce33c9d7bc8d86854f0626d7
This commit is contained in:
Alistair Delva 2020-06-08 23:23:24 +00:00 committed by Automerger Merge Worker
commit 486daea4c9
6 changed files with 41 additions and 6 deletions

View file

@ -623,8 +623,11 @@ provides the `aidl_lazy_test_1` interface.
`stop <service>` `stop <service>`
> Stop a service from running if it is currently running. > Stop a service from running if it is currently running.
`swapon_all <fstab>` `swapon_all [ <fstab> ]`
> Calls fs\_mgr\_swapon\_all on the given fstab file. > Calls fs\_mgr\_swapon\_all on the given fstab file.
If the fstab parameter is not specified, fstab.${ro.boot.fstab_suffix},
fstab.${ro.hardware} or fstab.${ro.hardware.platform} will be scanned for
under /odm/etc, /vendor/etc, or / at runtime, in that order.
`symlink <target> <path>` `symlink <target> <path>`
> Create a symbolic link at _path_ with the value _target_ > Create a symbolic link at _path_ with the value _target_

View file

@ -708,10 +708,20 @@ static Result<void> do_umount_all(const BuiltinArguments& args) {
return {}; return {};
} }
/* swapon_all [ <fstab> ] */
static Result<void> do_swapon_all(const BuiltinArguments& args) { static Result<void> do_swapon_all(const BuiltinArguments& args) {
auto swapon_all = ParseSwaponAll(args.args);
if (!swapon_all.ok()) return swapon_all.error();
Fstab fstab; Fstab fstab;
if (!ReadFstabFromFile(args[1], &fstab)) { if (swapon_all->empty()) {
return Error() << "Could not read fstab '" << args[1] << "'"; if (!ReadDefaultFstab(&fstab)) {
return Error() << "Could not read default fstab";
}
} else {
if (!ReadFstabFromFile(*swapon_all, &fstab)) {
return Error() << "Could not read fstab '" << *swapon_all << "'";
}
} }
if (!fs_mgr_swapon_all(fstab)) { if (!fs_mgr_swapon_all(fstab)) {
@ -1371,7 +1381,7 @@ const BuiltinFunctionMap& GetBuiltinFunctionMap() {
{"setrlimit", {3, 3, {false, do_setrlimit}}}, {"setrlimit", {3, 3, {false, do_setrlimit}}},
{"start", {1, 1, {false, do_start}}}, {"start", {1, 1, {false, do_start}}},
{"stop", {1, 1, {false, do_stop}}}, {"stop", {1, 1, {false, do_stop}}},
{"swapon_all", {1, 1, {false, do_swapon_all}}}, {"swapon_all", {0, 1, {false, do_swapon_all}}},
{"enter_default_mount_ns", {0, 0, {false, do_enter_default_mount_ns}}}, {"enter_default_mount_ns", {0, 0, {false, do_enter_default_mount_ns}}},
{"symlink", {2, 2, {true, do_symlink}}}, {"symlink", {2, 2, {true, do_symlink}}},
{"sysclktz", {1, 1, {false, do_sysclktz}}}, {"sysclktz", {1, 1, {false, do_sysclktz}}},

View file

@ -202,6 +202,14 @@ Result<void> check_setrlimit(const BuiltinArguments& args) {
return {}; return {};
} }
Result<void> check_swapon_all(const BuiltinArguments& args) {
auto options = ParseSwaponAll(args.args);
if (!options.ok()) {
return options.error();
}
return {};
}
Result<void> check_sysclktz(const BuiltinArguments& args) { Result<void> check_sysclktz(const BuiltinArguments& args) {
ReturnIfAnyArgsEmpty(); ReturnIfAnyArgsEmpty();

View file

@ -37,6 +37,7 @@ Result<void> check_restorecon(const BuiltinArguments& args);
Result<void> check_restorecon_recursive(const BuiltinArguments& args); Result<void> check_restorecon_recursive(const BuiltinArguments& args);
Result<void> check_setprop(const BuiltinArguments& args); Result<void> check_setprop(const BuiltinArguments& args);
Result<void> check_setrlimit(const BuiltinArguments& args); Result<void> check_setrlimit(const BuiltinArguments& args);
Result<void> check_swapon_all(const BuiltinArguments& args);
Result<void> check_sysclktz(const BuiltinArguments& args); Result<void> check_sysclktz(const BuiltinArguments& args);
Result<void> check_umount_all(const BuiltinArguments& args); Result<void> check_umount_all(const BuiltinArguments& args);
Result<void> check_wait(const BuiltinArguments& args); Result<void> check_wait(const BuiltinArguments& args);

View file

@ -652,11 +652,22 @@ Result<std::pair<int, std::vector<std::string>>> ParseRestorecon(
return std::pair(flag, paths); return std::pair(flag, paths);
} }
Result<std::string> ParseSwaponAll(const std::vector<std::string>& args) {
if (args.size() <= 1) {
if (SelinuxGetVendorAndroidVersion() <= __ANDROID_API_Q__) {
return Error() << "swapon_all requires at least 1 argument";
}
return {};
}
return args[1];
}
Result<std::string> ParseUmountAll(const std::vector<std::string>& args) { Result<std::string> ParseUmountAll(const std::vector<std::string>& args) {
if (SelinuxGetVendorAndroidVersion() <= __ANDROID_API_Q__) { if (args.size() <= 1) {
if (args.size() <= 1) { if (SelinuxGetVendorAndroidVersion() <= __ANDROID_API_Q__) {
return Error() << "umount_all requires at least 1 argument"; return Error() << "umount_all requires at least 1 argument";
} }
return {};
} }
return args[1]; return args[1];
} }

View file

@ -92,6 +92,8 @@ Result<MountAllOptions> ParseMountAll(const std::vector<std::string>& args);
Result<std::pair<int, std::vector<std::string>>> ParseRestorecon( Result<std::pair<int, std::vector<std::string>>> ParseRestorecon(
const std::vector<std::string>& args); const std::vector<std::string>& args);
Result<std::string> ParseSwaponAll(const std::vector<std::string>& args);
Result<std::string> ParseUmountAll(const std::vector<std::string>& args); Result<std::string> ParseUmountAll(const std::vector<std::string>& args);
void SetStdioToDevNull(char** argv); void SetStdioToDevNull(char** argv);