From c7b2386ff6e5554c183a27a3fad5542560f50cb1 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Tue, 29 Sep 2020 12:29:40 -0700 Subject: [PATCH] Fix "unable to close filehandle __ANONIO__ properly" warning --- PBot/MessageHistory_SQLite.pm | 16 +++++++++++++--- PBot/PBot.pm | 12 ++++++------ PBot/ProcessManager.pm | 2 ++ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/PBot/MessageHistory_SQLite.pm b/PBot/MessageHistory_SQLite.pm index a39938f7..68eb01eb 100644 --- a/PBot/MessageHistory_SQLite.pm +++ b/PBot/MessageHistory_SQLite.pm @@ -51,8 +51,15 @@ sub sqlite_commit_interval_trigger { sub sqlite_debug_trigger { my ($self, $section, $item, $newvalue) = @_; - $self->{dbh}->trace($self->{dbh}->parse_trace_flags("SQL|$newvalue")) if defined $self->{dbh}; + if ($newvalue) { + open $self->{trace_layer}, '>:via(PBot::SQLiteLoggerLayer)', PBot::SQLiteLogger->new(pbot => $self->{pbot}); + } else { + close $self->{trace_layer} if $self->{trace_layer}; + delete $self->{trace_layer}; + } + + $self->{dbh}->trace($self->{dbh}->parse_trace_flags("SQL|$newvalue")) if defined $self->{dbh}; } sub begin { @@ -67,8 +74,10 @@ sub begin { my $sqlite_debug = $self->{pbot}->{registry}->get_value('messagehistory', 'sqlite_debug'); use PBot::SQLiteLoggerLayer; use PBot::SQLiteLogger; - open $self->{trace_layer}, '>:via(PBot::SQLiteLoggerLayer)', PBot::SQLiteLogger->new(pbot => $self->{pbot}); - $self->{dbh}->trace($self->{dbh}->parse_trace_flags("SQL|$sqlite_debug"), $self->{trace_layer}); + if ($sqlite_debug) { + open $self->{trace_layer}, '>:via(PBot::SQLiteLoggerLayer)', PBot::SQLiteLogger->new(pbot => $self->{pbot}); + $self->{dbh}->trace($self->{dbh}->parse_trace_flags("SQL|$sqlite_debug"), $self->{trace_layer}); + } $self->{dbh}->do(<{dbh} and defined $self->{dbh}) { $self->{dbh}->commit() if $self->{new_entries}; $self->{dbh}->disconnect(); + close $self->{trace_layer} if $self->{trace_layer}; delete $self->{dbh}; } } diff --git a/PBot/PBot.pm b/PBot/PBot.pm index 07d16502..fb2737fc 100644 --- a/PBot/PBot.pm +++ b/PBot/PBot.pm @@ -100,16 +100,16 @@ sub initialize { } } - # let modules register signal handlers - $self->{atexit} = PBot::Registerable->new(%conf, pbot => $self); - $self->register_signal_handlers; - # make sure the data directory exists if (not -d $data_dir) { print STDERR "Data directory ($data_dir) does not exist; aborting...\n"; exit; } + # let modules register signal handlers + $self->{atexit} = PBot::Registerable->new(%conf, pbot => $self); + $self->register_signal_handlers; + # create logger $self->{logger} = PBot::Logger->new(pbot => $self, filename => "$data_dir/log/log", %conf); @@ -411,9 +411,9 @@ sub cmd_sl { sub cmd_die { my ($self, $context) = @_; $self->{logger}->log("$context->{hostmask} made me exit.\n"); - $self->atexit(); - $self->{conn}->privmsg($context->{from}, "Good-bye.") if defined $context->{from}; + $self->{conn}->privmsg($context->{from}, "Good-bye.") if $context->{from} ne 'stdin@pbot'; $self->{conn}->quit("Departure requested.") if defined $self->{conn}; + $self->atexit(); exit 0; } diff --git a/PBot/ProcessManager.pm b/PBot/ProcessManager.pm index e717a18c..1263cff7 100644 --- a/PBot/ProcessManager.pm +++ b/PBot/ProcessManager.pm @@ -210,6 +210,7 @@ sub execute_process { # print $context to pipe my $json = encode_json $context; print $writer "$json\n"; + close $writer; # end child exit 0; @@ -225,6 +226,7 @@ sub execute_process { sub process_pipe_reader { my ($self, $pid, $buf) = @_; + my $context = decode_json $buf or do { $self->{pbot}->{logger}->log("Failed to decode bad json: [$buf]\n"); return;