Fix up command line munging in init. Postpone the askfirst thing till

a bit later in run().
This commit is contained in:
Eric Andersen 2001-03-20 17:39:08 +00:00
parent 4ef37d0c17
commit 7ef1a5beb2
2 changed files with 152 additions and 128 deletions

78
init.c
View File

@ -188,6 +188,7 @@ static char console[32] = _PATH_CONSOLE;
static void delete_initAction(initAction * action);
/* Print a message to the specified device.
* Device may be bitwise-or'd from LOG | CONSOLE */
static void message(int device, char *fmt, ...)
@ -394,6 +395,23 @@ static void console_init()
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)
{
int i, j;
@ -402,6 +420,7 @@ static pid_t run(char *command, char *terminal, int get_enter)
char *tmpCmd, *s;
char *cmd[255], *cmdpath;
char buf[255];
struct stat sb;
static const char press_enter[] =
#ifdef CUSTOMIZED_BANNER
@ -447,8 +466,7 @@ static pid_t run(char *command, char *terminal, int get_enter)
signal(SIGHUP, SIG_DFL);
if ((fd = device_open(terminal, O_RDWR)) < 0) {
struct stat statBuf;
if (stat(terminal, &statBuf) != 0) {
if (stat(terminal, &sb) != 0) {
message(LOG | CONSOLE, "device '%s' does not exist.\n",
terminal);
exit(1);
@ -463,29 +481,6 @@ static pid_t run(char *command, char *terminal, int get_enter)
tcsetpgrp(0, getpgrp());
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 */
if (strpbrk(command, "~`!$^&*()=|\\{}[];\"'<>?") != NULL) {
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
{
struct stat sb;
if (stat (CORE_ENABLE_FLAG_FILE, &sb) == 0) {
struct rlimit limit;
limit.rlim_cur = RLIM_INFINITY;
limit.rlim_max = RLIM_INFINITY;
setrlimit(RLIMIT_CORE, &limit);
}
}
#endif
/* 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();
}
/* Fix up argv[0] to be certain we claim to be init */
argv[0]="init";
if (argc > 1)
argv[1][0]=0;
/* Make the command line just say "init" -- thats all, nothing else */
fixup_argv(argc, argv, "init");
/* Now run everything that needs to be run */

View File

@ -188,6 +188,7 @@ static char console[32] = _PATH_CONSOLE;
static void delete_initAction(initAction * action);
/* Print a message to the specified device.
* Device may be bitwise-or'd from LOG | CONSOLE */
static void message(int device, char *fmt, ...)
@ -394,6 +395,23 @@ static void console_init()
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)
{
int i, j;
@ -402,6 +420,7 @@ static pid_t run(char *command, char *terminal, int get_enter)
char *tmpCmd, *s;
char *cmd[255], *cmdpath;
char buf[255];
struct stat sb;
static const char press_enter[] =
#ifdef CUSTOMIZED_BANNER
@ -447,8 +466,7 @@ static pid_t run(char *command, char *terminal, int get_enter)
signal(SIGHUP, SIG_DFL);
if ((fd = device_open(terminal, O_RDWR)) < 0) {
struct stat statBuf;
if (stat(terminal, &statBuf) != 0) {
if (stat(terminal, &sb) != 0) {
message(LOG | CONSOLE, "device '%s' does not exist.\n",
terminal);
exit(1);
@ -463,29 +481,6 @@ static pid_t run(char *command, char *terminal, int get_enter)
tcsetpgrp(0, getpgrp());
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 */
if (strpbrk(command, "~`!$^&*()=|\\{}[];\"'<>?") != NULL) {
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
{
struct stat sb;
if (stat (CORE_ENABLE_FLAG_FILE, &sb) == 0) {
struct rlimit limit;
limit.rlim_cur = RLIM_INFINITY;
limit.rlim_max = RLIM_INFINITY;
setrlimit(RLIMIT_CORE, &limit);
}
}
#endif
/* 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();
}
/* Fix up argv[0] to be certain we claim to be init */
argv[0]="init";
if (argc > 1)
argv[1][0]=0;
/* Make the command line just say "init" -- thats all, nothing else */
fixup_argv(argc, argv, "init");
/* Now run everything that needs to be run */