(verbosely) skip the strip -x in the case of config -g
[unix-history] / sbin / init.chmr / cf_table.c
CommitLineData
9a6eb889
NW
1/*
2 * Copyright (c) 1993 Christoph M. Robitschko
800ffe89
NW
3 * All rights reserved.
4 *
800ffe89
NW
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
9a6eb889
NW
15 * This product includes software developed by Christoph M. Robitschko
16 * 4. The name of the author may not be used to endorse or promote products
17 * derived from this software withough specific prior written permission
800ffe89 18 *
9a6eb889
NW
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
800ffe89
NW
29 */
30
31/*
32 * cf_table.c
33 * The table of words that the configuration subsystem understands,
34 * along with local support functions.
35 */
36
37#ifdef CONFIGURE
38
39#include <stdlib.h>
40#include <unistd.h>
41#include <string.h>
42#include <ttyent.h>
43#include <sys/types.h>
44#include <sys/signal.h>
45#include <sys/time.h>
46#include <sys/resource.h>
47#include <sys/file.h>
48
49#include "init.h"
50#include "prototypes.h"
51#include "cf_defs.h"
52
53
54/* Prototypes for static functions */
55static int conf_env(char *, int, int, char **, int);
56static int conf_include(char *, int, int, char **, int);
57static int conf_waittimes(char *, int, int, char **, int);
58
59
60/* static variables */
61static struct rlimit proclimits[RLIM_NLIMITS];
62
63
64/* extern variables, referenced inb Commands table */
65extern int startup_single;
66extern struct ttyent RCent_auto;
67extern struct ttyent RCent_fast;
68extern struct ttyent Single_ent;
69extern int retrytime;
70extern int timeout_m2s_KILL;
71extern int timeout_m2s_TERM;
72extern int checkstatus;
73extern int checktime;
74
75
76
77#ifdef __STDC__
78# define CURLIM(_lim_) &proclimits[RLIMIT_##_lim_].rlim_cur
79# define MAXLIM(_lim_) &proclimits[RLIMIT_##_lim_].rlim_max
80#else
81# define CURLIM(_lim_) &proclimits[RLIMIT_/**/_lim_].rlim_cur
82# define MAXLIM(_lim_) &proclimits[RLIMIT_/**/_lim_].rlim_max
83#endif
84
85
86/*
87 * The table of all known words and actions
88 */
89
90const struct Command Commands[] = {
91
92#ifdef DEBUG
93 {"debug_level", 0+SUB, T_EX, 0, NOVAR},
94 {"LEVEL", 1, T_INT, MAXVAL, &debug, {5}},
95#endif
96
97 {"startup_state", 0+SUB, T_EX, 0, NOVAR},
98 {"singleuser_mode", 1, T_EX, 0, &startup_single, {1}},
99 {"multiuser_mode", 1, T_EX, 0, &startup_single, {0}},
100
101 {"setenv", 0+SUB, T_EX, 0, NOVAR},
102 {"VAR", 1+SUB, T_STR, 0, NOVAR},
103 {"STRING", 2, T_STR, CFUNC, conf_env, {0}},
104
105 {"include", 0+SUB, T_EX, 0, NOVAR},
106 {"FILE", 1, T_STR, CFUNC, conf_include, {0}},
107
108 {"singleusershell", 0+SUB, T_EX, 0, NOVAR},
109 {"COMMAND", 1, T_STR, 0, &Single_ent.ty_getty, {0}},
110 {"singleuserterminal", 0+SUB, T_EX, 0, NOVAR},
111 {"TYPE", 1, T_STR, 0, &Single_ent.ty_type, {0}},
112 {"singleuserdevice", 0+SUB, T_EX, 0, NOVAR},
113 {"DEVICE", 1, T_STR, 0, &Single_ent.ty_name, {0}},
114
115 {"autobootcommand", 0+SUB, T_EX, 0, NOVAR},
116 {"COMMAND", 1, T_STR, 0, &RCent_auto.ty_getty, {0}},
117 {"fastbootcommand", 0+SUB, T_EX, 0, NOVAR},
118 {"COMMAND", 1, T_STR, 0, &RCent_fast.ty_getty, {0}},
119
120 {"timeout", 0+SUB, T_EX, 0, NOVAR},
121 {"shutdown", 1+SUB, T_EX, 0, NOVAR},
122 {"sigterm", 2+SUB, T_EX, 0, NOVAR},
123 {"TIMEOUT", 3, T_INT, MAXVAL, &timeout_m2s_TERM, {300}},
124 {"sigkill", 2+SUB, T_EX, 0, NOVAR},
125 {"TIMEOUT", 3, T_INT, MAXVAL, &timeout_m2s_KILL, {300}},
126 {"error-retry", 1+SUB, T_EX, 0, NOVAR},
127 {"TIME", 2, T_TIME, 0, &retrytime, {0}},
128
129 {"respawn", 0+SUB, T_EX, 0, NOVAR},
130 {"checkstatus", 1+SUB, T_EX, 0, NOVAR},
131 {"yes", 2, T_EX, 0, &checkstatus, {1}},
132 {"on", 2, T_EX, 0, &checkstatus, {1}},
133 {"no", 2, T_EX, 0, &checkstatus, {0}},
134 {"off", 2, T_EX, 0, &checkstatus, {0}},
135 {"checktime", 1+SUB, T_EX, 0, NOVAR},
136 {"yes", 2, T_EX, 0, &checktime, {DEF_CHECKTIME}},
137 {"on", 2, T_EX, 0, &checktime, {DEF_CHECKTIME}},
138 {"no", 2, T_EX, 0, &checktime, {0}},
139 {"off", 2, T_EX, 0, &checktime, {0}},
140 {"TIMEOUT", 2, T_TIME, MAXVAL, &checktime, {300}},
141 {"waittimes", 1+SUB, T_EX, 0, NOVAR},
142 {"delete_list", 2, T_EX, CFUNC, conf_waittimes, {1}},
143 {"add_list", 2+SUB, T_EX, 0, NOVAR},
144 {"TIME", 3, T_TIME, CFUNC, conf_waittimes, {2}},
145
146 {"limit", 0+SUB, T_EX, 0, NOVAR},
147 {"cputime", 1+SUB, T_EX, 0, NOVAR},
148 {"unlimited", 2, T_EX, 0, CURLIM(CPU), {RLIM_INFINITY}},
149 {"default", 2, T_EX, 0, NOVAR},
150 {"LIMIT", 2, T_TIME, 0, CURLIM(CPU), {0}},
151 {"filesize", 1+SUB, T_EX, 0, NOVAR},
152 {"unlimited", 2, T_EX, 0, CURLIM(FSIZE), {RLIM_INFINITY}},
153 {"default", 2, T_EX, 0, NOVAR},
154 {"LIMIT", 2, T_BYTE, 0, CURLIM(FSIZE), {0}},
155 {"datasize", 1+SUB, T_EX, 0, NOVAR},
156 {"unlimited", 2, T_EX, 0, CURLIM(DATA), {RLIM_INFINITY}},
157 {"default", 2, T_EX, 0, NOVAR},
158 {"LIMIT", 2, T_BYTE, 0, CURLIM(DATA), {0}},
159 {"stacksize", 1+SUB, T_EX, 0, NOVAR},
160 {"unlimited", 2, T_EX, 0, CURLIM(STACK), {RLIM_INFINITY}},
161 {"default", 2, T_EX, 0, NOVAR},
162 {"LIMIT", 2, T_BYTE, 0, CURLIM(STACK), {0}},
163 {"coredumpsize", 1+SUB, T_EX, 0, NOVAR},
164 {"unlimited", 2, T_EX, 0, CURLIM(CORE), {RLIM_INFINITY}},
165 {"default", 2, T_EX, 0, NOVAR},
166 {"LIMIT", 2, T_BYTE, 0, CURLIM(CORE), {0}},
167 {"memoryuse", 1+SUB, T_EX, 0, NOVAR},
168 {"unlimited", 2, T_EX, 0, CURLIM(RSS), {RLIM_INFINITY}},
169 {"default", 2, T_EX, 0, NOVAR},
170 {"LIMIT", 2, T_BYTE, 0, CURLIM(RSS), {0}},
171 {"memorylocked", 1+SUB, T_EX, 0, NOVAR},
172 {"unlimited", 2, T_EX, 0, CURLIM(MEMLOCK), {RLIM_INFINITY}},
173 {"default", 2, T_EX, 0, NOVAR},
174 {"LIMIT", 2, T_BYTE, 0, CURLIM(MEMLOCK), {0}},
175 {"maxprocesses", 1+SUB, T_EX, 0, NOVAR},
176 {"unlimited", 2, T_EX, 0, CURLIM(NPROC), {RLIM_INFINITY}},
177 {"default", 2, T_EX, 0, NOVAR},
178 {"LIMIT", 2, T_INT, 0, CURLIM(NPROC), {0}},
179 {"openfiles", 1+SUB, T_EX, 0, NOVAR},
180 {"unlimited", 2, T_EX, 0, CURLIM(OFILE), {RLIM_INFINITY}},
181 {"default", 2, T_EX, 0, NOVAR},
182 {"LIMIT", 2, T_INT, 0, CURLIM(OFILE), {0}},
183
184 {"hardlimit", 0+SUB, T_EX, 0, NOVAR},
185 {"cputime", 1+SUB, T_EX, 0, NOVAR},
186 {"unlimited", 2, T_EX, 0, MAXLIM(CPU), {RLIM_INFINITY}},
187 {"default", 2, T_EX, 0, NOVAR},
188 {"LIMIT", 2, T_TIME, NRAISE, MAXLIM(CPU), {0}},
189 {"filesize", 1+SUB, T_EX, 0, NOVAR},
190 {"unlimited", 2, T_EX, 0, MAXLIM(FSIZE), {RLIM_INFINITY}},
191 {"default", 2, T_EX, 0, NOVAR},
192 {"LIMIT", 2, T_BYTE, NRAISE, MAXLIM(FSIZE), {0}},
193 {"datasize", 1+SUB, T_EX, 0, NOVAR},
194 {"unlimited", 2, T_EX, 0, MAXLIM(DATA), {RLIM_INFINITY}},
195 {"default", 2, T_EX, 0, NOVAR},
196 {"LIMIT", 2, T_BYTE, NRAISE, MAXLIM(DATA), {0}},
197 {"stacksize", 1+SUB, T_EX, 0, NOVAR},
198 {"unlimited", 2, T_EX, 0, MAXLIM(STACK), {RLIM_INFINITY}},
199 {"default", 2, T_EX, 0, NOVAR},
200 {"LIMIT", 2, T_BYTE, NRAISE, MAXLIM(STACK), {0}},
201 {"coredumpsize", 1+SUB, T_EX, 0, NOVAR},
202 {"unlimited", 2, T_EX, 0, MAXLIM(CORE), {RLIM_INFINITY}},
203 {"default", 2, T_EX, 0, NOVAR},
204 {"LIMIT", 2, T_BYTE, NRAISE, MAXLIM(CORE), {0}},
205 {"memoryuse", 1+SUB, T_EX, 0, NOVAR},
206 {"unlimited", 2, T_EX, 0, MAXLIM(RSS), {RLIM_INFINITY}},
207 {"default", 2, T_EX, 0, NOVAR},
208 {"LIMIT", 2, T_BYTE, NRAISE, MAXLIM(RSS), {0}},
209 {"memorylocked", 1+SUB, T_EX, 0, NOVAR},
210 {"unlimited", 2, T_EX, 0, MAXLIM(MEMLOCK), {RLIM_INFINITY}},
211 {"default", 2, T_EX, 0, NOVAR},
212 {"LIMIT", 2, T_BYTE, NRAISE, MAXLIM(MEMLOCK), {0}},
213 {"maxprocesses", 1+SUB, T_EX, 0, NOVAR},
214 {"unlimited", 2, T_EX, 0, MAXLIM(NPROC), {RLIM_INFINITY}},
215 {"default", 2, T_EX, 0, NOVAR},
216 {"LIMIT", 2, T_INT, NRAISE, MAXLIM(NPROC), {0}},
217 {"openfiles", 1+SUB, T_EX, 0, NOVAR},
218 {"unlimited", 2, T_EX, 0, MAXLIM(OFILE), {RLIM_INFINITY}},
219 {"default", 2, T_EX, 0, NOVAR},
220 {"LIMIT", 2, T_INT, NRAISE, MAXLIM(OFILE), {0}},
221};
222const int NCommands = (sizeof(Commands) / sizeof(struct Command));
223
224
225/*
226 * INIT-specific functions for configuration
227 */
228
229
230/*
231 * SETCONF
232 * called in each new process to set up configured things
233 */
234void
235setconf(void)
236{
237int f;
238
239 Debug (4, "Setting configuration");
240 for (f=0; f< RLIM_NLIMITS; f++)
241 (void) setrlimit(f, &proclimits[f]);
242 Debug(4, "Setting configuration completed");
243}
244
245
246
247/*
248 * GETCONF
249 * prepare for configuration
250 * called once before configure().
251 */
252void
253getconf(void)
254{
255int f;
256
257 for (f=0; f< RLIM_NLIMITS; f++)
258 (void) getrlimit(f, &proclimits[f]);
259}
260
261
262
263/*
264 * CHECKCONF
265 * check configured things etc.
266 * called once after configure().
267 */
268void
269checkconf(void)
270{
271int f;
272
273 /* Do not allow soft limits to be higher than the hard limits */
274 for (f=0; f<RLIM_NLIMITS; f++)
275 if (proclimits[f].rlim_cur > proclimits[f].rlim_max)
276 proclimits[f].rlim_cur = proclimits[f].rlim_max;
277}
278
279
280/*
281 * Support functions, referenced in Commands table
282 */
283
284/* Set an environment variable from the configuration file */
285static int
286conf_env(configfile, lineno, argc, argv, what)
287char *configfile;
288int lineno;
289int argc;
290char **argv;
291int what;
292{
293 iputenv(argv[1], argv[2]);
294 return(0);
295}
296
297/* Include another configuration file */
298static int
299conf_include(configfile, lineno, argc, argv, what)
300char *configfile;
301int lineno;
302int argc;
303char **argv;
304int what;
305{
306 configure(argv[1]);
307 return(0);
308}
309
310
311/* Configure the times to wait before restarting a getty that has failed */
312static int
313conf_waittimes(configfile, lineno, argc, argv, what)
314char *configfile;
315int lineno;
316int argc;
317char **argv;
318int what;
319{
320 Debug(0, "conf_waittimes not yet implemented.");
321 return(0);
322}
323
324#endif