Handle hostnames with upper-case letters
[webmin.git] / proc / openbsd-lib.pl
1 # openbsd-lib.pl
2 # Functions for parsing openbsd ps output
3
4 sub list_processes
5 {
6 local($pcmd, $line, $i, %pidmap, @plist);
7 $pcmd = @_ ? "-p $_[0]" : "";
8 open(PS, "ps -axwwww -o pid,ppid,user,vsz,%cpu,time,nice,tty,ruser,rgid,pgid,lstart,lim,command $pcmd |");
9 for($i=0; $line=<PS>; $i++) {
10         chop($line);
11         if ($line =~ /ps -axwwww/ || $line =~ /^\s*PID/) { $i--; next; }
12         $line =~ /^\s*(\d+)\s+(\d+)\s+(\S+)\s+(\d+)\s+([\d\.]+)\s+(\S+)\s+(-?\d+)\s+(\S+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(-|\S+\s+\S+\s+\d+\s+\S+\s+\d+|\d+)\s+(\S+)\s+(.*)$/;
13
14         $plist[$i]->{"pid"} = $1;
15         $plist[$i]->{"ppid"} = $2;
16         $plist[$i]->{"user"} = $3;
17         $plist[$i]->{"size"} = "$4 kB";
18         $plist[$i]->{"cpu"} = $5;
19         $plist[$i]->{"time"} = $6;
20         $plist[$i]->{"nice"} = $7;
21         $plist[$i]->{"_tty"} = $8;
22         $plist[$i]->{"_ruser"} = $9;
23         $plist[$i]->{"_rgroup"} = getgrgid($10);
24         $plist[$i]->{"_pgid"} = $11;
25         $plist[$i]->{"_lstart"} = $12;
26         $plist[$i]->{"_lim"} = $13 eq "-" ? "Unlimited" : $13;
27         $plist[$i]->{"args"} = $14;
28         }
29 close(PS);
30 return @plist;
31 }
32
33 # renice_proc(pid, nice)
34 sub renice_proc
35 {
36 return undef if (&is_readonly_mode());
37 local $out = &backquote_logged("renice $_[1] -p $_[0] 2>&1");
38 if ($?) { return $out; }
39 return undef;
40 }
41
42 foreach $ia (keys %text) {
43         if ($ia =~ /^freebsd(_\S+)/) {
44                 $info_arg_map{$1} = $text{$ia};
45                 }
46         }
47
48 @nice_range = (-20 .. 20);
49
50 $has_fuser_command = 0;
51
52 # get_new_pty()
53 # Returns the filehandles and names for a pty and tty
54 sub get_new_pty
55 {
56 local @ptys;
57 opendir(DEV, "/dev");
58 @ptys = map { "/dev/$_" } (grep { /^pty/ } readdir(DEV));
59 closedir(DEV);
60 local ($pty, $tty);
61 foreach $pty (@ptys) {
62         open(PTY, "+>$pty") || next;
63         local $tty = $pty;
64         $tty =~ s/pty/tty/;
65         open(TTY, "+>$tty") || next;
66         local $old = select(PTY); $| = 1;
67         select(TTY); $| = 1; select($old);
68         return (*PTY, *TTY, $pty, $tty);
69         }
70 return ();
71 }
72
73 1;
74