]> Pileus Git - ~andy/fetchmail/commitdiff
Dave Zarzycki's fixes.
authorEric S. Raymond <esr@thyrsus.com>
Sat, 10 Feb 2001 21:20:35 +0000 (21:20 -0000)
committerEric S. Raymond <esr@thyrsus.com>
Sat, 10 Feb 2001 21:20:35 +0000 (21:20 -0000)
svn path=/trunk/; revision=3039

NEWS
daemon.c
fetchmail-FAQ.html
fetchmail.c
fetchmail.h
socket.c

diff --git a/NEWS b/NEWS
index 3afc91937886de179b0f0c5f153433b5223052ff..b239fe4f021275ee5195da45d0d95b17ffe9e940 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@
 (The `lines' figures total .c, .h, .l, and .y files under version control.)
 
 * ODMR port fix for AIX.
+* Dave Zarzycki's fix for former FAQ item F5 (%h and %p not being expanded).
 
 fetchmail-5.6.3 (Wed Feb  7 10:56:21 EST 2001), 19901 lines:
 
index 10c52b6672e602c4b9243c71ad9e7cf662119be9..89f733acd2c0a2c6ccba3e79ac6c12e382f14ad1 100644 (file)
--- a/daemon.c
+++ b/daemon.c
@@ -82,13 +82,36 @@ sigchld_handler (int sig)
     lastsig = SIGCHLD;
 }
 
+void deal_with_sigchld(void)
+{
+  RETSIGTYPE sigchld_handler(int);
+#ifdef HAVE_SIGACTION
+  struct sigaction sa_new;
+
+  memset (&sa_new, 0, sizeof sa_new);
+  sigemptyset (&sa_new.sa_mask);
+  sa_new.sa_handler = SIG_IGN;
+
+  /* set up to catch child process termination signals */ 
+  sa_new.sa_handler = sigchld_handler;
+  sigaction (SIGCHLD, &sa_new, NULL);
+#if defined(SIGPWR)
+  sigaction (SIGPWR, &sa_new, NULL);
+#endif
+#else
+  signal(SIGCHLD, sigchld_handler); 
+#if defined(SIGPWR)
+  signal(SIGPWR, sigchld_handler); 
+#endif
+#endif /* HAVE_SIGACTION */
+}
+
 int
 daemonize (const char *logfile, void (*termhook)(int))
 /* detach from control TTY, become process group leader, catch SIGCHLD */
 {
   int fd;
   pid_t childpid;
-  RETSIGTYPE sigchld_handler(int);
 #ifdef HAVE_SIGACTION
   struct sigaction sa_new;
 #endif /* HAVE_SIGACTION */
@@ -221,20 +244,7 @@ nottyDetach:
   umask(022);
 #endif
 
-  /* set up to catch child process termination signals */ 
-#ifndef HAVE_SIGACTION
-  signal(SIGCHLD, sigchld_handler); 
-#else
-  sa_new.sa_handler = sigchld_handler;
-  sigaction (SIGCHLD, &sa_new, NULL);
-#endif /* HAVE_SIGACTION */
-#if defined(SIGPWR)
-#ifndef HAVE_SIGACTION
-  signal(SIGPWR, sigchld_handler); 
-#else
-  sigaction (SIGPWR, &sa_new, NULL);
-#endif /* HAVE_SIGACTION */
-#endif
+  deal_with_sigchld();
 
   return(0);
 }
index e0f47e9a4ec8a7599b16cdeef148ce1854509900..51c58ad18e3e3d5c17abd009c90fca74e6f422e6 100644 (file)
@@ -10,7 +10,7 @@
 <table width="100%" cellpadding=0><tr>
 <td width="30%">Back to <a href="index.html">Fetchmail Home Page</a>
 <td width="30%" align=center>To <a href="/~esr/sitemap.html">Site Map</a>
-<td width="30%" align=right>$Date: 2001/02/07 08:01:08 $
+<td width="30%" align=right>$Date: 2001/02/10 21:20:33 $
 </table>
 <HR>
 <H1>Frequently Asked Questions About Fetchmail</H1>
@@ -53,7 +53,6 @@ IP address?</a><br>
 <a href="#F2">F2. The .fetchmailrc parser won't accept my all-numeric user name.</a><br>
 <a href="#F3">F3. The .fetchmailrc parser won't accept my host or username beginning with `no'.</a><br>
 <a href="#F4">F4. I'm getting a `parse error' message I don't understand.</a><br>
-<a href="#F5">F5. The %h and %p escapes aren't being interporated correctly.</a><br>
 
 <h1>Configuration questions:</h1>
 
@@ -805,30 +804,6 @@ Yes, I know these ordering restrictions are hard to understand.
 Unfortunately, they're necessary in order to allow the `defaults' 
 feature to work.<P>
 
-<hr>
-<h2><a name="F5">F5. The %h and %p escapes aren't being interporated correctly.</a></h2>
-
-Note that %h and %p are only recognized as placeholders if they are a
-single word each; you cannot use %h:%p or other interpolations that
-aren't space-delimited.  If you happen to need such a thing, write a
-wrapper.  For example, in .fetchmailrc you can add this line:<p>
-
-<pre>
-plugin 'mywrap.sh %h %p'
-</pre>
-
-With mywrap.sh containing:<p>
-
-<pre>
-#! /bin/sh
-if test $# -ne 2 ; then
-  echo "usage: `basename $0` <host> <port>"
-  exit 1
-fi
-exec openssl 2>/dev/null s_client -connect $1:$2 -quiet
-exit 2 # never reached unless openssl fails
-</pre>
-
 <hr>
 <h2><a name="C1">C1. Why do I need a .fetchmailrc when running as root on my own machine?</a></h2>
 
@@ -2991,7 +2966,7 @@ switching to IMAP and using a short expunge interval.<p>
 <table width="100%" cellpadding=0><tr>
 <td width="30%">Back to <a href="index.html">Fetchmail Home Page</a>
 <td width="30%" align=center>To <a href="/~esr/sitemap.html">Site Map</a>
-<td width="30%" align=right>$Date: 2001/02/07 08:01:08 $
+<td width="30%" align=right>$Date: 2001/02/10 21:20:33 $
 </table>
 
 <P><ADDRESS>Eric S. Raymond <A HREF="mailto:esr@thyrsus.com">&lt;esr@snark.thyrsus.com&gt;</A></ADDRESS>
index 1394b5678c17ac3ba474c17d6c9b34392776e02e..56849bf2407f24a1862a4a6321e4d15980c0b015 100644 (file)
@@ -541,7 +541,10 @@ int main(int argc, char **argv)
      */
     if (run.poll_interval)
     {
-       if (!nodetach)
+       deal_with_sigchld();
+       if (nodetach)
+           deal_with_sigchld();
+       else
            daemonize(run.logfile, terminate_run);
        report(stdout, _("starting fetchmail %s daemon \n"), VERSION);
 
index ef6d4677d0f648d15ddc97996fa99bba14f38393..2dbff2f388e2f7c7ccdfd3eebc06653c83de8e94 100644 (file)
@@ -522,6 +522,7 @@ struct query *hostalloc(struct query *);
 int parsecmdline (int, char **, struct runctl *, struct query *);
 char *MD5Digest (unsigned char *);
 int POP3_auth_rpa(unsigned char *, unsigned char *, int socket);
+void deal_with_sigchld(void);
 int daemonize(const char *, void (*)(int));
 char *fm_getpassword(char *);
 void escapes(const char *, char *);
index 26a46c2a66d215cfb4b0712324be189dac97e6d7..64a1d7111fcde4583be7a2c30602265ba5bc38e7 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -71,22 +71,54 @@ static int h_errno;
 #endif /* NET_SECURITY */
 
 #ifdef HAVE_SOCKETPAIR
-const char **parse_plugin(const char *plugin, const char *host, const char *service)
+char *const *parse_plugin(const char *plugin, const char *host, const char *service)
 {      const char **argvec;
-       char *c, *p, *plugin_copy;
-       unsigned int s = 2 * sizeof(char*), i;
+       const char *c, *p;
+       char *cp, *plugin_copy;
+       unsigned int plugin_copy_len;
+       unsigned int plugin_offset = 0, plugin_copy_offset = 0;
+       unsigned int i, s = 2 * sizeof(char*), host_count = 0, service_count = 0;
+       unsigned int plugin_len = strlen(plugin);
+       unsigned int host_len = strlen(host);
+       unsigned int service_len = strlen(service);
+
+       for (c = p = plugin; *c; c++)
+       {       if (isspace(*c) && !isspace(*p))
+                       s += sizeof(char*);
+               if (*p == '%' && *c == 'h')
+                       host_count++;
+               if (*p == '%' && *c == 'p')
+                       service_count++;
+               p = c;
+       }
 
-       plugin_copy = strdup(plugin);
+       plugin_copy_len = plugin_len + host_len * host_count + service_len * service_count;
+       plugin_copy = malloc(plugin_copy_len + 1);
        if (!plugin_copy)
        {
                report(stderr, _("fetchmail: malloc failed\n"));
                return NULL;
        }
-       for (c = p = plugin_copy; *c; c++)
-       {       if (isspace(*c) && !isspace(*p))
-                       s += sizeof(char*);
-               p = c;
+
+       while (plugin_copy_offset < plugin_copy_len)
+       {       if ((plugin[plugin_offset] == '%') && (plugin[plugin_offset + 1] == 'h'))
+               {       strcat(plugin_copy + plugin_copy_offset, host);
+                       plugin_offset += 2;
+                       plugin_copy_offset += host_len;
+               }
+               else if ((plugin[plugin_offset] == '%') && (plugin[plugin_offset + 1] == 'p'))
+               {       strcat(plugin_copy + plugin_copy_offset, service);
+                       plugin_offset += 2;
+                       plugin_copy_offset += service_len;
+               }
+               else
+               {       plugin_copy[plugin_copy_offset] = plugin[plugin_offset];
+                       plugin_offset++;
+                       plugin_copy_offset++;
+               }
        }
+       plugin_copy[plugin_copy_len] = 0;
+
        argvec = malloc(s);
        if (!argvec)
        {
@@ -101,17 +133,11 @@ const char **parse_plugin(const char *plugin, const char *host, const char *serv
                }
                p = c;
        }
-       for (c = plugin_copy; *c; c++)
-       {       if (isspace(*c))
-                       *c = 0;
-       }
-       for (i = 0; argvec[i]; i++)
-       {       if (strcmp(argvec[i], "%h") == 0)
-                       argvec[i] = host;
-               if (strcmp(argvec[i], "%p") == 0)
-                       argvec[i] = service;
+       for (cp = plugin_copy; *cp; cp++)
+       {       if (isspace(*cp))
+                       *cp = 0;
        }
-       return argvec;
+       return (char *const*)argvec;
 }
 
 static int handle_plugin(const char *host,
@@ -149,7 +175,7 @@ static int handle_plugin(const char *host,
                (void) close(fds[0]);
                if (outlevel >= O_VERBOSE)
                    report(stderr, _("running %s (host %s service %s)\n"), plugin, host, service);
-               argvec = (char *const *)parse_plugin(plugin,host,service);
+               argvec = parse_plugin(plugin,host,service);
                execvp(*argvec, argvec);
                report(stderr, _("execvp(%s) failed\n"), *argvec);
                exit(0);