#endif
static int dotlock_deference_symlink (char *, size_t, const char *);
-static int dotlock_prepare (char *, size_t, const char *);
+static int dotlock_prepare (char *, size_t, const char *, int fd);
static int dotlock_check_stats (struct stat *, struct stat *);
-static int dotlock_dispatch (const char *);
+static int dotlock_dispatch (const char *, int fd);
#ifdef DL_STANDALONE
static int dotlock_init_privs (void);
if (optind == argc || Retry < 0)
usage (argv[0]);
- return dotlock_dispatch (argv[optind]);
+ return dotlock_dispatch (argv[optind], -1);
}
* mutt instead of mx.c's invoke_dotlock ().
*/
-int dotlock_invoke (const char *path, int flags, int retry)
+int dotlock_invoke (const char *path, int fd, int flags, int retry)
{
int currdir;
int r;
else
Retry = 0;
- r = dotlock_dispatch (path);
+ r = dotlock_dispatch (path, fd);
fchdir (currdir);
close (currdir);
#endif /* DL_STANDALONE */
-static int dotlock_dispatch (const char *f)
+static int dotlock_dispatch (const char *f, int fd)
{
char realpath[_POSIX_PATH_MAX];
* lengthy comment below.
*/
- if (dotlock_prepare (realpath, sizeof (realpath), f) != 0)
+ if (dotlock_prepare (realpath, sizeof (realpath), f, fd) != 0)
return DL_EX_ERROR;
/* Actually perform the locking operation. */
}
static int
-dotlock_prepare (char *bn, size_t l, const char *f)
+dotlock_prepare (char *bn, size_t l, const char *f, int _fd)
{
struct stat fsb, lsb;
char realpath[_POSIX_PATH_MAX];
if (chdir (dirname) == -1)
return -1;
-
- if ((fd = open (basename, O_RDONLY)) == -1)
+
+ if (_fd != -1)
+ fd = _fd;
+ else if ((fd = open (basename, O_RDONLY)) == -1)
return -1;
r = fstat (fd, &fsb);
- close (fd);
+
+ if (_fd == -1)
+ close (fd);
if (r == -1)
return -1;
#ifdef DL_STANDALONE
-static int invoke_dotlock (const char *path, int flags, int retry)
+static int invoke_dotlock (const char *path, int dummy, int flags, int retry)
{
char cmd[LONG_STRING + _POSIX_PATH_MAX];
char f[SHORT_STRING + _POSIX_PATH_MAX];
#endif
-static int dotlock_file (const char *path, int retry)
+static int dotlock_file (const char *path, int fd, int retry)
{
int r;
int flags = DL_FL_USEPRIV | DL_FL_RETRY;
if (retry) retry = 1;
retry_lock:
- if ((r = invoke_dotlock(path, flags, retry)) == DL_EX_EXIST)
+ if ((r = invoke_dotlock(path, fd, flags, retry)) == DL_EX_EXIST)
{
if (!option (OPTNOCURSES))
{
return (r == DL_EX_OK ? 0 : -1);
}
-static int undotlock_file (const char *path)
+static int undotlock_file (const char *path, int fd)
{
- return (invoke_dotlock(path, DL_FL_USEPRIV | DL_FL_UNLOCK, 0) == DL_EX_OK ?
+ return (invoke_dotlock(path, fd, DL_FL_USEPRIV | DL_FL_UNLOCK, 0) == DL_EX_OK ?
0 : -1);
}
#ifdef USE_DOTLOCK
if (r == 0 && dot)
- r = dotlock_file (path,timeout);
+ r = dotlock_file (path, fd, timeout);
#endif /* USE_DOTLOCK */
if (r == -1)
#ifdef USE_DOTLOCK
if (dot)
- undotlock_file (path);
+ undotlock_file (path, fd);
#endif
return 0;
}
#ifdef USE_DOTLOCK
- invoke_dotlock (path, DL_FL_UNLINK, 1);
+ invoke_dotlock (path, fd, DL_FL_UNLINK, 1);
#else
if (fstat (fd, &sb) == 0 && sb.st_size == 0)
unlink (path);