masqmail
view src/libident/id_query.c @ 72:ad034b57f3b2
fixed Debian bug 536060 (log files are closed after SIGHUP receival)
Explanation:
When run in daemon mode, first the log files are opened. They get
assigned to the file descriptors 3 and 4 usually. Then std{in,out,err}
are closed. When SIGHUP comes in, all open files are closes and
masqmail reexecutes itself. The new masqmail instance opens the log
files at fd 0 and 1 now, but std{in,out,err} are closed afterwards,
thus the log files are closed.
The fix is to close the log files before std{in,out,err} are closed,
in case the log files have higher fds. After std{in,out,err} were
closed, the log files get opened again, now.
See also: http://bugs.debian.org/536060
author | meillo@marmaro.de |
---|---|
date | Wed, 16 Jun 2010 10:32:20 +0200 |
parents | 08114f7dcc23 |
children |
line source
1 /*
2 ** id_query.c Transmit a query to an IDENT server
3 **
4 ** Author: Peter Eriksson <pen@lysator.liu.se>
5 */
7 #ifdef NeXT3
8 # include <libc.h>
9 #endif
11 #include <stdio.h>
12 #include <errno.h>
13 #include <signal.h>
15 #ifdef HAVE_ANSIHEADERS
16 # include <stdlib.h>
17 # include <string.h>
18 # include <unistd.h>
19 #endif
21 #include <sys/types.h>
22 #include <sys/wait.h>
23 #include <sys/time.h>
25 #ifdef _AIX
26 # include <sys/select.h>
27 #endif
29 #ifdef _AIX
30 # include <sys/select.h>
31 #endif
32 #ifdef VMS
33 # include <sys/socket.h> /* for fd_set */
34 #endif
35 #define IN_LIBIDENT_SRC
36 #include "ident.h"
39 /*
40 int
41 id_query __P4(ident_t *, id, int, lport, int, fport, struct timeval *, timeout)
42 */
44 int
45 id_query __P((ident_t * id, int lport, int fport, __STRUCT_TIMEVAL_P timeout))
46 {
47 #ifdef SIGRETURNTYPE
48 SIGRETURNTYPE(*old_sig) ();
49 #else
50 void (*old_sig) __P((int));
51 #endif
52 int res;
53 char buf[80];
54 fd_set ws;
56 sprintf(buf, "%d , %d\r\n", lport, fport);
58 if (timeout) {
59 FD_ZERO(&ws);
60 FD_SET(id->fd, &ws);
62 #ifdef __hpux
63 if ((res = select(FD_SETSIZE, (int *) 0, (int *) &ws, (int *) 0, timeout)) < 0)
64 #else
65 if ((res = select(FD_SETSIZE, (fd_set *) 0, &ws, (fd_set *) 0, timeout)) < 0)
66 #endif
67 return -1;
69 if (res == 0) {
70 errno = ETIMEDOUT;
71 return -1;
72 }
73 }
75 old_sig = signal(SIGPIPE, SIG_IGN);
77 res = write(id->fd, buf, strlen(buf));
79 signal(SIGPIPE, old_sig);
81 return res;
82 }