Currently, spawning a detached process, it assumes no input/output from/to its parent process.
To support synchronous invocation of gpg-agent for GnuPG, when input from detached process can be available, parent process could check if gpg-agent is ready for serving with the socket.
(1) GnuPG spawns gpg-agent process with pipe input+stderr
(2) gpg-agent can emit errors to stderr, emit "OK\n" when it's ready, or "ERR <ERRCODE>\n" to its stdout
(3) GnuPG checks pipe input to see gpg-agent is ready
(4) gpg-agent closes its stdout and stderr
(5) GnuPG closes pipe input
For now, I don't know if the scenario above works, let me try.