mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
See ChangeLog: Fri Jul 14 19:38:23 CEST 2000 Werner Koch
This commit is contained in:
parent
d1648b4d7a
commit
92cd255508
104 changed files with 5871 additions and 1540 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue