Hello guys, I wrote a bash script to validate a cached passphrase in gpg-agent and I have another script that will continue to use this cached passphrase to do its job. The script has no problem and works perfectly. I published this script in gitlab for demonstration:
https://gitlab.com/sofibox/maxicron/-/blob/master/usr/local/maxicron/gpg/gpgcron
But, I have 1 problem sometimes around 10-20 minutes [2 times perday] I notice that a new gpg-agent process running and it's gone randomly. Between this time, I also notice that, I was unable to read my cached passphrase in gpg-agent until the new gpg-agent process is terminated or killed.
So, I added some debug script to the code above to see the details of the randomly spawn gpg-agent process, and I found out the following log:
( I run this script each minute in cronjob * * * * * root /usr/local/maxicron/gpg/gpgcron KEY_ID --warning-only > /dev/null )
```
[gpgcron]: OK, gpg-agent daemon is running with the following process id(s):
--- (1) PID: 1734578 ---
Process id details:
PID MEMORY USER GROUP COMMAND ARGS
1734578 168996 root root gpg-agent gpg-agent --options /root/.gnupg/gpg-agent.conf --daemon
Process tree details:
systemd,1 --switched-root --system --deserialize 18
`-gpg-agent,1734578 --options /root/.gnupg/gpg-agent.conf --daemon
---------
--- (2) PID: 1874245 ---
Process id details:
PID MEMORY USER GROUP COMMAND ARGS
1874245 168996 root root gpg-agent gpg-agent --homedir /root/.gnupg --use-standard-socket --daemon
Process tree details:
systemd,1 --switched-root --system --deserialize 18
`-gpg-agent,1874245 --homedir /root/.gnupg --use-standard-socket --daemon
---------
[gpgcron]: Warning, gpg-agent current process id [1874245 1734578] is different from the cached process id [1734578]
[gpgcron]: Warning, there are 2 gpg-agent processes that are currently running: [1874245 1734578]
[gpgcron]: Warning, no passphrase is cached in gpg-agent for key id of [2B705B8B6FA943B1]
[gpgcron]: [gpgcron] is terminated!
```
You can see that, the PID 1874245 is a new gpg-agent process and it runs using this argument: --homedir /root/.gnupg --use-standard-socket --daemon
This process causes my script to failed to validate the passphrase cached in gpg-agent as shown in the output, but at some time, the new process will be terminated automatically and the passphrase can be validated again. So, with this weird behavior sometimes it causes my other script to return error because it was not able to use cached password from gpg-agent.
Any idea how to solved this ? Is this a bug ?
Thank you