#!/usr/bin/perl -T package VServer; our $VERSION = '1.1'; 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; } 1;