Close notifier socket before re-exec of daemon. Bug 2539
[exim.git] / src / exim_monitor / em_init.c
1 /*************************************************
2 * Exim monitor *
3 *************************************************/
4
5 /* Copyright (c) University of Cambridge 1995 - 2009 */
6 /* See the file NOTICE for conditions of use and distribution. */
7
8 /* This module contains code to initialize things from the
9 environment and the arguments. */
10
11
12 #include "em_hdr.h"
13
14
15
16 /*************************************************
17 * Decode stripchart config *
18 *************************************************/
19
20 /* First determine how many are requested, then compile the
21 regular expressions and save the title strings. Note that
22 stripchart_number is initialized to 1 or 2 to count the always-
23 present queue stripchart, and the optional size-monitoring
24 stripchart. */
25
26 static void decode_stripchart_config(uschar *s)
27 {
28 int i;
29
30 /* Loop: first time just counts, second time does the
31 work. */
32
33 for (i = 0; i <= 1; i++)
34
35 {
36 int first = 1;
37 int count = 0;
38 uschar *p = s;
39
40 if (*p == '/') p++; /* allow optional / at start */
41
42 /* This loops for all the substrings, using the first flag
43 to determine whether each is the first or second of the pairs. */
44
45 while (*p)
46 {
47 uschar *pp;
48 /* Handle continuations */
49 if (*p == '\n')
50 {
51 while (*(++p) == ' ' || *p == '\t');
52 if (*p == '/') p++;
53 }
54
55 /* Find the end of the string and count if first string */
56
57 pp = p;
58 while (*p && *p != '/') p++;
59 if (first) count++;
60
61 /* Take action on the second time round. */
62
63 if (i != 0)
64 {
65 uschar buffer[256];
66 int indx = count + stripchart_varstart - 1;
67 Ustrncpy(buffer, pp, p-pp);
68 buffer[p-pp] = 0;
69 if (first)
70 {
71 int offset;
72 const uschar *error;
73 if (!(stripchart_regex[indx] = pcre_compile(CS buffer, PCRE_COPT,
74 CCSS &error, &offset, NULL)))
75 {
76 printf("regular expression error: %s at offset %d "
77 "while compiling %s\n", error, offset, buffer);
78 exit(99);
79 }
80 }
81 else stripchart_title[indx] = string_copy(buffer);
82 }
83
84 /* Advance past the delimiter and flip the first/second flag */
85
86 p++;
87 first = !first;
88 }
89
90 /* On the first pass, we now know the number of stripcharts. Get
91 store for holding the pointers to the regular expressions and
92 title strings. */
93
94 if (i == 0)
95 {
96 stripchart_number += count;
97 stripchart_regex = (pcre **)store_malloc(stripchart_number * sizeof(pcre *));
98 stripchart_title = (uschar **)store_malloc(stripchart_number * sizeof(uschar *));
99 }
100 }
101 }
102
103
104 /*************************************************
105 * Initialize *
106 *************************************************/
107
108 void init(int argc, uschar **argv)
109 {
110 int x;
111 int erroroffset;
112 uschar *s;
113 const uschar *error;
114
115 argc = argc; /* These are currently unused. */
116 argv = argv;
117
118 /* Deal with simple values in the environment. */
119
120 s = US getenv("ACTION_OUTPUT");
121 if (s != NULL)
122 {
123 if (Ustrcmp(s, "no") == 0) action_output = FALSE;
124 if (Ustrcmp(s, "yes") == 0) action_output = TRUE;
125 }
126
127 s = US getenv("ACTION_QUEUE_UPDATE");
128 if (s != NULL)
129 {
130 if (Ustrcmp(s, "no") == 0) action_queue_update = FALSE;
131 if (Ustrcmp(s, "yes") == 0) action_queue_update = TRUE;
132 }
133
134 s = US getenv("BODY_MAX");
135 if (s != NULL && (x = Uatoi(s)) != 0) body_max = x;
136
137 s = US getenv("EXIM_PATH");
138 if (s != NULL) exim_path = string_copy(s);
139
140 s = US getenv("EXIMON_EXIM_CONFIG");
141 if (s != NULL) alternate_config = string_copy(s);
142
143 s = US getenv("LOG_BUFFER");
144 if (s != NULL)
145 {
146 uschar c[1];
147 if (sscanf(CS s, "%d%c", &x, c) > 0)
148 {
149 if (c[0] == 'K' || c[0] == 'k') x *= 1024;
150 if (x < 1024) x = 1024;
151 log_buffer_size = x;
152 }
153 }
154
155 s = US getenv("LOG_DEPTH");
156 if (s != NULL && (x = Uatoi(s)) != 0) log_depth = x;
157
158 s = US getenv("LOG_FILE_NAME");
159 if (s != NULL) log_file = string_copy(s);
160
161 s = US getenv("LOG_FONT");
162 if (s != NULL) log_font = string_copy(s);
163
164 s = US getenv("LOG_WIDTH");
165 if (s != NULL && (x = Uatoi(s)) != 0) log_width = x;
166
167 s = US getenv("MENU_EVENT");
168 if (s != NULL) menu_event = string_copy(s);
169
170 s = US getenv("MIN_HEIGHT");
171 if (s != NULL && (x = Uatoi(s)) > 0) min_height = x;
172
173 s = US getenv("MIN_WIDTH");
174 if (s != NULL && (x = Uatoi(s)) > 0) min_width = x;
175
176 s = US getenv("QUALIFY_DOMAIN");
177 if (s != NULL) qualify_domain = string_copy(s);
178 else qualify_domain = US""; /* Don't want NULL */
179
180 s = US getenv("QUEUE_DEPTH");
181 if (s != NULL && (x = Uatoi(s)) != 0) queue_depth = x;
182
183 s = US getenv("QUEUE_FONT");
184 if (s != NULL) queue_font = string_copy(s);
185
186 s = US getenv("QUEUE_INTERVAL");
187 if (s != NULL && (x = Uatoi(s)) != 0) queue_update = x;
188
189 s = US getenv("QUEUE_MAX_ADDRESSES");
190 if (s != NULL && (x = Uatoi(s)) != 0) queue_max_addresses = x;
191
192 s = US getenv("QUEUE_WIDTH");
193 if (s != NULL && (x = Uatoi(s)) != 0) queue_width = x;
194
195 s = US getenv("SPOOL_DIRECTORY");
196 if (s != NULL) spool_directory = string_copy(s);
197
198 s = US getenv("START_SMALL");
199 if (s != NULL && Ustrcmp(s, "yes") == 0) start_small = 1;
200
201 s = US getenv("TEXT_DEPTH");
202 if (s != NULL && (x = Uatoi(s)) != 0) text_depth = x;
203
204 s = US getenv("WINDOW_TITLE");
205 if (s != NULL) window_title = string_copy(s);
206
207 /* Deal with stripchart configuration. First see if we are monitoring
208 the size of a partition, then deal with log stripcharts in a separate
209 function */
210
211 s = US getenv("SIZE_STRIPCHART");
212 if (s != NULL && *s != 0)
213 {
214 stripchart_number++;
215 stripchart_varstart++;
216 size_stripchart = string_copy(s);
217 s = US getenv("SIZE_STRIPCHART_NAME");
218 if (s != NULL && *s != 0) size_stripchart_name = string_copy(s);
219 }
220
221 s = US getenv("LOG_STRIPCHARTS");
222 if (s != NULL) decode_stripchart_config(s);
223
224 s = US getenv("STRIPCHART_INTERVAL");
225 if (s != NULL && (x = Uatoi(s)) != 0) stripchart_update = x;
226
227 s = US getenv("QUEUE_STRIPCHART_NAME");
228 queue_stripchart_name = (s != NULL)? string_copy(s) : US"queue";
229
230 /* Compile the regex for matching yyyy-mm-dd at the start of a string. */
231
232 yyyymmdd_regex = pcre_compile("^\\d{4}-\\d\\d-\\d\\d\\s", PCRE_COPT,
233 CCSS &error, &erroroffset, NULL);
234 }
235
236 /* End of em_init.c */