2
0
mirror of https://gitlab.com/apparmor/apparmor synced 2025-08-25 19:47:23 +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:
Steve Beattie 2007-01-17 12:22:31 +00:00
parent 7964feb031
commit 51a676b3b4
2 changed files with 38 additions and 3 deletions

View File

@ -24,7 +24,6 @@
use strict; use strict;
use Data::Dumper; use Data::Dumper;
use Date::Parse;
use DBI; use DBI;
use Fcntl; use Fcntl;
use File::Temp qw(tempfile); use File::Temp qw(tempfile);
@ -101,6 +100,8 @@ my @verbose_buffer;
my @summary_buffer; my @summary_buffer;
my @terse_buffer; my @terse_buffer;
my $date_module = "None";
my %templates = ( my %templates = (
"path" => "(time,counter,type,profile,sdmode,mode,resource,prog,pid,severity) VALUES(?,?,'path',?,?,?,?,?,?,?)", "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',?,?,?,?,?,?,?)", "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: $!"; 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 # database handling functions
@ -406,7 +422,7 @@ sub process_event ($$) {
# have we rolled over to another second yet? # have we rolled over to another second yet?
if($time ne $lasttime) { if($time ne $lasttime) {
$counter = 0; $counter = 0;
$timestamp = str2time($time); $timestamp = parsedate($time);
$lasttime = $time; $lasttime = $time;
} }
} else { } else {
@ -985,6 +1001,20 @@ $SIG{INT} = \&sig_handler;
$SIG{TERM} = \&sig_handler; $SIG{TERM} = \&sig_handler;
$SIG{CHLD} = 'IGNORE'; $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 they want us to write a pid, do it
if($pidfile) { if($pidfile) {
if(open(PIDFILE, ">$pidfile")) { if(open(PIDFILE, ">$pidfile")) {

View File

@ -38,8 +38,11 @@ Url: http://forge.novell.com/modules/xfmod/project/?apparmor
Requires: perl Requires: perl
Requires: /bin/sh Requires: /bin/sh
AutoReqProv: no AutoReqProv: no
Requires: perl-DateManip
%else
Requires: perl-TimeDate
%endif %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 Obsoletes: subdomain-utils
Provides: subdomain-utils Provides: subdomain-utils
@ -90,6 +93,8 @@ fi
%changelog %changelog
* Wed Jan 17 2007 - sbeattie@suse.de * 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 - Add perl-gettext to list of dependencies
* Tue Dec 12 2006 - sbeattie@suse.de * Tue Dec 12 2006 - sbeattie@suse.de
- Add ksh to list of shells that should not be profiled - Add ksh to list of shells that should not be profiled