# include <sys/time.h>
#endif
#include <time.h>
-#include <errno.h>
#include <fcntl.h>
#ifdef HAVE_FLOCK
# include <sys/file.h>
#endif
-#ifdef HAVE_LOCKF
-# include <unistd.h>
-#endif
-
-#include <signal.h>
#if defined(HAVE_LIBLOCKFILE)
-#include <lockfile.h>
+# include <lockfile.h>
#endif
#ifdef LOCKDIR
lockname (file, &lkinfo, 0); /* get name of lock file */
#if !defined(HAVE_LIBLOCKFILE)
- unlink (lkinfo.curlock); /* remove lock file */
+ (void) m_unlink (lkinfo.curlock); /* remove lock file */
#else
lockfile_remove(lkinfo.curlock);
#endif /* HAVE_LIBLOCKFILE */
}
+#ifdef HAVE_FLOCK
/*
* Open and lock a file, using flock locking
*/
errno = saved_errno;
return -1;
}
-
+#endif /* HAVE_FLOCK */
/*
* Open and lock a file, using lockf locking
/* check for stale lockfile, else sleep */
if (curtime > st.st_ctime + RSECS)
- unlink (lkinfo.curlock);
+ (void) m_unlink (lkinfo.curlock);
else
sleep (5);
}
lockit (struct lockinfo *li)
{
int fd;
- char *curlock, *tmplock;
+ char *curlock, *tmpfile;
#if 0
char buffer[128];
#endif
curlock = li->curlock;
- tmplock = li->tmplock;
- if ((fd = mkstemp(tmplock)) == -1)
+ if ((tmpfile = m_mktemp(li->tmplock, &fd, NULL)) == NULL) {
+ advise(NULL, "unable to create temporary file in %s", get_temp_dir());
return -1;
+ }
#if 0
/* write our process id into lock file */
* Now try to create the real lock file
* by linking to the temporary file.
*/
- fd = link(tmplock, curlock);
- unlink(tmplock);
+ fd = link(tmpfile, curlock);
+ (void) m_unlink(tmpfile);
return (fd == -1 ? -1 : 0);
}