diff --git a/bean-query-daemon-lib.pl b/bean-query-daemon-lib.pl index ef3eafa..ad4eb1b 100644 --- a/bean-query-daemon-lib.pl +++ b/bean-query-daemon-lib.pl @@ -30,8 +30,12 @@ sub BeancountQuerySubmit($;$) { $BEANCOUNT_QUERY{format} = $format if defined $format; (tied %BEANCOUNT_QUERY)->shunlock; while (not defined $BEANCOUNT_QUERY{fifoName}) { sleep 1; } - die "Ceci n'est pas une pipe: BEANCOUNT_QUERY{fifoName}, $BEANCOUNT_QUERY{fifoName}:$!" - unless (-p $BEANCOUNT_QUERY{fifoName}); + unless (-p $BEANCOUNT_QUERY{fifoName}) { + (tied %BEANCOUNT_QUERY)->shlock; + $BEANCOUNT_QUERY{question} = $BEANCOUNT_QUERY{format} = undef; + (tied %BEANCOUNT_QUERY)->shunlock; + die "Ceci n'est pas une pipe: BEANCOUNT_QUERY{fifoName}, $BEANCOUNT_QUERY{fifoName}:$!" + } (tied %BEANCOUNT_QUERY)->shlock; return $BEANCOUNT_QUERY{fifoName}; } diff --git a/bean-query-goofy-daemon.plx b/bean-query-goofy-daemon.plx index 3bd2bea..8cfef8c 100755 --- a/bean-query-goofy-daemon.plx +++ b/bean-query-goofy-daemon.plx @@ -77,7 +77,7 @@ while (1) { (tied %query)->shlock; print STDERR "clearing fifo, $query{fifoName}..." if $VERBOSE > 2; no autodie 'unlink'; unlink($query{fifoName}); - $query{fifoName} = undef; + %query = (); (tied %query)->shunlock; print STDERR "fifo cleared & lock released." if $VERBOSE > 2; } @@ -87,9 +87,9 @@ while (1) { } elsif ($query{question} !~ /^[\-\@\w.\s\"\'\_\(\)]+$/) { print STDERR "Query string $query{question} looks suspicious, not running beancount query!\n"; (tied %query)->shlock; - $query{question} = $query{format} = undef; $query{fifoName} = mktemp("REJECTED_beancount-query-fifo-this-file-does-not-exist_${$}_XXXXXXXXX"); (tied %query)->shunlock; + sleep 2; } elsif (defined $query{format} and $query{format} !~ /^(?:csv|text)$/) { print STDERR "format string $query{format} is not text or csv, not running beancount query!\n"; (tied %query)->shlock; @@ -100,7 +100,7 @@ while (1) { my @cmd = ($BEANCOUNT_QUERY_CMD); push(@cmd, '-f', $query{format}) if defined $query{format}; push(@cmd, $LOAD_FILE, $query{question}); - print STDERR "Running query: $query{question}\n" if $VERBOSE > 0; + print STDERR "Runing query: $query{question}\n" if $VERBOSE > 0; open(my $beancountFH, "-|", @cmd); print STDERR "Running ", join(" ", @cmd), "\n" if $VERBOSE > 1; (tied %query)->shlock;