summaryrefslogtreecommitdiffstats
path: root/jnlib/dotlock.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2000-07-14 19:34:53 +0200
committerWerner Koch <wk@gnupg.org>2000-07-14 19:34:53 +0200
commit92cd25550836198cf1e3a6aac239eef98364359d (patch)
tree4fad355126fae79c93535e0e7c6afd91e384552a /jnlib/dotlock.c
parentSee ChangeLog: Thu May 25 18:39:11 CEST 2000 Werner Koch (diff)
downloadgnupg2-92cd25550836198cf1e3a6aac239eef98364359d.tar.xz
gnupg2-92cd25550836198cf1e3a6aac239eef98364359d.zip
See ChangeLog: Fri Jul 14 19:38:23 CEST 2000 Werner Koch
Diffstat (limited to 'jnlib/dotlock.c')
-rw-r--r--jnlib/dotlock.c40
1 files changed, 34 insertions, 6 deletions
diff --git a/jnlib/dotlock.c b/jnlib/dotlock.c
index 8e61f7a03..29ab65dff 100644
--- a/jnlib/dotlock.c
+++ b/jnlib/dotlock.c
@@ -1,5 +1,5 @@
/* dotlock.c - dotfile locking
- * Copyright (C) 1998,2000 Free Software Foundation, Inc.
+ * Copyright (C) 1998, 2000 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -42,14 +42,22 @@ struct dotlock_handle {
char *tname; /* name of lockfile template */
char *lockname; /* name of the real lockfile */
int locked; /* lock status */
+ int disable; /* locking */
};
static DOTLOCK all_lockfiles;
+static int never_lock;
static int read_lockfile( const char *name );
static void remove_lockfiles(void);
+void
+disable_dotlock(void)
+{
+ never_lock = 1;
+}
+
/****************
* Create a lockfile with the given name and return an object of
* type DOTLOCK which may be used later to actually do the lock.
@@ -88,6 +96,16 @@ create_dotlock( const char *file_to_lock )
return NULL;
h = jnlib_xcalloc( 1, sizeof *h );
+ if( never_lock ) {
+ h->disable = 1;
+ #ifdef _REENTRANT
+ /* fixme: aquire mutex on all_lockfiles */
+ #endif
+ h->next = all_lockfiles;
+ all_lockfiles = h;
+ return h;
+ }
+
#ifndef HAVE_DOSISH_SYSTEM
sprintf( pidstr, "%10d\n", (int)getpid() );
/* fixme: add the hostname to the second line (FQDN or IP addr?) */
@@ -191,6 +209,10 @@ make_dotlock( DOTLOCK h, long timeout )
const char *maybe_dead="";
int backoff=0;
+ if( h->disable ) {
+ return 0;
+ }
+
if( h->locked ) {
log_debug("oops, `%s' is already locked\n", h->lockname );
return 0;
@@ -259,6 +281,10 @@ release_dotlock( DOTLOCK h )
#else
int pid;
+ if( h->disable ) {
+ return 0;
+ }
+
if( !h->locked ) {
log_debug("oops, `%s' is not locked\n", h->lockname );
return 0;
@@ -333,11 +359,13 @@ remove_lockfiles()
while( h ) {
h2 = h->next;
- if( h->locked )
- unlink( h->lockname );
- unlink(h->tname);
- jnlib_free(h->tname);
- jnlib_free(h->lockname);
+ if( !h->disable ) {
+ if( h->locked )
+ unlink( h->lockname );
+ unlink(h->tname);
+ jnlib_free(h->tname);
+ jnlib_free(h->lockname);
+ }
jnlib_free(h);
h = h2;
}