mirror of
https://gitlab.com/apparmor/apparmor
synced 2025-08-24 19:17:19 +00:00
This patch modifies the aa-eventd daemon to use the Date::Parse module
(TimeDate) package for parsing dates and fall back to using Date::Manip if Date::Parse isn't available -- Date::Manip is more commonly available, but is written solely in perl and is more general-purpose and heavyweight than Date::Parse. The DateTime package (datetime.perl.org) doesn't suffice as it it either uses Date::Manip internally and DateTime::Format::Strptime also isn't commonly available. Given that our regex for identifying dates in syslog is pretty static; POSIX::strptime (implementing strptime(3)) functionality would probably be the best way to go -- except that perl's POSIX doesn't include strptime and POSIX::strptime is another not commonly available package. Sigh.
This commit is contained in:
parent
7964feb031
commit
51a676b3b4
@ -24,7 +24,6 @@
|
||||
use strict;
|
||||
|
||||
use Data::Dumper;
|
||||
use Date::Parse;
|
||||
use DBI;
|
||||
use Fcntl;
|
||||
use File::Temp qw(tempfile);
|
||||
@ -101,6 +100,8 @@ my @verbose_buffer;
|
||||
my @summary_buffer;
|
||||
my @terse_buffer;
|
||||
|
||||
my $date_module = "None";
|
||||
|
||||
my %templates = (
|
||||
"path" => "(time,counter,type,profile,sdmode,mode,resource,prog,pid,severity) VALUES(?,?,'path',?,?,?,?,?,?,?)",
|
||||
"link" => "(time,counter,type,profile,sdmode,resource,target,prog,pid,severity) VALUES(?,?,'link',?,?,?,?,?,?,?)",
|
||||
@ -154,6 +155,21 @@ sub daemonize {
|
||||
open STDERR, '>&STDOUT' or die "Can't dup stdout: $!";
|
||||
}
|
||||
|
||||
sub parsedate ($) {
|
||||
my $time = shift;
|
||||
my $timestamp = 0;
|
||||
if ($date_module eq 'TimeDate') {
|
||||
$timestamp = Date::Parse::str2time($time);
|
||||
} elsif ($date_module eq 'DateManip') {
|
||||
$timestamp = Date::Manip::UnixDate(Date::Manip::ParseDateString($time), '%s');
|
||||
} else {
|
||||
errlog "No date module found, exiing";
|
||||
kill HUP => -$$;
|
||||
}
|
||||
|
||||
return $timestamp;
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
# database handling functions
|
||||
|
||||
@ -406,7 +422,7 @@ sub process_event ($$) {
|
||||
# have we rolled over to another second yet?
|
||||
if($time ne $lasttime) {
|
||||
$counter = 0;
|
||||
$timestamp = str2time($time);
|
||||
$timestamp = parsedate($time);
|
||||
$lasttime = $time;
|
||||
}
|
||||
} else {
|
||||
@ -985,6 +1001,20 @@ $SIG{INT} = \&sig_handler;
|
||||
$SIG{TERM} = \&sig_handler;
|
||||
$SIG{CHLD} = 'IGNORE';
|
||||
|
||||
# Sigh, portable dates in perl sucks
|
||||
eval "use Date::Parse";
|
||||
if (!$@) {
|
||||
$date_module = 'TimeDate'
|
||||
} else {
|
||||
eval "use Date::Manip";
|
||||
if (!$@) {
|
||||
$date_module = 'DateManip'
|
||||
} else {
|
||||
errlog "Unable to load Date module; use either TimeDate or Date::Manip";
|
||||
$finished = 1;
|
||||
}
|
||||
}
|
||||
|
||||
# if they want us to write a pid, do it
|
||||
if($pidfile) {
|
||||
if(open(PIDFILE, ">$pidfile")) {
|
||||
|
@ -38,8 +38,11 @@ Url: http://forge.novell.com/modules/xfmod/project/?apparmor
|
||||
Requires: perl
|
||||
Requires: /bin/sh
|
||||
AutoReqProv: no
|
||||
Requires: perl-DateManip
|
||||
%else
|
||||
Requires: perl-TimeDate
|
||||
%endif
|
||||
Requires: perl-TimeDate perl-DBI perl-DBD-SQLite perl-File-Tail perl-gettext
|
||||
Requires: perl-DBI perl-DBD-SQLite perl-File-Tail perl-gettext
|
||||
Obsoletes: subdomain-utils
|
||||
Provides: subdomain-utils
|
||||
|
||||
@ -90,6 +93,8 @@ fi
|
||||
|
||||
%changelog
|
||||
* Wed Jan 17 2007 - sbeattie@suse.de
|
||||
- Fall back to Date::Manip if Date::Parse is not available
|
||||
* Wed Jan 17 2007 - sbeattie@suse.de
|
||||
- Add perl-gettext to list of dependencies
|
||||
* Tue Dec 12 2006 - sbeattie@suse.de
|
||||
- Add ksh to list of shells that should not be profiled
|
||||
|
Loading…
x
Reference in New Issue
Block a user