mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-18 14:17:03 +01:00
Add a flag parameter to dotlock_create.
This allows us to extend this function in the future.
This commit is contained in:
parent
567a31c2a0
commit
ed8e267859
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
* dotlock.c (dotlock_take, dotlock_take_unix, dotlock_take_w32):
|
* dotlock.c (dotlock_take, dotlock_take_unix, dotlock_take_w32):
|
||||||
Implement arbitrary timeout values.
|
Implement arbitrary timeout values.
|
||||||
|
(dotlock_create): Add arg FLAGS for future extensions.
|
||||||
|
|
||||||
2011-09-27 Werner Koch <wk@g10code.com>
|
2011-09-27 Werner Koch <wk@g10code.com>
|
||||||
|
|
||||||
|
@ -287,7 +287,7 @@ lock_spawning (lock_spawn_t *lock, const char *homedir, const char *name,
|
|||||||
if (!fname)
|
if (!fname)
|
||||||
return gpg_error_from_syserror ();
|
return gpg_error_from_syserror ();
|
||||||
|
|
||||||
*lock = dotlock_create (fname);
|
*lock = dotlock_create (fname, 0);
|
||||||
xfree (fname);
|
xfree (fname);
|
||||||
if (!*lock)
|
if (!*lock)
|
||||||
return gpg_error_from_syserror ();
|
return gpg_error_from_syserror ();
|
||||||
|
@ -53,7 +53,7 @@
|
|||||||
At program initialization time, the module should be explicitly
|
At program initialization time, the module should be explicitly
|
||||||
initialized:
|
initialized:
|
||||||
|
|
||||||
dotlock_create (NULL);
|
dotlock_create (NULL, 0);
|
||||||
|
|
||||||
This installs an atexit handler and may also initialize mutex etc.
|
This installs an atexit handler and may also initialize mutex etc.
|
||||||
It is optional for non-threaded applications. Only the first call
|
It is optional for non-threaded applications. Only the first call
|
||||||
@ -64,7 +64,7 @@
|
|||||||
|
|
||||||
dotlock_t h
|
dotlock_t h
|
||||||
|
|
||||||
h = dotlock_create (fname);
|
h = dotlock_create (fname, 0);
|
||||||
if (!h)
|
if (!h)
|
||||||
error ("error creating lock file: %s\n", strerror (errno));
|
error ("error creating lock file: %s\n", strerror (errno));
|
||||||
|
|
||||||
@ -656,17 +656,19 @@ dotlock_create_w32 (dotlock_t h, const char *file_to_lock)
|
|||||||
#ifdef HAVE_W32CE_SYSTEM
|
#ifdef HAVE_W32CE_SYSTEM
|
||||||
wchar_t *wname = utf8_to_wchar (h->lockname);
|
wchar_t *wname = utf8_to_wchar (h->lockname);
|
||||||
|
|
||||||
h->lockhd = INVALID_HANDLE_VALUE;
|
|
||||||
if (wname)
|
if (wname)
|
||||||
h->lockhd = CreateFile (wname,
|
h->lockhd = CreateFile (wname,
|
||||||
#else
|
|
||||||
h->lockhd = CreateFile (h->lockname,
|
|
||||||
#endif
|
|
||||||
GENERIC_READ|GENERIC_WRITE,
|
GENERIC_READ|GENERIC_WRITE,
|
||||||
FILE_SHARE_READ|FILE_SHARE_WRITE,
|
FILE_SHARE_READ|FILE_SHARE_WRITE,
|
||||||
NULL, OPEN_ALWAYS, 0, NULL);
|
NULL, OPEN_ALWAYS, 0, NULL);
|
||||||
#ifdef HAVE_W32CE_SYSTEM
|
else
|
||||||
|
h->lockhd = INVALID_HANDLE_VALUE;
|
||||||
jnlib_free (wname);
|
jnlib_free (wname);
|
||||||
|
#else
|
||||||
|
h->lockhd = CreateFile (h->lockname,
|
||||||
|
GENERIC_READ|GENERIC_WRITE,
|
||||||
|
FILE_SHARE_READ|FILE_SHARE_WRITE,
|
||||||
|
NULL, OPEN_ALWAYS, 0, NULL);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (h->lockhd == INVALID_HANDLE_VALUE)
|
if (h->lockhd == INVALID_HANDLE_VALUE)
|
||||||
@ -696,12 +698,15 @@ dotlock_create_w32 (dotlock_t h, const char *file_to_lock)
|
|||||||
POSIX systems a temporary file ".#lk.<hostname>.pid[.threadid] is
|
POSIX systems a temporary file ".#lk.<hostname>.pid[.threadid] is
|
||||||
used.
|
used.
|
||||||
|
|
||||||
|
FLAGS must be 0.
|
||||||
|
|
||||||
The function returns an new handle which needs to be released using
|
The function returns an new handle which needs to be released using
|
||||||
destroy_dotlock but gets also released at the termination of the
|
destroy_dotlock but gets also released at the termination of the
|
||||||
process. On error NULL is returned.
|
process. On error NULL is returned.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
dotlock_t
|
dotlock_t
|
||||||
dotlock_create (const char *file_to_lock)
|
dotlock_create (const char *file_to_lock, unsigned int flags)
|
||||||
{
|
{
|
||||||
static int initialized;
|
static int initialized;
|
||||||
dotlock_t h;
|
dotlock_t h;
|
||||||
@ -715,6 +720,12 @@ dotlock_create (const char *file_to_lock)
|
|||||||
if ( !file_to_lock )
|
if ( !file_to_lock )
|
||||||
return NULL; /* Only initialization was requested. */
|
return NULL; /* Only initialization was requested. */
|
||||||
|
|
||||||
|
if (flags)
|
||||||
|
{
|
||||||
|
jnlib_set_errno (EINVAL);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
h = jnlib_calloc (1, sizeof *h);
|
h = jnlib_calloc (1, sizeof *h);
|
||||||
if (!h)
|
if (!h)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -26,7 +26,7 @@ struct dotlock_handle;
|
|||||||
typedef struct dotlock_handle *dotlock_t;
|
typedef struct dotlock_handle *dotlock_t;
|
||||||
|
|
||||||
void dotlock_disable (void);
|
void dotlock_disable (void);
|
||||||
dotlock_t dotlock_create (const char *file_to_lock);
|
dotlock_t dotlock_create (const char *file_to_lock, unsigned int flags);
|
||||||
void dotlock_destroy (dotlock_t h);
|
void dotlock_destroy (dotlock_t h);
|
||||||
int dotlock_take (dotlock_t h, long timeout);
|
int dotlock_take (dotlock_t h, long timeout);
|
||||||
int dotlock_release (dotlock_t h);
|
int dotlock_release (dotlock_t h);
|
||||||
|
@ -90,7 +90,7 @@ lock_and_unlock (const char *fname)
|
|||||||
{
|
{
|
||||||
dotlock_t h;
|
dotlock_t h;
|
||||||
|
|
||||||
h = dotlock_create (fname);
|
h = dotlock_create (fname, 0);
|
||||||
if (!h)
|
if (!h)
|
||||||
die ("error creating lock file for `%s': %s", fname, strerror (errno));
|
die ("error creating lock file for `%s': %s", fname, strerror (errno));
|
||||||
inf ("lock created");
|
inf ("lock created");
|
||||||
@ -129,7 +129,7 @@ main (int argc, char **argv)
|
|||||||
sigaction (SIGINT, &nact, NULL);
|
sigaction (SIGINT, &nact, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
dotlock_create (NULL); /* Initialize (optional). */
|
dotlock_create (NULL, 0); /* Initialize (optional). */
|
||||||
|
|
||||||
lock_and_unlock (fname);
|
lock_and_unlock (fname);
|
||||||
|
|
||||||
|
@ -1969,7 +1969,7 @@ main (int argc, char **argv)
|
|||||||
|
|
||||||
gnupg_init_signals (0, emergency_cleanup);
|
gnupg_init_signals (0, emergency_cleanup);
|
||||||
|
|
||||||
dotlock_create (NULL); /* Register lock file cleanup. */
|
dotlock_create (NULL, 0); /* Register lock file cleanup. */
|
||||||
|
|
||||||
opt.session_env = session_env_new ();
|
opt.session_env = session_env_new ();
|
||||||
if (!opt.session_env)
|
if (!opt.session_env)
|
||||||
|
@ -507,9 +507,10 @@ dotlock_disable (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
dotlock_t
|
dotlock_t
|
||||||
dotlock_create (const char *file_to_lock)
|
dotlock_create (const char *file_to_lock, unsigned int flags)
|
||||||
{
|
{
|
||||||
(void)file_to_lock;
|
(void)file_to_lock;
|
||||||
|
(void)flags;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ maybe_create_keyring (char *filename, int force)
|
|||||||
/* To avoid races with other instances of gpg trying to create or
|
/* To avoid races with other instances of gpg trying to create or
|
||||||
update the keyring (it is removed during an update for a short
|
update the keyring (it is removed during an update for a short
|
||||||
time), we do the next stuff in a locked state. */
|
time), we do the next stuff in a locked state. */
|
||||||
lockhd = dotlock_create (filename);
|
lockhd = dotlock_create (filename, 0);
|
||||||
if (!lockhd)
|
if (!lockhd)
|
||||||
{
|
{
|
||||||
/* A reason for this to fail is that the directory is not
|
/* A reason for this to fail is that the directory is not
|
||||||
|
@ -306,7 +306,7 @@ keyring_lock (KEYRING_HANDLE hd, int yes)
|
|||||||
if (!keyring_is_writable(kr))
|
if (!keyring_is_writable(kr))
|
||||||
continue;
|
continue;
|
||||||
if (!kr->lockhd) {
|
if (!kr->lockhd) {
|
||||||
kr->lockhd = dotlock_create( kr->fname );
|
kr->lockhd = dotlock_create (kr->fname, 0);
|
||||||
if (!kr->lockhd) {
|
if (!kr->lockhd) {
|
||||||
log_info ("can't allocate lock for `%s'\n", kr->fname );
|
log_info ("can't allocate lock for `%s'\n", kr->fname );
|
||||||
rc = G10ERR_GENERAL;
|
rc = G10ERR_GENERAL;
|
||||||
|
@ -544,7 +544,7 @@ tdbio_set_dbname( const char *new_dbname, int create )
|
|||||||
db_name = fname;
|
db_name = fname;
|
||||||
#ifdef __riscos__
|
#ifdef __riscos__
|
||||||
if( !lockhandle )
|
if( !lockhandle )
|
||||||
lockhandle = dotlock_create (db_name);
|
lockhandle = dotlock_create (db_name, 0);
|
||||||
if( !lockhandle )
|
if( !lockhandle )
|
||||||
log_fatal( _("can't create lock for `%s'\n"), db_name );
|
log_fatal( _("can't create lock for `%s'\n"), db_name );
|
||||||
if( dotlock_make (lockhandle, -1) )
|
if( dotlock_make (lockhandle, -1) )
|
||||||
@ -567,7 +567,7 @@ tdbio_set_dbname( const char *new_dbname, int create )
|
|||||||
|
|
||||||
#ifndef __riscos__
|
#ifndef __riscos__
|
||||||
if( !lockhandle )
|
if( !lockhandle )
|
||||||
lockhandle = dotlock_create (db_name);
|
lockhandle = dotlock_create (db_name, 0);
|
||||||
if( !lockhandle )
|
if( !lockhandle )
|
||||||
log_fatal( _("can't create lock for `%s'\n"), db_name );
|
log_fatal( _("can't create lock for `%s'\n"), db_name );
|
||||||
#endif /* !__riscos__ */
|
#endif /* !__riscos__ */
|
||||||
@ -608,7 +608,7 @@ open_db()
|
|||||||
assert( db_fd == -1 );
|
assert( db_fd == -1 );
|
||||||
|
|
||||||
if (!lockhandle )
|
if (!lockhandle )
|
||||||
lockhandle = dotlock_create (db_name);
|
lockhandle = dotlock_create (db_name, 0);
|
||||||
if (!lockhandle )
|
if (!lockhandle )
|
||||||
log_fatal( _("can't create lock for `%s'\n"), db_name );
|
log_fatal( _("can't create lock for `%s'\n"), db_name );
|
||||||
#ifdef __riscos__
|
#ifdef __riscos__
|
||||||
|
@ -246,7 +246,7 @@ g13_create_container (ctrl_t ctrl, const char *filename, strlist_t keys)
|
|||||||
/* Take a lock and proceed with the creation. If there is a lock we
|
/* Take a lock and proceed with the creation. If there is a lock we
|
||||||
immediately return an error because for creation it does not make
|
immediately return an error because for creation it does not make
|
||||||
sense to wait. */
|
sense to wait. */
|
||||||
lock = dotlock_create (filename);
|
lock = dotlock_create (filename, 0);
|
||||||
if (!lock)
|
if (!lock)
|
||||||
return gpg_error_from_syserror ();
|
return gpg_error_from_syserror ();
|
||||||
if (dotlock_take (lock, 0))
|
if (dotlock_take (lock, 0))
|
||||||
|
@ -383,7 +383,7 @@ main ( int argc, char **argv)
|
|||||||
|
|
||||||
gnupg_init_signals (0, emergency_cleanup);
|
gnupg_init_signals (0, emergency_cleanup);
|
||||||
|
|
||||||
dotlock_create (NULL); /* Register locking cleanup. */
|
dotlock_create (NULL, 0); /* Register locking cleanup. */
|
||||||
|
|
||||||
opt.session_env = session_env_new ();
|
opt.session_env = session_env_new ();
|
||||||
if (!opt.session_env)
|
if (!opt.session_env)
|
||||||
|
@ -273,7 +273,7 @@ g13_mount_container (ctrl_t ctrl, const char *filename, const char *mountpoint)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Try to take a lock. */
|
/* Try to take a lock. */
|
||||||
lock = dotlock_create (filename);
|
lock = dotlock_create (filename, 0);
|
||||||
if (!lock)
|
if (!lock)
|
||||||
{
|
{
|
||||||
xfree (mountpoint_buffer);
|
xfree (mountpoint_buffer);
|
||||||
|
@ -928,7 +928,7 @@ main ( int argc, char **argv)
|
|||||||
|
|
||||||
gnupg_init_signals (0, emergency_cleanup);
|
gnupg_init_signals (0, emergency_cleanup);
|
||||||
|
|
||||||
dotlock_create (NULL); /* Register lockfile cleanup. */
|
dotlock_create (NULL, 0); /* Register lockfile cleanup. */
|
||||||
|
|
||||||
opt.session_env = session_env_new ();
|
opt.session_env = session_env_new ();
|
||||||
if (!opt.session_env)
|
if (!opt.session_env)
|
||||||
|
@ -214,7 +214,7 @@ keydb_add_resource (const char *url, int force, int secret, int *auto_created)
|
|||||||
all_resources[used_resources].secret = secret;
|
all_resources[used_resources].secret = secret;
|
||||||
|
|
||||||
all_resources[used_resources].lockhandle
|
all_resources[used_resources].lockhandle
|
||||||
= dotlock_create (filename);
|
= dotlock_create (filename, 0);
|
||||||
if (!all_resources[used_resources].lockhandle)
|
if (!all_resources[used_resources].lockhandle)
|
||||||
log_fatal ( _("can't create lock for `%s'\n"), filename);
|
log_fatal ( _("can't create lock for `%s'\n"), filename);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user