From: Simon Ruderich Date: Sun, 24 Jan 2016 00:11:02 +0000 (+0100) Subject: write debug output to ~/.config/fcscs/log X-Git-Url: https://ruderich.org/simon/gitweb/?p=fcscs%2Ffcscs.git;a=commitdiff_plain;h=37b381833bdc7b8479c61d1dffe5947f6c666532 write debug output to ~/.config/fcscs/log Reverts 30ff4d3e ("run_in_background: fix execution when debug mode is enabled") which is no longer necessary as debug output in background processes works fine now. --- diff --git a/bin/fcscs b/bin/fcscs index 8cffebd..7543a9d 100755 --- a/bin/fcscs +++ b/bin/fcscs @@ -344,7 +344,18 @@ package Screen { sub debug { my ($config, $module, @args) = @_; - say STDERR "$module: @args" if $config->{setting}{debug}; + return if not $config->{setting}{debug}; + + state $fh; # only open the file once per run + if (not defined $fh) { + # Ignore errors if the directory doesn't exist. + if (not open $fh, '>', "$ENV{HOME}/.config/fcscs/log") { + $fh = undef; # a failed open still writes a value to $fh + return; + } + } + + say $fh "$module: @args"; return; } @@ -461,9 +472,6 @@ sub run_in_background { my $pid = fork; defined $pid or die $!; if ($pid == 0) { # child - # Disable debug mode as writing will fail with closed STDERR. - $config->{setting}{debug} = 0; - $sub->(); } exit; @@ -904,7 +912,7 @@ Defaults in parentheses. =over -=item B enable debug mode (redirect stderr when enabling) (C<0>) +=item B enable debug mode, writes to I<~/.config/fcscs/log> (C<0>) =item B start in this mode, must be a valid mode mapping (C<\&mapping_mode_url>)