X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/ec68c7d9fca00e976df02842dc2c9d5a523567af..1ed08ad2184ac38d0a80e9a8146f378fb297c6a9:/sbr/lock_file.c diff --git a/sbr/lock_file.c b/sbr/lock_file.c index 0bf82f8a..8f1732b4 100644 --- a/sbr/lock_file.c +++ b/sbr/lock_file.c @@ -17,6 +17,8 @@ #include #include #include +#include "lock_file.h" +#include "m_mktemp.h" #ifdef HAVE_SYS_TIME_H # include @@ -88,7 +90,7 @@ static int lkopen_lockf (const char *, int, mode_t, int *); static int lkopen_flock (const char *, int, mode_t, int *); #endif /* HAVE_FLOCK */ -static enum locktype init_locktype(const char *); +static enum locktype init_locktype(const char *) PURE; static int lkopen_dot (const char *, int, mode_t, int *); static void lkclose_dot (int, const char *); @@ -131,7 +133,8 @@ lkopendata(const char *file, int access, mode_t mode, int *failed_to_lock) * Locking using the spool locking algorithm */ -int lkopenspool(const char *file, int access, mode_t mode, int *failed_to_lock) +int +lkopenspool(const char *file, int access, mode_t mode, int *failed_to_lock) { static bool deja_vu; @@ -312,7 +315,7 @@ lkopen (const char *file, int access, mode_t mode, enum locktype ltype, #endif /* HAVE_FLOCK */ default: - adios(NULL, "Internal locking error: unsupported lock type used!"); + die("Internal locking error: unsupported lock type used!"); } return -1; @@ -520,6 +523,7 @@ lkopen_dot (const char *file, int access, mode_t mode, int *failed_to_lock) lockname (file, &lkinfo, 1); } + close(fd); *failed_to_lock = 1; return -1; } @@ -573,7 +577,7 @@ lockit (struct lockinfo *li) fd = link(tmpfile, curlock); (void) m_unlink(tmpfile); - return (fd == -1 ? -1 : 0); + return fd == -1 ? -1 : 0; } #endif /* HAVE_LIBLOCKFILE */ @@ -626,7 +630,9 @@ lockname (const char *file, struct lockinfo *li, int isnewlock) snprintf (bp, sizeof(li->curlock) - bplen, "%s.lock", cp); -#if !defined(HAVE_LIBLOCKFILE) +#if defined(HAVE_LIBLOCKFILE) + NMH_UNUSED(isnewlock); +#else /* * If this is for a new lock, create a name for * the temporary lock file for lockit() @@ -745,20 +751,20 @@ init_locktype(const char *lockname) #ifdef HAVE_LOCKF return LOCKF_LOCKING; #else /* ! HAVE_LOCKF */ - adios(NULL, "lockf not supported on this system"); + die("lockf not supported on this system"); #endif /* HAVE_LOCKF */ } if (strcasecmp(lockname, "flock") == 0) { #ifdef HAVE_FLOCK return FLOCK_LOCKING; #else /* ! HAVE_FLOCK */ - adios(NULL, "flock not supported on this system"); + die("flock not supported on this system"); #endif /* HAVE_FLOCK */ } if (strcasecmp(lockname, "dot") == 0) { return DOT_LOCKING; } - adios(NULL, "Unknown lock type: \"%s\"", lockname); + die("Unknown lock type: \"%s\"", lockname); /* NOTREACHED */ return 0; }