Skip to content
Browse files

Fix Solaris in ProcFS

Fix BSD v5.12 %$hash issue
Make ppid a non-dependency
  • Loading branch information...
1 parent 14ea842 commit 8c9c354c2f596a67926d7e80ef04304ae761674d @SineSwiper committed Oct 24, 2012
Showing with 43 additions and 35 deletions.
  1. +16 −16 .travis.yml
  2. +1 −1 README.pod
  3. +1 −5 dist.ini
  4. +1 −1 lib/P9Y/ProcessTable/BSD.pm
  5. +17 −5 lib/P9Y/ProcessTable/ProcFS.pm
  6. +4 −5 lib/P9Y/ProcessTable/Process.pm
  7. +2 −1 t/51-basic.t
  8. +1 −1 weaver.ini
View
32 .travis.yml
@@ -1,16 +1,16 @@
-language: perl
-perl:
- - "5.16"
- - "5.14"
- - "5.12"
- - "5.10"
-
-install:
- # Deal with all of the DZIL dependancies, quickly and quietly
- - cpanm --quiet --notest --skip-satisfied Dist::Zilla
- - dzil authordeps | grep -vP '[^\w:]' | xargs -n 5 -P 10 cpanm --quiet --notest --skip-satisfied
-
- - export RELEASE_TESTING=1 AUTOMATED_TESTING=1 AUTHOR_TESTING=1 HARNESS_OPTIONS=j10:c HARNESS_TIMER=1
- - dzil listdeps | grep -vP '[^\w:]' | cpanm --verbose
-script:
- - dzil smoke --release --author
+language: perl
+perl:
+ - "5.16"
+ - "5.14"
+ - "5.12"
+ - "5.10"
+
+install:
+ # Deal with all of the DZIL dependancies, quickly and quietly
+ - cpanm --quiet --notest --skip-satisfied Dist::Zilla
+ - dzil authordeps | grep -vP '[^\w:]' | xargs -n 5 -P 10 cpanm --quiet --notest --skip-satisfied
+
+ - export RELEASE_TESTING=1 AUTOMATED_TESTING=1 AUTHOR_TESTING=1 HARNESS_OPTIONS=j10:c HARNESS_TIMER=1
+ - dzil listdeps | grep -vP '[^\w:]' | cpanm --verbose
+script:
+ - dzil smoke --release --author
View
2 README.pod
@@ -234,7 +234,7 @@ those networks/channels and get help:
irc.perl.org
-You can connect to the server at 'irc.perl.org' and join this channel: #distzilla then talk to this person for help: SineSwiper.
+You can connect to the server at 'irc.perl.org' and join this channel: #win32 then talk to this person for help: SineSwiper.
=back
View
6 dist.ini
@@ -23,14 +23,10 @@ copyright_year = 2012
-remove = Test::Compile
-remove = Test::UseAllModules
-remove = Test::Version
-; x_irc param isn't passing for some reason
--remove = MetaResourcesFromGit
; Special case in PodWeaver
-remove = PodWeaver
-[MetaResourcesFromGit]
-x_irc = irc://irc.perl.org/#win32
-bugtracker.web = https://github.com/%a/%r/issues
+x_irc = irc://irc.perl.org/#win32
[FileFinder::ByName / NoOSMods]
dir = lib
View
2 lib/P9Y/ProcessTable/BSD.pm
@@ -81,7 +81,7 @@ sub _process_hash {
};
my @state;
- foreach my $key (keys $states) {
+ foreach my $key (keys %$states) {
push @state, $states->{$key} if $info->{$key};
}
$hash->{state} = join ' ', @state;
View
22 lib/P9Y/ProcessTable/ProcFS.pm
@@ -125,12 +125,12 @@ sub _process_hash {
$hash->{ ttlflt} = $hash->{ minflt} + $hash->{ majflt};
$hash->{cttlflt} = $hash->{cminflt} + $hash->{cmajflt};
}
- elsif ($^O eq /solaris|sunos/i) {
+ elsif ($^O =~ /solaris|sunos/i) {
### Solaris ###
- my $ptr = $Config{longsize} >= 8 ? '%Q' : '%I';
+ my $ptr = $Config{longsize} >= 8 ? 'Q' : 'I';
my $data = $pdir->file('status')->slurp;
- my @data = unpack '%I[10]'.$ptr.'[4]%I[12]%C%I[4]', $data;
+ my @data = unpack 'I[10]'.$ptr.'[4]I[12]CI[4]', $data;
# 1 int pr_flags; /* flags (see below) */
# 2 int pr_nlwp; /* number of active lwps in the process */
@@ -151,7 +151,13 @@ sub _process_hash {
# 17 timestruc_t pr_stime; /* process system cpu time */
# 19 timestruc_t pr_cutime; /* sum of children's user times */
# 21 timestruc_t pr_cstime; /* sum of children's system times */
-
+
+ # some Solaris versions don't have pr_nzomb
+ if ($data[2] == $pid) {
+ @data = unpack 'I[9]'.$ptr.'[4]I[12]CI[4]', $data;
+ splice @data, 2, 0, (0);
+ }
+
state $stat_loc = [ qw(
flags threads . pid ppid pgrp sess . . . . . . . utime . stime . cutime . cstime .
) ];
@@ -166,7 +172,7 @@ sub _process_hash {
$hash->{ctime} = $hash->{cutime} + $hash->{stime};
$data = $pdir->file('psinfo')->slurp;
- @data = unpack '%I[11]'.$ptr.'[3]%I%S[2]%I[6]%16A%80A%I', $data;
+ @data = unpack 'I[11]'.$ptr.'[3]IS[2]I[6]A[16]A[80]I', $data;
#define PRFNSZ 16 /* Maximum size of execed filename */
#define PRARGSZ 80 /* number of chars of arguments */
@@ -195,6 +201,12 @@ sub _process_hash {
# 24 char pr_psargs[PRARGSZ]; /* initial characters of arg list */
# 25 int pr_wstat; /* if zombie, the wait() status */
+ # some Solaris versions don't have pr_nzomb
+ if ($data[2] == $pid) {
+ @data = unpack 'I[10]'.$ptr.'[3]IS[2]I[6]A[16]A[80]I', $data;
+ splice @data, 2, 0, (0);
+ }
+
state $psinfo_loc = [ qw(
. threads . pid ppid pgrp sess uid euid gid egid . size rss ttynum pctcpu pctmem start time ctime fname cmdline .
) ];
View
9 lib/P9Y/ProcessTable/Process.pm
@@ -31,7 +31,7 @@ has euid => ( is => 'rwp', predicate => 1 );
has egid => ( is => 'rwp', predicate => 1 );
has suid => ( is => 'rwp', predicate => 1 );
has sgid => ( is => 'rwp', predicate => 1 );
-has ppid => ( is => 'rwp', required => 1 );
+has ppid => ( is => 'rwp', predicate => 1 );
has pgrp => ( is => 'rwp', predicate => 1 );
has sess => ( is => 'rwp', predicate => 1 );
@@ -157,8 +157,7 @@ Unlike the other data methods (below), these two are settable by passing a value
== Process data methods
-Depending on the OS, the following methods are available. Also, all methods also have a {has_*} predicate, except for {pid} and {ppid} which
-are required (ie: exists on all OSs).
+Depending on the OS, the following methods are available. Also, all methods also have a {has_*} predicate, except for {pid}.
pid Process ID
uid UID of process
@@ -205,8 +204,8 @@ are required (ie: exists on all OSs).
pctcpu Percent CPU used
pctmem Percent memory used
-Make no assumptions about what is available and what is not, besides maybe {pid} & {ppid}. Instead, use the {has_*} methods and plan for
-alternatives if that data isn't available.
+Make no assumptions about what is available and what is not, not even {ppid}. Instead, use the {has_*} methods and plan for alternatives
+if that data isn't available.
= CAVEATS
View
3 t/51-basic.t
@@ -1,4 +1,4 @@
-use Test::Most tests => 3;
+use Test::Most tests => 4;
use P9Y::ProcessTable;
my @tbl;
@@ -7,6 +7,7 @@ lives_ok { @tbl = P9Y::ProcessTable->table } 'get table';
cmp_ok(@tbl, '>', 5, 'more than 5 processes');
my $p = P9Y::ProcessTable->process();
+isa_ok($p, 'P9Y::ProcessTable::Process') || always_explain P9Y::ProcessTable->_process_hash($$);
# neuter the ENV vars before posting
if ($p->has_environ) {
View
2 weaver.ini
@@ -29,7 +29,7 @@ websites = none
repository_link = none
bugs = metadata
bugs_content = Please report any bugs or feature requests via L<{WEB}|GitHub>.
-irc = irc.perl.org, #distzilla, SineSwiper
+irc = irc.perl.org, #win32, SineSwiper
[Authors]
[Legal]

0 comments on commit 8c9c354

Please sign in to comment.
Something went wrong with that request. Please try again.