X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/61ccf1dbeea93978803303d2cd43efa5da2cc7d1..b68ed2bccdade2c3ac04ca1005d261be89c71c51:/sbr/lock_file.c diff --git a/sbr/lock_file.c b/sbr/lock_file.c index 079f0896..1a562f9b 100644 --- a/sbr/lock_file.c +++ b/sbr/lock_file.c @@ -28,14 +28,9 @@ #ifdef HAVE_FLOCK # include #endif -#ifdef HAVE_LOCKF -# include -#endif - -#include #if defined(HAVE_LIBLOCKFILE) -#include +# include #endif #ifdef LOCKDIR @@ -340,7 +335,7 @@ lkclose_dot (int fd, const char *file) 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 */ @@ -385,6 +380,7 @@ lkopen_fcntl(const char *file, int access, mode_t mode) } +#ifdef HAVE_FLOCK /* * Open and lock a file, using flock locking */ @@ -417,7 +413,7 @@ lkopen_flock(const char *file, int access, mode_t mode) errno = saved_errno; return -1; } - +#endif /* HAVE_FLOCK */ /* * Open and lock a file, using lockf locking @@ -517,7 +513,7 @@ lkopen_dot (const char *file, int access, mode_t mode) /* check for stale lockfile, else sleep */ if (curtime > st.st_ctime + RSECS) - unlink (lkinfo.curlock); + (void) m_unlink (lkinfo.curlock); else sleep (5); } @@ -547,17 +543,18 @@ static int 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 */ @@ -571,8 +568,8 @@ lockit (struct lockinfo *li) * 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); }