From 1c5584c395d75121046e42a27d60df7b6c6e660e Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Tue, 19 Dec 2023 15:56:13 +0900 Subject: [PATCH] kbx: Create public-keys.d, after creating the homedir. * kbx/keyboxd.c (create_directories): Following the behavior of gpg-agent, call create_public_keys_directory after mkdir. -- Signed-off-by: NIIBE Yutaka --- kbx/keyboxd.c | 1 + tools/dotlock.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 tools/dotlock.c diff --git a/kbx/keyboxd.c b/kbx/keyboxd.c index 88a350a08..f875e115d 100644 --- a/kbx/keyboxd.c +++ b/kbx/keyboxd.c @@ -1262,6 +1262,7 @@ create_directories (void) { if (!opt.quiet) log_info (_("directory '%s' created\n"), home); + create_public_keys_directory (home); } } } diff --git a/tools/dotlock.c b/tools/dotlock.c new file mode 100644 index 000000000..27ae5205b --- /dev/null +++ b/tools/dotlock.c @@ -0,0 +1,87 @@ +/* dotlock.c - Command to handle dotlock. + * Copyright (C) 2023 g10 Code GmbH + * + * This file is part of GnuPG. + * + * GnuPG is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * GnuPG is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#ifdef HAVE_W32_SYSTEM +# include "windows.h" +#else +#include +#endif + +#include "dotlock.h" + +static void +lock (const char *fname) +{ + dotlock_t h; + unsigned int flags = DOTLOCK_FLAG_LOCK_BY_PARENT; + + h = dotlock_create (fname, flags); + if (!h) + die ("error creating lock file for '%s': %s", fname, strerror (errno)); + + if (dotlock_take (h, 0)) + die ("error taking lock"); +} + +static void +unlock (const char *fname, long timeout) +{ + dotlock_t h; + unsigned int flags = (DOTLOCK_FLAG_LOCK_BY_PARENT + | DOTLOCK_FLAG_READONLY); + + h = dotlock_create (fname, flags); + if (!h) + die ("error creating lock file for '%s': %s", fname, strerror (errno)); + + dotlock_destroy (h); +} + + +int +main (int argc, char **argv) +{ + const char *fname; + + fname = argv[argc-1]; + + if () + lock (fname); + else + unlock (fname); + + return 0; +} + + +/* +Local Variables: +compile-command: "cc -Wall -O2 -D_FILE_OFFSET_BITS=64 -o t-dotlock t-dotlock.c" +End: +*/