bin/heat: Keep the $statefile even after failed usbrelay.
[nethome.git] / bin / heat
index f30ffe1..1da4a35 100755 (executable)
--- a/bin/heat
+++ b/bin/heat
@@ -36,9 +36,7 @@ sub logmsg($) {
 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;
@@ -145,14 +143,12 @@ if (!defined $newstate) {
 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;