impermanence: replace many system calls with perl code, and use full path to commands

This commit is contained in:
Solene Rapenne 2022-03-15 21:12:47 +01:00
parent c85a0e8797
commit 4148d4ecd7
1 changed files with 15 additions and 7 deletions

View File

@ -120,12 +120,13 @@ sub populate_ramdisk {
# check if the mountpoint is already mounted with mfs
sub is_mounted {
my $impermanence_home = shift;
my $ret;
my $mounted = 0;
my @output;
# is this already mounted?
$ret = `df $impermanence_home | awk -v dest=$impermanence_home '/^mfs/ && \$NF == dest { print }'`;
if ( $ret =~ m/^mfs/ ) {
@output = split("\n", `/bin/df $impermanence_home`);
@output = split(" ", $output[$#output]);
if( $output[5] eq $impermanence_home && $output[0] =~ m/^mfs/ ) {
$mounted = 1;
}
return $mounted;
@ -135,15 +136,22 @@ sub is_mounted {
sub mount_mfs {
my ($user, $impermanence_home, $data) = @_;
my $ret;
my $filesystem;
saydebug("finding a ffs mountpoint to use for mfs");
if( is_mounted($impermanence_home) ) {
trap_error("ERROR: $impermanence_home is already mounted with MFS");
}
my $fs = `swapctl | tail -n 1 | cut -d ' ' -f 1 | tr -d '\n'`;
my @fs = split("\n", `/sbin/swapctl`);
@fs = split(" ",$fs[$#fs]);
$filesystem = $fs[0];
saydebug("mount the destination using mount_mfs from $fs");
$ret = system("mount_mfs", "-s", $data->{size}, $fs, $impermanence_home);
if( $filesystem !~ m|^/dev/| ) {
trap_error("found swap device $filesystem doesn't start with /dev");
}
saydebug("mount the destination using mount_mfs from $filesystem");
$ret = system("/sbin/mount_mfs", "-s", $data->{size}, $filesystem, $impermanence_home);
if( $ret != 0 ) {
trap_error("ERROR: mounting the mfs filesystem errored with error $ret");
} else {
@ -259,7 +267,7 @@ sub main {
}
if( $stop && is_mounted($impermanence_home) ) {
my $status = system("umount", $impermanence_home);
my $status = system("/sbin/umount", $impermanence_home);
if( $status != 0 ) {
trap_error("umount did exit with status $status");
}