forked from Normation/rudder-techniques
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Normation#301 from Kegeruneku/bug_4721/int/4721_in…
…tegrate_aix_process_date_patch Bug 4721/int/4721 integrate aix process date patch
- Loading branch information
Showing
2 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
rudder-agent/SOURCES/patches/fusioninventory/2.3.6/0003-unix-ps-etime-usage.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
--- a/lib/FusionInventory/Agent/Tools/Unix.pm 2014-04-17 16:06:39.112811462 +0200 | ||
+++ a/lib/FusionInventory/Agent/Tools/Unix.pm 2014-04-17 16:08:50.985349955 +0200 | ||
@@ -285,7 +285,7 @@ | ||
sub _getProcessesOther { | ||
my (%params) = ( | ||
command => | ||
- 'ps -A -o user,pid,pcpu,pmem,vsz,tty,stime,time,' . | ||
+ 'ps -A -o user,pid,pcpu,pmem,vsz,tty,etime,time' . ',' . | ||
($OSNAME eq 'solaris' ? 'comm' : 'command'), | ||
@_ | ||
); | ||
@@ -295,15 +295,15 @@ | ||
# skip headers | ||
my $line = <$handle>; | ||
|
||
- my (undef, undef, undef, $day, $month, $year) = localtime(time()); | ||
- $year = $year + 1900; | ||
- $month = $month + 1; | ||
+ # get the current timestamp | ||
+ my $localtime = time(); | ||
|
||
my @processes; | ||
|
||
while ($line = <$handle>) { | ||
+ | ||
next unless $line =~ | ||
- /^ | ||
+ /^ \s* | ||
(\S+) \s+ | ||
(\S+) \s+ | ||
(\S+) \s+ | ||
@@ -312,15 +312,16 @@ | ||
(\S+) \s+ | ||
(\S+) \s+ | ||
\S+ \s+ | ||
- (.*\S) | ||
+ (\S.*\S) | ||
/x; | ||
+ | ||
my $user = $1; | ||
my $pid = $2; | ||
my $cpu = $3; | ||
my $mem = $4; | ||
my $vsz = $5; | ||
my $tty = $6; | ||
- my $start = $7; | ||
+ my $etime = $7; | ||
my $cmd = $8; | ||
|
||
# Rudder #4314/Alex Tkatchenko: Workaround for a CFEngine bug that truncates | ||
@@ -337,7 +338,7 @@ | ||
MEM => $mem, | ||
VIRTUALMEMORY => $vsz, | ||
TTY => $tty, | ||
- STARTED => _getProcessStartTime($start, $day, $month, $year, $pid), | ||
+ STARTED => _getProcessStartTime($pid,$localtime,$etime), | ||
CMD => $cmd | ||
}; | ||
} | ||
@@ -372,43 +373,45 @@ | ||
); | ||
my $monthPattern = join ('|', keys %month); | ||
|
||
-# consistant time format | ||
-sub _getProcessStartTime { | ||
- my ($start, $day, $month, $year, $pid) = @_; | ||
- | ||
- if ($start =~ /^(\d{1,2}):(\d{2})/) { | ||
- # 10:00PM | ||
- return sprintf("%04d-%02d-%02d %s", $year, $month, $day, $start); | ||
- } | ||
+# Computes a consistent process starting time from either the process | ||
+# PID (using /proc) or using the process etime value. | ||
+# Arguments: | ||
+# - pid : Process pid | ||
+# - localtime : Current timestamp | ||
+# - elapsedtime : Process etime value | ||
|
||
- if ($start =~ /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun)(\d{2})[AP]M/) { | ||
- # Sat03PM | ||
- my $start_day = $2; | ||
- return sprintf("%04d-%02d-%02d", $year, $month, $start_day); | ||
- } | ||
+sub _getProcessStartTime { | ||
|
||
- if ($start =~ /^($monthPattern)(\d{2})/) { | ||
- # Apr03 | ||
- my $start_month = $month{$1}; | ||
- my $start_day = $2; | ||
- return sprintf("%04d-%02d-%02d", $year, $start_month, $start_day); | ||
- } | ||
+ my $pid = shift; | ||
+ my $localtime = shift; | ||
+ my $elapsedtime = shift; | ||
|
||
- if ($start =~ /^(\d{1,2})($monthPattern)\d{1,2}/) { | ||
- # 5Oct10 | ||
- my $start_day = $1; | ||
- my $start_month = $month{$2}; | ||
- return sprintf("%04d-%02d-%02d", $year, $start_month, $start_day); | ||
- } | ||
+ my ($min, $hour, $day, $month, $year); | ||
|
||
if (-f "/proc/$pid") { | ||
# this will work only on OS with /proc/$pid like Linux and FreeBSD | ||
my $stat = stat("/proc/$pid"); | ||
- my (undef, $min, $hour, $day, $month, $year) = localtime($stat->ctime()); | ||
- $year = $year + 1900; | ||
- $month = $month + 1; | ||
- return sprintf("%04d-%02d-%02d %s:%s", $year, $month, $day, $hour, $min); | ||
+ (undef, $min, $hour, $day, $month, $year) = localtime($stat->ctime()); | ||
+ } else { | ||
+ # POSIX specifies that ps etime entry looks like [[dd-]hh:]mm:ss | ||
+ # if either day and hour are not present then they will eat | ||
+ # up the minutes and seconds so split on a non digit and reverse it: | ||
+ my ($psec, $pmin, $phour, $pday) = reverse split(/\D/, $elapsedtime); | ||
+ | ||
+ # Compute a timestamp from the process etime value | ||
+ # (ternary operators prevent perl from complaining about possibly undefined | ||
+ # values, initializing them as 0) | ||
+ my $etime_secs = $psec+($pmin*60)+($phour?$phour*60*60:0)+($pday?$pday*24*60*60:0); | ||
+ | ||
+ # Substract this timestamp from the current time, creating the date at which | ||
+ # the process was launched | ||
+ (undef, $min, $hour, $day, $month, $year) = localtime($localtime-$etime_secs); | ||
} | ||
+ | ||
+ # Output the final date, after completing it (time + UNIX epoch) | ||
+ $year = $year + 1900; | ||
+ $month = $month + 1; | ||
+ return sprintf("%04d-%02d-%02d %02d:%02d", $year, $month, $day, $hour, $min); | ||
} | ||
|
||
sub getRoutingTable { |