Page MenuHome GnuPG

gpg/gpg2/gpgsm exit with code 2 even though decryption was successful
Closed, ResolvedPublic

Description

Under some circumstances, the gpg front-ends exit with exit code 2 even
when a decryption is actually successful. This happens with gpg 1.4.1
(from the debian package version 1.4.1-1.sarge7), if use-agent is set in
~/.gnupg/options but gpg cannot connect to agent. It then falls back to
reading the pass-phrase from the terminal and even
if the decryption is successful then, gpg exits with exit code 2:

$ gpg --decrypt file

You need a pass-phrase to unlock the secret key for
user: "Bernhard Herzog <bh@intevation.de>"
1024-bit ELG-E key, ID 2F11C50C, created 2001-01-02 (main key ID 9F884AC8)

gpg: can't connect to `/tmp/gpg-q0/S.gpg-agent': No such file or directory
gpg: encrypted with 1024-bit ELG-E key, ID 2F11C50C, created 2001-01-02

"Bernhard Herzog <bh@intevation.de>"

.... <decrypted content> ...
$ echo $?
2

With gpg2 and gpgsm version 2.0.3 the fallback is different, but they
still exit with code 2 if the initial attempt to connect to the agent
fails.

I would expect gpg, gpg2 and gpgsm to exit with code 0 if the operation
is successful, even though falling back to a different way to get the
pass-phrase was necessary.

Event Timeline

I agree with you for gpg 1.4 - However this has been fixed a while ago and
should not happen with 1.4.7. See T655.

GPG2 and GPGSM require the agent and thus returnning an error is fine. There is
fallback mechanism to start the agent on demand but that is more a hack than a
proper solution.

As it is easy to fix, I just did it for gpg2 and gpgsm (SVN -r 4473).

However it is disputable whether this is correct. The error occurs only if the
agent has crashed or the GPG_AGENT_INFO envvar is outdated.

werner claimed this task.
werner removed a project: In Progress.