7

On a Debian Jessie system:

$ ls -al ~/.gnupg/
total 58684
drwx------  2 username username     4096 Nov 28 20:52 .
drwxr-xr-x 50 username username     4096 Nov 28 19:33 ..
-rw-------  1 username username     9602 Jun 24 22:47 gpg.conf
-rw-r--r--  1 username username       18 Jun 25 21:07 .#lk0xb7f2fa50.hostname.5551
-rw-r--r--  1 username username       18 Aug 19 19:15 .#lk0xb8e9bf48.hostname.32133
-rw-r--r--  1 username username       18 Aug 19 19:15 .#lk0xb8e9dc48.hostname.32133
-rw-r--r--  1 username username       18 Nov 28 20:52 .#lk0xb9387478.hostname.24497
-rw-------  1 username username 30018875 Nov 18 21:49 pubring.gpg
-rw-------  1 username username 30018875 Nov 18 20:54 pubring.gpg~
-rw-------  1 username username      600 Jun 21 21:34 random_seed
-rw-------  1 username username     4890 May  7  2015 secring.gpg
-rw-------  1 username username     1440 Nov 18 18:50 trustdb.gpg

I have replaced the actual username with username and the actual hostname with hostname.

What is the origin/purpose of the files whose names begin .#lk0xb?

1 Answer 1

11

They are (as the "lk" suggests) lock files. A comment in the gnupg sources says

This function creates a lock file in the same directory as FILE_TO_LOCK using that name and a suffix of ".lock". Note that on POSIX systems a temporary file ".#lk..pid[.threadid] is used.

and also states that there is a cleanup function (to remove obsolete locks). You're seeing leftover lock-files where the cleanup function failed.

The pid and threadid do not match an earlier comment in the code (it seems that the comments are not updated). The actual code which makes the filename looks different from the comments (quoting from gnupg-1.4.19):

  snprintf (h->tname, tnamelen, "%.*s/.#lk%p.", dirpartlen, dirpart, h );
  h->nodename_off = strlen (h->tname);
  snprintf (h->tname+h->nodename_off, tnamelen - h->nodename_off,
           "%s.%d", nodename, (int)getpid ());

but of course, the code is more pertinent than the comments.

You must log in to answer this question.