aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS1
-rw-r--r--daemon.c40
-rw-r--r--fetchmail-FAQ.html29
-rw-r--r--fetchmail.c5
-rw-r--r--fetchmail.h1
-rw-r--r--socket.c64
6 files changed, 78 insertions, 62 deletions
diff --git a/NEWS b/NEWS
index 3afc9193..b239fe4f 100644
--- 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:
diff --git a/daemon.c b/daemon.c
index 10c52b66..89f733ac 100644
--- 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);
}
diff --git a/fetchmail-FAQ.html b/fetchmail-FAQ.html
index e0f47e9a..51c58ad1 100644
--- a/fetchmail-FAQ.html
+++ b/fetchmail-FAQ.html
@@ -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>
@@ -806,30 +805,6 @@ 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>
Ian T. Zimmerman &lt;itz@rahul.net&gt; asked:<p>
@@ -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>
diff --git a/fetchmail.c b/fetchmail.c
index 1394b567..56849bf2 100644
--- a/fetchmail.c
+++ b/fetchmail.c
@@ -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);
diff --git a/fetchmail.h b/fetchmail.h
index ef6d4677..2dbff2f3 100644
--- a/fetchmail.h
+++ b/fetchmail.h
@@ -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 *);
diff --git a/socket.c b/socket.c
index 26a46c2a..64a1d711 100644
--- 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);