--- a/wgnd-mkstruct.pl Fri Apr 27 16:30:05 2012 +0200
+++ b/wgnd-mkstruct.pl Mon Apr 30 11:01:27 2012 +0200
@@ -33,7 +33,26 @@
my $map = 'wgnd-mkstruct.map.pl';
-sub trace { print @_ if $ENV{DEBUG}; }
+BEGIN {
+
+ use Sys::Syslog;
+ openlog($ME, 'ndelay,nowait,pid', 'LOG_USER');
+ $SIG{__WARN__} = sub {
+ warn @_ if not defined $^S;
+ print STDERR "@_";
+ syslog('warning', "@_");
+ };
+ $SIG{__DIE__} = sub {
+ die @_ if not defined $^S;
+ print STDERR "@_";
+ syslog('err', "@_");
+ exit $?;
+ };
+
+ sub dolog { print "@_"; syslog('info', "@_"); }
+ sub trace { print @_ if $ENV{DEBUG}; }
+
+}
GetOptions(
"map=s" => \$map,
@@ -67,10 +86,10 @@
} elsif ($pid == 0) {
my $e = shift;
my $name = $e->fullname;
- print "$name was created\n" if $e->IN_CREATE;
- print "$name is no longer mounted\n" if $e->IN_UNMOUNT;
- print "$name is gone\n" if $e->IN_IGNORED;
- print "events for $name have been lost\n" if $e->IN_Q_OVERFLOW;
+ dolog "$name was created\n" if $e->IN_CREATE;
+ dolog "$name is no longer mounted\n" if $e->IN_UNMOUNT;
+ dolog "$name is gone\n" if $e->IN_IGNORED;
+ dolog "events for $name have been lost\n" if $e->IN_Q_OVERFLOW;
exec @rsync, $source->{$e->{w}->{name}}, $name;
warn "Can't exec: $!\n";
}
@@ -83,11 +102,14 @@
$inotify->poll;
while (-1 != (my $pid = wait)) {
my $e = $? >> 8;
- print "${ME}[$pid]: exit $e\n";
+ dolog "child ${ME}[$pid]: exit $e\n";
}
}
+END {
+ closelog;
+}
__END__