annotate src/libident/support.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 |
|
rev |
line source |
meillo@0
|
1 /*
|
meillo@0
|
2 ** support.c
|
meillo@0
|
3 **
|
meillo@0
|
4 ** Author: Pr Emanuelsson <pell@lysator.liu.se>
|
meillo@0
|
5 ** Hacked by: Peter Eriksson <pen@lysator.liu.se>
|
meillo@0
|
6 */
|
meillo@0
|
7 #include <stdio.h>
|
meillo@0
|
8 #include <ctype.h>
|
meillo@0
|
9
|
meillo@0
|
10 #ifdef HAVE_ANSIHEADERS
|
meillo@0
|
11 # include <stdlib.h>
|
meillo@0
|
12 # include <string.h>
|
meillo@0
|
13 #else
|
meillo@0
|
14 # define strchr(str, c) index(str, c)
|
meillo@0
|
15 #endif
|
meillo@0
|
16
|
meillo@0
|
17 #define IN_LIBIDENT_SRC
|
meillo@0
|
18 #include "ident.h"
|
meillo@0
|
19
|
meillo@0
|
20
|
meillo@10
|
21 char*
|
meillo@10
|
22 id_strdup __P1(char *, str)
|
meillo@0
|
23 {
|
meillo@10
|
24 char *cp;
|
meillo@0
|
25
|
meillo@10
|
26 cp = (char *) malloc(strlen(str) + 1);
|
meillo@10
|
27 if (cp == NULL) {
|
meillo@0
|
28 #ifdef DEBUG
|
meillo@10
|
29 perror("libident: malloc");
|
meillo@0
|
30 #endif
|
meillo@10
|
31 return NULL;
|
meillo@10
|
32 }
|
meillo@0
|
33
|
meillo@10
|
34 strcpy(cp, str);
|
meillo@0
|
35
|
meillo@10
|
36 return cp;
|
meillo@0
|
37 }
|
meillo@0
|
38
|
meillo@0
|
39
|
meillo@10
|
40 char*
|
meillo@10
|
41 id_strtok __P3(char *, cp, char *, cs, char *, dc)
|
meillo@0
|
42 {
|
meillo@10
|
43 static char *bp = 0;
|
meillo@10
|
44
|
meillo@10
|
45 if (cp)
|
meillo@10
|
46 bp = cp;
|
meillo@10
|
47
|
meillo@10
|
48 /*
|
meillo@10
|
49 ** No delimitor cs - return whole buffer and point at end
|
meillo@10
|
50 */
|
meillo@10
|
51 if (!cs) {
|
meillo@10
|
52 while (*bp)
|
meillo@10
|
53 bp++;
|
meillo@10
|
54 return cs;
|
meillo@10
|
55 }
|
meillo@10
|
56
|
meillo@10
|
57 /*
|
meillo@10
|
58 ** Skip leading spaces
|
meillo@10
|
59 */
|
meillo@10
|
60 while (isspace(*bp))
|
meillo@10
|
61 bp++;
|
meillo@10
|
62
|
meillo@10
|
63 /*
|
meillo@10
|
64 ** No token found?
|
meillo@10
|
65 */
|
meillo@10
|
66 if (!*bp)
|
meillo@10
|
67 return 0;
|
meillo@10
|
68
|
meillo@10
|
69 cp = bp;
|
meillo@10
|
70 while (*bp && !strchr(cs, *bp))
|
meillo@10
|
71 bp++;
|
meillo@10
|
72
|
meillo@10
|
73 /*
|
meillo@10
|
74 ** Remove trailing spaces
|
meillo@10
|
75 */
|
meillo@10
|
76 *dc = *bp;
|
meillo@10
|
77 for (dc = bp - 1; dc > cp && isspace(*dc); dc--);
|
meillo@10
|
78 *++dc = '\0';
|
meillo@10
|
79
|
meillo@0
|
80 bp++;
|
meillo@10
|
81
|
meillo@10
|
82 return cp;
|
meillo@0
|
83 }
|