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
78
init.c
78
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, ...)
|
||||||
@ -394,6 +395,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)
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
@ -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;
|
||||||
@ -535,16 +530,36 @@ static pid_t run(char *command, char *terminal, int get_enter)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
{
|
|
||||||
struct stat sb;
|
|
||||||
if (stat (CORE_ENABLE_FLAG_FILE, &sb) == 0) {
|
if (stat (CORE_ENABLE_FLAG_FILE, &sb) == 0) {
|
||||||
struct rlimit limit;
|
struct rlimit limit;
|
||||||
limit.rlim_cur = RLIM_INFINITY;
|
limit.rlim_cur = RLIM_INFINITY;
|
||||||
limit.rlim_max = RLIM_INFINITY;
|
limit.rlim_max = RLIM_INFINITY;
|
||||||
setrlimit(RLIMIT_CORE, &limit);
|
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,
|
||||||
@ -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 */
|
||||||
|
|
||||||
|
78
init/init.c
78
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, ...)
|
||||||
@ -394,6 +395,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)
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
@ -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;
|
||||||
@ -535,16 +530,36 @@ static pid_t run(char *command, char *terminal, int get_enter)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
{
|
|
||||||
struct stat sb;
|
|
||||||
if (stat (CORE_ENABLE_FLAG_FILE, &sb) == 0) {
|
if (stat (CORE_ENABLE_FLAG_FILE, &sb) == 0) {
|
||||||
struct rlimit limit;
|
struct rlimit limit;
|
||||||
limit.rlim_cur = RLIM_INFINITY;
|
limit.rlim_cur = RLIM_INFINITY;
|
||||||
limit.rlim_max = RLIM_INFINITY;
|
limit.rlim_max = RLIM_INFINITY;
|
||||||
setrlimit(RLIMIT_CORE, &limit);
|
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,
|
||||||
@ -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