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