Restarting gpg-agent
Peter Pentchev
roam at ringlet.net
Mon Mar 15 11:58:27 CET 2010
On Sun, Mar 14, 2010 at 10:16:00PM +0100, Michel Messerschmidt wrote:
> On Sun, Mar 14, 2010 at 12:24:14PM -0700, James Moe wrote:
> > Hello,
> > opensuse v11.2, linux 2.6.31.12-0.1-desktop x86_64, gpg v2.0.12.
> > The docs at <http://www.gnupg.org/> cover starting gpg-agent pretty
> > well. What is missing is how to re-start it.
> > If gpg-agent is terminated for some reason, or the system is booted,
> > the file <.gpg-agent.info> is left behind. Because the file exists, when
> > .bashrc is run it detects the file and does not start gpg-agent.
> > Is there some way to:
> > 1. Detect if gpg-agent is running. If not, erase <.gpg-agent.info>, or
> > 2. Erase <.gpg-agent.info> at boot time.
>
>
> This works for me (in .bashrc):
A good idea, and well written :) Just one minor thing...
> # start gpg-agent if no running instance is found
> if test -z "${GPG_AGENT_INFO}" ||
> ! kill -0 `grep GPG_AGENT_INFO ${GA_INFO_FILE} | cut -d: -f 2 -` 2>/dev/null; then
In this way, you risk a false positive if gpg-agent has died (or not
been started at all, but a .gpg-agent.info file has been left over)
and there is another process with the same process ID. This *can*
happen, whether by random chance at system startup, or by random
chance on a long-running system with PID's wrapping around.
A slightly better (if somewhat more convoluted) way could be
something like:
gpg_agent_pid=''
gpg_agent_running=''
if [ -n "${GPG_AGENT_INFO}" ] && [ -r "$GA_INFO_FILE" ]; then
gpg_agent_pid=`grep GPG_AGENT_INFO "${GA_INFO_FILE}" | cut -d: -f 2 -`
fi
if [ -n "$gpg_agent_pid" ] &&
expr "x$gpg_agent_pid" : 'x[0-9]*$' > /dev/null; then
if pgrep gpg-agent | fgrep -qw "$gpg_agent_pid" > /dev/null; then
gpg_agent_running='1'
fi
fi
if [ -n "$gpg_agent_running" ]; then
...
fi
Please don't take this as criticism, just an idea :) And, of course,
it assumes that the OS has pgrep(1).
G'luck,
Peter
--
Peter Pentchev roam at ringlet.net roam at space.bg roam at FreeBSD.org
PGP key: http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115 C354 651E EFB0 2527 DF13
What would this sentence be like if pi were 3?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: </pipermail/attachments/20100315/efc8f4c0/attachment.pgp>
More information about the Gnupg-users
mailing list