diff --git a/impermanence.pl b/impermanence.pl index 40260ca..7ce616a 100755 --- a/impermanence.pl +++ b/impermanence.pl @@ -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"); }