Follow-up to 57c97d8, issue #224: add swapon/swapoff fstab wrappers

The swapon and swapoff commands do not support a custom fstab, they
assume /etc/fstab is the only true source of swap devices and files.

This change adds rudimentary (!) support for figuring out any swap
device or file to use from any finit.fstab.  Please note, options are
not supported at the moment.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2022-04-26 22:57:22 +02:00
1 parent 26409bc860
commit 605c489937
2 files changed
+53 -4

No files matched your search

+25 -2
View File
@@ -323,6 +323,29 @@ static void fs_finalize(void)
fs_mount("tmpfs", "/tmp", "tmpfs", MS_NOSUID | MS_NODEV, "mode=1777");
}
static void fs_swapon(char *cmd, size_t len)
{
struct mntent *mnt;
FILE *fp;
if (!whichp("swapon"))
return;
fp = setmntent(fstab, "r");
if (!fp)
return;
while ((mnt = getmntent(fp))) {
if (strcmp(mnt->mnt_type, MNTTYPE_SWAP))
continue;
snprintf(cmd, len, "swapon %s", mnt->mnt_fsname);
run_interactive(cmd, "Enabling swap %s", mnt->mnt_fsname);
}
endmntent(fp);
}
static void fs_mount_all(void)
{
char cmd[256] = "mount -na";
@@ -361,8 +384,8 @@ static void fs_mount_all(void)
_d("Calling extra mount hook, after mount -a ...");
plugin_run_hooks(HOOK_MOUNT_POST);
if (whichp("swapon"))
run_interactive("swapon -ea", "Enabling system swap");
_d("Enable any swap ...");
fs_swapon(cmd, sizeof(cmd));
_d("Finalize, ensure common file systems are available ...");
fs_finalize();