Fix up command line munging in init. Postpone the askfirst thing till
a bit later in run().
This commit is contained in:
parent
4ef37d0c17
commit
7ef1a5beb2
140
init.c
140
init.c
@ -188,6 +188,7 @@ static char console[32] = _PATH_CONSOLE;
|
|||||||
static void delete_initAction(initAction * action);
|
static void delete_initAction(initAction * action);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Print a message to the specified device.
|
/* Print a message to the specified device.
|
||||||
* Device may be bitwise-or'd from LOG | CONSOLE */
|
* Device may be bitwise-or'd from LOG | CONSOLE */
|
||||||
static void message(int device, char *fmt, ...)
|
static void message(int device, char *fmt, ...)
|
||||||
@ -393,6 +394,23 @@ static void console_init()
|
|||||||
}
|
}
|
||||||
message(LOG, "console=%s\n", console);
|
message(LOG, "console=%s\n", console);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void fixup_argv(int argc, char **argv, char *new_argv0)
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
/* Fix up argv[0] to be certain we claim to be init */
|
||||||
|
len = strlen(argv[0]);
|
||||||
|
memset(argv[0], 0, len);
|
||||||
|
strncpy(argv[0], new_argv0, len);
|
||||||
|
|
||||||
|
/* Wipe argv[1]-argv[N] so they don't clutter the ps listing */
|
||||||
|
len = 1;
|
||||||
|
while (argc > len) {
|
||||||
|
memset(argv[len], 0, strlen(argv[len]));
|
||||||
|
len++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static pid_t run(char *command, char *terminal, int get_enter)
|
static pid_t run(char *command, char *terminal, int get_enter)
|
||||||
{
|
{
|
||||||
@ -402,6 +420,7 @@ static pid_t run(char *command, char *terminal, int get_enter)
|
|||||||
char *tmpCmd, *s;
|
char *tmpCmd, *s;
|
||||||
char *cmd[255], *cmdpath;
|
char *cmd[255], *cmdpath;
|
||||||
char buf[255];
|
char buf[255];
|
||||||
|
struct stat sb;
|
||||||
static const char press_enter[] =
|
static const char press_enter[] =
|
||||||
|
|
||||||
#ifdef CUSTOMIZED_BANNER
|
#ifdef CUSTOMIZED_BANNER
|
||||||
@ -447,8 +466,7 @@ static pid_t run(char *command, char *terminal, int get_enter)
|
|||||||
signal(SIGHUP, SIG_DFL);
|
signal(SIGHUP, SIG_DFL);
|
||||||
|
|
||||||
if ((fd = device_open(terminal, O_RDWR)) < 0) {
|
if ((fd = device_open(terminal, O_RDWR)) < 0) {
|
||||||
struct stat statBuf;
|
if (stat(terminal, &sb) != 0) {
|
||||||
if (stat(terminal, &statBuf) != 0) {
|
|
||||||
message(LOG | CONSOLE, "device '%s' does not exist.\n",
|
message(LOG | CONSOLE, "device '%s' does not exist.\n",
|
||||||
terminal);
|
terminal);
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -463,29 +481,6 @@ static pid_t run(char *command, char *terminal, int get_enter)
|
|||||||
tcsetpgrp(0, getpgrp());
|
tcsetpgrp(0, getpgrp());
|
||||||
set_term(0);
|
set_term(0);
|
||||||
|
|
||||||
if (get_enter == TRUE) {
|
|
||||||
/*
|
|
||||||
* Save memory by not exec-ing anything large (like a shell)
|
|
||||||
* before the user wants it. This is critical if swap is not
|
|
||||||
* enabled and the system has low memory. Generally this will
|
|
||||||
* be run on the second virtual console, and the first will
|
|
||||||
* be allowed to start a shell or whatever an init script
|
|
||||||
* specifies.
|
|
||||||
*/
|
|
||||||
#ifdef DEBUG_INIT
|
|
||||||
message(LOG, "Waiting for enter to start '%s' (pid %d, console %s)\r\n",
|
|
||||||
command, getpid(), terminal);
|
|
||||||
#endif
|
|
||||||
write(fileno(stdout), press_enter, sizeof(press_enter) - 1);
|
|
||||||
getc(stdin);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef DEBUG_INIT
|
|
||||||
/* Log the process name and args */
|
|
||||||
message(LOG, "Starting pid %d, console %s: '%s'\r\n",
|
|
||||||
getpid(), terminal, command);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* See if any special /bin/sh requiring characters are present */
|
/* See if any special /bin/sh requiring characters are present */
|
||||||
if (strpbrk(command, "~`!$^&*()=|\\{}[];\"'<>?") != NULL) {
|
if (strpbrk(command, "~`!$^&*()=|\\{}[];\"'<>?") != NULL) {
|
||||||
cmd[0] = SHELL;
|
cmd[0] = SHELL;
|
||||||
@ -497,7 +492,7 @@ static pid_t run(char *command, char *terminal, int get_enter)
|
|||||||
} else {
|
} else {
|
||||||
/* Convert command (char*) into cmd (char**, one word per string) */
|
/* Convert command (char*) into cmd (char**, one word per string) */
|
||||||
for (tmpCmd = command, i = 0;
|
for (tmpCmd = command, i = 0;
|
||||||
(tmpCmd = strsep(&command, " \t")) != NULL;) {
|
(tmpCmd = strsep(&command, " \t")) != NULL;) {
|
||||||
if (*tmpCmd != '\0') {
|
if (*tmpCmd != '\0') {
|
||||||
cmd[i] = tmpCmd;
|
cmd[i] = tmpCmd;
|
||||||
tmpCmd++;
|
tmpCmd++;
|
||||||
@ -507,53 +502,73 @@ static pid_t run(char *command, char *terminal, int get_enter)
|
|||||||
cmd[i] = NULL;
|
cmd[i] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdpath = cmd[0];
|
cmdpath = cmd[0];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Interactive shells want to see a dash in argv[0]. This
|
Interactive shells want to see a dash in argv[0]. This
|
||||||
typically is handled by login, argv will be setup this
|
typically is handled by login, argv will be setup this
|
||||||
way if a dash appears at the front of the command path
|
way if a dash appears at the front of the command path
|
||||||
(like "-/bin/sh").
|
(like "-/bin/sh").
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (*cmdpath == '-') {
|
if (*cmdpath == '-') {
|
||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
/* skip over the dash */
|
/* skip over the dash */
|
||||||
++cmdpath;
|
++cmdpath;
|
||||||
|
|
||||||
/* find the last component in the command pathname */
|
/* find the last component in the command pathname */
|
||||||
s = get_last_path_component(cmdpath);
|
s = get_last_path_component(cmdpath);
|
||||||
|
|
||||||
/* make a new argv[0] */
|
/* make a new argv[0] */
|
||||||
if ((cmd[0] = malloc(strlen(s)+2)) == NULL) {
|
if ((cmd[0] = malloc(strlen(s)+2)) == NULL) {
|
||||||
message(LOG | CONSOLE, "malloc failed");
|
message(LOG | CONSOLE, "malloc failed");
|
||||||
cmd[0] = cmdpath;
|
cmd[0] = cmdpath;
|
||||||
} else {
|
} else {
|
||||||
cmd[0][0] = '-';
|
cmd[0][0] = '-';
|
||||||
strcpy(cmd[0]+1, s);
|
strcpy(cmd[0]+1, s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (get_enter == TRUE) {
|
||||||
|
/*
|
||||||
|
* Save memory by not exec-ing anything large (like a shell)
|
||||||
|
* before the user wants it. This is critical if swap is not
|
||||||
|
* enabled and the system has low memory. Generally this will
|
||||||
|
* be run on the second virtual console, and the first will
|
||||||
|
* be allowed to start a shell or whatever an init script
|
||||||
|
* specifies.
|
||||||
|
*/
|
||||||
|
#ifdef DEBUG_INIT
|
||||||
|
message(LOG, "Waiting for enter to start '%s' (pid %d, console %s)\r\n",
|
||||||
|
cmd[0], getpid(), terminal);
|
||||||
|
#endif
|
||||||
|
write(fileno(stdout), press_enter, sizeof(press_enter) - 1);
|
||||||
|
getc(stdin);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG_INIT
|
||||||
|
/* Log the process name and args */
|
||||||
|
message(LOG, "Starting pid %d, console %s: '%s'\r\n",
|
||||||
|
getpid(), terminal, command);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined BB_FEATURE_INIT_COREDUMPS
|
#if defined BB_FEATURE_INIT_COREDUMPS
|
||||||
{
|
if (stat (CORE_ENABLE_FLAG_FILE, &sb) == 0) {
|
||||||
struct stat sb;
|
struct rlimit limit;
|
||||||
if (stat (CORE_ENABLE_FLAG_FILE, &sb) == 0) {
|
limit.rlim_cur = RLIM_INFINITY;
|
||||||
struct rlimit limit;
|
limit.rlim_max = RLIM_INFINITY;
|
||||||
limit.rlim_cur = RLIM_INFINITY;
|
setrlimit(RLIMIT_CORE, &limit);
|
||||||
limit.rlim_max = RLIM_INFINITY;
|
|
||||||
setrlimit(RLIMIT_CORE, &limit);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Now run it. The new program will take over this PID,
|
/* Now run it. The new program will take over this PID,
|
||||||
* so nothing further in init.c should be run. */
|
* so nothing further in init.c should be run. */
|
||||||
execve(cmdpath, cmd, environment);
|
execve(cmdpath, cmd, environment);
|
||||||
|
|
||||||
/* We're still here? Some error happened. */
|
/* We're still here? Some error happened. */
|
||||||
message(LOG | CONSOLE, "Bummer, could not run '%s': %s\n", cmdpath,
|
message(LOG | CONSOLE, "Bummer, could not run '%s': %s\n", cmdpath,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
return pid;
|
return pid;
|
||||||
@ -937,11 +952,8 @@ extern int init_main(int argc, char **argv)
|
|||||||
parse_inittab();
|
parse_inittab();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fix up argv[0] to be certain we claim to be init */
|
/* Make the command line just say "init" -- thats all, nothing else */
|
||||||
argv[0]="init";
|
fixup_argv(argc, argv, "init");
|
||||||
|
|
||||||
if (argc > 1)
|
|
||||||
argv[1][0]=0;
|
|
||||||
|
|
||||||
/* Now run everything that needs to be run */
|
/* Now run everything that needs to be run */
|
||||||
|
|
||||||
|
140
init/init.c
140
init/init.c
@ -188,6 +188,7 @@ static char console[32] = _PATH_CONSOLE;
|
|||||||
static void delete_initAction(initAction * action);
|
static void delete_initAction(initAction * action);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Print a message to the specified device.
|
/* Print a message to the specified device.
|
||||||
* Device may be bitwise-or'd from LOG | CONSOLE */
|
* Device may be bitwise-or'd from LOG | CONSOLE */
|
||||||
static void message(int device, char *fmt, ...)
|
static void message(int device, char *fmt, ...)
|
||||||
@ -393,6 +394,23 @@ static void console_init()
|
|||||||
}
|
}
|
||||||
message(LOG, "console=%s\n", console);
|
message(LOG, "console=%s\n", console);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void fixup_argv(int argc, char **argv, char *new_argv0)
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
/* Fix up argv[0] to be certain we claim to be init */
|
||||||
|
len = strlen(argv[0]);
|
||||||
|
memset(argv[0], 0, len);
|
||||||
|
strncpy(argv[0], new_argv0, len);
|
||||||
|
|
||||||
|
/* Wipe argv[1]-argv[N] so they don't clutter the ps listing */
|
||||||
|
len = 1;
|
||||||
|
while (argc > len) {
|
||||||
|
memset(argv[len], 0, strlen(argv[len]));
|
||||||
|
len++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static pid_t run(char *command, char *terminal, int get_enter)
|
static pid_t run(char *command, char *terminal, int get_enter)
|
||||||
{
|
{
|
||||||
@ -402,6 +420,7 @@ static pid_t run(char *command, char *terminal, int get_enter)
|
|||||||
char *tmpCmd, *s;
|
char *tmpCmd, *s;
|
||||||
char *cmd[255], *cmdpath;
|
char *cmd[255], *cmdpath;
|
||||||
char buf[255];
|
char buf[255];
|
||||||
|
struct stat sb;
|
||||||
static const char press_enter[] =
|
static const char press_enter[] =
|
||||||
|
|
||||||
#ifdef CUSTOMIZED_BANNER
|
#ifdef CUSTOMIZED_BANNER
|
||||||
@ -447,8 +466,7 @@ static pid_t run(char *command, char *terminal, int get_enter)
|
|||||||
signal(SIGHUP, SIG_DFL);
|
signal(SIGHUP, SIG_DFL);
|
||||||
|
|
||||||
if ((fd = device_open(terminal, O_RDWR)) < 0) {
|
if ((fd = device_open(terminal, O_RDWR)) < 0) {
|
||||||
struct stat statBuf;
|
if (stat(terminal, &sb) != 0) {
|
||||||
if (stat(terminal, &statBuf) != 0) {
|
|
||||||
message(LOG | CONSOLE, "device '%s' does not exist.\n",
|
message(LOG | CONSOLE, "device '%s' does not exist.\n",
|
||||||
terminal);
|
terminal);
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -463,29 +481,6 @@ static pid_t run(char *command, char *terminal, int get_enter)
|
|||||||
tcsetpgrp(0, getpgrp());
|
tcsetpgrp(0, getpgrp());
|
||||||
set_term(0);
|
set_term(0);
|
||||||
|
|
||||||
if (get_enter == TRUE) {
|
|
||||||
/*
|
|
||||||
* Save memory by not exec-ing anything large (like a shell)
|
|
||||||
* before the user wants it. This is critical if swap is not
|
|
||||||
* enabled and the system has low memory. Generally this will
|
|
||||||
* be run on the second virtual console, and the first will
|
|
||||||
* be allowed to start a shell or whatever an init script
|
|
||||||
* specifies.
|
|
||||||
*/
|
|
||||||
#ifdef DEBUG_INIT
|
|
||||||
message(LOG, "Waiting for enter to start '%s' (pid %d, console %s)\r\n",
|
|
||||||
command, getpid(), terminal);
|
|
||||||
#endif
|
|
||||||
write(fileno(stdout), press_enter, sizeof(press_enter) - 1);
|
|
||||||
getc(stdin);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef DEBUG_INIT
|
|
||||||
/* Log the process name and args */
|
|
||||||
message(LOG, "Starting pid %d, console %s: '%s'\r\n",
|
|
||||||
getpid(), terminal, command);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* See if any special /bin/sh requiring characters are present */
|
/* See if any special /bin/sh requiring characters are present */
|
||||||
if (strpbrk(command, "~`!$^&*()=|\\{}[];\"'<>?") != NULL) {
|
if (strpbrk(command, "~`!$^&*()=|\\{}[];\"'<>?") != NULL) {
|
||||||
cmd[0] = SHELL;
|
cmd[0] = SHELL;
|
||||||
@ -497,7 +492,7 @@ static pid_t run(char *command, char *terminal, int get_enter)
|
|||||||
} else {
|
} else {
|
||||||
/* Convert command (char*) into cmd (char**, one word per string) */
|
/* Convert command (char*) into cmd (char**, one word per string) */
|
||||||
for (tmpCmd = command, i = 0;
|
for (tmpCmd = command, i = 0;
|
||||||
(tmpCmd = strsep(&command, " \t")) != NULL;) {
|
(tmpCmd = strsep(&command, " \t")) != NULL;) {
|
||||||
if (*tmpCmd != '\0') {
|
if (*tmpCmd != '\0') {
|
||||||
cmd[i] = tmpCmd;
|
cmd[i] = tmpCmd;
|
||||||
tmpCmd++;
|
tmpCmd++;
|
||||||
@ -507,53 +502,73 @@ static pid_t run(char *command, char *terminal, int get_enter)
|
|||||||
cmd[i] = NULL;
|
cmd[i] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdpath = cmd[0];
|
cmdpath = cmd[0];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Interactive shells want to see a dash in argv[0]. This
|
Interactive shells want to see a dash in argv[0]. This
|
||||||
typically is handled by login, argv will be setup this
|
typically is handled by login, argv will be setup this
|
||||||
way if a dash appears at the front of the command path
|
way if a dash appears at the front of the command path
|
||||||
(like "-/bin/sh").
|
(like "-/bin/sh").
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (*cmdpath == '-') {
|
if (*cmdpath == '-') {
|
||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
/* skip over the dash */
|
/* skip over the dash */
|
||||||
++cmdpath;
|
++cmdpath;
|
||||||
|
|
||||||
/* find the last component in the command pathname */
|
/* find the last component in the command pathname */
|
||||||
s = get_last_path_component(cmdpath);
|
s = get_last_path_component(cmdpath);
|
||||||
|
|
||||||
/* make a new argv[0] */
|
/* make a new argv[0] */
|
||||||
if ((cmd[0] = malloc(strlen(s)+2)) == NULL) {
|
if ((cmd[0] = malloc(strlen(s)+2)) == NULL) {
|
||||||
message(LOG | CONSOLE, "malloc failed");
|
message(LOG | CONSOLE, "malloc failed");
|
||||||
cmd[0] = cmdpath;
|
cmd[0] = cmdpath;
|
||||||
} else {
|
} else {
|
||||||
cmd[0][0] = '-';
|
cmd[0][0] = '-';
|
||||||
strcpy(cmd[0]+1, s);
|
strcpy(cmd[0]+1, s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (get_enter == TRUE) {
|
||||||
|
/*
|
||||||
|
* Save memory by not exec-ing anything large (like a shell)
|
||||||
|
* before the user wants it. This is critical if swap is not
|
||||||
|
* enabled and the system has low memory. Generally this will
|
||||||
|
* be run on the second virtual console, and the first will
|
||||||
|
* be allowed to start a shell or whatever an init script
|
||||||
|
* specifies.
|
||||||
|
*/
|
||||||
|
#ifdef DEBUG_INIT
|
||||||
|
message(LOG, "Waiting for enter to start '%s' (pid %d, console %s)\r\n",
|
||||||
|
cmd[0], getpid(), terminal);
|
||||||
|
#endif
|
||||||
|
write(fileno(stdout), press_enter, sizeof(press_enter) - 1);
|
||||||
|
getc(stdin);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG_INIT
|
||||||
|
/* Log the process name and args */
|
||||||
|
message(LOG, "Starting pid %d, console %s: '%s'\r\n",
|
||||||
|
getpid(), terminal, command);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined BB_FEATURE_INIT_COREDUMPS
|
#if defined BB_FEATURE_INIT_COREDUMPS
|
||||||
{
|
if (stat (CORE_ENABLE_FLAG_FILE, &sb) == 0) {
|
||||||
struct stat sb;
|
struct rlimit limit;
|
||||||
if (stat (CORE_ENABLE_FLAG_FILE, &sb) == 0) {
|
limit.rlim_cur = RLIM_INFINITY;
|
||||||
struct rlimit limit;
|
limit.rlim_max = RLIM_INFINITY;
|
||||||
limit.rlim_cur = RLIM_INFINITY;
|
setrlimit(RLIMIT_CORE, &limit);
|
||||||
limit.rlim_max = RLIM_INFINITY;
|
|
||||||
setrlimit(RLIMIT_CORE, &limit);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Now run it. The new program will take over this PID,
|
/* Now run it. The new program will take over this PID,
|
||||||
* so nothing further in init.c should be run. */
|
* so nothing further in init.c should be run. */
|
||||||
execve(cmdpath, cmd, environment);
|
execve(cmdpath, cmd, environment);
|
||||||
|
|
||||||
/* We're still here? Some error happened. */
|
/* We're still here? Some error happened. */
|
||||||
message(LOG | CONSOLE, "Bummer, could not run '%s': %s\n", cmdpath,
|
message(LOG | CONSOLE, "Bummer, could not run '%s': %s\n", cmdpath,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
return pid;
|
return pid;
|
||||||
@ -937,11 +952,8 @@ extern int init_main(int argc, char **argv)
|
|||||||
parse_inittab();
|
parse_inittab();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fix up argv[0] to be certain we claim to be init */
|
/* Make the command line just say "init" -- thats all, nothing else */
|
||||||
argv[0]="init";
|
fixup_argv(argc, argv, "init");
|
||||||
|
|
||||||
if (argc > 1)
|
|
||||||
argv[1][0]=0;
|
|
||||||
|
|
||||||
/* Now run everything that needs to be run */
|
/* Now run everything that needs to be run */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user