]> Pileus Git - ~andy/fetchmail/commitdiff
Accept more options with a running daemon.
authorMatthias Andree <matthias.andree@gmx.de>
Sat, 18 Dec 2010 15:07:57 +0000 (16:07 +0100)
committerMatthias Andree <matthias.andree@gmx.de>
Sat, 18 Dec 2010 15:07:57 +0000 (16:07 +0100)
NEWS
fetchmail.c
fetchmail.h
options.c

diff --git a/NEWS b/NEWS
index ead799b4d025330c0647d9a158083beb16a28507..85349b6e51030033871b02415c7a3992e1f10076 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -84,6 +84,10 @@ NOTE THIS IS AN ALPHA RELEASE THAT HAS NOT BEEN THOROUGHLY TESTED!
   Non-DNS based alias keywords such as "aka" remain.
 * Kerberos IV support was removed.
 
+# CHANGES
+* A foreground fetchmail can now accept a few more options while another copy is
+  running in the background.
+
 --------------------------------------------------------------------------------
 
 fetchmail-6.3.20 (not yet released):
index d2da8b62886261989c64e7cffb0857220c8e499a..a32eeb5766346a7d6377700143ac1cf5121ebb5c 100644 (file)
@@ -427,6 +427,8 @@ int main(int argc, char **argv)
 {
     int bkgd = FALSE;
     int implicitmode = FALSE;
+    flag safewithbg = FALSE; /** if parsed options are compatible with a
+                             fetchmail copy running in the background */
     struct query *ctl;
     netrc_entry *netrc_list;
     char *netrc_file, *tmpbuf;
@@ -470,7 +472,7 @@ int main(int argc, char **argv)
 
 #define IDFILE_NAME    ".fetchids"
     run.idfile = prependdir (IDFILE_NAME, fmhome);
-  
+
     outlevel = O_NORMAL;
 
     /*
@@ -494,7 +496,7 @@ int main(int argc, char **argv)
     {
        int i;
 
-       i = parsecmdline(argc, argv, &cmd_run, &cmd_opts);
+       i = parsecmdline(argc, argv, &cmd_run, &cmd_opts, &safewithbg);
        if (i < 0)
            exit(PS_SYNTAX);
 
@@ -759,17 +761,23 @@ int main(int argc, char **argv)
        else if (getpid() == pid)
            /* this test enables re-execing on a changed rcfile */
            fm_lock_assert();
-       else if (argc > 1)
+       else if (argc > 1 && !safewithbg)
        {
            fprintf(stderr,
                    GT_("fetchmail: can't accept options while a background fetchmail is running.\n"));
+           {
+               int i;
+               fprintf(stderr, "argc = %d, arg list:\n", argc);
+               for (i = 1; i < argc; i++) fprintf(stderr, "arg %d = \"%s\"\n", i, argv[i]);
+           }
            return(PS_EXCLUDE);
        }
        else if (kill(pid, SIGUSR1) == 0)
        {
-           fprintf(stderr,
-                   GT_("fetchmail: background fetchmail at %ld awakened.\n"),
-                   (long)pid);
+           if (outlevel > O_SILENT)
+               fprintf(stderr,
+                       GT_("fetchmail: background fetchmail at %ld awakened.\n"),
+                       (long)pid);
            return(0);
        }
        else
index a1b8f119e68702400b43dee1e0bc4542f5487263..4e4031eab4b71ccd3bb1446d7cef0b452e7e3e67 100644 (file)
@@ -636,7 +636,7 @@ int do_otp(int sock, const char *command, struct query *ctl);
 extern char currentwd[1024], rcfiledir[1024];
 
 struct query *hostalloc(struct query *); 
-int parsecmdline (int, char **, struct runctl *, struct query *);
+int parsecmdline (int, char **, struct runctl *, struct query *, flag *);
 char *prependdir (const char *, const char *);
 char *MD5Digest (unsigned const char *);
 void hmac_md5 (const unsigned char *, size_t, const unsigned char *, size_t, unsigned char *, size_t);
index ee2abe97e8890babeac2c56dd52a0bd7f591b955..9c23516b0b9d40fe63d2169ec4e513cc2cd3f5da 100644 (file)
--- a/options.c
+++ b/options.c
@@ -201,7 +201,10 @@ static int xatoi(char *s, int *errflagptr)
 int parsecmdline (int argc /** argument count */,
                  char **argv /** argument strings */,
                  struct runctl *rctl /** global run controls to modify */,
-                 struct query *ctl /** option record to initialize */)
+                 struct query *ctl /** option record to initialize */,
+                 flag *safewithbg /** set to whether options are
+                                    compatible with another copy
+                                    running in the background */)
 {
     /*
      * return value: if positive, argv index of last parsed option + 1
@@ -216,9 +219,12 @@ int parsecmdline (int argc /** argument count */,
     int errflag = 0;   /* TRUE when a syntax error is detected */
     int helpflag = 0;  /* TRUE when option help was explicitly requested */
     int option_index;
+    int option_safe;   /* to track if option currently parsed is safe
+                          with a background copy */
     char *buf, *cp;
 
     rctl->poll_interval = -1;
+    *safewithbg = TRUE;
 
     memset(ctl, '\0', sizeof(struct query));    /* start clean */
     ctl->smtp_socket = -1;
@@ -227,6 +233,8 @@ int parsecmdline (int argc /** argument count */,
           (c = getopt_long(argc,argv,shortoptions,
                            longoptions, &option_index)) != -1)
     {
+       option_safe = FALSE;
+
        switch (c) {
 #ifdef HAVE_LIBPWMD
        case 'C':
@@ -241,18 +249,21 @@ int parsecmdline (int argc /** argument count */,
 #endif
        case 'V':
            versioninfo = TRUE;
+           option_safe = TRUE;
            break;
        case 'c':
            check_only = TRUE;
            break;
        case 's':
            outlevel = O_SILENT;
+           option_safe = 1;
            break;
        case 'v':
            if (outlevel >= O_VERBOSE)
                outlevel = O_DEBUG;
            else
                outlevel = O_VERBOSE;
+           option_safe = TRUE;
            break;
        case 'd':
            rctl->poll_interval = xatoi(optarg, &errflag);
@@ -565,6 +576,7 @@ int parsecmdline (int argc /** argument count */,
 
        case LA_CONFIGDUMP:
            configdump = TRUE;
+           option_safe = TRUE;
            break;
 
        case LA_SYSLOG:
@@ -593,9 +605,11 @@ int parsecmdline (int argc /** argument count */,
            break;
 
        case '?':
+           helpflag = 1;
        default:
-           helpflag++;
+           break;
        }
+       *safewithbg &= option_safe;
     }
 
     if (errflag || ocount > 1 || helpflag) {