- tcsetattr(fd, TCSANOW, &tty);
-}
-
-static void console_init(void)
-{
- int fd;
- int tried = 0;
- struct vt_stat vt;
- struct serial_struct sr;
- char *s;
-
- if ((s = getenv("CONSOLE")) != NULL || (s = getenv("console")) != NULL) {
- safe_strncpy(console, s, sizeof(console));
-#if #cpu(sparc)
- /* sparc kernel supports console=tty[ab] parameter which is also
- * passed to init, so catch it here */
- /* remap tty[ab] to /dev/ttyS[01] */
- if (strcmp(s, "ttya") == 0)
- safe_strncpy(console, SC_0, sizeof(console));
- else if (strcmp(s, "ttyb") == 0)
- safe_strncpy(console, SC_1, sizeof(console));
-#endif
- } else {
- /* 2.2 kernels: identify the real console backend and try to use it */
- if (ioctl(0, TIOCGSERIAL, &sr) == 0) {
- /* this is a serial console */
- snprintf(console, sizeof(console) - 1, SC_FORMAT, sr.line);
- } else if (ioctl(0, VT_GETSTATE, &vt) == 0) {
- /* this is linux virtual tty */
- snprintf(console, sizeof(console) - 1, VC_FORMAT, vt.v_active);
- } else {
- safe_strncpy(console, _PATH_CONSOLE, sizeof(console));
- tried++;
- }
- }
-
- while ((fd = open(console, O_RDONLY | O_NONBLOCK)) < 0 && tried < 2) {
- /* Can't open selected console -- try
- logical system console and VT_MASTER */
- safe_strncpy(console, (tried == 0 ? _PATH_CONSOLE : CURRENT_VC),
- sizeof(console));
- tried++;
- }
- if (fd < 0) {
- /* Perhaps we should panic here? */
-#ifndef CONFIG_SYSLOGD
- log_console =
-#endif
- safe_strncpy(console, bb_dev_null, sizeof(console));
- } else {
- s = getenv("TERM");
- /* check for serial console */
- if (ioctl(fd, TIOCGSERIAL, &sr) == 0) {
- /* Force the TERM setting to vt102 for serial console --
- * if TERM is set to linux (the default) */
- if (s == NULL || strcmp(s, "linux") == 0)
- putenv("TERM=vt102");
-#ifndef CONFIG_SYSLOGD
- log_console = console;
-#endif
- } else {
- if (s == NULL)
- putenv("TERM=linux");
- }
- close(fd);
- }
- messageD(LOG, "console=%s", 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);
- safe_strncpy(argv[0], new_argv0, len + 1);
-
- /* 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++;
- }