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