diff options
author | Matthias Andree <matthias.andree@gmx.de> | 2006-04-02 10:47:58 +0000 |
---|---|---|
committer | Matthias Andree <matthias.andree@gmx.de> | 2006-04-02 10:47:58 +0000 |
commit | 54833b53da596625b194c40732f67aa9dd0ece54 (patch) | |
tree | 27cbc572fe209c07f761fa1d6deb0bbdfb9fdc10 /lock.c | |
parent | 884266c5f0f1d53c15fa2e9d98132c0749c576ff (diff) | |
download | fetchmail-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.c | 25 |
1 files changed, 17 insertions, 8 deletions
@@ -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) |