aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2000-09-14 22:01:31 +0000
committerEric Andersen <andersen@codepoet.org>2000-09-14 22:01:31 +0000
commit7e3bf6e339a2d1e28fc8ee53ca57919f32eba6d6 (patch)
tree85ee868c652b45c0859554d73b702acff5df7879
parentce40fc044bc50897739581ec0f9fcda38791384d (diff)
downloadbusybox-w32-7e3bf6e339a2d1e28fc8ee53ca57919f32eba6d6.tar.gz
busybox-w32-7e3bf6e339a2d1e28fc8ee53ca57919f32eba6d6.tar.bz2
busybox-w32-7e3bf6e339a2d1e28fc8ee53ca57919f32eba6d6.zip
Add in a patch from robotti@metconnect.com and Chip Rosenthal to make
init do login shell stuff. -Erik
-rw-r--r--examples/inittab20
-rw-r--r--init.c66
-rw-r--r--init/init.c66
-rw-r--r--scripts/inittab20
4 files changed, 134 insertions, 38 deletions
diff --git a/examples/inittab b/examples/inittab
index bb547b740..2515264c7 100644
--- a/examples/inittab
+++ b/examples/inittab
@@ -44,7 +44,6 @@
44# tty2::askfirst:/bin/sh 44# tty2::askfirst:/bin/sh
45# 45#
46 46
47
48# Boot-time system configuration/initialization script. 47# Boot-time system configuration/initialization script.
49# This is run first except when booting in single-user mode. 48# This is run first except when booting in single-user mode.
50# 49#
@@ -52,16 +51,23 @@
52 51
53# /bin/sh invocations on selected ttys 52# /bin/sh invocations on selected ttys
54# 53#
55# Start an "askfirst" shell on the console (whatever that may be) 54# Note below that we prefix the shell commands with a "-" to indicate to the
56::askfirst:/bin/sh 55# shell that it is supposed to be a login shell. Normally this is handled by
57# Start an "askfirst" shell on /dev/tty2 56# login, but since we are bypassing login in this case, BusyBox lets you do
58tty2::askfirst:/bin/sh 57# this yourself...
58#
59# Start an "askfirst" shell on the console (whatever that may be).
60::askfirst:-/bin/sh
61#
62# Start an "askfirst" shell on /dev/tty2-4
63tty2::askfirst:-/bin/sh
64tty3::askfirst:-/bin/sh
65tty4::askfirst:-/bin/sh
59 66
60# /sbin/getty invocations for selected ttys 67# /sbin/getty invocations for selected ttys
61# 68#
62tty4::respawn:/sbin/getty 38400 tty4
63tty5::respawn:/sbin/getty 38400 tty5 69tty5::respawn:/sbin/getty 38400 tty5
64 70tty6::respawn:/sbin/getty 38400 tty6
65 71
66# Example of how to put a getty on a serial line (for a terminal) 72# Example of how to put a getty on a serial line (for a terminal)
67# 73#
diff --git a/init.c b/init.c
index b3ae97d2e..7af8c4a95 100644
--- a/init.c
+++ b/init.c
@@ -120,10 +120,12 @@ static _syscall2(int, bdflush, int, func, int, data);
120 120
121#define VT_PRIMARY "/dev/tty1" /* Primary virtual console */ 121#define VT_PRIMARY "/dev/tty1" /* Primary virtual console */
122#define VT_SECONDARY "/dev/tty2" /* Virtual console */ 122#define VT_SECONDARY "/dev/tty2" /* Virtual console */
123#define VT_LOG "/dev/tty3" /* Virtual console */ 123#define VT_THIRD "/dev/tty3" /* Virtual console */
124#define VT_FOURTH "/dev/tty4" /* Virtual console */
125#define VT_LOG "/dev/tty5" /* Virtual console */
124#define SERIAL_CON0 "/dev/ttyS0" /* Primary serial console */ 126#define SERIAL_CON0 "/dev/ttyS0" /* Primary serial console */
125#define SERIAL_CON1 "/dev/ttyS1" /* Serial console */ 127#define SERIAL_CON1 "/dev/ttyS1" /* Serial console */
126#define SHELL "/bin/sh" /* Default shell */ 128#define SHELL "-/bin/sh" /* Default shell */
127#define INITTAB "/etc/inittab" /* inittab file location */ 129#define INITTAB "/etc/inittab" /* inittab file location */
128#ifndef INIT_SCRIPT 130#ifndef INIT_SCRIPT
129#define INIT_SCRIPT "/etc/init.d/rcS" /* Default sysinit script. */ 131#define INIT_SCRIPT "/etc/init.d/rcS" /* Default sysinit script. */
@@ -171,6 +173,8 @@ initAction *initActionList = NULL;
171 173
172 174
173static char *secondConsole = VT_SECONDARY; 175static char *secondConsole = VT_SECONDARY;
176static char *thirdConsole = VT_THIRD;
177static char *fourthConsole = VT_FOURTH;
174static char *log = VT_LOG; 178static char *log = VT_LOG;
175static int kernelVersion = 0; 179static int kernelVersion = 0;
176static char termType[32] = "TERM=linux"; 180static char termType[32] = "TERM=linux";
@@ -371,11 +375,13 @@ static void console_init()
371 /* Perhaps we should panic here? */ 375 /* Perhaps we should panic here? */
372 snprintf(console, sizeof(console) - 1, "/dev/null"); 376 snprintf(console, sizeof(console) - 1, "/dev/null");
373 } else { 377 } else {
374 /* check for serial console and disable logging to tty3 & running a 378 /* check for serial console and disable logging to tty5 & running a
375 * shell to tty2 */ 379 * shell to tty2-4 */
376 if (ioctl(0, TIOCGSERIAL, &sr) == 0) { 380 if (ioctl(0, TIOCGSERIAL, &sr) == 0) {
377 log = NULL; 381 log = NULL;
378 secondConsole = NULL; 382 secondConsole = NULL;
383 thirdConsole = NULL;
384 fourthConsole = NULL;
379 /* Force the TERM setting to vt102 for serial console -- 385 /* Force the TERM setting to vt102 for serial console --
380 * iff TERM is set to linux (the default) */ 386 * iff TERM is set to linux (the default) */
381 if (strcmp( termType, "TERM=linux" ) == 0) 387 if (strcmp( termType, "TERM=linux" ) == 0)
@@ -393,7 +399,7 @@ static pid_t run(char *command, char *terminal, int get_enter)
393 int i, fd; 399 int i, fd;
394 pid_t pid; 400 pid_t pid;
395 char *tmpCmd; 401 char *tmpCmd;
396 char *cmd[255]; 402 char *cmd[255], *cmdpath;
397 char buf[255]; 403 char buf[255];
398 static const char press_enter[] = 404 static const char press_enter[] =
399 405
@@ -404,11 +410,9 @@ static pid_t run(char *command, char *terminal, int get_enter)
404 "SHELL=/bin/sh", 410 "SHELL=/bin/sh",
405 termType, 411 termType,
406 "USER=root", 412 "USER=root",
407 "ENV=/etc/profile",
408 0 413 0
409 }; 414 };
410 415
411
412 if ((pid = fork()) == 0) { 416 if ((pid = fork()) == 0) {
413 /* Clean up */ 417 /* Clean up */
414 ioctl(0, TIOCNOTTY, 0); 418 ioctl(0, TIOCNOTTY, 0);
@@ -481,6 +485,34 @@ static pid_t run(char *command, char *terminal, int get_enter)
481 cmd[i] = NULL; 485 cmd[i] = NULL;
482 } 486 }
483 487
488 cmdpath = cmd[0];
489
490 /*
491 Interactive shells want to see a dash in argv[0]. This
492 typically is handled by login, argv will be setup this
493 way if a dash appears at the front of the command path
494 (like "-/bin/sh").
495 */
496
497 if (*cmdpath == '-') {
498 char *s;
499
500 /* skip over the dash */
501 ++cmdpath;
502
503 /* find the last component in the command pathname */
504 s = get_last_path_component(cmdpath);
505
506 /* make a new argv[0] */
507 if ((cmd[0] = malloc(strlen(s)+2)) == NULL) {
508 message(LOG | CONSOLE, "malloc failed");
509 cmd[0] = cmdpath;
510 } else {
511 cmd[0][0] = '-';
512 strcpy(cmd[0]+1, s);
513 }
514 }
515
484#if defined BB_FEATURE_INIT_COREDUMPS 516#if defined BB_FEATURE_INIT_COREDUMPS
485 { 517 {
486 struct stat sb; 518 struct stat sb;
@@ -495,11 +527,11 @@ static pid_t run(char *command, char *terminal, int get_enter)
495 527
496 /* Now run it. The new program will take over this PID, 528 /* Now run it. The new program will take over this PID,
497 * so nothing further in init.c should be run. */ 529 * so nothing further in init.c should be run. */
498 execve(cmd[0], cmd, environment); 530 execve(cmdpath, cmd, environment);
499 531
500 /* We're still here? Some error happened. */ 532 /* We're still here? Some error happened. */
501 message(LOG | CONSOLE, "Bummer, could not run '%s': %s\n", cmd[0], 533 message(LOG | CONSOLE, "Bummer, could not run '%s': %s\n", cmdpath,
502 strerror(errno)); 534 strerror(errno));
503 exit(-1); 535 exit(-1);
504 } 536 }
505 return pid; 537 return pid;
@@ -795,6 +827,12 @@ void parse_inittab(void)
795 /* Askfirst shell on tty2 */ 827 /* Askfirst shell on tty2 */
796 if (secondConsole != NULL) 828 if (secondConsole != NULL)
797 new_initAction(ASKFIRST, SHELL, secondConsole); 829 new_initAction(ASKFIRST, SHELL, secondConsole);
830 /* Askfirst shell on tty3 */
831 if (thirdConsole != NULL)
832 new_initAction(ASKFIRST, SHELL, thirdConsole);
833 /* Askfirst shell on tty4 */
834 if (fourthConsole != NULL)
835 new_initAction(ASKFIRST, SHELL, fourthConsole);
798 /* sysinit */ 836 /* sysinit */
799 new_initAction(SYSINIT, INIT_SCRIPT, console); 837 new_initAction(SYSINIT, INIT_SCRIPT, console);
800 838
@@ -958,9 +996,13 @@ extern int init_main(int argc, char **argv)
958 /* Check if we are supposed to be in single user mode */ 996 /* Check if we are supposed to be in single user mode */
959 if (argc > 1 && (!strcmp(argv[1], "single") || 997 if (argc > 1 && (!strcmp(argv[1], "single") ||
960 !strcmp(argv[1], "-s") || !strcmp(argv[1], "1"))) { 998 !strcmp(argv[1], "-s") || !strcmp(argv[1], "1"))) {
961 /* Ask first then start a shell on tty2 */ 999 /* Ask first then start a shell on tty2-4 */
962 if (secondConsole != NULL) 1000 if (secondConsole != NULL)
963 new_initAction(ASKFIRST, SHELL, secondConsole); 1001 new_initAction(ASKFIRST, SHELL, secondConsole);
1002 if (thirdConsole != NULL)
1003 new_initAction(ASKFIRST, SHELL, thirdConsole);
1004 if (fourthConsole != NULL)
1005 new_initAction(ASKFIRST, SHELL, fourthConsole);
964 /* Start a shell on tty1 */ 1006 /* Start a shell on tty1 */
965 new_initAction(RESPAWN, SHELL, console); 1007 new_initAction(RESPAWN, SHELL, console);
966 } else { 1008 } else {
diff --git a/init/init.c b/init/init.c
index b3ae97d2e..7af8c4a95 100644
--- a/init/init.c
+++ b/init/init.c
@@ -120,10 +120,12 @@ static _syscall2(int, bdflush, int, func, int, data);
120 120
121#define VT_PRIMARY "/dev/tty1" /* Primary virtual console */ 121#define VT_PRIMARY "/dev/tty1" /* Primary virtual console */
122#define VT_SECONDARY "/dev/tty2" /* Virtual console */ 122#define VT_SECONDARY "/dev/tty2" /* Virtual console */
123#define VT_LOG "/dev/tty3" /* Virtual console */ 123#define VT_THIRD "/dev/tty3" /* Virtual console */
124#define VT_FOURTH "/dev/tty4" /* Virtual console */
125#define VT_LOG "/dev/tty5" /* Virtual console */
124#define SERIAL_CON0 "/dev/ttyS0" /* Primary serial console */ 126#define SERIAL_CON0 "/dev/ttyS0" /* Primary serial console */
125#define SERIAL_CON1 "/dev/ttyS1" /* Serial console */ 127#define SERIAL_CON1 "/dev/ttyS1" /* Serial console */
126#define SHELL "/bin/sh" /* Default shell */ 128#define SHELL "-/bin/sh" /* Default shell */
127#define INITTAB "/etc/inittab" /* inittab file location */ 129#define INITTAB "/etc/inittab" /* inittab file location */
128#ifndef INIT_SCRIPT 130#ifndef INIT_SCRIPT
129#define INIT_SCRIPT "/etc/init.d/rcS" /* Default sysinit script. */ 131#define INIT_SCRIPT "/etc/init.d/rcS" /* Default sysinit script. */
@@ -171,6 +173,8 @@ initAction *initActionList = NULL;
171 173
172 174
173static char *secondConsole = VT_SECONDARY; 175static char *secondConsole = VT_SECONDARY;
176static char *thirdConsole = VT_THIRD;
177static char *fourthConsole = VT_FOURTH;
174static char *log = VT_LOG; 178static char *log = VT_LOG;
175static int kernelVersion = 0; 179static int kernelVersion = 0;
176static char termType[32] = "TERM=linux"; 180static char termType[32] = "TERM=linux";
@@ -371,11 +375,13 @@ static void console_init()
371 /* Perhaps we should panic here? */ 375 /* Perhaps we should panic here? */
372 snprintf(console, sizeof(console) - 1, "/dev/null"); 376 snprintf(console, sizeof(console) - 1, "/dev/null");
373 } else { 377 } else {
374 /* check for serial console and disable logging to tty3 & running a 378 /* check for serial console and disable logging to tty5 & running a
375 * shell to tty2 */ 379 * shell to tty2-4 */
376 if (ioctl(0, TIOCGSERIAL, &sr) == 0) { 380 if (ioctl(0, TIOCGSERIAL, &sr) == 0) {
377 log = NULL; 381 log = NULL;
378 secondConsole = NULL; 382 secondConsole = NULL;
383 thirdConsole = NULL;
384 fourthConsole = NULL;
379 /* Force the TERM setting to vt102 for serial console -- 385 /* Force the TERM setting to vt102 for serial console --
380 * iff TERM is set to linux (the default) */ 386 * iff TERM is set to linux (the default) */
381 if (strcmp( termType, "TERM=linux" ) == 0) 387 if (strcmp( termType, "TERM=linux" ) == 0)
@@ -393,7 +399,7 @@ static pid_t run(char *command, char *terminal, int get_enter)
393 int i, fd; 399 int i, fd;
394 pid_t pid; 400 pid_t pid;
395 char *tmpCmd; 401 char *tmpCmd;
396 char *cmd[255]; 402 char *cmd[255], *cmdpath;
397 char buf[255]; 403 char buf[255];
398 static const char press_enter[] = 404 static const char press_enter[] =
399 405
@@ -404,11 +410,9 @@ static pid_t run(char *command, char *terminal, int get_enter)
404 "SHELL=/bin/sh", 410 "SHELL=/bin/sh",
405 termType, 411 termType,
406 "USER=root", 412 "USER=root",
407 "ENV=/etc/profile",
408 0 413 0
409 }; 414 };
410 415
411
412 if ((pid = fork()) == 0) { 416 if ((pid = fork()) == 0) {
413 /* Clean up */ 417 /* Clean up */
414 ioctl(0, TIOCNOTTY, 0); 418 ioctl(0, TIOCNOTTY, 0);
@@ -481,6 +485,34 @@ static pid_t run(char *command, char *terminal, int get_enter)
481 cmd[i] = NULL; 485 cmd[i] = NULL;
482 } 486 }
483 487
488 cmdpath = cmd[0];
489
490 /*
491 Interactive shells want to see a dash in argv[0]. This
492 typically is handled by login, argv will be setup this
493 way if a dash appears at the front of the command path
494 (like "-/bin/sh").
495 */
496
497 if (*cmdpath == '-') {
498 char *s;
499
500 /* skip over the dash */
501 ++cmdpath;
502
503 /* find the last component in the command pathname */
504 s = get_last_path_component(cmdpath);
505
506 /* make a new argv[0] */
507 if ((cmd[0] = malloc(strlen(s)+2)) == NULL) {
508 message(LOG | CONSOLE, "malloc failed");
509 cmd[0] = cmdpath;
510 } else {
511 cmd[0][0] = '-';
512 strcpy(cmd[0]+1, s);
513 }
514 }
515
484#if defined BB_FEATURE_INIT_COREDUMPS 516#if defined BB_FEATURE_INIT_COREDUMPS
485 { 517 {
486 struct stat sb; 518 struct stat sb;
@@ -495,11 +527,11 @@ static pid_t run(char *command, char *terminal, int get_enter)
495 527
496 /* Now run it. The new program will take over this PID, 528 /* Now run it. The new program will take over this PID,
497 * so nothing further in init.c should be run. */ 529 * so nothing further in init.c should be run. */
498 execve(cmd[0], cmd, environment); 530 execve(cmdpath, cmd, environment);
499 531
500 /* We're still here? Some error happened. */ 532 /* We're still here? Some error happened. */
501 message(LOG | CONSOLE, "Bummer, could not run '%s': %s\n", cmd[0], 533 message(LOG | CONSOLE, "Bummer, could not run '%s': %s\n", cmdpath,
502 strerror(errno)); 534 strerror(errno));
503 exit(-1); 535 exit(-1);
504 } 536 }
505 return pid; 537 return pid;
@@ -795,6 +827,12 @@ void parse_inittab(void)
795 /* Askfirst shell on tty2 */ 827 /* Askfirst shell on tty2 */
796 if (secondConsole != NULL) 828 if (secondConsole != NULL)
797 new_initAction(ASKFIRST, SHELL, secondConsole); 829 new_initAction(ASKFIRST, SHELL, secondConsole);
830 /* Askfirst shell on tty3 */
831 if (thirdConsole != NULL)
832 new_initAction(ASKFIRST, SHELL, thirdConsole);
833 /* Askfirst shell on tty4 */
834 if (fourthConsole != NULL)
835 new_initAction(ASKFIRST, SHELL, fourthConsole);
798 /* sysinit */ 836 /* sysinit */
799 new_initAction(SYSINIT, INIT_SCRIPT, console); 837 new_initAction(SYSINIT, INIT_SCRIPT, console);
800 838
@@ -958,9 +996,13 @@ extern int init_main(int argc, char **argv)
958 /* Check if we are supposed to be in single user mode */ 996 /* Check if we are supposed to be in single user mode */
959 if (argc > 1 && (!strcmp(argv[1], "single") || 997 if (argc > 1 && (!strcmp(argv[1], "single") ||
960 !strcmp(argv[1], "-s") || !strcmp(argv[1], "1"))) { 998 !strcmp(argv[1], "-s") || !strcmp(argv[1], "1"))) {
961 /* Ask first then start a shell on tty2 */ 999 /* Ask first then start a shell on tty2-4 */
962 if (secondConsole != NULL) 1000 if (secondConsole != NULL)
963 new_initAction(ASKFIRST, SHELL, secondConsole); 1001 new_initAction(ASKFIRST, SHELL, secondConsole);
1002 if (thirdConsole != NULL)
1003 new_initAction(ASKFIRST, SHELL, thirdConsole);
1004 if (fourthConsole != NULL)
1005 new_initAction(ASKFIRST, SHELL, fourthConsole);
964 /* Start a shell on tty1 */ 1006 /* Start a shell on tty1 */
965 new_initAction(RESPAWN, SHELL, console); 1007 new_initAction(RESPAWN, SHELL, console);
966 } else { 1008 } else {
diff --git a/scripts/inittab b/scripts/inittab
index bb547b740..2515264c7 100644
--- a/scripts/inittab
+++ b/scripts/inittab
@@ -44,7 +44,6 @@
44# tty2::askfirst:/bin/sh 44# tty2::askfirst:/bin/sh
45# 45#
46 46
47
48# Boot-time system configuration/initialization script. 47# Boot-time system configuration/initialization script.
49# This is run first except when booting in single-user mode. 48# This is run first except when booting in single-user mode.
50# 49#
@@ -52,16 +51,23 @@
52 51
53# /bin/sh invocations on selected ttys 52# /bin/sh invocations on selected ttys
54# 53#
55# Start an "askfirst" shell on the console (whatever that may be) 54# Note below that we prefix the shell commands with a "-" to indicate to the
56::askfirst:/bin/sh 55# shell that it is supposed to be a login shell. Normally this is handled by
57# Start an "askfirst" shell on /dev/tty2 56# login, but since we are bypassing login in this case, BusyBox lets you do
58tty2::askfirst:/bin/sh 57# this yourself...
58#
59# Start an "askfirst" shell on the console (whatever that may be).
60::askfirst:-/bin/sh
61#
62# Start an "askfirst" shell on /dev/tty2-4
63tty2::askfirst:-/bin/sh
64tty3::askfirst:-/bin/sh
65tty4::askfirst:-/bin/sh
59 66
60# /sbin/getty invocations for selected ttys 67# /sbin/getty invocations for selected ttys
61# 68#
62tty4::respawn:/sbin/getty 38400 tty4
63tty5::respawn:/sbin/getty 38400 tty5 69tty5::respawn:/sbin/getty 38400 tty5
64 70tty6::respawn:/sbin/getty 38400 tty6
65 71
66# Example of how to put a getty on a serial line (for a terminal) 72# Example of how to put a getty on a serial line (for a terminal)
67# 73#