aboutsummaryrefslogtreecommitdiffstats
path: root/common/t-dotlock.c
diff options
context:
space:
mode:
authorNIIBE Yutaka <[email protected]>2022-03-18 01:53:10 +0000
committerNIIBE Yutaka <[email protected]>2022-03-18 03:01:45 +0000
commita30359cecb5b8ac73906264ded617a35794a0b0a (patch)
treefb1ab250a27d71e31ef4f5b8e34a0e79f2a30fbc /common/t-dotlock.c
parentscd: Fix DEVINFO with no --watch. (diff)
downloadgnupg-a30359cecb5b8ac73906264ded617a35794a0b0a.tar.gz
gnupg-a30359cecb5b8ac73906264ded617a35794a0b0a.zip
common: More heavy test condition for t-dotlock.c.
* common/t-dotlock.c (lock_and_unlock): Use usleep and faster. Loop at least once. Use getrandom for random time. (main): Add new option --one-shot to run lock/unlock once. -- GnuPG-bug-id: 5884 Signed-off-by: NIIBE Yutaka <[email protected]>
Diffstat (limited to 'common/t-dotlock.c')
-rw-r--r--common/t-dotlock.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/common/t-dotlock.c b/common/t-dotlock.c
index e2d22f66d..48f2e1f67 100644
--- a/common/t-dotlock.c
+++ b/common/t-dotlock.c
@@ -43,6 +43,8 @@
#include <unistd.h>
#ifdef HAVE_W32_SYSTEM
# include "windows.h"
+#else
+#include <sys/random.h>
#endif
#include "dotlock.h"
@@ -233,23 +235,32 @@ static void
lock_and_unlock (const char *fname)
{
dotlock_t h;
+ unsigned long usec;
h = dotlock_create (fname, 0);
if (!h)
die ("error creating lock file for '%s': %s", fname, strerror (errno));
inf ("lock created");
- while (!ctrl_c_pending ())
+ do
{
+#ifdef HAVE_W32_SYSTEM
+ usec = 10000;
+#else
+ getrandom (&usec, sizeof (usec), 0);
+ usec &= 0xffff;
+ usec |= 0x0f00;
+#endif
if (dotlock_take (h, -1))
die ("error taking lock");
inf ("lock taken");
- sleep (1);
+ usleep (usec);
if (dotlock_release (h))
die ("error releasing lock");
inf ("lock released");
- sleep (1);
+ usleep (usec);
}
+ while (!ctrl_c_pending ());
dotlock_destroy (h);
inf ("lock destroyed");
}
@@ -260,8 +271,14 @@ main (int argc, char **argv)
{
const char *fname;
+ if (argc > 1 && !strcmp (argv[1], "--one-shot"))
+ {
+ ctrl_c_pending_flag = 1;
+ argc--;
+ }
+
if (argc > 1)
- fname = argv[1];
+ fname = argv[argc-1];
else
{
#ifdef HAVE_W32_SYSTEM