sub spawn($) {
my($cmd)=@_;
$cmd.=" >&2";
- system $cmd or return 1;
- warn "$cmd: $!";
- return 0;
+ system $cmd and die "$cmd: $!";
}
my($trash,$min,$hour)=localtime;
my $minutes=$hour*60+$min;
die "state!={s|0|1}" if $newstate!~/^[s01]$/;
sub setstate() {
info "->$newstate";
+ writefile $statefile,"$newstate\n" if $state ne $newstate;
+ logmsg "$state->$newstate" if $state ne $newstate;
my $both={"s"=>[0,0],"0"=>[1,0],"1"=>[1,1]}->{$newstate};
- $state eq $newstate or unlink $statefile or warn "$statefile: $!";
- ( spawn "$usbrelay 1 ".$both->[0]
- and spawn "$usbrelay 2 ".$both->[1])
- or do { unlink $statefile; die "usbrelay error"; };
- $state eq $newstate or writefile $statefile,"$newstate\n";
+ spawn "$usbrelay 1 ".$both->[0];
+ spawn "$usbrelay 2 ".$both->[1];
info "\n";
- logmsg "$state->$newstate" if $state ne $newstate;
}
my $newreset=shift;
die "Excessive args: ".join(" ",@ARGV) if @ARGV;