aboutsummaryrefslogtreecommitdiffstats
path: root/lock.c
diff options
context:
space:
mode:
authorMatthias Andree <matthias.andree@gmx.de>2006-04-02 10:47:58 +0000
committerMatthias Andree <matthias.andree@gmx.de>2006-04-02 10:47:58 +0000
commit54833b53da596625b194c40732f67aa9dd0ece54 (patch)
tree27cbc572fe209c07f761fa1d6deb0bbdfb9fdc10 /lock.c
parent884266c5f0f1d53c15fa2e9d98132c0749c576ff (diff)
downloadfetchmail-54833b53da596625b194c40732f67aa9dd0ece54.tar.gz
fetchmail-54833b53da596625b194c40732f67aa9dd0ece54.tar.bz2
fetchmail-54833b53da596625b194c40732f67aa9dd0ece54.zip
Add pidfile option, requested by Héctor García.
svn path=/branches/BRANCH_6-3/; revision=4770
Diffstat (limited to 'lock.c')
-rw-r--r--lock.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/lock.c b/lock.c
index 89f767da..277e20bf 100644
--- a/lock.c
+++ b/lock.c
@@ -21,30 +21,39 @@
#include "fetchmail.h"
#include "i18n.h"
+#include "lock.h"
static char *lockfile; /* name of lockfile */
static int lock_acquired; /* have we acquired a lock */
-void lock_setup(void)
+void lock_setup(struct runctl *ctl)
/* set up the global lockfile name */
{
/* set up to do lock protocol */
-#define FETCHMAIL_PIDFILE "fetchmail.pid"
+ const char *const FETCHMAIL_PIDFILE="fetchmail.pid";
+
+ /* command-line option override */
+ if (ctl->pidfile) {
+ lockfile = xstrdup(ctl->pidfile);
+ return;
+ }
+
+ /* defaults */
if (getuid() == ROOT_UID) {
- lockfile = (char *)xmalloc(
- sizeof(PID_DIR) + sizeof(FETCHMAIL_PIDFILE) + 1);
+ lockfile = (char *)xmalloc(strlen(PID_DIR)
+ + strlen(FETCHMAIL_PIDFILE) + 2); /* 2: "/" and NUL */
strcpy(lockfile, PID_DIR);
strcat(lockfile, "/");
strcat(lockfile, FETCHMAIL_PIDFILE);
} else {
- lockfile = (char *)xmalloc(strlen(fmhome)+sizeof(FETCHMAIL_PIDFILE)+2);
+ lockfile = (char *)xmalloc(strlen(fmhome)
+ + strlen(FETCHMAIL_PIDFILE) + 3); /* 3: "/", "." and NUL */
strcpy(lockfile, fmhome);
strcat(lockfile, "/");
- if (fmhome == home)
- strcat(lockfile, ".");
+ if (fmhome == home)
+ strcat(lockfile, ".");
strcat(lockfile, FETCHMAIL_PIDFILE);
}
-#undef FETCHMAIL_PIDFILE
}
static void unlockit(void)