impermanence: replace many system calls with perl code, and use full path to commands
This commit is contained in:
parent
c85a0e8797
commit
4148d4ecd7
|
@ -120,12 +120,13 @@ sub populate_ramdisk {
|
||||||
# check if the mountpoint is already mounted with mfs
|
# check if the mountpoint is already mounted with mfs
|
||||||
sub is_mounted {
|
sub is_mounted {
|
||||||
my $impermanence_home = shift;
|
my $impermanence_home = shift;
|
||||||
my $ret;
|
|
||||||
my $mounted = 0;
|
my $mounted = 0;
|
||||||
|
my @output;
|
||||||
|
|
||||||
# is this already mounted?
|
# is this already mounted?
|
||||||
$ret = `df $impermanence_home | awk -v dest=$impermanence_home '/^mfs/ && \$NF == dest { print }'`;
|
@output = split("\n", `/bin/df $impermanence_home`);
|
||||||
if ( $ret =~ m/^mfs/ ) {
|
@output = split(" ", $output[$#output]);
|
||||||
|
if( $output[5] eq $impermanence_home && $output[0] =~ m/^mfs/ ) {
|
||||||
$mounted = 1;
|
$mounted = 1;
|
||||||
}
|
}
|
||||||
return $mounted;
|
return $mounted;
|
||||||
|
@ -135,15 +136,22 @@ sub is_mounted {
|
||||||
sub mount_mfs {
|
sub mount_mfs {
|
||||||
my ($user, $impermanence_home, $data) = @_;
|
my ($user, $impermanence_home, $data) = @_;
|
||||||
my $ret;
|
my $ret;
|
||||||
|
my $filesystem;
|
||||||
|
|
||||||
saydebug("finding a ffs mountpoint to use for mfs");
|
saydebug("finding a ffs mountpoint to use for mfs");
|
||||||
if( is_mounted($impermanence_home) ) {
|
if( is_mounted($impermanence_home) ) {
|
||||||
trap_error("ERROR: $impermanence_home is already mounted with MFS");
|
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");
|
if( $filesystem !~ m|^/dev/| ) {
|
||||||
$ret = system("mount_mfs", "-s", $data->{size}, $fs, $impermanence_home);
|
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 ) {
|
if( $ret != 0 ) {
|
||||||
trap_error("ERROR: mounting the mfs filesystem errored with error $ret");
|
trap_error("ERROR: mounting the mfs filesystem errored with error $ret");
|
||||||
} else {
|
} else {
|
||||||
|
@ -259,7 +267,7 @@ sub main {
|
||||||
}
|
}
|
||||||
|
|
||||||
if( $stop && is_mounted($impermanence_home) ) {
|
if( $stop && is_mounted($impermanence_home) ) {
|
||||||
my $status = system("umount", $impermanence_home);
|
my $status = system("/sbin/umount", $impermanence_home);
|
||||||
if( $status != 0 ) {
|
if( $status != 0 ) {
|
||||||
trap_error("umount did exit with status $status");
|
trap_error("umount did exit with status $status");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue