summaryrefslogtreecommitdiffstats
path: root/common/dotlock.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* common: Clean up the temporary file at dotlock_destroy.NIIBE Yutaka2023-12-201-0/+6
| | | | | | | | | * common/dotlock.c (dotlock_destroy): Clean up the temporary file created when it fails. -- Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
* common: Support not-removing the lockfile by dotlock_destroy.NIIBE Yutaka2023-12-201-1/+4
| | | | | | | | | * common/dotlock.c (dotlock_destroy): Keep the lock when DOTLOCK_LOCK_BY_PARENT. -- Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
* common: Fix a possible resource leak for dotlock.NIIBE Yutaka2023-12-201-2/+5
| | | | | | | | | * common/dotlock.c (dotlock_destroy_unix): Don't release ->TNAME here. (dotlock_destroy): Release the memory unconditionally. -- Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
* common: Enhance dotlock, so that we can have a CLI util.NIIBE Yutaka2023-12-191-10/+134
| | | | | | | | | | | | | | | | * common/dotlock.h (DOTLOCK_LOCK_BY_PARENT, DOTLOCK_LOCKED): New. * common/dotlock.c [HAVE_POSIX_SYSTEM]: Include <dirent.h>. (dotlock_get_process_id, dotlock_detect_tname): New. (dotlock_create_unix): Handle the case when no_write option is specified. Not creating the lock file, but detect the the file of tname. (dotlock_create) [HAVE_POSIX_SYSTEM]: Add support of DOTLOCK_LOCK_BY_PARENT and DOTLOCK_LOCKED for dotlock CLI util. (dotlock_take_unix): Support the case of DOTLOCK_LOCK_BY_PARENT. -- Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
* common: Add an info callback to dotlock.Werner Koch2023-12-181-10/+148
| | | | | | | | | | | | | * common/dotlock.h (enum dotlock_reasons): New. (DOTLOCK_PREPARE_CREATE): New flag. * common/dotlock.c (struct dotlock_handle): Add info_cb and info_cb_value. (dotlock_create): Support the new flag. (dotlock_finish_create): New. (read_lockfile): Silence in case of ENOENT. (dotlock_set_info_cb): New. Use callback after all error and info messages. (dotlock_take_unix, dotlock_take_w32): Allow termination by callback.
* common: Improve error return for dotlock.Werner Koch2023-12-121-2/+8
| | | | | | * common/dotlock.c (dotlock_take_unix): Return a ETIMEDOUT insteaad of EACCESS on timeout. (dotlock_take_w32): Ditto.
* common: Improve lock strategy for dotlock.Werner Koch2023-10-021-40/+54
| | | | | | | | | | | | | | | | | | | | | | | | | * common/dotlock.c (next_wait_interval): New. (dotlock_take_unix): Use new function. (dotlock_take_w32): Ditto. -- In particular when using a dotlock file for protecting the spawning and several processes try to spawn the agent or another component, we often run into long delays. The solution is to is to exponential backoff and also to reduce the initial delay from 50ms to 4ms. We further limit the maximum wait period to about 2 seconds and then repeat at intervals of 512, 1024 and 2048ms. In the wait-forever case we add a small random value to have different intervals per process. GnuPG-bug-id: 3380 For testing this code snippet in the spawning function might be useful: const char *s; if ((s=getenv("hold_gpg_file"))) while (!gnupg_access (s, F_OK)) gnupg_sleep (1);
* common: Remove Windows CE support in common.NIIBE Yutaka2022-11-161-5/+0
| | | | | | | | | | | | | | | | | * common/Makefile.am (HAVE_W32CE_SYSTEM): Remove conditional build. (common_sources): Remove exechelp-w32ce.c. * common/asshelp.c [HAVE_W32CE_SYSTEM]: Remove the support. * common/common-defs.h [HAVE_W32CE_SYSTEM]: Likewise. * common/dotlock.c [HAVE_W32CE_SYSTEM]: Likewise. * common/exechelp-posix.c [HAVE_W32CE_SYSTEM]: Likewise. * common/exechelp-w32.c [HAVE_W32CE_SYSTEM]: Likewise. * common/gettime.c [HAVE_W32CE_SYSTEM]: Likewise. * common/exechelp-w32ce.c: Remove. * po/POTFILES.in: Update to remove common/exechelp-w32ce.c. -- Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
* common: Fix another race condition, and address the other one.NIIBE Yutaka2022-03-191-12/+34
| | | | | | | | | | * common/dotlock.c (dotlock_take_unix): Do same when same PID process detects stale lockfile. Add comment. -- GnuPG-bug-id: 5884 Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
* common: Fix a race condition removing stale lockfile.NIIBE Yutaka2022-03-181-9/+24
| | | | | | | | | | | * common/dotlock.c (read_lockfile): Return the file descriptor when R_FD is available. (dotlock_take_unix): Check the case the lockfile was already removed. -- GnuPG-bug-id: 5884 Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
* gpg,w32: Fix gnupg_remove.Werner Koch2021-01-111-0/+2
| | | | | | | | | | | | | | | | | | | | | | | * common/sysutils.c (map_w32_to_errno): New. (gnupg_w32_set_errno): New. (gnupg_remove) [w32]: Set ERRNO -- To support Unicode gnupg_remove was changed to use DeleteFileW and not properly tested because the code was alreadt used in Windows CE. However, ERRNO was not set and thus Dirmngr failed due to if (!gnupg_remove (fname)) log_info (_("removed stale te[...] file '%s'\n"), fname); else if (errno != ENOENT) { err = gpg_error_from_syserror (); log_error (_("problem remov[...] file '%s': %s\n"), fname, gpg_strerror (err)); goto leave; } GnuPG-bug-id: 5230
* common: Remove superfluous debug output from dotlock.c.Werner Koch2020-12-211-2/+0
| | | | | | | | | | * common/dotlock.c (dotlock_create_unix): Remove debug output. -- This was left over from developement about 10 years ago. Exhibits itself when using sshfs. GnuPG-bug-id: 5193
* w32: Allow Unicode filenames for dotlockWerner Koch2020-10-201-21/+34
| | | | | | | | | | | | * common/dotlock.c (any8bitchar) [W32]: New. (dotlock_create_w32): Use strconcat and CreateFileW. * common/t-dotlock.c: Source include dotlock.c and modify to allow manual testing on Windows. -- GnuPG-bug-id: 5098 Signed-off-by: Werner Koch <wk@gnupg.org>
* Spelling cleanup.Daniel Kahn Gillmor2020-02-191-2/+2
| | | | | | | | | | | | | | | | No functional changes, just fixing minor spelling issues. --- Most of these were identified from the command line by running: codespell \ --ignore-words-list fpr,stati,keyserver,keyservers,asign,cas,iff,ifset \ --skip '*.po,ChangeLog*,help.*.txt,*.jpg,*.eps,*.pdf,*.png,*.gpg,*.asc' \ doc g13 g10 kbx agent artwork scd tests tools am common dirmngr sm \ NEWS README README.maint TODO Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
* doc: Typ fix in commentWerner Koch2019-12-231-1/+1
| | | | --
* all: fix spelling and typosDaniel Kahn Gillmor2018-10-241-1/+1
| | | | Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
* Spelling fixes in docs and comments.NIIBE Yutaka2017-04-281-1/+1
| | | | | | | | | | -- In addition, fix trailing spaces in tests/inittests. GnuPG-bug-id: 3121 Reported-by: ka7 (klemens) Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
* Clarify text of LGPLv2+/GPLv2+ licensed files.Werner Koch2017-02-241-2/+2
| | | | --
* Clean up word replication.Yuri Chornoivan2017-02-211-3/+3
| | | | | | | | | -- This fixes extra word repetitions (like "the the" or "is is") in the code and docs. Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
* Change all http://www.gnu.org in license notices to https://Werner Koch2016-11-051-1/+1
| | | | --
* common: Make sure dotlock functions set a proper ERRNO.Werner Koch2016-01-131-17/+87
| | | | | | | | | | | | | * common/dotlock.c (map_w32_to_errno): New. (read_lockfile): Return a proper ERRNO. (dotlock_create_unix): Do not let log functions clobber ERRNO. (dotlock_take_unix): Ditto. (dotlock_release_unix): Ditto. (dotlock_create_w32): Set proper ERRNO. (dotlock_take_w32): Ditto. (dotlock_release_w32): Ditto. Signed-off-by: Werner Koch <wk@gnupg.org>
* Fix typos found using codespell.Justus Winter2015-11-171-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * agent/cache.c: Fix typos. * agent/call-pinentry.c: Likewise. * agent/call-scd.c: Likewise. * agent/command-ssh.c: Likewise. * agent/command.c: Likewise. * agent/divert-scd.c: Likewise. * agent/findkey.c: Likewise. * agent/gpg-agent.c: Likewise. * agent/w32main.c: Likewise. * common/argparse.c: Likewise. * common/audit.c: Likewise. * common/audit.h: Likewise. * common/convert.c: Likewise. * common/dotlock.c: Likewise. * common/exechelp-posix.c: Likewise. * common/exechelp-w32.c: Likewise. * common/exechelp-w32ce.c: Likewise. * common/exechelp.h: Likewise. * common/helpfile.c: Likewise. * common/i18n.h: Likewise. * common/iobuf.c: Likewise. * common/iobuf.h: Likewise. * common/localename.c: Likewise. * common/logging.c: Likewise. * common/openpgp-oid.c: Likewise. * common/session-env.c: Likewise. * common/sexputil.c: Likewise. * common/sysutils.c: Likewise. * common/t-sexputil.c: Likewise. * common/ttyio.c: Likewise. * common/util.h: Likewise. * dirmngr/cdblib.c: Likewise. * dirmngr/certcache.c: Likewise. * dirmngr/crlcache.c: Likewise. * dirmngr/dirmngr-client.c: Likewise. * dirmngr/dirmngr.c: Likewise. * dirmngr/dirmngr_ldap.c: Likewise. * dirmngr/dns-stuff.c: Likewise. * dirmngr/http.c: Likewise. * dirmngr/ks-engine-hkp.c: Likewise. * dirmngr/ks-engine-ldap.c: Likewise. * dirmngr/ldap-wrapper.c: Likewise. * dirmngr/ldap.c: Likewise. * dirmngr/misc.c: Likewise. * dirmngr/ocsp.c: Likewise. * dirmngr/validate.c: Likewise. * g10/encrypt.c: Likewise. * g10/getkey.c: Likewise. * g10/gpg.c: Likewise. * g10/gpgv.c: Likewise. * g10/import.c: Likewise. * g10/keydb.c: Likewise. * g10/keydb.h: Likewise. * g10/keygen.c: Likewise. * g10/keyid.c: Likewise. * g10/keylist.c: Likewise. * g10/keyring.c: Likewise. * g10/mainproc.c: Likewise. * g10/misc.c: Likewise. * g10/options.h: Likewise. * g10/packet.h: Likewise. * g10/parse-packet.c: Likewise. * g10/pkclist.c: Likewise. * g10/pkglue.c: Likewise. * g10/plaintext.c: Likewise. * g10/server.c: Likewise. * g10/sig-check.c: Likewise. * g10/sqlite.c: Likewise. * g10/tdbio.c: Likewise. * g10/test-stubs.c: Likewise. * g10/tofu.c: Likewise. * g10/trust.c: Likewise. * g10/trustdb.c: Likewise. * g13/create.c: Likewise. * g13/mountinfo.c: Likewise. * kbx/keybox-blob.c: Likewise. * kbx/keybox-file.c: Likewise. * kbx/keybox-init.c: Likewise. * kbx/keybox-search-desc.h: Likewise. * kbx/keybox-search.c: Likewise. * kbx/keybox-update.c: Likewise. * scd/apdu.c: Likewise. * scd/app-openpgp.c: Likewise. * scd/app-p15.c: Likewise. * scd/app.c: Likewise. * scd/ccid-driver.c: Likewise. * scd/command.c: Likewise. * scd/iso7816.c: Likewise. * sm/base64.c: Likewise. * sm/call-agent.c: Likewise. * sm/call-dirmngr.c: Likewise. * sm/certchain.c: Likewise. * sm/gpgsm.c: Likewise. * sm/import.c: Likewise. * sm/keydb.c: Likewise. * sm/minip12.c: Likewise. * sm/qualified.c: Likewise. * sm/server.c: Likewise. * tools/gpg-check-pattern.c: Likewise. * tools/gpgconf-comp.c: Likewise. * tools/gpgkey2ssh.c: Likewise. * tools/gpgparsemail.c: Likewise. * tools/gpgtar.c: Likewise. * tools/rfc822parse.c: Likewise. * tools/symcryptrun.c: Likewise. Signed-off-by: Justus Winter <justus@g10code.com>
* common: Remove JNLIB from boiler plate (jnlib merge).Werner Koch2015-04-241-3/+3
| | | | | | | * common/README.jnlib: Remove. -- This is the final part of merging jnlib into gnupg/common.
* common: Remove libjnlib-config.h (jnlib merge).Werner Koch2015-04-241-46/+45
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * common/libjnlib-config.h: Remove. * common/common-defs.h (getenv) [HAVE_GETENV]: New. From removed header. (getpid) [HAVE_W32CE_SYSTEM]: New. From removed header. * common/argparse.c: Include util.h and common-defs.h. Replace jnlib_ macro names for non-GNUPG builds by x* names. * common/dotlock.c: Ditto. * common/logging.c: Include util.h and common-defs.h. Replace jnlib_ symbol names by x* names. * common/strlist.c: Ditto. * common/utf8conv.c: Ditto. * common/w32-reg.c: Ditto. * common/mischelp.c: Ditto. Also remove _jnlib_free. * common/stringhelp.c: Ditto. (JNLIB_LOG_WITH_PREFIX): Do not depend on this macro. * common/logging.h (JNLIB_LOG_WITH_PREFIX): Do not depend on this macro. -- This is part 1 of the patches to merge the jnlib files into common/. It does not make much sense to keep jnlib/ files separate. They are not often use elsewhere and maintaining the complex marcos stuff is too troublesome for the future. Signed-off-by: Werner Koch <wk@gnupg.org>
* avoid double-close in unusual dotlock situationsDaniel Kahn Gillmor2014-12-221-2/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * common/dotlock.c: (dotlock_create_unix) avoid double-close() in unusual situations. -- close(2) says: close() should not be retried after an EINTR since this may cause a reused descriptor from another thread to be closed. Before this patch was applied, if close(fd) failed with EINTR, it would be closed again in the write_failed: block. It could also have been closed a second time in the case that (use_hardlinks_p (h->tname)) evaluated to something other than 0 or 1. This patch avoids both of those scenarios. Note that close() could still be called twice on the same file descriptor if the first close(fd) fails but errno is not EINTR. I'm not sure the right thing to do in that scenario. An alternate resolution could be to unequivocally set fd to -1 after the first failed close(fd), avoiding the errno == EINTR test. Debian-Bug-Id: 773423
* Silence several warnings when building under Windows.Werner Koch2014-03-071-0/+1
| | | | | | | | | | | | | | | | | | | | | | | * agent/call-scd.c (start_scd): Replace int by assuan_fd_t. (start_pinentry): Ditto. * common/asshelp.c (start_new_gpg_agent): Replace int by assuan_fd_t. * common/dotlock.c (GNUPG_MAJOR_VERSION): Include stringhelp.h for prototypes on Windows and some other platforms. * common/logging.c (fun_writer): Declare addrbuf only if needed. * g10/decrypt.c (decrypt_message_fd) [W32]: Return not_implemented. * g10/encrypt.c (encrypt_crypt) [W32]: Return error if used in server mode. * g10/dearmor.c (dearmor_file, enarmor_file): Replace GNUPG_INVALID_FD by -1 as temporary hack for Windows. * g10/export.c (do_export): Ditto. * g10/revoke.c (gen_desig_revoke, gen_revoke): Ditto. * g10/sign.c (sign_file, clearsign_file, sign_symencrypt_file): Ditto. * g10/server.c (cmd_verify, gpg_server) [W32]: Return an error. -- The gpg server mode is not actual working and thus we can avoid the warnings by explicitly disabling the mode. We keep it working under Unix, though.
* Change all quotes in strings and comments to the new GNU standard.Werner Koch2012-06-051-17/+17
| | | | | | | | | | | | | | | | | | | The asymmetric quotes used by GNU in the past (`...') don't render nicely on modern systems. We now use two \x27 characters ('...'). The proper solution would be to use the correct Unicode symmetric quotes here. However this has the disadvantage that the system requires Unicode support. We don't want that today. If Unicode is available a generated po file can be used to output proper quotes. A simple sed script like the one used for en@quote is sufficient to change them. The changes have been done by applying sed -i "s/\`\([^'\`]*\)'/'\1'/g" to most files and fixing obvious problems by hand. The msgid strings in the po files were fixed with a similar command.
* Revert last change, add comment about link() return values.Marcus Brinkmann2012-01-031-21/+11
| | | | | * common/dotlock.c (use_hardlinks_p, dotlock_take_unix): Do not check return value of link().
* Fix compiler warnings.Marcus Brinkmann2012-01-031-9/+21
| | | | | | | * common/dotlock.c (use_hardlinks_p, dotlock_take_unix): Check return value of link(). * g13/g13.c: Make sure err is initialized. * scd/scdaemon.c (main) [!USE_GCRY_THREAD_CBS]: Do not define ERR.
* Allow distribution of dotlock.* also under a modified BSD licenseWerner Koch2011-10-241-0/+36
|
* Change JNLIB license to LGPLv3+ or GPLv2+.Werner Koch2011-09-301-6/+17
| | | | This is to allow the use of this code with code under GPLv2(only).
* Add prefix macro for dotlock functions.Werner Koch2011-09-301-8/+13
| | | | Also fixed a type in the GLIB version.
* Add dotlock_get_fd and dotlock_set_fd.Werner Koch2011-09-291-2/+34
|
* Make dotlock.c thread-safe on pthread systems.Werner Koch2011-09-291-25/+74
| | | | This is achieved by passing the define DOTLOCK_USE_PTHREAD.
* Add a flag parameter to dotlock_create.Werner Koch2011-09-281-7/+18
| | | | This allows us to extend this function in the future.
* Allow arbitrary timeouts with dotlock.Werner Koch2011-09-281-37/+82
|
* Improved the dotlock module.Werner Koch2011-09-271-41/+372
| | | | | | | - It is now more portable and may be used outside of GnuPG - vfat file systems are now supported. - The use of link(2) is more robust. - Wrote extensive documentation.
* Renamed the lock functions.Werner Koch2011-09-231-311/+419
| | | | Also cleaned up the dotlock code for easier readability.
* Remove support for RISCOS from dotlock.cWerner Koch2011-09-221-58/+7
|
* Nuked almost all trailing white space.post-nuke-of-trailing-wsWerner Koch2011-02-041-31/+30
| | | | | | | | We better do this once and for all instead of cluttering all future commits with diffs of trailing white spaces. In the majority of cases blank or single lines are affected and thus this change won't disturb a git blame too much. For future commits the pre-commit scripts checks that this won't happen again.
* More changes for CE. gpgsm does now build and run a keylisting.Werner Koch2010-03-241-9/+21
|
* Merged jnlib into common.Werner Koch2010-03-101-0/+713