diff options
Diffstat (limited to 'lib/VServer.pm')
-rw-r--r-- | lib/VServer.pm | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/VServer.pm b/lib/VServer.pm new file mode 100644 index 0000000..8c70bde --- /dev/null +++ b/lib/VServer.pm @@ -0,0 +1,40 @@ +#!/usr/bin/perl -T + +package VServer; +our $VERSION = '1.0'; + +use strict; +use warnings; + +sub get_context_id($) { + my $vserver = shift; + if ($vserver =~ /^([-a-z0-9._]*)$/) { + $vserver = $1; + }; + + my $dir = "/etc/vservers/$vserver"; + return unless -d $dir; + + open(my $context, '<', "$dir/context") || return undef; + + my $cid = undef; + while (<$context>) { + if ($_ =~ m/([0-9]*)/) { + $cid = $1; + last; + } + } + + close $context; + return $cid; +} + +sub get_proc_dir($) { + my $context = shift; + my $dir = "/proc/virtual/$context/"; + + return $dir if (-d $dir); + return undef; +} + +1; |