init: fix compile-time error; fix exiting on broken config file
parse_config: cosmetics
This commit is contained in:
parent
02a1c6a7c3
commit
a474b68991
36
init/init.c
36
init/init.c
@ -777,12 +777,10 @@ static void parse_inittab(void)
|
|||||||
fclose(file);
|
fclose(file);
|
||||||
#else
|
#else
|
||||||
char *token[4];
|
char *token[4];
|
||||||
static const char actions[] ALIGN1 = {
|
/* order must correspond to SYSINIT..RESTART constants */
|
||||||
|
static const char actions[] ALIGN1 =
|
||||||
"sysinit\0""respawn\0""askfirst\0""wait\0""once\0"
|
"sysinit\0""respawn\0""askfirst\0""wait\0""once\0"
|
||||||
"ctrlaltdel\0""shutdown\0""restart\0"
|
"ctrlaltdel\0""shutdown\0""restart\0";
|
||||||
};
|
|
||||||
enum {STR_SYSINIT=0, STR_RESPAWN, STR_ASKFIRST, STR_WAIT, STR_ONCE,
|
|
||||||
STR_CTRLALTDEL, STR_SHUTDOWN, STR_RESTART};
|
|
||||||
|
|
||||||
parser_t *parser = config_open(INITTAB);
|
parser_t *parser = config_open(INITTAB);
|
||||||
/* No inittab file -- set up some default behavior */
|
/* No inittab file -- set up some default behavior */
|
||||||
@ -798,6 +796,7 @@ static void parse_inittab(void)
|
|||||||
new_init_action(RESTART, "init", "");
|
new_init_action(RESTART, "init", "");
|
||||||
/* Askfirst shell on tty1-4 */
|
/* Askfirst shell on tty1-4 */
|
||||||
new_init_action(ASKFIRST, bb_default_login_shell, "");
|
new_init_action(ASKFIRST, bb_default_login_shell, "");
|
||||||
|
//TODO: VC_1 instead of ""? "" is console -> ctty problems -> angry users
|
||||||
new_init_action(ASKFIRST, bb_default_login_shell, VC_2);
|
new_init_action(ASKFIRST, bb_default_login_shell, VC_2);
|
||||||
new_init_action(ASKFIRST, bb_default_login_shell, VC_3);
|
new_init_action(ASKFIRST, bb_default_login_shell, VC_3);
|
||||||
new_init_action(ASKFIRST, bb_default_login_shell, VC_4);
|
new_init_action(ASKFIRST, bb_default_login_shell, VC_4);
|
||||||
@ -807,28 +806,25 @@ static void parse_inittab(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* optional_tty:ignored_runlevel:action:command
|
/* optional_tty:ignored_runlevel:action:command
|
||||||
* i.e. 4 tokens, minimum number of tokens is 2 ("::sysinit:echo foo")
|
* Delims are not to be collapsed and need exactly 4 tokens
|
||||||
* We require tokens not to be collapsed -- need exactly 4 tokens.
|
|
||||||
*/
|
*/
|
||||||
while (config_read(parser, token, -4, 2, ":", '#') >= 0) {
|
while (config_read(parser, token, -4, 0, ":", '#') >= 0) {
|
||||||
int action = -1;
|
int action;
|
||||||
char *tty = token[0];
|
char *tty = token[0];
|
||||||
char *action_string = token[2];
|
|
||||||
char *command = token[3];
|
|
||||||
|
|
||||||
if (action_string)
|
if (!token[3]) /* less than 4 tokens */
|
||||||
action = index_in_strings(actions, action_string);
|
goto bad_entry;
|
||||||
if (action < 0 || !command || !strlen(command))
|
action = index_in_strings(actions, token[2]);
|
||||||
|
if (action < 0 || !token[3][0]) /* token[3]: command */
|
||||||
goto bad_entry;
|
goto bad_entry;
|
||||||
if (tty) {
|
|
||||||
/* turn .*TTY -> /dev/TTY */
|
/* turn .*TTY -> /dev/TTY */
|
||||||
if (!strncmp(tty, "/dev/", 5))
|
if (tty[0]) {
|
||||||
|
if (strncmp(tty, "/dev/", 5) == 0)
|
||||||
tty += 5;
|
tty += 5;
|
||||||
tty = concat_path_file("/dev/", tty);
|
tty = concat_path_file("/dev/", tty);
|
||||||
} else
|
}
|
||||||
tty = ""; /* XXX: ugh. */
|
new_init_action(1 << action, token[3], tty);
|
||||||
new_init_action (1<<action, command, tty);
|
if (tty[0])
|
||||||
if (ENABLE_FEATURE_CLEAN_UP)
|
|
||||||
free(tty);
|
free(tty);
|
||||||
continue;
|
continue;
|
||||||
bad_entry:
|
bad_entry:
|
||||||
|
@ -60,12 +60,12 @@ int FAST_FUNC config_read(parser_t *parser, char **tokens, int ntokens, int mint
|
|||||||
{
|
{
|
||||||
char *line, *q;
|
char *line, *q;
|
||||||
int ii, seen;
|
int ii, seen;
|
||||||
/* do not treat subsequent delimiters as one delimiter */
|
/* do not treat consecutive delimiters as one delimiter */
|
||||||
bool noreduce = (ntokens < 0);
|
bool noreduce = (ntokens < 0);
|
||||||
if (noreduce)
|
if (noreduce)
|
||||||
ntokens = -ntokens;
|
ntokens = -ntokens;
|
||||||
|
|
||||||
memset(tokens, 0, sizeof(void *) * ntokens);
|
memset(tokens, 0, sizeof(tokens[0]) * ntokens);
|
||||||
config_free_data(parser);
|
config_free_data(parser);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user