From f46603f6d1c66c3a479e561480feec743daa6b02 Mon Sep 17 00:00:00 2001 From: Jan Kratochvil Date: Sat, 8 Jan 2022 10:02:44 +0100 Subject: [PATCH] bin/heat: Keep the $statefile even after failed usbrelay. --- bin/heat | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/bin/heat b/bin/heat index f30ffe1..1da4a35 100755 --- 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; -- 1.8.3.1