line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#line 1 |
2
|
|
|
|
|
|
|
package Proc::ProcessTable; |
3
|
2
|
|
|
2
|
|
85680
|
|
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
82
|
|
4
|
|
|
|
|
|
|
use 5.006; |
5
|
2
|
|
|
2
|
|
13
|
|
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
93
|
|
6
|
2
|
|
|
2
|
|
21
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
260
|
|
7
|
2
|
|
|
2
|
|
13
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
908
|
|
8
|
2
|
|
|
2
|
|
12
|
use Fcntl; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
857
|
|
9
|
|
|
|
|
|
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK $AUTOLOAD); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
require Exporter; |
12
|
|
|
|
|
|
|
require DynaLoader; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
@ISA = qw(Exporter DynaLoader); |
15
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
16
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
17
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
18
|
|
|
|
|
|
|
@EXPORT = qw( |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
$VERSION = '0.47'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub AUTOLOAD { |
24
|
|
|
|
|
|
|
# This AUTOLOAD is used to 'autoload' constants from the constant() |
25
|
|
|
|
|
|
|
# XS function. If a constant is not found then control is passed |
26
|
|
|
|
|
|
|
# to the AUTOLOAD in AutoLoader. |
27
|
0
|
|
|
0
|
|
|
|
28
|
0
|
|
|
|
|
|
my $constname; |
29
|
0
|
0
|
|
|
|
|
($constname = $AUTOLOAD) =~ s/.*:://; |
30
|
0
|
0
|
|
|
|
|
my $val = constant($constname, @_ ? $_[0] : 0); |
31
|
0
|
0
|
|
|
|
|
if ($! != 0) { |
32
|
0
|
|
|
|
|
|
if ($! =~ /Invalid/) { |
33
|
0
|
|
|
|
|
|
$AutoLoader::AUTOLOAD = $AUTOLOAD; |
34
|
|
|
|
|
|
|
goto &AutoLoader::AUTOLOAD; |
35
|
|
|
|
|
|
|
} |
36
|
0
|
|
|
|
|
|
else { |
37
|
|
|
|
|
|
|
croak "Your vendor has not defined Proc::ProcessTable macro $constname"; |
38
|
|
|
|
|
|
|
} |
39
|
0
|
|
|
|
|
|
} |
40
|
0
|
|
|
|
|
|
eval "sub $AUTOLOAD { $val }"; |
41
|
|
|
|
|
|
|
goto &$AUTOLOAD; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
bootstrap Proc::ProcessTable $VERSION; |
45
|
|
|
|
|
|
|
|
46
|
2
|
|
|
2
|
|
2370
|
# Preloaded methods go here. |
|
2
|
|
|
|
|
7100
|
|
|
2
|
|
|
|
|
94
|
|
47
|
2
|
|
|
2
|
|
14
|
use Proc::ProcessTable::Process; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1307
|
|
48
|
|
|
|
|
|
|
use File::Find; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
my %TTYDEVS; |
51
|
|
|
|
|
|
|
our $TTYDEVSFILE = "/tmp/TTYDEVS"; # Where we store the TTYDEVS hash |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub new |
54
|
0
|
|
|
0
|
|
|
{ |
55
|
0
|
|
0
|
|
|
|
my ($this, %args) = @_; |
56
|
0
|
|
|
|
|
|
my $class = ref($this) || $this; |
57
|
0
|
|
|
|
|
|
my $self = {}; |
58
|
|
|
|
|
|
|
bless $self, $class; |
59
|
0
|
|
|
|
|
|
|
60
|
0
|
0
|
0
|
|
|
|
mutex_new(1); |
61
|
|
|
|
|
|
|
if ( exists $args{cache_ttys} && $args{cache_ttys} == 1 ) |
62
|
0
|
|
|
|
|
|
{ |
63
|
|
|
|
|
|
|
$self->{cache_ttys} = 1 |
64
|
|
|
|
|
|
|
} |
65
|
0
|
0
|
0
|
|
|
|
|
66
|
|
|
|
|
|
|
if ( exists $args{enable_ttys} && (! $args{enable_ttys})) |
67
|
0
|
|
|
|
|
|
{ |
68
|
0
|
0
|
|
|
|
|
$self->{enable_ttys} = 0; |
69
|
0
|
|
|
|
|
|
if ($self->{'cache_ttys'}) { |
70
|
|
|
|
|
|
|
carp("cache_ttys specified with enable_ttys, cache_ttys a no-op"); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
else |
74
|
0
|
|
|
|
|
|
{ |
75
|
|
|
|
|
|
|
$self->{enable_ttys} = 1; |
76
|
|
|
|
|
|
|
} |
77
|
0
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
my $status = $self->initialize; |
79
|
0
|
0
|
|
|
|
|
mutex_new(0); |
80
|
|
|
|
|
|
|
if($status) |
81
|
0
|
|
|
|
|
|
{ |
82
|
|
|
|
|
|
|
return $self; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
else |
85
|
0
|
|
|
|
|
|
{ |
86
|
|
|
|
|
|
|
return undef; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub initialize |
91
|
0
|
|
|
0
|
|
|
{ |
92
|
|
|
|
|
|
|
my ($self) = @_; |
93
|
0
|
0
|
|
|
|
|
|
94
|
|
|
|
|
|
|
if ($self->{enable_ttys}) |
95
|
|
|
|
|
|
|
{ |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# Get the mapping of TTYs to device nums |
98
|
0
|
0
|
|
|
|
|
# reading/writing the cache if we are caching |
99
|
|
|
|
|
|
|
if( $self->{cache_ttys} ) |
100
|
|
|
|
|
|
|
{ |
101
|
0
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
require Storable; |
103
|
0
|
0
|
|
|
|
|
|
104
|
|
|
|
|
|
|
if( -r $TTYDEVSFILE ) |
105
|
0
|
|
|
|
|
|
{ |
106
|
0
|
|
|
|
|
|
$_ = Storable::retrieve($TTYDEVSFILE); |
107
|
|
|
|
|
|
|
%Proc::ProcessTable::TTYDEVS = %$_; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
else |
110
|
0
|
|
|
|
|
|
{ |
111
|
0
|
|
|
|
|
|
$self->_get_tty_list; |
112
|
0
|
|
|
|
|
|
my $old_umask = umask; |
113
|
|
|
|
|
|
|
umask 022; |
114
|
0
|
0
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sysopen( my $ttydevs_fh, $TTYDEVSFILE, O_WRONLY | O_EXCL | O_CREAT ) |
116
|
0
|
|
|
|
|
|
or die "$TTYDEVSFILE was created by other process"; |
117
|
0
|
|
|
|
|
|
Storable::store_fd( \%Proc::ProcessTable::TTYDEVS, $ttydevs_fh ); |
118
|
|
|
|
|
|
|
close $ttydevs_fh; |
119
|
0
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
umask $old_umask; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
else |
124
|
0
|
|
|
|
|
|
{ |
125
|
|
|
|
|
|
|
$self->_get_tty_list; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
# Call the os-specific initialization |
130
|
|
|
|
|
|
|
$self->_initialize_os; |
131
|
0
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
return 1; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
############################################### |
136
|
|
|
|
|
|
|
# Generate a hash mapping TTY numbers to paths. |
137
|
|
|
|
|
|
|
# This might be faster in Table.xs, |
138
|
|
|
|
|
|
|
# but it's a lot more portable here |
139
|
|
|
|
|
|
|
############################################### |
140
|
|
|
|
|
|
|
sub _get_tty_list |
141
|
0
|
|
|
0
|
|
|
{ |
142
|
0
|
|
|
|
|
|
my ($self) = @_; |
143
|
|
|
|
|
|
|
undef %Proc::ProcessTable::TTYDEVS; |
144
|
|
|
|
|
|
|
find({ wanted => |
145
|
0
|
0
|
0
|
0
|
|
|
sub{ |
146
|
0
|
|
|
|
|
|
$File::Find::prune = 1 if -d $_ && ! -x $_; |
147
|
|
|
|
|
|
|
my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, |
148
|
0
|
0
|
|
|
|
|
$atime,$mtime,$ctime,$blksize,$blocks) = stat($File::Find::name); |
149
|
|
|
|
|
|
|
$Proc::ProcessTable::TTYDEVS{$rdev} = $File::Find::name |
150
|
0
|
|
|
|
|
|
if(-c $File::Find::name); |
151
|
|
|
|
|
|
|
}, no_chdir => 1}, |
152
|
|
|
|
|
|
|
"/dev" |
153
|
|
|
|
|
|
|
); |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
0
|
|
|
0
|
|
|
# Apparently needed for mod_perl |
157
|
|
|
|
|
|
|
sub DESTROY {} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
1; |
160
|
|
|
|
|
|
|
__END__ |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
#line 263 |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
|