Handle hostnames with upper-case letters
[webmin.git] / proc / macos-lib.pl
1 # macos-lib.pl
2 # Functions for parsing macos server ps output
3
4 sub list_processes
5 {
6 local($pcmd, $line, $i, %pidmap, @plist);
7 if (@_) {
8         open(PS, "ps xlwwwwp $_[0] |");
9         }
10 else {
11         open(PS, "ps axlwwww |");
12         }
13 for($i=0; $line=<PS>; $i++) {
14         chop($line);
15         if ($line =~ /ps axlwwww/ || $line =~ /^\s*UID\s+PID/) { $i--; next; }
16         if ($line =~ /^\s*(\d+)\s+(\d+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(\S+)\s+(\d+)\s+(...)\s+(\S+)\s+(\d+:\d+)\s+(.*)/) {
17                 if ($3 <= 0) { $i--; next; }
18                 $plist[$i]->{"pid"} = $3;
19                 $plist[$i]->{"ppid"} = $4;
20                 $plist[$i]->{"size"} = $8;
21                 $plist[$i]->{"time"} = $13;
22                 $plist[$i]->{"nice"} = $6;
23                 $plist[$i]->{"_tty"} = $12 eq '?' ? $text{'edit_none'} : "/dev/tty$12";
24                 $plist[$i]->{"args"} = $14;
25                 $pidmap{$3} = $plist[$i];
26                 }
27         elsif ($line =~ /^\s*(\d+)\s+(\d+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(...)\s+(\S+)\s+(\d+:\S+)\s+(.*)/) {
28                 if ($2 <= 0) { $i--; next; }
29                 $plist[$i]->{"pid"} = $2;
30                 $plist[$i]->{"ppid"} = $3;
31                 $plist[$i]->{"size"} = $7;
32                 $plist[$i]->{"time"} = $12;
33                 $plist[$i]->{"nice"} = $6;
34                 $plist[$i]->{"_tty"} = $11 eq '??' ? $text{'edit_none'} : "/dev/tty$11";
35                 $plist[$i]->{"args"} = $13;
36                 $pidmap{$2} = $plist[$i];
37                 }
38         else {
39                 # Unknown line?
40                 $i--;
41                 }
42         }
43 close(PS);
44 open(PS, "ps auxwwww $_[0] |");
45 while($line = <PS>) {
46         chop($line);
47         $line =~ /^(\S+)\s+(\d+)\s+(\S+)\s+(\S+)/ || next;
48         if ($pidmap{$2}) {
49                 $pidmap{$2}->{"user"} = $1;
50                 $pidmap{$2}->{"cpu"} = "$3 %";
51                 }
52         }
53 close(PS);
54 return @plist;
55 }
56
57 # renice_proc(pid, nice)
58 sub renice_proc
59 {
60 return undef if (&is_readonly_mode());
61 local $out = &backquote_logged("renice $_[1] -p $_[0] 2>&1");
62 if ($?) { return $out; }
63 return undef;
64 }
65
66 %info_arg_map=( "_tty", $text{'macos_tty'} );
67
68 @nice_range = (-20 .. 20);
69
70 $has_fuser_command = 0;
71
72 # get_new_pty()
73 # Returns the filehandles and names for a pty and tty
74 sub get_new_pty
75 {
76 local @ptys;
77 opendir(DEV, "/dev");
78 @ptys = map { "/dev/$_" } (grep { /^pty/ } readdir(DEV));
79 closedir(DEV);
80 local ($pty, $tty);
81 foreach $pty (@ptys) {
82         open(PTY, "+>$pty") || next;
83         local $tty = $pty;
84         $tty =~ s/pty/tty/;
85         open(TTY, "+>$tty") || next;
86         local $old = select(PTY); $| = 1;
87         select(TTY); $| = 1; select($old);
88         return (*PTY, *TTY, $pty, $tty);
89         }
90 return ();
91 }
92
93 1;
94