Respect ro.boot.fstab_suffix in swapon_all

While mount_all and umount_all were updated to use ro.boot.fstab_suffix,
I neglected to update swapon_all. Trivially copied from umount_all.

Bug: 142424832
Change-Id: Icd706fe7a1fe16c687cd2811b0a3158d7d2e224e
This commit is contained in:
Alistair Delva 2020-06-08 11:04:53 -07:00
parent 46f25dee36
commit afaa5fbccc
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 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.
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>`
> 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 {};
}
/* swapon_all [ <fstab> ] */
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;
if (!ReadFstabFromFile(args[1], &fstab)) {
return Error() << "Could not read fstab '" << args[1] << "'";
if (swapon_all->empty()) {
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)) {
@ -1371,7 +1381,7 @@ const BuiltinFunctionMap& GetBuiltinFunctionMap() {
{"setrlimit", {3, 3, {false, do_setrlimit}}},
{"start", {1, 1, {false, do_start}}},
{"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}}},
{"symlink", {2, 2, {true, do_symlink}}},
{"sysclktz", {1, 1, {false, do_sysclktz}}},

View file

@ -202,6 +202,14 @@ Result<void> check_setrlimit(const BuiltinArguments& args) {
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) {
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_setprop(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_umount_all(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);
}
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) {
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 {};
}
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(
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);
void SetStdioToDevNull(char** argv);