Filename | /usr/local/src/github.com/foswiki/core/lib/CPAN/lib/CGI/Session/Driver/file.pm |
Statements | Executed 86 statements in 3.24ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 795µs | 973µs | BEGIN@10 | CGI::Session::Driver::file::
2 | 1 | 1 | 194µs | 1.11ms | store | CGI::Session::Driver::file::
3 | 2 | 1 | 181µs | 181µs | CORE:close (opcode) | CGI::Session::Driver::file::
2 | 1 | 1 | 145µs | 145µs | CORE:truncate (opcode) | CGI::Session::Driver::file::
3 | 2 | 1 | 131µs | 668µs | _file | CGI::Session::Driver::file::
1 | 1 | 1 | 128µs | 452µs | retrieve | CGI::Session::Driver::file::
3 | 2 | 1 | 97µs | 97µs | CORE:sysopen (opcode) | CGI::Session::Driver::file::
5 | 3 | 1 | 59µs | 59µs | CORE:ftlink (opcode) | CGI::Session::Driver::file::
1 | 1 | 1 | 29µs | 38µs | BEGIN@5 | CGI::Session::Driver::file::
3 | 2 | 1 | 25µs | 25µs | CORE:flock (opcode) | CGI::Session::Driver::file::
1 | 1 | 1 | 25µs | 33µs | init | CGI::Session::Driver::file::
1 | 1 | 1 | 24µs | 145µs | BEGIN@7 | CGI::Session::Driver::file::
2 | 1 | 1 | 24µs | 24µs | CORE:print (opcode) | CGI::Session::Driver::file::
1 | 1 | 1 | 21µs | 2.76ms | BEGIN@9 | CGI::Session::Driver::file::
3 | 2 | 1 | 19µs | 19µs | CORE:ftis (opcode) | CGI::Session::Driver::file::
1 | 1 | 1 | 18µs | 164µs | BEGIN@11 | CGI::Session::Driver::file::
2 | 2 | 1 | 17µs | 17µs | CORE:readline (opcode) | CGI::Session::Driver::file::
1 | 1 | 1 | 16µs | 50µs | BEGIN@16 | CGI::Session::Driver::file::
1 | 1 | 1 | 14µs | 14µs | BEGIN@8 | CGI::Session::Driver::file::
1 | 1 | 1 | 11µs | 11µs | BEGIN@13 | CGI::Session::Driver::file::
3 | 1 | 1 | 9µs | 9µs | CORE:subst (opcode) | CGI::Session::Driver::file::
1 | 1 | 1 | 8µs | 8µs | CORE:ftdir (opcode) | CGI::Session::Driver::file::
1 | 1 | 1 | 7µs | 7µs | DESTROY | CGI::Session::Driver::file::
3 | 1 | 1 | 6µs | 6µs | CORE:match (opcode) | CGI::Session::Driver::file::
0 | 0 | 0 | 0s | 0s | remove | CGI::Session::Driver::file::
0 | 0 | 0 | 0s | 0s | traverse | CGI::Session::Driver::file::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package CGI::Session::Driver::file; | ||||
2 | |||||
3 | # $Id: file.pm 447 2008-11-01 03:46:08Z markstos $ | ||||
4 | |||||
5 | 2 | 61µs | 2 | 48µs | # spent 38µs (29+9) within CGI::Session::Driver::file::BEGIN@5 which was called:
# once (29µs+9µs) by CGI::Session::_load_pluggables at line 5 # spent 38µs making 1 call to CGI::Session::Driver::file::BEGIN@5
# spent 10µs making 1 call to strict::import |
6 | |||||
7 | 2 | 49µs | 2 | 265µs | # spent 145µs (24+120) within CGI::Session::Driver::file::BEGIN@7 which was called:
# once (24µs+120µs) by CGI::Session::_load_pluggables at line 7 # spent 145µs making 1 call to CGI::Session::Driver::file::BEGIN@7
# spent 120µs making 1 call to Exporter::import |
8 | 2 | 50µs | 1 | 14µs | # spent 14µs within CGI::Session::Driver::file::BEGIN@8 which was called:
# once (14µs+0s) by CGI::Session::_load_pluggables at line 8 # spent 14µs making 1 call to CGI::Session::Driver::file::BEGIN@8 |
9 | 2 | 76µs | 2 | 5.51ms | # spent 2.76ms (21µs+2.74) within CGI::Session::Driver::file::BEGIN@9 which was called:
# once (21µs+2.74ms) by CGI::Session::_load_pluggables at line 9 # spent 2.76ms making 1 call to CGI::Session::Driver::file::BEGIN@9
# spent 2.74ms making 1 call to Exporter::import |
10 | 2 | 243µs | 1 | 973µs | # spent 973µs (795+179) within CGI::Session::Driver::file::BEGIN@10 which was called:
# once (795µs+179µs) by CGI::Session::_load_pluggables at line 10 # spent 973µs making 1 call to CGI::Session::Driver::file::BEGIN@10 |
11 | 2 | 58µs | 2 | 310µs | # spent 164µs (18+146) within CGI::Session::Driver::file::BEGIN@11 which was called:
# once (18µs+146µs) by CGI::Session::_load_pluggables at line 11 # spent 164µs making 1 call to CGI::Session::Driver::file::BEGIN@11
# spent 146µs making 1 call to vars::import |
12 | |||||
13 | # spent 11µs within CGI::Session::Driver::file::BEGIN@13 which was called:
# once (11µs+0s) by CGI::Session::_load_pluggables at line 19 | ||||
14 | # keep historical behavior | ||||
15 | |||||
16 | 2 | 56µs | 2 | 84µs | # spent 50µs (16+34) within CGI::Session::Driver::file::BEGIN@16 which was called:
# once (16µs+34µs) by CGI::Session::_load_pluggables at line 16 # spent 50µs making 1 call to CGI::Session::Driver::file::BEGIN@16
# spent 34µs making 1 call to strict::unimport |
17 | |||||
18 | 1 | 13µs | *FileName = \$CGI::Session::File::FileName; | ||
19 | 1 | 1.52ms | 1 | 11µs | } # spent 11µs making 1 call to CGI::Session::Driver::file::BEGIN@13 |
20 | |||||
21 | 1 | 11µs | @CGI::Session::Driver::file::ISA = ( "CGI::Session::Driver" ); | ||
22 | 1 | 2µs | $CGI::Session::Driver::file::VERSION = '4.38'; | ||
23 | 1 | 1µs | $FileName = "cgisess_%s"; | ||
24 | 1 | 1µs | $NoFlock = 0; | ||
25 | 1 | 1µs | $UMask = 0660; | ||
26 | 2 | 5µs | $NO_FOLLOW = eval { O_NOFOLLOW } || 0; | ||
27 | |||||
28 | # spent 33µs (25+8) within CGI::Session::Driver::file::init which was called:
# once (25µs+8µs) by CGI::Session::Driver::new at line 38 of /usr/local/src/github.com/foswiki/core/lib/CPAN/lib/CGI/Session/Driver.pm | ||||
29 | 6 | 35µs | my $self = shift; | ||
30 | $self->{Directory} ||= File::Spec->tmpdir(); | ||||
31 | |||||
32 | 1 | 8µs | unless ( -d $self->{Directory} ) { # spent 8µs making 1 call to CGI::Session::Driver::file::CORE:ftdir | ||
33 | require File::Path; | ||||
34 | unless ( File::Path::mkpath($self->{Directory}) ) { | ||||
35 | return $self->set_error( "init(): couldn't create directory path: $!" ); | ||||
36 | } | ||||
37 | } | ||||
38 | |||||
39 | $self->{NoFlock} = $NoFlock unless exists $self->{NoFlock}; | ||||
40 | $self->{UMask} = $UMask unless exists $self->{UMask}; | ||||
41 | |||||
42 | return 1; | ||||
43 | } | ||||
44 | |||||
45 | sub _file { | ||||
46 | 15 | 149µs | my ($self,$sid) = @_; | ||
47 | my $id = $sid; | ||||
48 | 3 | 9µs | $id =~ s|\\|/|g; # spent 9µs making 3 calls to CGI::Session::Driver::file::CORE:subst, avg 3µs/call | ||
49 | |||||
50 | 3 | 6µs | if ($id =~ m|/|) # spent 6µs making 3 calls to CGI::Session::Driver::file::CORE:match, avg 2µs/call | ||
51 | { | ||||
52 | return $self->set_error( "_file(): Session ids cannot contain \\ or / chars: $sid" ); | ||||
53 | } | ||||
54 | |||||
55 | 3 | 522µs | return File::Spec->catfile($self->{Directory}, sprintf( $FileName, $sid )); # spent 522µs making 3 calls to File::Spec::Unix::catfile, avg 174µs/call | ||
56 | } | ||||
57 | |||||
58 | # spent 452µs (128+324) within CGI::Session::Driver::file::retrieve which was called:
# once (128µs+324µs) by CGI::Session::load at line 748 of /usr/local/src/github.com/foswiki/core/lib/CPAN/lib/CGI/Session.pm | ||||
59 | 12 | 199µs | my $self = shift; | ||
60 | my ($sid) = @_; | ||||
61 | |||||
62 | 1 | 238µs | my $path = $self->_file($sid); # spent 238µs making 1 call to CGI::Session::Driver::file::_file | ||
63 | |||||
64 | 1 | 8µs | return 0 unless -e $path; # spent 8µs making 1 call to CGI::Session::Driver::file::CORE:ftis | ||
65 | |||||
66 | # make certain our filehandle goes away when we fall out of scope | ||||
67 | local *FH; | ||||
68 | |||||
69 | 1 | 9µs | if (-l $path) { # spent 9µs making 1 call to CGI::Session::Driver::file::CORE:ftlink | ||
70 | unlink($path) or | ||||
71 | return $self->set_error("retrieve(): '$path' appears to be a symlink and I couldn't remove it: $!"); | ||||
72 | return 0; # we deleted this so we have no hope of getting back anything | ||||
73 | } | ||||
74 | 1 | 34µs | sysopen(FH, $path, O_RDONLY | $NO_FOLLOW ) || return $self->set_error( "retrieve(): couldn't open '$path': $!" ); # spent 34µs making 1 call to CGI::Session::Driver::file::CORE:sysopen | ||
75 | |||||
76 | 1 | 11µs | $self->{NoFlock} || flock(FH, LOCK_SH) or return $self->set_error( "retrieve(): couldn't lock '$path': $!" ); # spent 11µs making 1 call to CGI::Session::Driver::file::CORE:flock | ||
77 | |||||
78 | my $rv = ""; | ||||
79 | 1 | 14µs | while ( <FH> ) { # spent 14µs making 1 call to CGI::Session::Driver::file::CORE:readline | ||
80 | 1 | 15µs | 1 | 3µs | $rv .= $_; # spent 3µs making 1 call to CGI::Session::Driver::file::CORE:readline |
81 | } | ||||
82 | 1 | 7µs | close(FH); # spent 7µs making 1 call to CGI::Session::Driver::file::CORE:close | ||
83 | return $rv; | ||||
84 | } | ||||
85 | |||||
- - | |||||
88 | # spent 1.11ms (194µs+911µs) within CGI::Session::Driver::file::store which was called 2 times, avg 553µs/call:
# 2 times (194µs+911µs) by CGI::Session::flush at line 262 of /usr/local/src/github.com/foswiki/core/lib/CPAN/lib/CGI/Session.pm, avg 553µs/call | ||||
89 | 28 | 674µs | my $self = shift; | ||
90 | my ($sid, $datastr) = @_; | ||||
91 | |||||
92 | 2 | 430µs | my $path = $self->_file($sid); # spent 430µs making 2 calls to CGI::Session::Driver::file::_file, avg 215µs/call | ||
93 | |||||
94 | # make certain our filehandle goes away when we fall out of scope | ||||
95 | local *FH; | ||||
96 | |||||
97 | my $mode = O_WRONLY|$NO_FOLLOW; | ||||
98 | |||||
99 | # kill symlinks when we spot them | ||||
100 | 2 | 39µs | if (-l $path) { # spent 39µs making 2 calls to CGI::Session::Driver::file::CORE:ftlink, avg 20µs/call | ||
101 | unlink($path) or | ||||
102 | return $self->set_error("store(): '$path' appears to be a symlink and I couldn't remove it: $!"); | ||||
103 | } | ||||
104 | |||||
105 | 2 | 11µs | $mode = O_RDWR|O_CREAT|O_EXCL unless -e $path; # spent 11µs making 2 calls to CGI::Session::Driver::file::CORE:ftis, avg 6µs/call | ||
106 | |||||
107 | 2 | 64µs | sysopen(FH, $path, $mode, $self->{UMask}) or return $self->set_error( "store(): couldn't open '$path': $!" ); # spent 64µs making 2 calls to CGI::Session::Driver::file::CORE:sysopen, avg 32µs/call | ||
108 | |||||
109 | # sanity check to make certain we're still ok | ||||
110 | 2 | 10µs | if (-l $path) { # spent 10µs making 2 calls to CGI::Session::Driver::file::CORE:ftlink, avg 5µs/call | ||
111 | return $self->set_error("store(): '$path' is a symlink, check for malicious processes"); | ||||
112 | } | ||||
113 | |||||
114 | # prevent race condition (RT#17949) | ||||
115 | 2 | 14µs | $self->{NoFlock} || flock(FH, LOCK_EX) or return $self->set_error( "store(): couldn't lock '$path': $!" ); # spent 14µs making 2 calls to CGI::Session::Driver::file::CORE:flock, avg 7µs/call | ||
116 | 2 | 145µs | truncate(FH, 0) or return $self->set_error( "store(): couldn't truncate '$path': $!" ); # spent 145µs making 2 calls to CGI::Session::Driver::file::CORE:truncate, avg 73µs/call | ||
117 | |||||
118 | 2 | 24µs | print FH $datastr; # spent 24µs making 2 calls to CGI::Session::Driver::file::CORE:print, avg 12µs/call | ||
119 | 2 | 175µs | close(FH) or return $self->set_error( "store(): couldn't close '$path': $!" ); # spent 175µs making 2 calls to CGI::Session::Driver::file::CORE:close, avg 87µs/call | ||
120 | return 1; | ||||
121 | } | ||||
122 | |||||
123 | |||||
124 | sub remove { | ||||
125 | my $self = shift; | ||||
126 | my ($sid) = @_; | ||||
127 | my $path = $self -> _file($sid); | ||||
128 | unlink($path) or return $self->set_error( "remove(): couldn't unlink '$path': $!" ); | ||||
129 | return 1; | ||||
130 | } | ||||
131 | |||||
132 | |||||
133 | sub traverse { | ||||
134 | my $self = shift; | ||||
135 | my ($coderef) = @_; | ||||
136 | |||||
137 | unless ( $coderef && ref($coderef) && (ref $coderef eq 'CODE') ) { | ||||
138 | croak "traverse(): usage error"; | ||||
139 | } | ||||
140 | |||||
141 | opendir( DIRHANDLE, $self->{Directory} ) | ||||
142 | or return $self->set_error( "traverse(): couldn't open $self->{Directory}, " . $! ); | ||||
143 | |||||
144 | my $filename_pattern = $FileName; | ||||
145 | $filename_pattern =~ s/\./\\./g; | ||||
146 | $filename_pattern =~ s/\%s/(\.\+)/g; | ||||
147 | while ( my $filename = readdir(DIRHANDLE) ) { | ||||
148 | next if $filename =~ m/^\.\.?$/; | ||||
149 | my $full_path = File::Spec->catfile($self->{Directory}, $filename); | ||||
150 | my $mode = (stat($full_path))[2] | ||||
151 | or return $self->set_error( "traverse(): stat failed for $full_path: " . $! ); | ||||
152 | next if S_ISDIR($mode); | ||||
153 | if ( $filename =~ /^$filename_pattern$/ ) { | ||||
154 | $coderef->($1); | ||||
155 | } | ||||
156 | } | ||||
157 | closedir( DIRHANDLE ); | ||||
158 | return 1; | ||||
159 | } | ||||
160 | |||||
161 | |||||
162 | # spent 7µs within CGI::Session::Driver::file::DESTROY which was called:
# once (7µs+0s) by Foswiki::LoginManager::finish at line 183 of /usr/local/src/github.com/foswiki/core/lib/Foswiki/LoginManager.pm | ||||
163 | 1 | 10µs | my $self = shift; | ||
164 | } | ||||
165 | |||||
166 | 1 | 9µs | 1; | ||
167 | |||||
168 | __END__; | ||||
sub CGI::Session::Driver::file::CORE:close; # opcode | |||||
sub CGI::Session::Driver::file::CORE:flock; # opcode | |||||
# spent 8µs within CGI::Session::Driver::file::CORE:ftdir which was called:
# once (8µs+0s) by CGI::Session::Driver::file::init at line 32 | |||||
sub CGI::Session::Driver::file::CORE:ftis; # opcode | |||||
# spent 59µs within CGI::Session::Driver::file::CORE:ftlink which was called 5 times, avg 12µs/call:
# 2 times (39µs+0s) by CGI::Session::Driver::file::store at line 100, avg 20µs/call
# 2 times (10µs+0s) by CGI::Session::Driver::file::store at line 110, avg 5µs/call
# once (9µs+0s) by CGI::Session::Driver::file::retrieve at line 69 | |||||
# spent 6µs within CGI::Session::Driver::file::CORE:match which was called 3 times, avg 2µs/call:
# 3 times (6µs+0s) by CGI::Session::Driver::file::_file at line 50, avg 2µs/call | |||||
# spent 24µs within CGI::Session::Driver::file::CORE:print which was called 2 times, avg 12µs/call:
# 2 times (24µs+0s) by CGI::Session::Driver::file::store at line 118, avg 12µs/call | |||||
sub CGI::Session::Driver::file::CORE:readline; # opcode | |||||
# spent 9µs within CGI::Session::Driver::file::CORE:subst which was called 3 times, avg 3µs/call:
# 3 times (9µs+0s) by CGI::Session::Driver::file::_file at line 48, avg 3µs/call | |||||
sub CGI::Session::Driver::file::CORE:sysopen; # opcode | |||||
# spent 145µs within CGI::Session::Driver::file::CORE:truncate which was called 2 times, avg 73µs/call:
# 2 times (145µs+0s) by CGI::Session::Driver::file::store at line 116, avg 73µs/call |