Page MenuHome GnuPG

0001-common-dotlock-Clean-up-for-error-info-warning-messa.patch

Authored By
gniibe
Thu, Nov 27, 7:14 AM
Size
25 KB
Subscribers
None

0001-common-dotlock-Clean-up-for-error-info-warning-messa.patch

From c93ffb99608cd9f95e94c3d0b26078335f303638 Mon Sep 17 00:00:00 2001
From: NIIBE Yutaka <gniibe@fsij.org>
Date: Thu, 27 Nov 2025 15:00:13 +0900
Subject: [PATCH] common:dotlock: Clean up for error/info/warning message.
* common/dotlock.c (my_info_*,my_error_*,my_debug_1): Remove.
(struct dotlock_handle): Rename to msg_cb from info_cb, and
to msg_cb_arg from info_cb_value.
(default_msg_cb): New.
(read_lockfile): Use msg_cb and msg_cb_arg.
(dotlock_create_unix, dotlock_create_w32): Likewise.
(dotlock_take_unix, dotlock_take_w32): Likewise.
(dotlock_release_unix, dotlock_release_w32): Likewise.
(dotlock_release): Likewise.
(dotlock_create_with): New.
(dotlock_finish_create, dotlock_set_info_cb): Remove.
(dotlock_create): Use dotlock_create_with.
* common/dotlock.h (define dotlock_create_with): New.
(dotlock_finish_create, dotlock_set_info_cb): Remove.
(DOTLOCK_LOCKED_ALREADY, DOTLOCK_FATAL): New.
(DOTLOCK_PREPARE_CREATE): Remove.
* common/t-dotlock.c (lock_and_unlock): Use new internal API.
* kbx/backend-sqlite.c (create_or_open_database): Ditto.
--
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
---
common/dotlock.c | 272 +++++++++++++++----------------------------
common/dotlock.h | 29 ++---
common/t-dotlock.c | 4 +-
kbx/backend-sqlite.c | 12 +-
4 files changed, 122 insertions(+), 195 deletions(-)
diff --git a/common/dotlock.c b/common/dotlock.c
index b96854afb..a1527ec91 100644
--- a/common/dotlock.c
+++ b/common/dotlock.c
@@ -344,24 +344,8 @@
#endif
#ifdef GNUPG_MAJOR_VERSION
-# define my_info_0(a) log_info ((a))
-# define my_info_1(a,b) log_info ((a), (b))
-# define my_info_2(a,b,c) log_info ((a), (b), (c))
-# define my_info_3(a,b,c,d) log_info ((a), (b), (c), (d))
-# define my_error_0(a) log_error ((a))
-# define my_error_1(a,b) log_error ((a), (b))
-# define my_error_2(a,b,c) log_error ((a), (b), (c))
-# define my_debug_1(a,b) log_debug ((a), (b))
-# define my_fatal_0(a) log_fatal ((a))
+# define my_fatal_0(a) default_msg_cb (NULL, DOTLOCK_FATAL, (a))
#else
-# define my_info_0(a) fprintf (stderr, (a))
-# define my_info_1(a,b) fprintf (stderr, (a), (b))
-# define my_info_2(a,b,c) fprintf (stderr, (a), (b), (c))
-# define my_info_3(a,b,c,d) fprintf (stderr, (a), (b), (c), (d))
-# define my_error_0(a) fprintf (stderr, (a))
-# define my_error_1(a,b) fprintf (stderr, (a), (b))
-# define my_error_2(a,b,c) fprintf (stderr, (a), (b), (c))
-# define my_debug_1(a,b) fprintf (stderr, (a), (b))
# define my_fatal_0(a) do { fprintf (stderr,(a)); fflush (stderr); \
abort (); } while (0)
#endif
@@ -383,11 +367,10 @@ struct dotlock_handle
int extra_fd; /* A place for the caller to store an FD. */
- /* An optional info callback - see dotlock_set_info_cb. */
- int (*info_cb)(dotlock_t, void *,
- enum dotlock_reasons reason,
- const char *,...);
- void *info_cb_value;
+ int (*msg_cb)(dotlock_t, void *,
+ enum dotlock_reasons reason,
+ const char *, ...);
+ void *msg_cb_arg;
#ifdef HAVE_DOSISH_SYSTEM
@@ -474,7 +457,28 @@ any8bitchar (const char *string)
#endif /*HAVE_DOSISH_SYSTEM*/
+static int
+default_msg_cb (dotlock_t h, void *opaque, enum dotlock_reasons reason,
+ const char *format, ...)
+{
+ va_list arg_ptr;
+ int level = GPGRT_LOGLVL_INFO;
+
+ (void)h;
+ (void)opaque;
+#ifdef GNUPG_MAJOR_VERSION
+ va_start (arg_ptr, format);
+ log_logv (level, format, arg_ptr);
+ va_end (arg_ptr);
+ if (reason == DOTLOCK_FATAL)
+ abort ();
+#else
+ (void)level;
+ vfprintf (stderr, format, arg_ptr);
+#endif
+ return 0;
+}
/* Entirely disable all locking. This function should be called
before any locking is done. It may be called right at startup of
@@ -538,14 +542,9 @@ read_lockfile (dotlock_t h, int *same_node, int *r_fd)
{
int e = errno;
if (errno != ENOENT)
- {
- my_info_2 ("error opening lockfile '%s': %s\n",
- h->lockname, strerror(errno) );
- if (h->info_cb)
- h->info_cb (h, h->info_cb_value, DOTLOCK_FILE_ERROR,
- "error opening lockfile '%s': %s\n",
- h->lockname, strerror (errno) );
- }
+ h->msg_cb (h, h->msg_cb_arg, DOTLOCK_FILE_ERROR,
+ "error opening lockfile '%s': %s\n",
+ h->lockname, strerror (errno) );
if (buffer != buffer_space)
xfree (buffer);
my_set_errno (e); /* Need to return ERRNO here. */
@@ -562,11 +561,9 @@ read_lockfile (dotlock_t h, int *same_node, int *r_fd)
if (res < 0)
{
int e = errno;
- my_info_1 ("error reading lockfile '%s'\n", h->lockname );
- if (h->info_cb)
- h->info_cb (h, h->info_cb_value, DOTLOCK_FILE_ERROR,
- "error reading lockfile '%s': %s\n",
- h->lockname, strerror (errno) );
+ h->msg_cb (h, h->msg_cb_arg, DOTLOCK_FILE_ERROR,
+ "error reading lockfile '%s': %s\n",
+ h->lockname, strerror (errno) );
close (fd);
if (buffer != buffer_space)
xfree (buffer);
@@ -585,10 +582,8 @@ read_lockfile (dotlock_t h, int *same_node, int *r_fd)
if (nread < 11)
{
- my_info_1 ("invalid size of lockfile '%s'\n", h->lockname);
- if (h->info_cb)
- h->info_cb (h, h->info_cb_value, DOTLOCK_INV_FILE,
- "invalid size of lockfile '%s'\n", h->lockname);
+ h->msg_cb (h, h->msg_cb_arg, DOTLOCK_INV_FILE,
+ "invalid size of lockfile '%s'\n", h->lockname);
if (buffer != buffer_space)
xfree (buffer);
my_set_errno (EINVAL);
@@ -599,10 +594,8 @@ read_lockfile (dotlock_t h, int *same_node, int *r_fd)
|| (buffer[10] = 0, pid = atoi (buffer)) == -1
|| !pid )
{
- my_error_2 ("invalid pid %d in lockfile '%s'\n", pid, h->lockname);
- if (h->info_cb)
- h->info_cb (h, h->info_cb_value, DOTLOCK_INV_FILE,
- "invalid pid %d in lockfile '%s'\n", pid, h->lockname);
+ h->msg_cb (h, h->msg_cb_arg, DOTLOCK_INV_FILE,
+ "invalid pid %d in lockfile '%s'\n", pid, h->lockname);
if (buffer != buffer_space)
xfree (buffer);
my_set_errno (EINVAL);
@@ -814,12 +807,9 @@ dotlock_create_unix (dotlock_t h, const char *file_to_lock)
int saveerrno = errno;
all_lockfiles = h->next;
UNLOCK_all_lockfiles ();
- my_error_2 (_("failed to create temporary file '%s': %s\n"),
- h->tname, strerror (errno));
- if (h->info_cb)
- h->info_cb (h, h->info_cb_value, DOTLOCK_WAITING,
- _("failed to create temporary file '%s': %s\n"),
- h->tname, strerror (errno));
+ h->msg_cb (h, h->msg_cb_arg, DOTLOCK_WAITING,
+ _("failed to create temporary file '%s': %s\n"),
+ h->tname, strerror (errno));
xfree (h->tname);
xfree (h);
my_set_errno (saveerrno);
@@ -851,12 +841,9 @@ dotlock_create_unix (dotlock_t h, const char *file_to_lock)
default:
{
int saveerrno = errno;
- my_error_2 ("can't check whether hardlinks are supported for '%s': %s\n"
- , h->tname, strerror (saveerrno));
- if (h->info_cb)
- h->info_cb (h, h->info_cb_value, DOTLOCK_CONFIG_TEST,
- "can't check whether hardlinks are supported for '%s': %s\n"
- , h->tname, strerror (saveerrno));
+ h->msg_cb (h, h->msg_cb_arg, DOTLOCK_CONFIG_TEST,
+ "can't check whether hardlinks are supported for '%s': %s\n",
+ h->tname, strerror (saveerrno));
my_set_errno (saveerrno);
}
goto write_failed;
@@ -899,12 +886,9 @@ dotlock_create_unix (dotlock_t h, const char *file_to_lock)
int saveerrno = errno;
all_lockfiles = h->next;
UNLOCK_all_lockfiles ();
- my_error_2 (_("error writing to '%s': %s\n"), h->tname, strerror (errno));
- if (h->info_cb)
- h->info_cb (h, h->info_cb_value, DOTLOCK_FILE_ERROR,
- _("error writing to '%s': %s\n"),
- h->tname, strerror (errno));
-
+ h->msg_cb (h, h->msg_cb_arg, DOTLOCK_FILE_ERROR,
+ _("error writing to '%s': %s\n"),
+ h->tname, strerror (errno));
if ( fd != -1 )
close (fd);
unlink (h->tname);
@@ -970,11 +954,9 @@ dotlock_create_w32 (dotlock_t h, const char *file_to_lock)
int saveerrno = map_w32_to_errno (GetLastError ());
all_lockfiles = h->next;
UNLOCK_all_lockfiles ();
- my_error_2 (_("can't create '%s': %s\n"), h->lockname, w32_strerror (-1));
- if (h->info_cb)
- h->info_cb (h, h->info_cb_value, DOTLOCK_FILE_ERROR,
- _("can't create '%s': %s\n"),
- h->lockname, w32_strerror (-1));
+ h->msg_cb (h, h->msg_cb_arg, DOTLOCK_FILE_ERROR,
+ _("can't create '%s': %s\n"),
+ h->lockname, w32_strerror (-1));
xfree (h->lockname);
xfree (h);
my_set_errno (saveerrno);
@@ -1000,10 +982,6 @@ dotlock_create_w32 (dotlock_t h, const char *file_to_lock)
POSIX systems a temporary file ".#lk.<hostname>.pid[.threadid] is
used.
- FLAGS may include DOTLOCK_PREPARE_CREATE bit, which only allocates
- the handle and requires a further call to dotlock_finish_create.
- This can be used to set a callback between these calls.
-
FLAGS may include DOTLOCK_LOCK_BY_PARENT bit, when it's the parent
process controlling the lock. This is used by dotlock_tool in
gpgconf.
@@ -1017,7 +995,11 @@ dotlock_create_w32 (dotlock_t h, const char *file_to_lock)
*/
dotlock_t
-dotlock_create (const char *file_to_lock, unsigned int flags)
+dotlock_create_with (const char *file_to_lock, unsigned int flags,
+ int (*msg_cb)(dotlock_t, void *,
+ enum dotlock_reasons reason,
+ const char *, ...),
+ void *msg_cb_arg)
{
static int initialized;
dotlock_t h;
@@ -1044,7 +1026,7 @@ dotlock_create (const char *file_to_lock, unsigned int flags)
flags &= ~(DOTLOCK_LOCK_BY_PARENT | DOTLOCK_LOCKED);
}
#endif
- if ((flags & ~DOTLOCK_PREPARE_CREATE))
+ if (flags)
{
my_set_errno (EINVAL);
return NULL;
@@ -1058,6 +1040,8 @@ dotlock_create (const char *file_to_lock, unsigned int flags)
h->by_parent = by_parent;
h->no_write = no_write;
#endif
+ h->msg_cb = msg_cb;
+ h->msg_cb_arg = msg_cb_arg;
if (never_lock)
{
@@ -1069,24 +1053,6 @@ dotlock_create (const char *file_to_lock, unsigned int flags)
return h;
}
- if ((flags & DOTLOCK_PREPARE_CREATE))
- return h;
- else
- return dotlock_finish_create (h, file_to_lock);
-}
-
-
-/* This function may be used along with dotlock_create (file_name,
- * DOTLOCK_PREPARE_CREATE) to finish the creation call. The given
- * filename shall be the same as passed to dotlock_create. On success
- * the same handle H is returned, on error NULL is returned and H is
- * released. */
-dotlock_t
-dotlock_finish_create (dotlock_t h, const char *file_to_lock)
-{
- if (!h || !file_to_lock)
- return NULL;
-
#ifdef HAVE_DOSISH_SYSTEM
return dotlock_create_w32 (h, file_to_lock);
#else /*!HAVE_DOSISH_SYSTEM */
@@ -1113,24 +1079,11 @@ dotlock_get_fd (dotlock_t h)
}
-/* Set a callback function for info diagnostics. The callback
- * function CB is called with the handle, the opaque value OPAQUE, a
- * reason code, and a format string with its arguments. The callback
- * shall return 0 to continue operation or true in which case the
- * current function will be terminated with an error. */
-void
-dotlock_set_info_cb (dotlock_t h,
- int (*cb)(dotlock_t, void *,
- enum dotlock_reasons reason,
- const char *,...),
- void *opaque)
+dotlock_t
+dotlock_create (const char *file_to_lock, unsigned int flags)
{
- h->info_cb = cb;
- h->info_cb_value = opaque;
+ return dotlock_create_with (file_to_lock, flags, default_msg_cb, NULL);
}
-
-
-
#ifdef HAVE_POSIX_SYSTEM
/* Unix specific code of destroy_dotlock. */
@@ -1289,12 +1242,9 @@ dotlock_take_unix (dotlock_t h, long timeout)
else if (fd == -1)
{
saveerrno = errno;
- my_error_2 ("lock not made: open(O_EXCL) of '%s' failed: %s\n",
- h->lockname, strerror (saveerrno));
- if (h->info_cb)
- h->info_cb (h, h->info_cb_value, DOTLOCK_FILE_ERROR,
- "lock not made: open(O_EXCL) of '%s' failed: %s\n",
- h->lockname, strerror (saveerrno));
+ h->msg_cb (h, h->msg_cb_arg, DOTLOCK_FILE_ERROR,
+ "lock not made: open(O_EXCL) of '%s' failed: %s\n",
+ h->lockname, strerror (saveerrno));
my_set_errno (saveerrno);
return -1;
}
@@ -1315,12 +1265,9 @@ dotlock_take_unix (dotlock_t h, long timeout)
}
/* Write error. */
saveerrno = errno;
- my_error_2 ("lock not made: writing to '%s' failed: %s\n",
- h->lockname, strerror (errno));
- if (h->info_cb)
- h->info_cb (h, h->info_cb_value, DOTLOCK_FILE_ERROR,
- "lock not made: writing to '%s' failed: %s\n",
- h->lockname, strerror (errno));
+ h->msg_cb (h, h->msg_cb_arg, DOTLOCK_FILE_ERROR,
+ "lock not made: writing to '%s' failed: %s\n",
+ h->lockname, strerror (errno));
close (fd);
unlink (h->lockname);
my_set_errno (saveerrno);
@@ -1337,12 +1284,9 @@ dotlock_take_unix (dotlock_t h, long timeout)
if (stat (h->tname, &sb))
{
saveerrno = errno;
- my_error_1 ("lock not made: Oops: stat of tmp file failed: %s\n",
- strerror (errno));
- if (h->info_cb)
- h->info_cb (h, h->info_cb_value, DOTLOCK_FILE_ERROR,
- "lock not made: Oops: stat of tmp file failed: %s\n",
- strerror (errno));
+ h->msg_cb (h, h->msg_cb_arg, DOTLOCK_FILE_ERROR,
+ "lock not made: Oops: stat of tmp file failed: %s\n",
+ strerror (errno));
/* In theory this might be a severe error: It is possible
that link succeeded but stat failed due to changed
permissions. We can't do anything about it, though. */
@@ -1363,14 +1307,13 @@ dotlock_take_unix (dotlock_t h, long timeout)
if ( errno != ENOENT )
{
saveerrno = errno;
- my_info_0 ("cannot read lockfile\n");
- if (h->info_cb)
- h->info_cb (h, h->info_cb_value, DOTLOCK_FILE_ERROR,
- "cannot read lockfile\n");
+ h->msg_cb (h, h->msg_cb_arg, DOTLOCK_FILE_ERROR,
+ "cannot read lockfile\n");
my_set_errno (saveerrno);
return -1;
}
- my_info_0 ("lockfile disappeared\n");
+ h->msg_cb (h, h->msg_cb_arg, DOTLOCK_FILE_ERROR,
+ "lockfile disappeared\n");
goto again;
}
else if ( (pid == dotlock_get_process_id (h) && same_node && !h->by_parent)
@@ -1417,11 +1360,9 @@ dotlock_take_unix (dotlock_t h, long timeout)
*/
unlink (h->lockname);
- my_info_1 (_("removing stale lockfile (created by %d)\n"), pid);
close (fd);
- if (h->info_cb)
- h->info_cb (h, h->info_cb_value, DOTLOCK_STALE_REMOVED,
- _("removing stale lockfile (created by %d)\n"), pid);
+ h->msg_cb (h, h->msg_cb_arg, DOTLOCK_STALE_REMOVED,
+ _("removing stale lockfile (created by %d)\n"), pid);
goto again;
}
@@ -1446,13 +1387,10 @@ dotlock_take_unix (dotlock_t h, long timeout)
if (sumtime >= 1500)
{
sumtime = 0;
- my_info_3 (_("waiting for lock (held by %d%s) %s...\n"),
- pid, maybe_dead, maybe_deadlock(h)? _("(deadlock?) "):"");
- if (h->info_cb
- && h->info_cb (h, h->info_cb_value, DOTLOCK_WAITING,
- _("waiting for lock (held by %d%s) %s...\n"),
- pid, maybe_dead,
- maybe_deadlock(h)? _("(deadlock?) "):""))
+ if (h->msg_cb (h, h->msg_cb_arg, DOTLOCK_WAITING,
+ _("waiting for lock (held by %d%s) %s...\n"),
+ pid, maybe_dead,
+ maybe_deadlock(h)? _("(deadlock?) "):""))
{
my_set_errno (ECANCELED);
return -1;
@@ -1495,12 +1433,9 @@ dotlock_take_w32 (dotlock_t h, long timeout)
w32err = GetLastError ();
if (w32err != ERROR_LOCK_VIOLATION)
{
- my_error_2 (_("lock '%s' not made: %s\n"),
- h->lockname, w32_strerror (w32err));
- if (h->info_cb)
- h->info_cb (h, h->info_cb_value, DOTLOCK_FILE_ERROR,
- _("lock '%s' not made: %s\n"),
- h->lockname, w32_strerror (w32err));
+ h->msg_cb (h, h->msg_cb_arg, DOTLOCK_FILE_ERROR,
+ _("lock '%s' not made: %s\n"),
+ h->lockname, w32_strerror (w32err));
my_set_errno (map_w32_to_errno (w32err));
return -1;
}
@@ -1515,10 +1450,8 @@ dotlock_take_w32 (dotlock_t h, long timeout)
if (wtime >= 800)
{
- my_info_1 (_("waiting for lock %s...\n"), h->lockname);
- if (h->info_cb
- && h->info_cb (h, h->info_cb_value, DOTLOCK_WAITING,
- _("waiting for lock %s...\n"), h->lockname))
+ if (h->msg_cb (h, h->msg_cb_arg, DOTLOCK_WAITING,
+ _("waiting for lock %s...\n"), h->lockname))
{
my_set_errno (ECANCELED);
return -1;
@@ -1548,7 +1481,8 @@ dotlock_take (dotlock_t h, long timeout)
if ( h->locked )
{
- my_info_1 ("Oops, '%s' is already locked\n", h->lockname);
+ h->msg_cb (h, h->msg_cb_arg, DOTLOCK_LOCKED_ALREADY,
+ "Oops, '%s' is already locked\n", h->lockname);
return 0;
}
@@ -1575,19 +1509,15 @@ dotlock_release_unix (dotlock_t h)
if ( pid == -1 )
{
saveerrno = errno;
- my_error_0 ("release_dotlock: lockfile error\n");
- if (h->info_cb)
- h->info_cb (h, h->info_cb_value, DOTLOCK_FILE_ERROR,
- "release_dotlock: lockfile error\n");
+ h->msg_cb (h, h->msg_cb_arg, DOTLOCK_FILE_ERROR,
+ "release_dotlock: lockfile error\n");
my_set_errno (saveerrno);
return -1;
}
if ( pid != dotlock_get_process_id (h) || !same_node )
{
- my_error_1 ("release_dotlock: not our lock (pid=%d)\n", pid);
- if (h->info_cb)
- h->info_cb (h, h->info_cb_value, DOTLOCK_CONFLICT,
- "release_dotlock: not our lock (pid=%d)\n", pid);
+ h->msg_cb (h, h->msg_cb_arg, DOTLOCK_CONFLICT,
+ "release_dotlock: not our lock (pid=%d)\n", pid);
my_set_errno (EACCES);
return -1;
}
@@ -1595,12 +1525,9 @@ dotlock_release_unix (dotlock_t h)
if ( unlink( h->lockname ) )
{
saveerrno = errno;
- my_error_1 ("release_dotlock: error removing lockfile '%s'\n",
- h->lockname);
- if (h->info_cb)
- h->info_cb (h, h->info_cb_value, DOTLOCK_FILE_ERROR,
- "release_dotlock: error removing lockfile '%s'\n",
- h->lockname);
+ h->msg_cb (h, h->msg_cb_arg, DOTLOCK_FILE_ERROR,
+ "release_dotlock: error removing lockfile '%s'\n",
+ h->lockname);
my_set_errno (saveerrno);
return -1;
}
@@ -1623,12 +1550,9 @@ dotlock_release_w32 (dotlock_t h)
{
int ec = (int)GetLastError ();
- my_error_2 ("release_dotlock: error removing lockfile '%s': %s\n",
- h->lockname, w32_strerror (ec));
- if (h->info_cb)
- h->info_cb (h, h->info_cb_value, DOTLOCK_FILE_ERROR,
- "release_dotlock: error removing lockfile '%s': %s\n",
- h->lockname, w32_strerror (ec));
+ h->msg_cb (h, h->msg_cb_arg, DOTLOCK_FILE_ERROR,
+ "release_dotlock: error removing lockfile '%s': %s\n",
+ h->lockname, w32_strerror (ec));
my_set_errno (map_w32_to_errno (ec));
return -1;
}
@@ -1661,10 +1585,8 @@ dotlock_release (dotlock_t h)
{
if (!never_lock)
{
- my_info_1 ("Oops, '%s' is not locked\n", h->lockname);
- if (h->info_cb)
- h->info_cb (h, h->info_cb_value, DOTLOCK_NOT_LOCKED,
- "Oops, '%s' is not locked\n", h->lockname);
+ h->msg_cb (h, h->msg_cb_arg, DOTLOCK_NOT_LOCKED,
+ "Oops, '%s' is not locked\n", h->lockname);
}
return 0;
}
diff --git a/common/dotlock.h b/common/dotlock.h
index a2e10ab78..8030dade5 100644
--- a/common/dotlock.h
+++ b/common/dotlock.h
@@ -77,6 +77,7 @@
# endif /*_DOTLOCK_PREFIX*/
# define dotlock_disable _DOTLOCK_PREFIX(dotlock_disable)
# define dotlock_create _DOTLOCK_PREFIX(dotlock_create)
+# define dotlock_create_with _DOTLOCK_PREFIX(dotlock_create_with)
# define dotlock_set_fd _DOTLOCK_PREFIX(dotlock_set_fd)
# define dotlock_get_fd _DOTLOCK_PREFIX(dotlock_get_fd)
# define dotlock_destroy _DOTLOCK_PREFIX(dotlock_destroy)
@@ -99,30 +100,30 @@ typedef struct dotlock_handle *dotlock_t;
enum dotlock_reasons
{
- DOTLOCK_CONFIG_TEST, /* Can't check system - function terminates. */
- DOTLOCK_FILE_ERROR, /* General file error - function terminates. */
- DOTLOCK_INV_FILE, /* Invalid file - function terminates. */
- DOTLOCK_CONFLICT, /* Something is wrong - function terminates. */
- DOTLOCK_NOT_LOCKED, /* Not locked - No action required. */
- DOTLOCK_STALE_REMOVED, /* Stale lock file was removed - retrying. */
- DOTLOCK_WAITING /* Waiting for the lock - may be terminated. */
+ DOTLOCK_CONFIG_TEST, /* Can't check system - function terminates. */
+ DOTLOCK_FILE_ERROR, /* General file error - function terminates. */
+ DOTLOCK_INV_FILE, /* Invalid file - function terminates. */
+ DOTLOCK_CONFLICT, /* Something is wrong - function terminates. */
+ DOTLOCK_NOT_LOCKED, /* Not locked - No action required. */
+ DOTLOCK_STALE_REMOVED, /* Stale lock file was removed - retrying. */
+ DOTLOCK_WAITING, /* Waiting for the lock - may be terminated. */
+ DOTLOCK_LOCKED_ALREADY, /* Not locked - No action required. */
+ DOTLOCK_FATAL /* Fatal runtime error. */
};
/* Flags for dotlock_create. */
-#define DOTLOCK_PREPARE_CREATE (1U << 5) /* Require dotlock_finish_create. */
#define DOTLOCK_LOCK_BY_PARENT (1U << 6) /* Used by dotlock_tool. */
#define DOTLOCK_LOCKED (1U << 7) /* Used by dotlock_tool. */
void dotlock_disable (void);
dotlock_t dotlock_create (const char *file_to_lock, unsigned int flags);
-dotlock_t dotlock_finish_create (dotlock_t h, const char *file_to_lock);
+dotlock_t dotlock_create_with (const char *file_to_lock, unsigned int flags,
+ int (*cb)(dotlock_t, void *,
+ enum dotlock_reasons reason,
+ const char *, ...),
+ void *cb_arg);
void dotlock_set_fd (dotlock_t h, int fd);
int dotlock_get_fd (dotlock_t h);
-void dotlock_set_info_cb (dotlock_t h,
- int (*cb)(dotlock_t, void *,
- enum dotlock_reasons reason,
- const char *,...),
- void *opaque);
void dotlock_destroy (dotlock_t h);
int dotlock_take (dotlock_t h, long timeout);
int dotlock_is_locked (dotlock_t h);
diff --git a/common/t-dotlock.c b/common/t-dotlock.c
index 87e62bb33..d30e60d39 100644
--- a/common/t-dotlock.c
+++ b/common/t-dotlock.c
@@ -255,11 +255,9 @@ lock_and_unlock (const char *fname)
dotlock_t h;
unsigned long usec;
- h = dotlock_create (fname, DOTLOCK_PREPARE_CREATE);
+ h = dotlock_create_with (fname, lock_info_cb, NULL);
if (!h)
die ("error creating lock file for '%s': %s", fname, strerror (errno));
- dotlock_set_info_cb (h, lock_info_cb, NULL);
- h = dotlock_finish_create (h, fname);
if (!h)
die ("error finishing lock file creation for '%s': %s",
fname, strerror (errno));
diff --git a/kbx/backend-sqlite.c b/kbx/backend-sqlite.c
index 739089330..9d25a077b 100644
--- a/kbx/backend-sqlite.c
+++ b/kbx/backend-sqlite.c
@@ -557,7 +557,15 @@ dblock_info_cb (dotlock_t h, void *opaque, enum dotlock_reasons reason,
log_error ("sending status line failed: %s\n", gpg_strerror (err));
rc = 1; /* snprintf failed. */
}
+ }
+ else
+ {
+ va_start (arg_ptr, format);
+ log_logv (GPGRT_LOGLVL_INFO, format, arg_ptr);
+ va_end (arg_ptr);
+ if (reason == DOTLOCK_FATAL)
+ abort ();
}
return rc;
}
@@ -663,7 +671,7 @@ create_or_open_database (ctrl_t ctrl, const char *filename)
/* To avoid races with other temporary instances of keyboxd trying
* to create or update the database, we run the database with a lock
* file held. */
- database_lock = dotlock_create (filename, DOTLOCK_PREPARE_CREATE);
+ database_lock = dotlock_create_with (filename, 0, dblock_info_cb, ctrl);
if (!database_lock)
{
err = gpg_error_from_syserror ();
@@ -671,8 +679,6 @@ create_or_open_database (ctrl_t ctrl, const char *filename)
log_info ("can't allocate dotlock handle: %s\n", gpg_strerror (err));
goto leave;
}
- dotlock_set_info_cb (database_lock, dblock_info_cb, ctrl);
- database_lock = dotlock_finish_create (database_lock, filename);
if (!database_lock)
{
err = gpg_error_from_syserror ();
--
2.47.2

File Metadata

Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
45/e8/69a42734b4e0976c184650b214be

Event Timeline