]> Pileus Git - ~andy/fetchmail/commitdiff
- make fetchmail --silent --quit really silent, Debian Bug #229014 by
authorMatthias Andree <matthias.andree@gmx.de>
Sun, 30 Oct 2005 17:54:27 +0000 (17:54 -0000)
committerMatthias Andree <matthias.andree@gmx.de>
Sun, 30 Oct 2005 17:54:27 +0000 (17:54 -0000)
  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

NEWS
fetchmail.c
fetchmail.h
fetchmail.man
options.c

diff --git a/NEWS b/NEWS
index bb06e1b0d694c57856f750b502e82a7c5e5ad69d..4106e425f3782673df9e4135e5827dc6759b0d9f 100644 (file)
--- 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.
index 57c05f8eaf91508980132adbd8465e1ee35cfd41..5f442d546dd0043dc012da3f108fb13f2a8cad98 100644 (file)
@@ -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";
index b38685928b46b0e12415a7ddea5565a1edd0394d..c75d07b0d6da17c44f65779803a459a0c2e2f3d7 100644 (file)
@@ -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 */
index 5f134f75be2a67dc22c9eb029d33926bb73c4289..9343255f7430eb8e035b2dd1bc4ba1484b2b8a12 100644 (file)
@@ -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
index 6bf121644c6b1640cc30f757f96a916766ee5a23..3e99a1e239de64a7d2eb16dafa0e3897bc6db62d 100644 (file)
--- 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);