aboutsummaryrefslogtreecommitdiffstats
path: root/lock.c
diff options
context:
space:
mode:
authorMatthias Andree <matthias.andree@gmx.de>2006-11-19 18:45:06 +0000
committerMatthias Andree <matthias.andree@gmx.de>2006-11-19 18:45:06 +0000
commit4cf7de8173924ba038373c375f394c904d4173ae (patch)
treedff43b1fb2e5f1c0e364ff8dad46bdf15dc13f9d /lock.c
parenteed0da9232f67df0e8f3b80133ca4319cd4886ab (diff)
downloadfetchmail-4cf7de8173924ba038373c375f394c904d4173ae.tar.gz
fetchmail-4cf7de8173924ba038373c375f394c904d4173ae.tar.bz2
fetchmail-4cf7de8173924ba038373c375f394c904d4173ae.zip
Support lockfiles in non-writable directories.
svn path=/branches/BRANCH_6-3/; revision=4946
Diffstat (limited to 'lock.c')
-rw-r--r--lock.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/lock.c b/lock.c
index e56fe344..111559e7 100644
--- a/lock.c
+++ b/lock.c
@@ -91,12 +91,27 @@ int fm_lock_state(void)
fclose(lockfp); /* not checking should be safe, file mode was "r" */
if (args == EOF || args == 0 || kill(pid, 0) == -1) {
+ /* ^ could not read PID || process does not exist */
+ /* => lockfile is stale, unlink it */
pid = 0;
-
fprintf(stderr,GT_("fetchmail: removing stale lockfile\n"));
if (unlink(lockfile)) {
if (errno != ENOENT) {
perror(lockfile);
+ /* we complain but we don't exit; it might be
+ * writable for us, but in a directory we cannot
+ * write to. This means we can write the new PID to
+ * the file. Truncate to be safe in case the PID is
+ * recycled by another process later.
+ * \bug we should use fcntl() style locks or
+ * something else instead in a future release. */
+ if (truncate(lockfile, (off_t)0)) {
+ /* but if we cannot truncate the file either,
+ * assume that we cannot write to it later,
+ * complain and quit. */
+ perror(lockfile);
+ exit(PS_EXCLUDE);
+ }
}
}
}