Commit 54833b53 authored by Matthias Andree's avatar Matthias Andree

Add pidfile option, requested by Héctor García.

svn path=/branches/BRANCH_6-3/; revision=4770
parent 884266c5
......@@ -69,7 +69,8 @@ fetchmail_SOURCES= fetchmail.h getopt.h \
driver.c transact.c sink.c smtp.c \
uid.c mxget.c md5ify.c cram.c kerberos.c gssapi.c \
opie.c rpa.c interface.c netrc.c \
unmime.c conf.c checkalias.c lock.c \
unmime.c conf.c checkalias.c \
lock.h lock.c \
rcfile_l.l rcfile_y.y ucs/norm_charmap.c \
libesmtp/getaddrinfo.h libesmtp/getaddrinfo.c \
KAME/getnameinfo.c
......
......@@ -36,6 +36,12 @@ fetchmail 6.3.4 (not yet released):
* lexer: add %option noyywrap to avoid link errors about missing yywrap().
* a few more type fixes for report/snprintf, patch by Miloslav Trmac.
# CHANGES:
* pidfile: there is a new command-line (--pidfile PATH) and global option for
the rcfile (set pidfile [=] "/path/to/pidfile") option to allow overriding
the default location of the PID file.
Requested by Héctor García, Debian maintainer.
fetchmail 6.3.3 (released 2006-03-30):
# KNOWN BUGS:
......
......@@ -43,6 +43,7 @@
#include "smtp.h"
#include "netrc.h"
#include "i18n.h"
#include "lock.h"
#ifndef ENETUNREACH
#define ENETUNREACH 128 /* Interactive doesn't know this */
......@@ -315,7 +316,7 @@ int main(int argc, char **argv)
#endif /* POP3_ENABLE */
/* construct the lockfile */
lock_setup();
lock_setup(&run);
#ifdef HAVE_SETRLIMIT
/*
......@@ -1067,6 +1068,8 @@ static int load_params(int argc, char **argv, int optind)
run.logfile = cmd_run.logfile;
if (cmd_run.idfile)
run.idfile = cmd_run.idfile;
if (cmd_run.pidfile)
run.pidfile = cmd_run.pidfile;
/* do this before the keep/fetchall test below, otherwise -d0 may fail */
if (cmd_run.poll_interval >= 0)
run.poll_interval = cmd_run.poll_interval;
......
......@@ -157,15 +157,17 @@ typedef char flag;
#define FLAG_TRUE 2
#define FLAG_FALSE 1
/** run control data */
struct runctl
{
char *logfile;
char *idfile;
int poll_interval;
char *logfile; /** where to write log information */
char *idfile; /** where to store UID data */
char *pidfile; /** where to record the PID of daemon mode processes */
char *postmaster;
char *properties;
int poll_interval;
flag bouncemail;
flag spambounce;
char *properties;
flag use_syslog;
flag invisible;
flag showdots;
......@@ -505,14 +507,6 @@ int gen_transact();
#endif
extern struct msgblk msgblk;
/* lock.c: concurrency locking */
void lock_setup(void);
void lock_assert(void);
void lock_or_die(void);
void fm_lock_release(void);
int lock_state(void);
void lock_dispose(void);
/* use these to track what was happening when the nonresponse timer fired */
#define GENERAL_WAIT 0 /* unknown wait type */
#define OPEN_WAIT 1 /* waiting from mailserver open */
......
......@@ -747,6 +747,11 @@ and renames it into the place of the real idfile only if the temporary
file has been written successfully. This avoids the truncation of
idfiles when running out of disk space.
.TP
.B \--pidfile <pathname>
(Keyword: pidfile; since fetchmail v6.3.4)
Override the default location of the PID file. Default: see
"ENVIRONMENT" below.
.TP
.B \-n | \-\-norewrite
(Keyword: no rewrite)
Normally,
......
......@@ -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)
......
#ifndef FM_LOCK_H
#define FM_LOCK_H
/* lock.c: concurrency locking */
void lock_setup(struct runctl *);
void lock_assert(void);
void lock_or_die(void);
void fm_lock_release(void);
int lock_state(void);
void lock_dispose(void);
#endif
......@@ -24,6 +24,7 @@
enum {
LA_INVISIBLE = 256,
LA_PIDFILE,
LA_SYSLOG,
LA_NOSYSLOG,
LA_POSTMASTER,
......@@ -73,6 +74,7 @@ static const struct option longoptions[] = {
{"nosyslog", no_argument, (int *) 0, LA_NOSYSLOG },
{"fetchmailrc",required_argument,(int *) 0, 'f' },
{"idfile", required_argument, (int *) 0, 'i' },
{"pidfile", required_argument, (int *) 0, LA_PIDFILE },
{"postmaster",required_argument, (int *) 0, LA_POSTMASTER },
{"nobounce", no_argument, (int *) 0, LA_NOBOUNCE },
......@@ -287,6 +289,9 @@ int parsecmdline (int argc /** argument count */,
case 'i':
rctl->idfile = prependdir (optarg, currentwd);
break;
case LA_PIDFILE:
rctl->pidfile = prependdir (optarg, currentwd);
break;
case LA_POSTMASTER:
rctl->postmaster = (char *) xstrdup(optarg);
break;
......@@ -591,6 +596,7 @@ int parsecmdline (int argc /** argument count */,
P(GT_(" --invisible don't write Received & enable host spoofing\n"));
P(GT_(" -f, --fetchmailrc specify alternate run control file\n"));
P(GT_(" -i, --idfile specify alternate UIDs file\n"));
P(GT_(" --pidfile specify alternate PID (lock) file\n"));
P(GT_(" --postmaster specify recipient of last resort\n"));
P(GT_(" --nobounce redirect bounces from user to postmaster.\n"));
#ifdef CAN_MONITOR
......@@ -621,7 +627,7 @@ int parsecmdline (int argc /** argument count */,
P(GT_(" --tracepolls add poll-tracing information to Received header\n"));
P(GT_(" -u, --username specify users's login on server\n"));
P(GT_(" -a, --all retrieve old and new messages\n"));
P(GT_(" -a, --[fetch]all retrieve old and new messages\n"));
P(GT_(" -K, --nokeep delete new messages after retrieval\n"));
P(GT_(" -k, --keep save new messages after retrieval\n"));
P(GT_(" -F, --flush delete old messages from server\n"));
......
This diff is collapsed.
This diff is collapsed.
......@@ -69,6 +69,7 @@ int prc_lineno = 1;
set { return SET; }
logfile { return LOGFILE; }
idfile { return IDFILE; }
pidfile { return PIDFILE; }
daemon { return DAEMON; }
syslog { return SYSLOG; }
invisible { return INVISIBLE; }
......
......@@ -68,7 +68,7 @@ extern char * yytext;
%token INTERFACE MONITOR PLUGIN PLUGOUT
%token IS HERE THERE TO MAP WILDCARD
%token BATCHLIMIT FETCHLIMIT FETCHSIZELIMIT FASTUIDL EXPUNGE PROPERTIES
%token SET LOGFILE DAEMON SYSLOG IDFILE INVISIBLE POSTMASTER BOUNCEMAIL
%token SET LOGFILE DAEMON SYSLOG IDFILE PIDFILE INVISIBLE POSTMASTER BOUNCEMAIL
%token SPAMBOUNCE SHOWDOTS
%token <proto> PROTO AUTHTYPE
%token <sval> STRING
......@@ -95,6 +95,7 @@ optmap : MAP | /* EMPTY */;
/* future global options should also have the form SET <name> optmap <value> */
statement : SET LOGFILE optmap STRING {run.logfile = prependdir ($4, rcfiledir);}
| SET IDFILE optmap STRING {run.idfile = prependdir ($4, rcfiledir);}
| SET PIDFILE optmap STRING {run.pidfile = prependdir ($4, rcfiledir);}
| SET DAEMON optmap NUMBER {run.poll_interval = $4;}
| SET POSTMASTER optmap STRING {run.postmaster = xstrdup($4);}
| SET BOUNCEMAIL {run.bouncemail = TRUE;}
......@@ -578,7 +579,4 @@ char *prependdir (const char *file, const char *dir)
return newfile;
}
/* easier to do this than cope with variations in where the library lives */
int yywrap(void) {return 1;}
/* rcfile_y.y ends here */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment