Sam Varshavchik wrote:
> It looks to me like your patch reinvents the wheel.
I'm not sure why wheels have to be reinvented every now and then, but
on the ChangeLog I found the following:
http://cvs.sourceforge.net/viewcvs.py/courier/courier/courier/ChangeLog?rev=1.600&view=markup
: 2002-08-01 Mr. Sam <his mail addr>
:
: * courier/ldapaliasd.c (sigalarm): Reestablish handlers for SIGHUP
: and SIGALRM, after catching those signals.
There is no corresponding fix for courierfilter. The patch I resend was
prepared and tested on 0.43.2 -courierfilter hasn't changed since. This
patch also amends global filter startups according to specifications in
http://www.courier-mta.org/courierfilter.html
: [...]
: After initializing the socket, the mail filter must then close
: its file descriptor #3. File descriptor 3 is inherited [...]
Without this patch there is no file descriptor #3 when the filter is
started using the filterctl.
--- courierfilter-0.43.2.c 2003-01-05 05:01:15.000000000 +0100
+++ courierfilter.c 2004-02-23 17:54:22.850556000 +0100
@@ -265,7 +265,26 @@
** when all copies of the write side of the pipe are closed.
**
*/
-
+static int reserve3(int* pipe3fd)
+{
+ int devnull = -1, dupped = -1;
+ pipe3fd[0] = pipe3fd[1] = -1;
+ close(3);
+ if (open("/dev/null", O_RDONLY) != 3
+ || pipe(pipe3fd) < 0
+ || close(3)
+ || (dupped = dup(pipe3fd[1])) != 3)
+ {
+ fprintf(stderr, "Unable to reserve file descriptor 3.\n");
+ close(devnull);
+ close(dupped);
+ close(pipe3fd[0]);
+ close(pipe3fd[1]);
+ return (1);
+ }
+ close(pipe3fd[1]);
+ return (0);
+}
static int start()
{
@@ -289,17 +308,11 @@
return (-1);
}
}
- close(3);
- if (open("/dev/null", O_RDONLY) != 3
- || pipe(pipe3fd) < 0
- || close(3)
- || dup(pipe3fd[1]) != 3)
+ if (reserve3(pipe3fd))
{
- fprintf(stderr, "Unable to reserve file descriptor 3.\n");
return (1);
}
- close(pipe3fd[1]);
fcntl(lockfd, F_SETFD, FD_CLOEXEC);
fcntl(pipe3fd[0], F_SETFD, FD_CLOEXEC);
@@ -329,7 +342,13 @@
if (sighup_received)
{
sighup_received=0;
- sighup();
+ if (reserve3(pipe3fd) == 0)
+ {
+ sighup();
+ close(3);
+ close(pipe3fd[0]);
+ }
+ signal(SIGHUP, sighuphandler);
}
#if HAVE_SIGSUSPEND