aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Andree <matthias.andree@gmx.de>2005-10-30 17:54:27 +0000
committerMatthias Andree <matthias.andree@gmx.de>2005-10-30 17:54:27 +0000
commit98ff8ea5f7d45b7beab07d5c7242e2f7dafcd26b (patch)
treed5b30838278fb5f025b172546074b57d3c546105
parent71afdc215eaa15ffc6e6ec7a60390bd2b66d84e7 (diff)
downloadfetchmail-98ff8ea5f7d45b7beab07d5c7242e2f7dafcd26b.tar.gz
fetchmail-98ff8ea5f7d45b7beab07d5c7242e2f7dafcd26b.tar.bz2
fetchmail-98ff8ea5f7d45b7beab07d5c7242e2f7dafcd26b.zip
- make fetchmail --silent --quit really silent, Debian Bug #229014 by
Dr. Andreas Krüger. - cleanup --quit handling again (so that --silent --quit just kills the existing daemon, rather than continue running), and document it more clearly. - Print an error message if multiple "defaults" records are found in the configuration file. svn path=/trunk/; revision=4372
-rw-r--r--NEWS7
-rw-r--r--fetchmail.c52
-rw-r--r--fetchmail.h1
-rw-r--r--fetchmail.man19
-rw-r--r--options.c1
5 files changed, 50 insertions, 30 deletions
diff --git a/NEWS b/NEWS
index bb06e1b0..4106e425 100644
--- a/NEWS
+++ b/NEWS
@@ -240,6 +240,13 @@ fetchmail 6.3.0 (not yet released officially):
* fetchmailconf -V now prints the fetchmailconf version. Matthias Andree
* Add support for SubjectAltName (RFC-2595 or 2818), to avoid bogus certificate
mismatch errors. Patch by Roland Stigge, Debian Bug#201113. (MA)
+* make fetchmail --silent --quit really silent, Debian Bug #229014 by Dr.
+ Andreas Krüger. Matthias Andree
+* cleanup --quit handling again (so that --silent --quit just kills the
+ existing daemon, rather than continue running), and document it more clearly.
+ Matthias Andree
+* Print an error message if multiple "defaults" records are found in the
+ configuration file. Matthias Andree
# INTERNAL CHANGES
* Switched to automake. Matthias Andree.
diff --git a/fetchmail.c b/fetchmail.c
index 57c05f8e..5f442d54 100644
--- a/fetchmail.c
+++ b/fetchmail.c
@@ -60,6 +60,7 @@ int outlevel; /* see the O_.* constants above */
struct runctl run; /* global controls for this run */
flag nodetach; /* if TRUE, don't detach daemon process */
flag quitmode; /* if --quit was set */
+int quitind; /* optind after position of last --quit option */
flag check_only; /* if --probe was set */
flag versioninfo; /* emit only version info */
char *user; /* the name of the invoking user */
@@ -69,6 +70,8 @@ char *program_name; /* the name to prefix error messages with */
flag configdump; /* dump control blocks for configurator */
char *fetchmailhost; /* either `localhost' or the host's FQDN */
+static int quitonly; /* if we should quit after killing the running daemon */
+
static int querystatus; /* status of query */
static int successes; /* count number of successful polls */
static int activecount; /* count number of active entries */
@@ -194,8 +197,16 @@ int main(int argc, char **argv)
}
#endif
- if ((parsecmdline(argc,argv, &cmd_run, &cmd_opts)) < 0)
- exit(PS_SYNTAX);
+ {
+ int i;
+
+ i = parsecmdline(argc, argv, &cmd_run, &cmd_opts);
+ if (i < 0)
+ exit(PS_SYNTAX);
+
+ if (quitmode && quitind == argc)
+ quitonly = 1;
+ }
if (versioninfo)
{
@@ -258,8 +269,8 @@ int main(int argc, char **argv)
system("uname -a");
}
- /* avoid parsing the config file if all we're doing is killing a daemon */
- if (!(quitmode && argc == 2))
+ /* avoid parsing the config file if all we're doing is killing a daemon */
+ if (!quitonly)
implicitmode = load_params(argc, argv, optind);
#if defined(HAVE_SYSLOG)
@@ -366,7 +377,7 @@ int main(int argc, char **argv)
pid = bkgd ? -pid : pid;
/* if no mail servers listed and nothing in background, we're done */
- if (!(quitmode && argc == 2) && pid == 0 && querylist == NULL) {
+ if (!quitonly && pid == 0 && querylist == NULL) {
(void)fputs(GT_("fetchmail: no mailservers have been specified.\n"),stderr);
exit(PS_SYNTAX);
}
@@ -374,17 +385,11 @@ int main(int argc, char **argv)
/* perhaps user asked us to kill the other fetchmail */
if (quitmode)
{
- if (pid == 0)
+ if (pid == 0 || pid == getpid())
+ /* this test enables re-execing on a changed rcfile
+ * for pid == getpid() */
{
- fprintf(stderr,GT_("fetchmail: no other fetchmail is running\n"));
- if (argc == 2)
- exit(PS_EXCLUDE);
- }
- else if (getpid() == pid)
- {
- /* this test enables re-execing on a changed rcfile */
- if (argc == 2)
- {
+ if (quitonly) {
fprintf(stderr,GT_("fetchmail: no other fetchmail is running\n"));
exit(PS_EXCLUDE);
}
@@ -397,10 +402,11 @@ int main(int argc, char **argv)
}
else
{
- fprintf(stderr,GT_("fetchmail: %s fetchmail at %d killed.\n"),
- bkgd ? GT_("background") : GT_("foreground"), pid);
+ if (outlevel > O_SILENT)
+ fprintf(stderr,GT_("fetchmail: %s fetchmail at %d killed.\n"),
+ bkgd ? GT_("background") : GT_("foreground"), pid);
fm_lock_release();
- if (argc == 2)
+ if (quitonly)
exit(0);
else
pid = 0;
@@ -902,6 +908,9 @@ static void optmerge(struct query *h2, struct query *h1, int force)
#undef FLAG_MERGE
}
+/** Load configuration files.
+ * \return - true if no servers found on the command line
+ * - false if servers found on the command line */
static int load_params(int argc, char **argv, int optind)
{
int implicitmode, st;
@@ -1006,9 +1015,12 @@ static int load_params(int argc, char **argv, int optind)
}
/* don't allow a defaults record after the first */
- for (ctl = querylist; ctl; ctl = ctl->next)
- if (ctl != querylist && strcmp(ctl->server.pollname, "defaults") == 0)
+ for (ctl = querylist; ctl; ctl = ctl->next) {
+ if (ctl != querylist && strcmp(ctl->server.pollname, "defaults") == 0) {
+ fprintf(stderr, GT_("fetchmail: Error: multiple \"defaults\" records in config file.\n"));
exit(PS_SYNTAX);
+ }
+ }
/* use localhost if we never fetch the FQDN of this host */
fetchmailhost = "localhost";
diff --git a/fetchmail.h b/fetchmail.h
index b3868592..c75d07b0 100644
--- a/fetchmail.h
+++ b/fetchmail.h
@@ -412,6 +412,7 @@ extern flag peek_capable; /* can we read msgs without setting seen? */
extern struct runctl run; /* global controls for this run */
extern flag nodetach; /* if TRUE, don't detach daemon process */
extern flag quitmode; /* if --quit was set */
+extern int quitind; /* optind after position of last --quit option */
extern flag check_only; /* if --check was set */
extern char *rcfile; /* path name of rc file */
extern int linelimit; /* limit # lines retrieved per site */
diff --git a/fetchmail.man b/fetchmail.man
index 5f134f75..9343255f 100644
--- a/fetchmail.man
+++ b/fetchmail.man
@@ -1021,16 +1021,13 @@ flags indicating that connections have wedged due to failed
authentication or multiple timeouts.
.PP
The option
-.B --quit
+.B \-\-quit
will kill a running daemon process instead of waking it up (if there
-is no such process,
-.I fetchmail
-notifies you). If the --quit option is the only command-line option,
-that's all there is to it.
-.PP
-The quit option may also be mixed with other command-line options; its
-effect is to kill any running daemon before doing what the other
-options specify in combination with the fetchmailrc file.
+is no such process, \fIfetchmail\fP will notify you.
+If the \-\-quit option appears last on the command line, \fIfetchmail\fP
+will kill the running daemon process and then quit. Otherwise,
+\fIfetchmail\fP will first kill a running daemon process and then
+continue running with the other options.
.PP
The
.B \-L <filename>
@@ -1069,7 +1066,9 @@ option was used.
.PP
The
.B \-N
-or --nodetach option suppresses backgrounding and detachment of the
+or
+.B --nodetach
+option suppresses backgrounding and detachment of the
daemon process from its control terminal. This is useful
for debugging or when fetchmail runs as the child of a supervisor
process such as
diff --git a/options.c b/options.c
index 6bf12164..3e99a1e2 100644
--- a/options.c
+++ b/options.c
@@ -267,6 +267,7 @@ struct query *ctl; /* option record to be initialized */
break;
case 'q':
quitmode = TRUE;
+ quitind = optind;
break;
case 'L':
rctl->logfile = prependdir (optarg, currentwd);