Page MenuHome GnuPG

gpg-agent auto-detection of socket removal doesn't trigger actual shutdown
Closed, ResolvedPublic

Description

I'm trying to delete an explicitly-set $GNUPGHOME on a Linux system to see if a
running gpg-agent will terminate automatically, thanks to the inotify support.

It doesn't seem to work correctly yet :/ (i'm doing this test on a build from
git, with commit ID 0c56ad5a8d89d69a9ed00571720b3b105f955214)

Here's the test:

    export GNUPGHOME=$(mktemp -d)
    killall gpg-agent
    gpg-connect-agent 'getinfo pid' /bye
    rm -rf "$GNUPGHOME"
    sleep 1
    pidof gpg-agent

I tried stracing the gpg-agent process during this and i noticed that it *does*
receive some inotify events, but it doesn't then actually act on them correctly
:/ Below is some diagnostics (sorry if there's line-wrap, it's not clear to me
how to post non-line-wrapped info on this bugtracker)

dkg@tester:~$ lsof -p 18160
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
gpg-agent 18160 dkg cwd DIR 254,1 4096 2 /
gpg-agent 18160 dkg rtd DIR 254,1 4096 2 /
gpg-agent 18160 dkg txt REG 0,41 1682104 3678858
/home/dkg/tmp/gnupg2/bin/gpg-agent
gpg-agent 18160 dkg mem REG 254,1 1977808 2979
/usr/lib/locale/locale-archive
gpg-agent 18160 dkg mem REG 254,1 1685264 139908
/lib/x86_64-linux-gnu/libc-2.24.so
gpg-agent 18160 dkg mem REG 254,1 135448 145908
/lib/x86_64-linux-gnu/libpthread-2.24.so
gpg-agent 18160 dkg mem REG 254,1 18928 1769
/usr/lib/x86_64-linux-gnu/libnpth.so.0.0.5
gpg-agent 18160 dkg mem REG 254,1 80528 137309
/lib/x86_64-linux-gnu/libgpg-error.so.0.19.1
gpg-agent 18160 dkg mem REG 254,1 76872 2574
/usr/lib/x86_64-linux-gnu/libassuan.so.0.7.3
gpg-agent 18160 dkg mem REG 254,1 1107992 142595
/lib/x86_64-linux-gnu/libgcrypt.so.20.1.3
gpg-agent 18160 dkg mem REG 254,1 149192 133987
/lib/x86_64-linux-gnu/ld-2.24.so
gpg-agent 18160 dkg 0r CHR 1,3 0t0 2052 /dev/null
gpg-agent 18160 dkg 1w CHR 1,3 0t0 2052 /dev/null
gpg-agent 18160 dkg 2w CHR 1,3 0t0 2052 /dev/null
gpg-agent 18160 dkg 3u unix 0xffff8801570b6c00 0t0 3693951
/home/dkg/tmp/tmp.LcDU1Qvjpg/S.gpg-agent type=STREAM
gpg-agent 18160 dkg 4u unix 0xffff8801f207b800 0t0 3693953
/home/dkg/tmp/tmp.LcDU1Qvjpg/S.gpg-agent.rstrd type=STREAM
gpg-agent 18160 dkg 5u unix 0xffff8800d85d4000 0t0 3693955
/home/dkg/tmp/tmp.LcDU1Qvjpg/S.gpg-agent.brwsr type=STREAM
gpg-agent 18160 dkg 6u unix 0xffff8800d85d4400 0t0 3693957
/home/dkg/tmp/tmp.LcDU1Qvjpg/S.gpg-agent.ssh type=STREAM
gpg-agent 18160 dkg 7r a_inode 0,11 0 8307 inotify
dkg@tester:~$ strace -f -tt -T -s 512 -p 18160
strace: Process 18160 attached
01:58:57.369973 pselect6(8, [3 4 5 6 7], NULL, NULL, {0, 478425909}, {[], 8}) =
0 (Timeout) <0.479076>
01:58:57.849287 pselect6(8, [3 4 5 6 7], NULL, NULL, {2, 1530}, {[], 8}) = 0
(Timeout) <2.002177>
01:58:59.851684 pselect6(8, [3 4 5 6 7], NULL, NULL, {2, 1832}, {[], 8}) = 0
(Timeout) <2.002197>
01:59:01.854075 pselect6(8, [3 4 5 6 7], NULL, NULL, {2, 2031}, {[], 8}) = 1 (in
[7], left {1, 748721130}) <0.251350>
01:59:02.105641 read(7,
"\1\0\0\0\0\2\0\0\0\0\0\0\20\0\0\0S.gpg-agent.ssh\0\1\0\0\0\0\2\0\0\0\0\0\0
\0\0\0S.gpg-agent.brwsr\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 120) = 80 <0.000064>
01:59:02.105880 pselect6(8, [3 4 5 6 7], NULL, NULL, {1, 748206628}, {[], 8}) =
1 (in [7], left {1, 748196608}) <0.000054>
01:59:02.106073 read(7, "\1\0\0\0\0\2\0\0\0\0\0\0
\0\0\0S.gpg-agent.rstrd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0\0\0\2\0\0\0\0\0\0\20\0\0\0S.gpg-agent\0\0\0\0\0",

  1. = 80 <0.000046>

01:59:02.106223 pselect6(8, [3 4 5 6 7], NULL, NULL, {1, 747844527}, {[], 8}) =
1 (in [7], left {1, 747836987}) <0.000035>
01:59:02.106392 read(7, "\1\0\0\0\0\2\0@\0\0\0\0
\0\0\0private-keys-v1.d\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 120) = 48 <0.000030>
01:59:02.106506 pselect6(8, [3 4 5 6 7], NULL, NULL, {1, 747558844}, {[], 8}) =
0 (Timeout) <1.749545>
01:59:03.856240 pselect6(8, [3 4 5 6 7], NULL, NULL, {2, 10798}, {[], 8}) = 0
(Timeout) <2.002246>
01:59:05.858749 pselect6(8, [3 4 5 6 7], NULL, NULL, {2, 2293}, {[], 8}) = 0
(Timeout) <2.002174>
01:59:07.861214 pselect6(8, [3 4 5 6 7], NULL, NULL, {2, 6577}, {[], 8}) = 0
(Timeout) <2.002185>
01:59:09.863616 pselect6(8, [3 4 5 6 7], NULL, NULL, {2, 2252}, {[], 8}) = 0
(Timeout) <2.002179>
01:59:11.866089 pselect6(8, [3 4 5 6 7], NULL, NULL, {2, 1842}, {[], 8}) = 0
(Timeout) <2.002247>
01:59:13.868637 pselect6(8, [3 4 5 6 7], NULL, NULL, {2, 2252}, {[], 8}) = 0
(Timeout) <2.002237>
01:59:15.871139 pselect6(8, [3 4 5 6 7], NULL, NULL, {2, 1652}, {[], 8}) = 0
(Timeout) <2.002149>
01:59:17.873483 pselect6(8, [3 4 5 6 7], NULL, NULL, {2, 1485}, {[], 8}) = 0
(Timeout) <2.002193>
01:59:19.875854 pselect6(8, [3 4 5 6 7], NULL, NULL, {2, 1609}, {[], 8}) = 0
(Timeout) <2.002155>
01:59:21.878185 pselect6(8, [3 4 5 6 7], NULL, NULL, {2, 1572}, {[], 8}) = 0
(Timeout) <2.002168>
01:59:23.880544 pselect6(8, [3 4 5 6 7], NULL, NULL, {2, 1690}, {[], 8}) = 0
(Timeout) <2.002167>
01:59:25.882989 pselect6(8, [3 4 5 6 7], NULL, NULL, {2, 1821}, {[], 8}) = 0
(Timeout) <2.002182>
01:59:27.885404 pselect6(8, [3 4 5 6 7], NULL, NULL, {2, 1673}, {[], 8}) = 0
(Timeout) <2.002174>
01:59:29.887792 pselect6(8, [3 4 5 6 7], NULL, NULL, {2, 1770}, {[], 8}) = 0
(Timeout) <2.002175>
01:59:31.890172 pselect6(8, [3 4 5 6 7], NULL, NULL, {2, 2074}, {[], 8}) = 0
(Timeout) <2.002081>
01:59:33.892467 clone(strace: Process 18171 attached
<unfinished ...>
[pid 18171] 01:59:33.892611 set_robust_list(0x7f4ee86eb9e0, 24 <unfinished ...>
[pid 18160] 01:59:33.892646 <... clone resumed> child_stack=0x7f4ee86eaff0,
flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID,
parent_tidptr=0x7f4ee86eb9d0, tls=0x7f4ee86eb700, child_tidptr=0x7f4ee86eb9d0) =
18171 <0.000134>
[pid 18171] 01:59:33.892680 <... set_robust_list resumed> ) = 0 <0.000046>
[pid 18160] 01:59:33.892706 pselect6(8, [3 4 5 6 7], NULL, NULL, {2, 278707},
{[], 8} <unfinished ...>
[pid 18171] 01:59:33.892766 stat("/home/dkg/tmp/tmp.LcDU1Qvjpg/S.gpg-agent",
0x7f4ee86ead10) = -1 ENOENT (No such file or directory) <0.000038>
[pid 18171] 01:59:33.892872 socket(AF_UNIX, SOCK_STREAM, 0) = 8 <0.000034>
[pid 18171] 01:59:33.892945 stat("/home/dkg/tmp/tmp.LcDU1Qvjpg/S.gpg-agent",
0x7f4ee86ead10) = -1 ENOENT (No such file or directory) <0.000025>
[pid 18171] 01:59:33.893019 connect(8, {sa_family=AF_UNIX,
sun_path="/home/dkg/tmp/tmp.LcDU1Qvjpg/S.gpg-agent"}, 42) = -1 ENOENT (No such
file or directory) <0.000029>
[pid 18171] 01:59:33.893121
open("/usr/share/locale/en_US.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT
(No such file or directory) <0.000020>
[pid 18171] 01:59:33.893183
open("/usr/share/locale/en_US.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT
(No such file or directory) <0.000017>
[pid 18171] 01:59:33.893236 open("/usr/share/locale/en_US/LC_MESSAGES/libc.mo",
O_RDONLY) = -1 ENOENT (No such file or directory) <0.000018>
[pid 18171] 01:59:33.893290
open("/usr/share/locale/en.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No
such file or directory) <0.000016>
[pid 18171] 01:59:33.893341
open("/usr/share/locale/en.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No
such file or directory) <0.000016>
[pid 18171] 01:59:33.893393 open("/usr/share/locale/en/LC_MESSAGES/libc.mo",
O_RDONLY) = -1 ENOENT (No such file or directory) <0.000018>
[pid 18171] 01:59:33.893454 close(8) = 0 <0.000021>
[pid 18171] 01:59:33.893527 write(2, "gpg-agent[18160]: can't connect my own
socket: IPC connect call failed", 70) = 70 <0.000013>
[pid 18171] 01:59:33.893595 write(2, "\n", 1) = 1 <0.000013>
[pid 18171] 01:59:33.893655 write(2, "gpg-agent[18160]: ", 18) = 18 <0.000013>
[pid 18171] 01:59:33.893703 write(2, "this process is useless - shutting
down\n", 40) = 40 <0.000013>
[pid 18171] 01:59:33.893754 madvise(0x7f4ee7eeb000, 8368128, MADV_DONTNEED) = 0
<0.000022>
[pid 18171] 01:59:33.893808 exit(0) = ?
[pid 18171] 01:59:33.893853 +++ exited with 0 +++
01:59:35.895204 <... pselect6 resumed> ) = 0 (Timeout) <2.002450>
01:59:35.895347 close(7) = 0 <0.000053>
01:59:35.895499 write(2, "gpg-agent[18160]: gpg-agent (GnuPG) 2.1.16-beta229",

  1. = 50 <0.000027>

01:59:35.895605 write(2, " stopped\n", 9) = 9 <0.000025>
01:59:35.895685 close(3) = 0 <0.000031>
01:59:35.895813 exit_group(0) = ?
01:59:35.896275 +++ exited with 0 +++

Details

Version
2.1.15+git

Event Timeline

dkg added projects: gnupg, Bug Report.
dkg added a subscriber: dkg.

I'm attaching the lsof and strace transcript in text form so it can be read
without linebreaks

It seems to be solved now but see the comment in
2f7d4c3 agent: Move inotify code to common and improve it.

thanks, that seems to have resolved the problem in my tests.

Okay, we can then add the code to dirmngr.

werner claimed this task.
werner removed a project: Restricted Project.