diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2001-02-10 21:20:35 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2001-02-10 21:20:35 +0000 |
commit | ad89715a43c50c3d50409730318c42ba9dc96d3f (patch) | |
tree | 12a34e96650cef80cd8d6212c4238a9af2a53766 | |
parent | 53813c522b794b61c7080c40f95a1043912b2dcb (diff) | |
download | fetchmail-ad89715a43c50c3d50409730318c42ba9dc96d3f.tar.gz fetchmail-ad89715a43c50c3d50409730318c42ba9dc96d3f.tar.bz2 fetchmail-ad89715a43c50c3d50409730318c42ba9dc96d3f.zip |
Dave Zarzycki's fixes.
svn path=/trunk/; revision=3039
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | daemon.c | 40 | ||||
-rw-r--r-- | fetchmail-FAQ.html | 29 | ||||
-rw-r--r-- | fetchmail.c | 5 | ||||
-rw-r--r-- | fetchmail.h | 1 | ||||
-rw-r--r-- | socket.c | 64 |
6 files changed, 78 insertions, 62 deletions
@@ -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: @@ -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 <itz@rahul.net> 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"><esr@snark.thyrsus.com></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 *); @@ -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); |