1 /* $Cambridge: exim/src/exim_monitor/em_init.c,v 1.2 2005/01/04 10:00:42 ph10 Exp $ */
3 /*************************************************
5 *************************************************/
7 /* Copyright (c) University of Cambridge 1995 - 2005 */
8 /* See the file NOTICE for conditions of use and distribution. */
10 /* This module contains code to initialize things from the
11 environment and the arguments. */
18 /*************************************************
19 * Decode stripchart config *
20 *************************************************/
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
28 static void decode_stripchart_config(uschar *s)
32 /* Loop: first time just counts, second time does the
35 for (i = 0; i <= 1; i++)
42 if (*p == '/') p++; /* allow optional / at start */
44 /* This loops for all the substrings, using the first flag
45 to determine whether each is the first or second of the pairs. */
50 /* Handle continuations */
53 while (*(++p) == ' ' || *p == '\t');
57 /* Find the end of the string and count if first string */
60 while (*p && *p != '/') p++;
63 /* Take action on the second time round. */
68 int indx = count + stripchart_varstart - 1;
69 Ustrncpy(buffer, pp, p-pp);
75 stripchart_regex[indx] = pcre_compile(CS buffer, PCRE_COPT,
76 (const char **)&error, &offset, NULL);
77 if (stripchart_regex[indx] == NULL)
79 printf("regular expression error: %s at offset %d "
80 "while compiling %s\n", error, offset, buffer);
84 else stripchart_title[indx] = string_copy(buffer);
87 /* Advance past the delimiter and flip the first/second flag */
93 /* On the first pass, we now know the number of stripcharts. Get
94 store for holding the pointers to the regular expressions and
99 stripchart_number += count;
100 stripchart_regex = (pcre **)store_malloc(stripchart_number * sizeof(pcre *));
101 stripchart_title = (uschar **)store_malloc(stripchart_number * sizeof(uschar *));
107 /*************************************************
109 *************************************************/
111 void init(int argc, uschar **argv)
118 argc = argc; /* These are currently unused. */
121 /* Deal with simple values in the environment. */
123 s = US getenv("ACTION_OUTPUT");
126 if (Ustrcmp(s, "no") == 0) action_output = FALSE;
127 if (Ustrcmp(s, "yes") == 0) action_output = TRUE;
130 s = US getenv("ACTION_QUEUE_UPDATE");
133 if (Ustrcmp(s, "no") == 0) action_queue_update = FALSE;
134 if (Ustrcmp(s, "yes") == 0) action_queue_update = TRUE;
137 s = US getenv("BODY_MAX");
138 if (s != NULL && (x = Uatoi(s)) != 0) body_max = x;
140 s = US getenv("EXIM_PATH");
141 if (s != NULL) exim_path = string_copy(s);
143 s = US getenv("EXIMON_EXIM_CONFIG");
144 if (s != NULL) alternate_config = string_copy(s);
146 s = US getenv("LOG_BUFFER");
150 if (sscanf(CS s, "%d%c", &x, c) > 0)
152 if (c[0] == 'K' || c[0] == 'k') x *= 1024;
153 if (x < 1024) x = 1024;
158 s = US getenv("LOG_DEPTH");
159 if (s != NULL && (x = Uatoi(s)) != 0) log_depth = x;
161 s = US getenv("LOG_FILE_NAME");
162 if (s != NULL) log_file = string_copy(s);
164 s = US getenv("LOG_FONT");
165 if (s != NULL) log_font = string_copy(s);
167 s = US getenv("LOG_WIDTH");
168 if (s != NULL && (x = Uatoi(s)) != 0) log_width = x;
170 s = US getenv("MENU_EVENT");
171 if (s != NULL) menu_event = string_copy(s);
173 s = US getenv("MIN_HEIGHT");
174 if (s != NULL && (x = Uatoi(s)) > 0) min_height = x;
176 s = US getenv("MIN_WIDTH");
177 if (s != NULL && (x = Uatoi(s)) > 0) min_width = x;
179 s = US getenv("QUALIFY_DOMAIN");
180 if (s != NULL) qualify_domain = string_copy(s);
181 else qualify_domain = US""; /* Don't want NULL */
183 s = US getenv("QUEUE_DEPTH");
184 if (s != NULL && (x = Uatoi(s)) != 0) queue_depth = x;
186 s = US getenv("QUEUE_FONT");
187 if (s != NULL) queue_font = string_copy(s);
189 s = US getenv("QUEUE_INTERVAL");
190 if (s != NULL && (x = Uatoi(s)) != 0) queue_update = x;
192 s = US getenv("QUEUE_MAX_ADDRESSES");
193 if (s != NULL && (x = Uatoi(s)) != 0) queue_max_addresses = x;
195 s = US getenv("QUEUE_WIDTH");
196 if (s != NULL && (x = Uatoi(s)) != 0) queue_width = x;
198 s = US getenv("SPOOL_DIRECTORY");
199 if (s != NULL) spool_directory = string_copy(s);
201 s = US getenv("START_SMALL");
202 if (s != NULL && Ustrcmp(s, "yes") == 0) start_small = 1;
204 s = US getenv("TEXT_DEPTH");
205 if (s != NULL && (x = Uatoi(s)) != 0) text_depth = x;
207 s = US getenv("WINDOW_TITLE");
208 if (s != NULL) window_title = string_copy(s);
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
214 s = US getenv("SIZE_STRIPCHART");
215 if (s != NULL && *s != 0)
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);
224 s = US getenv("LOG_STRIPCHARTS");
225 if (s != NULL) decode_stripchart_config(s);
227 s = US getenv("STRIPCHART_INTERVAL");
228 if (s != NULL && (x = Uatoi(s)) != 0) stripchart_update = x;
230 s = US getenv("QUEUE_STRIPCHART_NAME");
231 queue_stripchart_name = (s != NULL)? string_copy(s) : US"queue";
233 /* Compile the regex for matching yyyy-mm-dd at the start of a string. */
235 yyyymmdd_regex = pcre_compile("^\\d{4}-\\d\\d-\\d\\d\\s", PCRE_COPT,
236 (const char **)&error, &erroroffset, NULL);
239 /* End of em_init.c */