blob: 8a5aa5487a2bb2cfa58c46a54eabe79f6e85c44a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#!/usr/bin/perl -T
package VServer;
our $VERSION = '1.2';
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;
}
sub get_config_dir($) {
my $context = shift;
my $dir = qx(/usr/sbin/vuname --xid $context --get context 2> /dev/null);
return undef unless ($? eq 0);
chomp($dir);
return $dir;
}
sub get_name($) {
my $context = shift;
my $dir = get_config_dir($context) || return undef;
my $name = undef;
open(my $file, "<", "$dir/name") || return undef;
while (<$file>) {
chomp($name = $_);
last;
}
close($file);
return $name;
}
1;
|