test: Stop gpg-agent daemons that are started for the test framework's gpg key

They normally shutdown when the GNUPGHOME directory is deleted, but on
NFS they keep the directory from being deleted. And also, this avoids
a number of them piling up while the test suite is running.
This commit is contained in:
Joey Hess 2020-08-28 14:28:42 -04:00
parent 6fb7ecde35
commit cde3e5eb0c
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
4 changed files with 39 additions and 4 deletions

View file

@ -416,7 +416,7 @@ testHarness tmpdir cmd a = ifM (inPath (unGpgCmd cmd))
, return Nothing
)
where
var = "GNUPGHOME"
var = "GNUPGHOME"
setup = do
orig <- getEnv var
@ -431,9 +431,16 @@ testHarness tmpdir cmd a = ifM (inPath (unGpgCmd cmd))
[testSecretKey, testKey]
return orig
cleanup (Just (Just v)) = setEnv var v True
cleanup (Just Nothing) = unsetEnv var
cleanup Nothing = return ()
cleanup (Just (Just v)) = stopgpgagent >> setEnv var v True
cleanup (Just Nothing) = stopgpgagent >> unsetEnv var
cleanup Nothing = stopgpgagent
-- Recent versions of gpg automatically start gpg-agent, or perhaps
-- other daemons. Stop them when done. This only affects
-- daemons started for the GNUPGHOME that was used.
-- Older gpg may not support this, so ignore failure.
stopgpgagent = void $ boolSystem "gpgconf"
[Param "--kill", Param "all"]
go (Just _) = Just <$> a
go Nothing = return Nothing