From 9fb0576765624cc27a1c06aebc9f4ef5df31ba30 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Wed, 9 Sep 2015 01:18:14 +0200 Subject: [PATCH] Add a configuration option 'null-stderr=YES'. To send STDERR to /dev/null for type=tunnel. --- Changelog | 2 ++ interimap.1 | 6 ++++++ interimap.sample | 1 + lib/Net/IMAP/InterIMAP.pm | 16 +++++++++++++++- 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Changelog b/Changelog index 0d56bac..23d2a17 100644 --- a/Changelog +++ b/Changelog @@ -4,6 +4,8 @@ interimap (0.2) upstream enabled for the remote server, and disabled for the local server. * Add traffic statistics after closing the connection to the IMAP server. + * Add a configuration option 'null-stderr=YES' to send STDERR to + /dev/null for type=tunnel. -- Guilhem Moulin Wed, 09 Sep 2015 00:44:35 +0200 diff --git a/interimap.1 b/interimap.1 index bb97cf4..dc3b49b 100644 --- a/interimap.1 +++ b/interimap.1 @@ -318,6 +318,12 @@ advertizing it. (Default: \(lqNO\(rq for the \(lq[local]\(rq section, \(lqYES\(rq for the \(lq[remote]\(rq section.) +.TP +.I null-stderr +Whether to redirect \fIcommand\fR's standard error to \(lq/dev/null\(rq +for type \fItype\fR=tunnel. +(Default: \(lqNO\(rq.) + .SH KNOWN BUGS AND LIMITATIONS .IP \[bu] diff --git a/interimap.sample b/interimap.sample index e469c98..86d41dd 100644 --- a/interimap.sample +++ b/interimap.sample @@ -6,6 +6,7 @@ ignore-mailbox = ^virtual/ [local] type = tunnel command = /usr/lib/dovecot/imap +null-stderr = YES [remote] # type = imaps diff --git a/lib/Net/IMAP/InterIMAP.pm b/lib/Net/IMAP/InterIMAP.pm index 966b965..db6f484 100644 --- a/lib/Net/IMAP/InterIMAP.pm +++ b/lib/Net/IMAP/InterIMAP.pm @@ -49,6 +49,7 @@ my %OPTIONS = ( password => qr/\A([\x01-\x7F]+)\z/, auth => qr/\A($RE_ATOM_CHAR+(?: $RE_ATOM_CHAR+)*)\z/, command => qr/\A(\/\P{Control}+)\z/, + 'null-stderr' => qr/\A(YES|NO)\z/i, compress => qr/\A($RE_ATOM_CHAR+(?: $RE_ATOM_CHAR+)*)\z/, SSL_fingerprint => qr/\A([A-Za-z0-9]+\$\p{AHex}+)\z/, SSL_cipher_list => qr/\A(\P{Control}+)\z/, @@ -248,11 +249,24 @@ sub new($%) { open STDIN, '<&', $rd or $self->panic("Can't dup: $!"); open STDOUT, '>&', $wd or $self->panic("Can't dup: $!"); + my $stderr2; + if (uc ($self->{'null-stderr'} // 'NO') eq 'YES') { + open $stderr2, '>&', *STDERR; + open STDERR, '>', '/dev/null' or $self->panic("Can't open /dev/null: $!"); + } + my $sigset = POSIX::SigSet::->new(SIGINT); my $oldsigset = POSIX::SigSet::->new(); sigprocmask(SIG_BLOCK, $sigset, $oldsigset) // $self->panic("Can't block SIGINT: $!"); - exec $command or $self->panic("Can't exec: $!"); + unless (exec $command) { + my $err = $!; + if (defined $stderr2) { + close STDERR; + open STDERR, '>&', $stderr2; + } + $self->panic("Can't exec: $err"); + } } # parent -- 2.39.2