GnuPG 2.1.14, file sm/call-agent.c
Many functions contain this declaration:
struct default_inq_parm_s inq_parm = { ctrl, agent_ctx };
And later these statements:
rc = start_agent (ctrl); if (rc) return rc;
When the agent is not already started, the initialization of inq_parm is done
too early because agent_ctx is NULL at that time.
agent_ctx becomes non-NULL in start_agent(), but this non-NULL value is not
copied to inq_parm->ctx.
(This causes effects like not being able to import a PKCS#12 file with
pinentry-mode=loopback if the agent has not been started before.)
Fix:
Each time you see the lines above, add this line after the »return rc;«:
inq_parm->ctx = agent_ctx;
Thank you.