threads / patch / 46430

patcht: lib-gpg: flush gpg agent on startup

Subject: [PATCH] t: lib-gpg: flush gpg agent on startup

## tl;dr

4 messages between Jul 20, 2017 and Jul 20, 2017. Diffs are folded; open one to read it.

replies: 3people: 2as markdown or json

santiago@nyu.edu· Jul 20, 2017, 16:58 UTC · lore
From: Santiago Torres <santiago@nyu.edu>

When running gpg-relevant tests, a gpg-daemon is spawned for each GNUPGHOME used. This daemon may stay running after the test and cache file descriptors for the trash directories, even after the trash directory is removed. This leads to ENOENT errors when attempting to create files if tests are run multiple times.

Add a cleanup script to force flushing the gpg-agent for that GNUPGHOME (if any) before setting up the GPG relevant-environment.

Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Santiago Torres <santiago@nyu.edu>
---
 t/lib-gpg.sh | 1 +
 1 file changed, 1 insertion(+)
Show changes to t/lib-gpg.sh +1 −0
diff --git a/t/lib-gpg.sh b/t/lib-gpg.sh
index ec2aa8f68..7a6c7ee6f 100755
--- a/t/lib-gpg.sh
+++ b/t/lib-gpg.sh
@@ -31,6 +31,7 @@ then
 		chmod 0700 ./gpghome &&
 		GNUPGHOME="$(pwd)/gpghome" &&
 		export GNUPGHOME &&
+		gpgconf --kill gpg-agent 2>&1 >/dev/null
 		gpg --homedir "${GNUPGHOME}" 2>/dev/null --import \
 			"$TEST_DIRECTORY"/lib-gpg/keyring.gpg &&
 		gpg --homedir "${GNUPGHOME}" 2>/dev/null --import-ownertrust \
-- 
2.13.3
Santiago Torres· Jul 20, 2017, 17:01 UTC · re: santiago@nyu.edu · lore

Re: [PATCH] t: lib-gpg: flush gpg agent on startup

This is the patch that stemmed from [1].

I tried to keep it simple and not noisy, alhtough it breaks the && chain, it needs to be run right before the --import command. I also decided to drop the switch chain in case that regression was to be introduced in the future in other versions (hopefully gpgconf goes nowhere by then).

I was able to test this on debian oldstable/stable and arch.

Cheers! -Santiago.

[1] https://public-inbox.org/git/xmqqvampmnmv.fsf@gitster.mtv.corp.google.com/
On Thu, Jul 20, 2017 at 12:58:14PM -0400, santiago@nyu.edu wrote:
Show 32 quoted lines
> From: Santiago Torres <santiago@nyu.edu>
> 
> When running gpg-relevant tests, a gpg-daemon is spawned for each
> GNUPGHOME used. This daemon may stay running after the test and cache
> file descriptors for the trash directories, even after the trash
> directory is removed. This leads to ENOENT errors when attempting to
> create files if tests are run multiple times.
> 
> Add a cleanup script to force flushing the gpg-agent for that GNUPGHOME
> (if any) before setting up the GPG relevant-environment.
> 
> Helped-by: Junio C Hamano <gitster@pobox.com>
> Signed-off-by: Santiago Torres <santiago@nyu.edu>
> ---
>  t/lib-gpg.sh | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/t/lib-gpg.sh b/t/lib-gpg.sh
> index ec2aa8f68..7a6c7ee6f 100755
> --- a/t/lib-gpg.sh
> +++ b/t/lib-gpg.sh
> @@ -31,6 +31,7 @@ then
>  		chmod 0700 ./gpghome &&
>  		GNUPGHOME="$(pwd)/gpghome" &&
>  		export GNUPGHOME &&
> +		gpgconf --kill gpg-agent 2>&1 >/dev/null
>  		gpg --homedir "${GNUPGHOME}" 2>/dev/null --import \
>  			"$TEST_DIRECTORY"/lib-gpg/keyring.gpg &&
>  		gpg --homedir "${GNUPGHOME}" 2>/dev/null --import-ownertrust \
> -- 
> 2.13.3
> 
Junio C Hamano· Jul 20, 2017, 20:00 UTC · re: Santiago Torres · lore

Re: [PATCH] t: lib-gpg: flush gpg agent on startup

Santiago Torres <santiago@nyu.edu> writes:
Show 7 quoted lines
> This is the patch that stemmed from [1].
>
> I tried to keep it simple and not noisy, alhtough it breaks the &&
> chain, it needs to be run right before the --import command. I also
> decided to drop the switch chain in case that regression was to be
> introduced in the future in other versions (hopefully gpgconf goes
> nowhere by then).
I'm inclined to do
	...
	export GNUPGHOME &&
	( gpgconf --kill gpg-agent 2>&1 >/dev/null || : ) &&
	gpg --homedir ... --import ...

Imagine "chmod 0777 ./gpghome" failed and what happens. We skip the part that exports GNUPGHOME and attempts to kill gpg-agent as if nothing bad happened, and then we try to "--import". At that point we do not know what value GNUPGHOME has---are we clobbering the real keychain the user who runs the test has?

With that "run it but ignore the outcome even if we failed to.", we do not have to worry about any of that ;-)

Show 41 quoted lines
>
> I was able to test this on debian oldstable/stable and arch.
>
> Cheers!
> -Santiago.
>
> [1] https://public-inbox.org/git/xmqqvampmnmv.fsf@gitster.mtv.corp.google.com/
>
> On Thu, Jul 20, 2017 at 12:58:14PM -0400, santiago@nyu.edu wrote:
>> From: Santiago Torres <santiago@nyu.edu>
>> 
>> When running gpg-relevant tests, a gpg-daemon is spawned for each
>> GNUPGHOME used. This daemon may stay running after the test and cache
>> file descriptors for the trash directories, even after the trash
>> directory is removed. This leads to ENOENT errors when attempting to
>> create files if tests are run multiple times.
>> 
>> Add a cleanup script to force flushing the gpg-agent for that GNUPGHOME
>> (if any) before setting up the GPG relevant-environment.
>> 
>> Helped-by: Junio C Hamano <gitster@pobox.com>
>> Signed-off-by: Santiago Torres <santiago@nyu.edu>
>> ---
>>  t/lib-gpg.sh | 1 +
>>  1 file changed, 1 insertion(+)
>> 
>> diff --git a/t/lib-gpg.sh b/t/lib-gpg.sh
>> index ec2aa8f68..7a6c7ee6f 100755
>> --- a/t/lib-gpg.sh
>> +++ b/t/lib-gpg.sh
>> @@ -31,6 +31,7 @@ then
>>  		chmod 0700 ./gpghome &&
>>  		GNUPGHOME="$(pwd)/gpghome" &&
>>  		export GNUPGHOME &&
>> +		gpgconf --kill gpg-agent 2>&1 >/dev/null
>>  		gpg --homedir "${GNUPGHOME}" 2>/dev/null --import \
>>  			"$TEST_DIRECTORY"/lib-gpg/keyring.gpg &&
>>  		gpg --homedir "${GNUPGHOME}" 2>/dev/null --import-ownertrust \
>> -- 
>> 2.13.3
>> 
Santiago Torres· Jul 20, 2017, 20:25 UTC · re: Junio C Hamano · lore

Re: [PATCH] t: lib-gpg: flush gpg agent on startup

> With that "run it but ignore the outcome even if we failed to.", we
> do not have to worry about any of that ;-)
Oh right! thanks for the suggestion! Let me re-roll...

Thanks, -Santiago.

← back to recent threads