[PATCH] gpg: fix redirection of stderr of gpgkeys helpers to stdout

Andrey Skvortsov andrej.skvortzov at gmail.com
Mon May 23 12:30:29 CEST 2016

Without the patch stderr is associated with the parent's stdout
stream and therefore all error messages from called helper
(gpg_keys_{hkp, ldap, curl, ...}) go to gpg's stdout instead of
stderr like all other error messages do.

Even debug messages (if enabled) between stderr redirection and execlp
call go in this case to stdout.

For example,
$ gpg --recv-keys 1CC5206765C54F1C  2> /dev/null
gpg: DBG: execlp: /usr/local/libexec/gnupg/gpgkeys_hkp
gpgkeys: key 1CC5206765C54F1C not found on keyserver

The problem is that dup2(from[1],STDOUT_FILENO), that is called later,
closes STDOUT_FILENO file descriptor, but this does not affect
STDERR_FILENO that is still associated with parent's stdout stream.

Signed-off-by: Andrey Skvortsov <andrej.skvortzov at gmail.com>

If properly route stderr into pipe as it's done with stdout,
then all error messages will go into iobuf and will not appear
at all nether in stdout, nor in stderr. I'd prefer to see error
messages from helper in stderr.

 g10/exec.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/g10/exec.c b/g10/exec.c
index 30108eb..cb29f9d 100644
--- a/g10/exec.c
+++ b/g10/exec.c
@@ -391,10 +391,6 @@ exec_write(struct exec_info **info,const char *program,
              keep their stdout/stderr */
-	      /* implied close of STDERR */
-	      if(dup2(STDOUT_FILENO,STDERR_FILENO)==-1)
-		_exit(1);
 	      /* implied close of STDOUT */

More information about the Gnupg-devel mailing list