wgnd-mkstruct.pl
changeset 13 71d654155a56
parent 9 0ed7846bef6f
equal deleted inserted replaced
12:0b5decd90ad8 13:71d654155a56
    31 # File::Rsync in squeeze does not support --xattrs yet
    31 # File::Rsync in squeeze does not support --xattrs yet
    32 #use File::Rsync;
    32 #use File::Rsync;
    33 
    33 
    34 my $map = 'wgnd-mkstruct.map.pl';
    34 my $map = 'wgnd-mkstruct.map.pl';
    35 
    35 
    36 sub trace { print @_ if $ENV{DEBUG}; }
    36 BEGIN {
       
    37 
       
    38     use Sys::Syslog;
       
    39     openlog($ME, 'ndelay,nowait,pid', 'LOG_USER');
       
    40     $SIG{__WARN__} = sub {
       
    41         warn @_ if not defined $^S;
       
    42         print STDERR "@_";
       
    43         syslog('warning', "@_");
       
    44     };
       
    45     $SIG{__DIE__} = sub {
       
    46         die @_ if not defined $^S;
       
    47         print STDERR "@_";
       
    48         syslog('err', "@_");
       
    49         exit $?;
       
    50     };
       
    51 
       
    52     sub dolog { print "@_"; syslog('info', "@_"); }
       
    53     sub trace { print @_ if $ENV{DEBUG}; }
       
    54 
       
    55 }
    37 
    56 
    38 GetOptions(
    57 GetOptions(
    39     "map=s"  => \$map,
    58     "map=s"  => \$map,
    40     "h|help" => sub { pod2usage( -verbose => 0, -exitval => 0 ) },
    59     "h|help" => sub { pod2usage( -verbose => 0, -exitval => 0 ) },
    41     "m|man"  => sub {
    60     "m|man"  => sub {
    65             if (not defined $pid) {
    84             if (not defined $pid) {
    66                 warn "Can't fork: $!\n";
    85                 warn "Can't fork: $!\n";
    67             } elsif ($pid == 0) {
    86             } elsif ($pid == 0) {
    68                 my $e = shift;
    87                 my $e = shift;
    69                 my $name = $e->fullname;
    88                 my $name = $e->fullname;
    70                 print "$name was created\n" if $e->IN_CREATE;
    89                 dolog "$name was created\n" if $e->IN_CREATE;
    71                 print "$name is no longer mounted\n" if $e->IN_UNMOUNT;
    90                 dolog "$name is no longer mounted\n" if $e->IN_UNMOUNT;
    72                 print "$name is gone\n" if $e->IN_IGNORED;
    91                 dolog "$name is gone\n" if $e->IN_IGNORED;
    73                 print "events for $name have been lost\n" if $e->IN_Q_OVERFLOW;
    92                 dolog "events for $name have been lost\n" if $e->IN_Q_OVERFLOW;
    74                 exec @rsync, $source->{$e->{w}->{name}}, $name;
    93                 exec @rsync, $source->{$e->{w}->{name}}, $name;
    75                 warn "Can't exec: $!\n";
    94                 warn "Can't exec: $!\n";
    76             }
    95             }
    77 
    96 
    78         }) or die "Can't add watch: $!\n";
    97         }) or die "Can't add watch: $!\n";
    81 while (1) {
   100 while (1) {
    82 
   101 
    83     $inotify->poll;
   102     $inotify->poll;
    84     while (-1 != (my $pid = wait)) {
   103     while (-1 != (my $pid = wait)) {
    85         my $e = $? >> 8;
   104         my $e = $? >> 8;
    86         print "${ME}[$pid]: exit $e\n";
   105         dolog "child ${ME}[$pid]: exit $e\n";
    87     }
   106     }
    88 
   107 
    89 }
   108 }
    90 
   109 
       
   110 END {
       
   111     closelog;
       
   112 }
    91 
   113 
    92 __END__
   114 __END__
    93 
   115 
    94 =pod
   116 =pod
    95 
   117