aboutsummaryrefslogtreecommitdiffstats
path: root/common/dotlock.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/dotlock.c')
-rw-r--r--common/dotlock.c61
1 files changed, 30 insertions, 31 deletions
diff --git a/common/dotlock.c b/common/dotlock.c
index c41f69481..507546562 100644
--- a/common/dotlock.c
+++ b/common/dotlock.c
@@ -1,5 +1,5 @@
/* dotlock.c - dotfile locking
- * Copyright (C) 1998, 2000, 2001, 2003, 2004,
+ * Copyright (C) 1998, 2000, 2001, 2003, 2004,
* 2005, 2006, 2008, 2010 Free Software Foundation, Inc.
*
* This file is part of JNLIB.
@@ -61,7 +61,7 @@
/* The object describing a lock. */
-struct dotlock_handle
+struct dotlock_handle
{
struct dotlock_handle *next;
char *lockname; /* Name of the actual lockfile. */
@@ -112,7 +112,7 @@ disable_dotlock(void)
Calling this function with NULL does only install the atexit
handler and may thus be used to assure that the cleanup is called
after all other atexit handlers.
-
+
This function creates a lock file in the same directory as
FILE_TO_LOCK using that name and a suffix of ".lock". Note that on
POSIX systems a temporary file ".#lk.<hostname>.pid[.threadid] is
@@ -174,7 +174,7 @@ create_dotlock (const char *file_to_lock)
nodename = "unknown";
else
nodename = utsbuf.nodename;
-
+
#ifdef __riscos__
{
char *iter = (char *) nodename;
@@ -223,15 +223,15 @@ create_dotlock (const char *file_to_lock)
"%s/%d", nodename, (int)getpid () );
#endif /* __riscos__ */
- do
+ do
{
jnlib_set_errno (0);
fd = open (h->tname, O_WRONLY|O_CREAT|O_EXCL,
S_IRUSR|S_IRGRP|S_IROTH|S_IWUSR );
- }
+ }
while (fd == -1 && errno == EINTR);
- if ( fd == -1 )
+ if ( fd == -1 )
{
all_lockfiles = h->next;
log_error (_("failed to create temporary file `%s': %s\n"),
@@ -303,11 +303,11 @@ create_dotlock (const char *file_to_lock)
reasons why a lock file can't be created and thus the process
would not stop as expected but spin til until Windows crashes.
Our solution is to keep the lock file open; that does not
- harm. */
+ harm. */
{
#ifdef HAVE_W32CE_SYSTEM
wchar_t *wname = utf8_to_wchar (h->lockname);
-
+
h->lockhd = INVALID_HANDLE_VALUE;
if (wname)
h->lockhd = CreateFile (wname,
@@ -318,7 +318,7 @@ create_dotlock (const char *file_to_lock)
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL, OPEN_ALWAYS, 0, NULL);
#ifdef HAVE_W32CE_SYSTEM
- jnlib_free (wname);
+ jnlib_free (wname);
#endif
}
if (h->lockhd == INVALID_HANDLE_VALUE)
@@ -355,7 +355,7 @@ destroy_dotlock (dotlock_t h)
h->next = NULL;
break;
}
-
+
/* Then destroy the lock. */
if (!h->disable)
{
@@ -364,7 +364,7 @@ destroy_dotlock (dotlock_t h)
{
OVERLAPPED ovl;
- memset (&ovl, 0, sizeof ovl);
+ memset (&ovl, 0, sizeof ovl);
UnlockFileEx (h->lockhd, 0, 1, 0, &ovl);
}
CloseHandle (h->lockhd);
@@ -414,7 +414,7 @@ make_dotlock (dotlock_t h, long timeout)
if ( h->disable )
return 0; /* Locks are completely disabled. Return success. */
- if ( h->locked )
+ if ( h->locked )
{
#ifndef __riscos__
log_debug ("Oops, `%s' is already locked\n", h->lockname);
@@ -438,19 +438,19 @@ make_dotlock (dotlock_t h, long timeout)
return -1;
}
# else /* __riscos__ */
- if ( !renamefile(h->tname, h->lockname) )
+ if ( !renamefile(h->tname, h->lockname) )
{
h->locked = 1;
return 0; /* okay */
}
- if ( errno != EEXIST )
+ if ( errno != EEXIST )
{
log_error( "lock not made: rename() failed: %s\n", strerror(errno) );
return -1;
}
# endif /* __riscos__ */
- if ( (pid = read_lockfile (h, &same_node)) == -1 )
+ if ( (pid = read_lockfile (h, &same_node)) == -1 )
{
if ( errno != ENOENT )
{
@@ -480,11 +480,11 @@ make_dotlock (dotlock_t h, long timeout)
# endif /* __riscos__ */
}
- if ( timeout == -1 )
+ if ( timeout == -1 )
{
/* Wait until lock has been released. */
struct timeval tv;
-
+
log_info (_("waiting for lock (held by %d%s) %s...\n"),
pid, maybe_dead, maybe_deadlock(h)? _("(deadlock?) "):"");
@@ -503,7 +503,7 @@ make_dotlock (dotlock_t h, long timeout)
OVERLAPPED ovl;
/* Lock one byte at offset 0. The offset is given by OVL. */
- memset (&ovl, 0, sizeof ovl);
+ memset (&ovl, 0, sizeof ovl);
if (LockFileEx (h->lockhd, (LOCKFILE_EXCLUSIVE_LOCK
| LOCKFILE_FAIL_IMMEDIATELY), 0, 1, 0, &ovl))
{
@@ -518,7 +518,7 @@ make_dotlock (dotlock_t h, long timeout)
return -1;
}
- if ( timeout == -1 )
+ if ( timeout == -1 )
{
/* Wait until lock has been released. */
log_info (_("waiting for lock %s...\n"), h->lockname);
@@ -561,8 +561,8 @@ release_dotlock (dotlock_t h)
#ifdef HAVE_DOSISH_SYSTEM
{
OVERLAPPED ovl;
-
- memset (&ovl, 0, sizeof ovl);
+
+ memset (&ovl, 0, sizeof ovl);
if (!UnlockFileEx (h->lockhd, 0, 1, 0, &ovl))
{
log_error ("release_dotlock: error removing lockfile `%s': %s\n",
@@ -573,7 +573,7 @@ release_dotlock (dotlock_t h)
#else
pid = read_lockfile (h, &same_node);
- if ( pid == -1 )
+ if ( pid == -1 )
{
log_error( "release_dotlock: lockfile error\n");
return -1;
@@ -594,7 +594,7 @@ release_dotlock (dotlock_t h)
/* Fixme: As an extra check we could check whether the link count is
now really at 1. */
#else /* __riscos__ */
- if ( renamefile (h->lockname, h->tname) )
+ if ( renamefile (h->lockname, h->tname) )
{
log_error ("release_dotlock: error renaming lockfile `%s' to `%s'\n",
h->lockname, h->tname);
@@ -622,7 +622,7 @@ read_lockfile (dotlock_t h, int *same_node )
char *buffer, *p;
size_t expected_len;
int res, nread;
-
+
*same_node = 0;
expected_len = 10 + 1 + h->nodename_len + 1;
if ( expected_len >= sizeof buffer_space)
@@ -655,7 +655,7 @@ read_lockfile (dotlock_t h, int *same_node )
if (res < 0)
{
log_info ("error reading lockfile `%s'", h->lockname );
- close (fd);
+ close (fd);
if (buffer != buffer_space)
jnlib_free (buffer);
jnlib_set_errno (0); /* Do not return an inappropriate ERRNO. */
@@ -679,7 +679,7 @@ read_lockfile (dotlock_t h, int *same_node )
if (buffer[10] != '\n'
|| (buffer[10] = 0, pid = atoi (buffer)) == -1
#ifndef __riscos__
- || !pid
+ || !pid
#else /* __riscos__ */
|| (!pid && riscos_getpid())
#endif /* __riscos__ */
@@ -693,7 +693,7 @@ read_lockfile (dotlock_t h, int *same_node )
}
if (nread == expected_len
- && !memcmp (h->tname+h->nodename_off, buffer+11, h->nodename_len)
+ && !memcmp (h->tname+h->nodename_off, buffer+11, h->nodename_len)
&& buffer[11+h->nodename_len] == '\n')
*same_node = 1;
@@ -711,10 +711,10 @@ void
dotlock_remove_lockfiles (void)
{
dotlock_t h, h2;
-
+
h = all_lockfiles;
all_lockfiles = NULL;
-
+
while ( h )
{
h2 = h->next;
@@ -722,4 +722,3 @@ dotlock_remove_lockfiles (void)
h = h2;
}
}
-