-static int lkopen(const char *, int, mode_t, enum locktype);
+static int lkopen(const char *, int, mode_t, enum locktype, int *);
-static int lkopen_fcntl (const char *, int, mode_t);
+static int lkopen_fcntl (const char *, int, mode_t, int *);
-static int lkopen_lockf (const char *, int, mode_t);
+static int lkopen_lockf (const char *, int, mode_t, int *);
-static int lkopen_flock (const char *, int, mode_t);
+static int lkopen_flock (const char *, int, mode_t, int *);
-static int lkopen_dot (const char *, int, mode_t);
+static int lkopen_dot (const char *, int, mode_t, int *);
static void lkclose_dot (int, const char *);
static void lockname (const char *, struct lockinfo *, int);
static void timerON (char *, int);
static void lkclose_dot (int, const char *);
static void lockname (const char *, struct lockinfo *, int);
static void timerON (char *, int);
-lkopendata(const char *file, int access, mode_t mode)
+lkopendata(const char *file, int access, mode_t mode, int *failed_to_lock)
- return lkopen(file, access, mode, datalocktype);
+ return lkopen(file, access, mode, datalocktype, failed_to_lock);
-int lkopenspool(const char *file, int access, mode_t mode)
+int lkopenspool(const char *file, int access, mode_t mode, int *failed_to_lock)
- return lkopen(file, access, mode, spoollocktype);
+ return lkopen(file, access, mode, spoollocktype, failed_to_lock);
- if ((fd = lkopendata(file, oflags, 0666)) == -1)
+ if ((fd = lkopendata(file, oflags, 0666, failed_to_lock)) == -1)
- if ((fd = lkopenspool(file, oflags, 0666)) == -1)
+ if ((fd = lkopenspool(file, oflags, 0666, &failed_to_lock)) == -1)
-lkopen (const char *file, int access, mode_t mode, enum locktype ltype)
+lkopen (const char *file, int access, mode_t mode, enum locktype ltype,
+ int *failed_to_lock)
- return lkopen_fcntl(file, access, mode);
+ return lkopen_fcntl(file, access, mode, failed_to_lock);
- return lkopen_flock(file, access, mode);
+ return lkopen_flock(file, access, mode, failed_to_lock);
- return lkopen_lockf(file, access, mode);
+ return lkopen_lockf(file, access, mode, failed_to_lock);
lockname (file, &lkinfo, 0); /* get name of lock file */
#if !defined(HAVE_LIBLOCKFILE)
lockname (file, &lkinfo, 0); /* get name of lock file */
#if !defined(HAVE_LIBLOCKFILE)
-lkopen_fcntl(const char *file, int access, mode_t mode)
+lkopen_fcntl(const char *file, int access, mode_t mode, int *failed_to_lock)
-lkopen_flock(const char *file, int access, mode_t mode)
+lkopen_flock(const char *file, int access, mode_t mode, int *failed_to_lock)
{
int fd, i, saved_errno, locktype;
{
int fd, i, saved_errno, locktype;
-lkopen_lockf(const char *file, int access, mode_t mode)
+lkopen_lockf(const char *file, int access, mode_t mode, int *failed_to_lock)
{
int fd, i, saved_errno, saved_access;
{
int fd, i, saved_errno, saved_access;
-lkopen_dot (const char *file, int access, mode_t mode)
+lkopen_dot (const char *file, int access, mode_t mode, int *failed_to_lock)
/* attempt to create lock file */
if (lockit (&lkinfo) == 0) {
/* if successful, turn on timer and return */
/* attempt to create lock file */
if (lockit (&lkinfo) == 0) {
/* if successful, turn on timer and return */
- * and are never able to stat the lock file.
+ * and are never able to stat the lock file. Or, if
+ * we can stat the lockfile but exceed LOCK_RETRIES
+ * seconds waiting for it (by falling out of the loop).
time (&curtime);
/* check for stale lockfile, else sleep */
if (curtime > st.st_ctime + RSECS)
time (&curtime);
/* check for stale lockfile, else sleep */
if (curtime > st.st_ctime + RSECS)
- if ((fd = mkstemp(tmplock)) == -1)
+ if ((tmpfile = m_mktemp(li->tmplock, &fd, NULL)) == NULL) {
+ advise(NULL, "unable to create temporary file in %s", li->tmplock);