aboutsummaryrefslogtreecommitdiff
path: root/init/init.c
diff options
context:
space:
mode:
Diffstat (limited to 'init/init.c')
-rw-r--r--init/init.c35
1 files changed, 25 insertions, 10 deletions
diff --git a/init/init.c b/init/init.c
index 2eb8f1a54..fa1af6d7c 100644
--- a/init/init.c
+++ b/init/init.c
@@ -12,13 +12,21 @@
12#include "libbb.h" 12#include "libbb.h"
13#include <syslog.h> 13#include <syslog.h>
14#include <paths.h> 14#include <paths.h>
15#include <sys/reboot.h>
16#include <sys/resource.h> 15#include <sys/resource.h>
16#ifdef __linux__
17#include <linux/vt.h> 17#include <linux/vt.h>
18#endif
18#if ENABLE_FEATURE_UTMP 19#if ENABLE_FEATURE_UTMP
19# include <utmp.h> /* DEAD_PROCESS */ 20# include <utmp.h> /* DEAD_PROCESS */
20#endif 21#endif
22#include "reboot.h" /* reboot() constants */
21 23
24/* Used only for sanitizing purposes in set_sane_term() below. On systems where
25 * the baud rate is stored in a separate field, we can safely disable them. */
26#ifndef CBAUD
27# define CBAUD 0
28# define CBAUDEX 0
29#endif
22 30
23/* Was a CONFIG_xxx option. A lot of people were building 31/* Was a CONFIG_xxx option. A lot of people were building
24 * not fully functional init by switching it on! */ 32 * not fully functional init by switching it on! */
@@ -89,13 +97,6 @@ static const char *log_console = VC_5;
89enum { 97enum {
90 L_LOG = 0x1, 98 L_LOG = 0x1,
91 L_CONSOLE = 0x2, 99 L_CONSOLE = 0x2,
92#ifndef RB_HALT_SYSTEM
93 RB_HALT_SYSTEM = 0xcdef0123, /* FIXME: this overflows enum */
94 RB_ENABLE_CAD = 0x89abcdef,
95 RB_DISABLE_CAD = 0,
96 RB_POWER_OFF = 0x4321fedc,
97 RB_AUTOBOOT = 0x01234567,
98#endif
99}; 100};
100 101
101/* Print a message to the specified device. 102/* Print a message to the specified device.
@@ -166,7 +167,9 @@ static void message(int where, const char *fmt, ...)
166 167
167static void console_init(void) 168static void console_init(void)
168{ 169{
170#ifdef VT_OPENQRY
169 int vtno; 171 int vtno;
172#endif
170 char *s; 173 char *s;
171 174
172 s = getenv("CONSOLE"); 175 s = getenv("CONSOLE");
@@ -190,6 +193,7 @@ static void console_init(void)
190 } 193 }
191 194
192 s = getenv("TERM"); 195 s = getenv("TERM");
196#ifdef VT_OPENQRY
193 if (ioctl(STDIN_FILENO, VT_OPENQRY, &vtno) != 0) { 197 if (ioctl(STDIN_FILENO, VT_OPENQRY, &vtno) != 0) {
194 /* Not a linux terminal, probably serial console. 198 /* Not a linux terminal, probably serial console.
195 * Force the TERM setting to vt102 199 * Force the TERM setting to vt102
@@ -198,8 +202,10 @@ static void console_init(void)
198 putenv((char*)"TERM=vt102"); 202 putenv((char*)"TERM=vt102");
199 if (!ENABLE_FEATURE_INIT_SYSLOG) 203 if (!ENABLE_FEATURE_INIT_SYSLOG)
200 log_console = NULL; 204 log_console = NULL;
201 } else if (!s) 205 } else
202 putenv((char*)"TERM=linux"); 206#endif
207 if (!s)
208 putenv((char*)"TERM=" CONFIG_INIT_TERMINAL_TYPE);
203} 209}
204 210
205/* Set terminal settings to reasonable defaults. 211/* Set terminal settings to reasonable defaults.
@@ -220,8 +226,10 @@ static void set_sane_term(void)
220 tty.c_cc[VSTOP] = 19; /* C-s */ 226 tty.c_cc[VSTOP] = 19; /* C-s */
221 tty.c_cc[VSUSP] = 26; /* C-z */ 227 tty.c_cc[VSUSP] = 26; /* C-z */
222 228
229#ifdef __linux__
223 /* use line discipline 0 */ 230 /* use line discipline 0 */
224 tty.c_line = 0; 231 tty.c_line = 0;
232#endif
225 233
226 /* Make it be sane */ 234 /* Make it be sane */
227 tty.c_cflag &= CBAUD | CBAUDEX | CSIZE | CSTOPB | PARENB | PARODD; 235 tty.c_cflag &= CBAUD | CBAUDEX | CSIZE | CSTOPB | PARENB | PARODD;
@@ -709,10 +717,12 @@ static void restart_handler(int sig UNUSED_PARAM)
709 717
710 run_shutdown_and_kill_processes(); 718 run_shutdown_and_kill_processes();
711 719
720#ifdef RB_ENABLE_CAD
712 /* Allow Ctrl-Alt-Del to reboot the system. 721 /* Allow Ctrl-Alt-Del to reboot the system.
713 * This is how kernel sets it up for init, we follow suit. 722 * This is how kernel sets it up for init, we follow suit.
714 */ 723 */
715 reboot(RB_ENABLE_CAD); /* misnomer */ 724 reboot(RB_ENABLE_CAD); /* misnomer */
725#endif
716 726
717 if (open_stdio_to_tty(a->terminal)) { 727 if (open_stdio_to_tty(a->terminal)) {
718 dbg_message(L_CONSOLE, "Trying to re-exec %s", a->command); 728 dbg_message(L_CONSOLE, "Trying to re-exec %s", a->command);
@@ -855,9 +865,11 @@ int init_main(int argc UNUSED_PARAM, char **argv)
855 ) { 865 ) {
856 bb_show_usage(); 866 bb_show_usage();
857 } 867 }
868#ifdef RB_DISABLE_CAD
858 /* Turn off rebooting via CTL-ALT-DEL - we get a 869 /* Turn off rebooting via CTL-ALT-DEL - we get a
859 * SIGINT on CAD so we can shut things down gracefully... */ 870 * SIGINT on CAD so we can shut things down gracefully... */
860 reboot(RB_DISABLE_CAD); /* misnomer */ 871 reboot(RB_DISABLE_CAD); /* misnomer */
872#endif
861 } 873 }
862 874
863 /* Figure out where the default console should be */ 875 /* Figure out where the default console should be */
@@ -880,6 +892,8 @@ int init_main(int argc UNUSED_PARAM, char **argv)
880 message(L_CONSOLE | L_LOG, "init started: %s", bb_banner); 892 message(L_CONSOLE | L_LOG, "init started: %s", bb_banner);
881#endif 893#endif
882 894
895/* struct sysinfo is linux-specific */
896#ifdef __linux__
883 /* Make sure there is enough memory to do something useful. */ 897 /* Make sure there is enough memory to do something useful. */
884 if (ENABLE_SWAPONOFF) { 898 if (ENABLE_SWAPONOFF) {
885 struct sysinfo info; 899 struct sysinfo info;
@@ -895,6 +909,7 @@ int init_main(int argc UNUSED_PARAM, char **argv)
895 run_actions(SYSINIT); /* wait and removing */ 909 run_actions(SYSINIT); /* wait and removing */
896 } 910 }
897 } 911 }
912#endif
898 913
899 /* Check if we are supposed to be in single user mode */ 914 /* Check if we are supposed to be in single user mode */
900 if (argv[1] 915 if (argv[1]