On Fri, Oct 16, 2009 at 1:12 AM, Laurent MARTIN <[email protected]> wrote:
> Hi!
> I've recently upgraded one of my old website to mod_perl (ModPerl::PerlRun)
> and I'm not able to make GnuPG (0.10) work properly :/ As soon as I try to
> encrypt a plaintext file, I get an empty encrypted file. See below what I
> get in error log with the 'trace' option set to true:
> protocol error: expected SHM_GET_XXX got \n at
> /usr/lib/perl5/site_perl/5.8.5/GnuPG.pm line 154
>
> Any clue? Thanks in advance :)
>
This might be because the GnuPG module executes the 'gpg' binary directly to
run it's commands and it plays with STDIN, STDOUT and STDERR to do that.
I had a similar issue using GnuPG::Interface under mod_perl, but was able to
solve it by untieing and saving STDIN and STDOUT when making calls to
GnuPG::Interface (the example below calls Mail::GPG which in turn uses
GnuPG::Interface to do the grunt work):
use constant MP => ( exists $ENV{MOD_PERL} );
use constant MP2 => ( exists $ENV{MOD_PERL_API_VERSION} and
$ENV{MOD_PERL_API_VERSION} >= 2 );
# mod_perl ties STDIN and STDOUT which conflicts with GnuPG::Interface
my ( $stdin, $stdout );
if ( MP and not MP2 ) {
$stdin = tied *STDIN;
$stdout = tied *STDOUT;
untie *STDIN;
untie *STDOUT;
}
my $mg = Mail::GPG->new( gnupg_hash_init => \%GNUPG_OPTIONS );
my $key_id = eval { $mg->query_keyring( search => $name ); };
if ( MP and not MP2 ) {
tie *STDIN, ref $stdin, $stdin;
tie *STDOUT, ref $stdout, $stdout;
}
die "query_keyring failed: $@" if $@;
Note though that I only noticed the issues with mod_perl1 and not with
mod_perl2 so it may be something different that you are seeing. Here's
hoping it gives you some hints on where to look next...
Cheers,
Cees