3 # Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
4 # based on vps by Krischan Jodies
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 # Wrapper for ps. Adds security context number and name
23 # (c) 2002 krischan.jodies@sernet.de
26 # 1.1 Added error messages
28 if ($ARGV[0] eq "--help") {
34 $lockdir = "/var/run/vservers";
38 $context=get_context("self");
41 print "Can not find my security context. Is this a ctx kernel?\n";
45 exec("@PKGLIBDIR@/chcontext-compat --silent --ctx 1 $0 @ARGV");
46 print "Can not execute chcontext\n";
51 if (! open PS, "ps @ARGV|") {
52 print "Can not execute ps\n";
61 $header =~ /(.*) PID(.+)/;
64 $left_length = length($left);
65 print "${left} PID CONTEXT ${right}\n";
67 $pid = substr $line,$left_length,$pid_length;
68 print substr $line,0,$left_length;
70 $context = get_context($pid);
71 $context_name = getcontextname($context);
72 printf " %-3s %-10s",$context,$context_name;
73 print substr $line,$left_length + $pid_length;
84 open STATUS, "/proc/$pid/status";
88 if (/s_context: (\d+)/) {
98 if (exists $name{$_[0]}) {
113 opendir LOCKDIR, "$lockdir";
114 while ($file=readdir(LOCKDIR)) {
115 if (-f "$lockdir/$file") {
116 open FILE, "$lockdir/$file";
117 $file =~ s/(.+)\.ctx/$1/;
119 if (/S_CONTEXT=(\d+)/) {