aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2011-09-28 13:41:58 +0000
committerWerner Koch <[email protected]>2011-09-28 13:41:58 +0000
commited8e267859a00233fee89a6b1b7fb3d74ceced96 (patch)
treee74d7b7af18297021f1e7548899d07badb464a0a /common
parentAllow arbitrary timeouts with dotlock. (diff)
downloadgnupg-ed8e267859a00233fee89a6b1b7fb3d74ceced96.tar.gz
gnupg-ed8e267859a00233fee89a6b1b7fb3d74ceced96.zip
Add a flag parameter to dotlock_create.
This allows us to extend this function in the future.
Diffstat (limited to 'common')
-rw-r--r--common/ChangeLog1
-rw-r--r--common/asshelp.c2
-rw-r--r--common/dotlock.c25
-rw-r--r--common/dotlock.h4
-rw-r--r--common/t-dotlock.c4
5 files changed, 24 insertions, 12 deletions
diff --git a/common/ChangeLog b/common/ChangeLog
index 0f66a4122..da016bd7c 100644
--- a/common/ChangeLog
+++ b/common/ChangeLog
@@ -2,6 +2,7 @@
* dotlock.c (dotlock_take, dotlock_take_unix, dotlock_take_w32):
Implement arbitrary timeout values.
+ (dotlock_create): Add arg FLAGS for future extensions.
2011-09-27 Werner Koch <[email protected]>
diff --git a/common/asshelp.c b/common/asshelp.c
index 96d9a242a..c5d8bdf84 100644
--- a/common/asshelp.c
+++ b/common/asshelp.c
@@ -287,7 +287,7 @@ lock_spawning (lock_spawn_t *lock, const char *homedir, const char *name,
if (!fname)
return gpg_error_from_syserror ();
- *lock = dotlock_create (fname);
+ *lock = dotlock_create (fname, 0);
xfree (fname);
if (!*lock)
return gpg_error_from_syserror ();
diff --git a/common/dotlock.c b/common/dotlock.c
index e3e9fa3d2..37a1df3c6 100644
--- a/common/dotlock.c
+++ b/common/dotlock.c
@@ -53,7 +53,7 @@
At program initialization time, the module should be explicitly
initialized:
- dotlock_create (NULL);
+ dotlock_create (NULL, 0);
This installs an atexit handler and may also initialize mutex etc.
It is optional for non-threaded applications. Only the first call
@@ -64,7 +64,7 @@
dotlock_t h
- h = dotlock_create (fname);
+ h = dotlock_create (fname, 0);
if (!h)
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
wchar_t *wname = utf8_to_wchar (h->lockname);
- h->lockhd = INVALID_HANDLE_VALUE;
if (wname)
h->lockhd = CreateFile (wname,
+ GENERIC_READ|GENERIC_WRITE,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL, OPEN_ALWAYS, 0, NULL);
+ else
+ h->lockhd = INVALID_HANDLE_VALUE;
+ jnlib_free (wname);
#else
h->lockhd = CreateFile (h->lockname,
-#endif
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL, OPEN_ALWAYS, 0, NULL);
-#ifdef HAVE_W32CE_SYSTEM
- jnlib_free (wname);
#endif
}
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
used.
+ FLAGS must be 0.
+
The function returns an new handle which needs to be released using
destroy_dotlock but gets also released at the termination of the
process. On error NULL is returned.
*/
+
dotlock_t
-dotlock_create (const char *file_to_lock)
+dotlock_create (const char *file_to_lock, unsigned int flags)
{
static int initialized;
dotlock_t h;
@@ -715,6 +720,12 @@ dotlock_create (const char *file_to_lock)
if ( !file_to_lock )
return NULL; /* Only initialization was requested. */
+ if (flags)
+ {
+ jnlib_set_errno (EINVAL);
+ return NULL;
+ }
+
h = jnlib_calloc (1, sizeof *h);
if (!h)
return NULL;
diff --git a/common/dotlock.h b/common/dotlock.h
index 5fb7891fa..666d0b72c 100644
--- a/common/dotlock.h
+++ b/common/dotlock.h
@@ -26,8 +26,8 @@ struct dotlock_handle;
typedef struct dotlock_handle *dotlock_t;
void dotlock_disable (void);
-dotlock_t dotlock_create (const char *file_to_lock);
-void dotlock_destroy ( dotlock_t h );
+dotlock_t dotlock_create (const char *file_to_lock, unsigned int flags);
+void dotlock_destroy (dotlock_t h);
int dotlock_take (dotlock_t h, long timeout);
int dotlock_release (dotlock_t h);
void dotlock_remove_lockfiles (void);
diff --git a/common/t-dotlock.c b/common/t-dotlock.c
index a352f6e95..f81b95276 100644
--- a/common/t-dotlock.c
+++ b/common/t-dotlock.c
@@ -90,7 +90,7 @@ lock_and_unlock (const char *fname)
{
dotlock_t h;
- h = dotlock_create (fname);
+ h = dotlock_create (fname, 0);
if (!h)
die ("error creating lock file for `%s': %s", fname, strerror (errno));
inf ("lock created");
@@ -129,7 +129,7 @@ main (int argc, char **argv)
sigaction (SIGINT, &nact, NULL);
}
- dotlock_create (NULL); /* Initialize (optional). */
+ dotlock_create (NULL, 0); /* Initialize (optional). */
lock_and_unlock (fname);