diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2021-04-29 19:03:26 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2021-04-29 19:11:20 +0300 |
commit | 9eca2fa180cb562128a9db1bad8c77d0b3bdc6a4 (patch) | |
tree | 76e402ef9ed270619d6618a060de75237f10bda1 /dotlock | |
parent | 6a1152b883407a5cc7d77faa023d2948ac70e8de (diff) | |
download | mailutils-9eca2fa180cb562128a9db1bad8c77d0b3bdc6a4.tar.gz mailutils-9eca2fa180cb562128a9db1bad8c77d0b3bdc6a4.tar.bz2 |
Further improvements of the locker interface.
This fixes a bug that prevented previous versions of mailutils to
retry aquiring the lock.
Locking configuration (the "locking" section) is improved.
* dotlock/dotlock.c: New options: --retry (-r), --delay (-t),
--pid-check (-p).
Use the "locking" capability.
* libmailutils/base/locker.c: Remove the uses of assert().
(mu_locker_lock_mode): Fix the retry loop.
(lock_dotlock): Use mu_asprintf to create temporary lock name.
Return EAGAIN on temporary error conditions.
(lock_kernel): Fix typo (EACCES).
* libmailutils/cli/stdcapa.c (cb_locker_flags): Locker flags are
deprecated.
(cb_locker_retry_timeout,cb_locker_retry_count): Clear the
MU_LOCKER_RETRY flag, if supplied a zero value.
(cb_locker_external): Clear the MU_LOCKER_EXTERNAL flag (revert
to the dotlock locker type) if the value is a false boolean value.
* libmailutils/tests/Makefile.am: Add new test.
* libmailutils/tests/testsuite.at: Include new test,
* libmailutils/tests/lck.c: New test program.
* libmailutils/tests/lock.at: New test.
Diffstat (limited to 'dotlock')
-rw-r--r-- | dotlock/dotlock.c | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/dotlock/dotlock.c b/dotlock/dotlock.c index 03d23977f..1bb11590b 100644 --- a/dotlock/dotlock.c +++ b/dotlock/dotlock.c @@ -29,9 +29,11 @@ static const char *file; static int unlock; static int flags; -static int retries; +static unsigned retries; static unsigned force; static int debug; +static unsigned retry_sleep = 0; +static int pid_check; static void cli_force (struct mu_parseopt *po, struct mu_option *opt, char const *arg) @@ -66,10 +68,18 @@ static struct mu_option dotlock_options[] = { N_("forcibly break an existing lock older than a certain time"), mu_c_uint, &force, cli_force }, - { "retry", 'r', N_("RETRIES"), MU_OPTION_ARG_OPTIONAL, + { "retry", 'r', N_("RETRIES"), MU_OPTION_DEFAULT, N_("retry the lock a few times"), - mu_c_int, &retries }, + mu_c_uint, &retries }, + { "delay", 't', N_("SECONDS"), MU_OPTION_DEFAULT, + N_("delay between two successive locking attempts (in seconds)"), + mu_c_uint, &retry_sleep }, + + { "pid-check", 'p', NULL, MU_OPTION_DEFAULT, + N_("check if the PID of lock owner is still active"), + mu_c_bool, &pid_check }, + { "debug", 'd', NULL, MU_OPTION_DEFAULT, N_("print details of failure reasons to stderr"), mu_c_bool, &debug }, @@ -80,8 +90,6 @@ static struct mu_option dotlock_options[] = { struct mu_cfg_param dotlock_cfg_param[] = { { "force", mu_c_time, &force, 0, NULL, N_("Forcibly break an existing lock older than the specified time.") }, - { "retry", mu_c_int, &retries, 0, NULL, - N_("Number of times to retry acquiring the lock.") }, { "debug", mu_c_bool, &debug, 0, NULL, N_("Print details of failure reasons to stderr.") }, { NULL } @@ -103,6 +111,7 @@ static struct mu_cli_setup cli = { char *capa[] = { "debug", + "locking", NULL }; @@ -144,9 +153,12 @@ main (int argc, char *argv[]) flags |= MU_LOCKER_TIME; } - if (retries != 0) + if (retries || retry_sleep) flags |= MU_LOCKER_RETRY; - + + if (pid_check) + flags |= MU_LOCKER_PID; + if ((err = mu_locker_create (&locker, file, flags))) { if (debug) @@ -157,8 +169,10 @@ main (int argc, char *argv[]) if (force != 0) mu_locker_set_expire_time (locker, force); - if (retries != 0) + if (retries) mu_locker_set_retries (locker, retries); + if (retry_sleep) + mu_locker_set_retry_sleep (locker, retry_sleep); if (setegid (mailgid) < 0) return MU_DL_EX_ERROR; @@ -168,7 +182,7 @@ main (int argc, char *argv[]) else err = mu_locker_lock (locker); - setegid(usergid); + setegid (usergid); mu_locker_destroy (&locker); |