mirror of
https://github.com/sheumann/hush.git
synced 2024-12-27 16:31:24 +00:00
Ha! Got init working.
-Erik
This commit is contained in:
parent
ff719d663e
commit
2f6c04f63c
6
Makefile
6
Makefile
@ -17,12 +17,12 @@
|
|||||||
|
|
||||||
|
|
||||||
PROG=busybox
|
PROG=busybox
|
||||||
VERSION=0.31
|
VERSION=0.32
|
||||||
BUILDTIME=$(shell date "+%Y%m%d-%H%M")
|
BUILDTIME=$(shell date "+%Y%m%d-%H%M")
|
||||||
|
|
||||||
# Comment out the following to make a debuggable build
|
# Comment out the following to make a debuggable build
|
||||||
# Leave this off for production use.
|
# Leave this off for production use.
|
||||||
DODEBUG=true
|
DODEBUG=false
|
||||||
# If you want a static binary, turn this on. I can't think
|
# If you want a static binary, turn this on. I can't think
|
||||||
# of many situations where anybody would ever want it static,
|
# of many situations where anybody would ever want it static,
|
||||||
# but...
|
# but...
|
||||||
@ -34,7 +34,7 @@ ARCH=`uname -m | sed -e 's/i.86/i386/' | sed -e 's/sparc.*/sparc/'`
|
|||||||
|
|
||||||
# -D_GNU_SOURCE is needed because environ is used in init.c
|
# -D_GNU_SOURCE is needed because environ is used in init.c
|
||||||
ifeq ($(DODEBUG),true)
|
ifeq ($(DODEBUG),true)
|
||||||
CFLAGS=-Wall -g -D_GNU_SOURCE
|
CFLAGS=-Wall -g -D_GNU_SOURCE -DDEBUG_INIT
|
||||||
STRIP=
|
STRIP=
|
||||||
LDFLAGS=
|
LDFLAGS=
|
||||||
else
|
else
|
||||||
|
@ -15,12 +15,12 @@
|
|||||||
#define BB_DMESG
|
#define BB_DMESG
|
||||||
//#define BB_DUTMP
|
//#define BB_DUTMP
|
||||||
//#define BB_FDFLUSH
|
//#define BB_FDFLUSH
|
||||||
//#define BB_FIND
|
#define BB_FIND
|
||||||
//#define BB_FSCK_MINIX
|
#define BB_FSCK_MINIX
|
||||||
//#define BB_MKFS_MINIX
|
#define BB_MKFS_MINIX
|
||||||
#define BB_CHVT
|
#define BB_CHVT
|
||||||
#define BB_DEALLOCVT
|
#define BB_DEALLOCVT
|
||||||
//#define BB_GREP
|
#define BB_GREP
|
||||||
//#define BB_HALT
|
//#define BB_HALT
|
||||||
#define BB_INIT
|
#define BB_INIT
|
||||||
#define BB_KILL
|
#define BB_KILL
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
Name: busybox
|
Name: busybox
|
||||||
Version: 0.29alpha
|
Version: 0.32
|
||||||
Release: 1
|
Release: 1
|
||||||
Group: System/Utilities
|
Group: System/Utilities
|
||||||
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
|
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
|
||||||
@ -7,7 +7,7 @@ Copyright: GPL
|
|||||||
Packager : Erik Andersen <andersen@lineo.com>
|
Packager : Erik Andersen <andersen@lineo.com>
|
||||||
Conflicts: fileutils grep shellutils
|
Conflicts: fileutils grep shellutils
|
||||||
Buildroot: /tmp/%{Name}-%{Version}
|
Buildroot: /tmp/%{Name}-%{Version}
|
||||||
Source: busybox-0.29a1.tar.gz
|
Source: busybox-0.32.tar.gz
|
||||||
|
|
||||||
%Description
|
%Description
|
||||||
BusyBox is a suite of "tiny" Unix utilities in a multi-call binary. It
|
BusyBox is a suite of "tiny" Unix utilities in a multi-call binary. It
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
Name: busybox
|
Name: busybox
|
||||||
Version: 0.29alpha
|
Version: 0.32
|
||||||
Release: 1
|
Release: 1
|
||||||
Group: System/Utilities
|
Group: System/Utilities
|
||||||
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
|
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
|
||||||
@ -7,7 +7,7 @@ Copyright: GPL
|
|||||||
Packager : Erik Andersen <andersen@lineo.com>
|
Packager : Erik Andersen <andersen@lineo.com>
|
||||||
Conflicts: fileutils grep shellutils
|
Conflicts: fileutils grep shellutils
|
||||||
Buildroot: /tmp/%{Name}-%{Version}
|
Buildroot: /tmp/%{Name}-%{Version}
|
||||||
Source: busybox-0.29a1.tar.gz
|
Source: busybox-0.32.tar.gz
|
||||||
|
|
||||||
%Description
|
%Description
|
||||||
BusyBox is a suite of "tiny" Unix utilities in a multi-call binary. It
|
BusyBox is a suite of "tiny" Unix utilities in a multi-call binary. It
|
||||||
|
100
init.c
100
init.c
@ -42,14 +42,15 @@
|
|||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
/* Turn this on to debug init so it won't reboot when killed */
|
/* Turn this on to debug init so it won't reboot when killed */
|
||||||
#define DEBUG_INIT
|
//#define DEBUG_INIT
|
||||||
|
|
||||||
#define CONSOLE "/dev/console" /* Logical system console */
|
#define CONSOLE "/dev/console" /* Logical system console */
|
||||||
#define VT_PRIMARY "/dev/tty0" /* Virtual console master */
|
#define VT_PRIMARY "/dev/tty0" /* Virtual console master */
|
||||||
#define VT_SECONDARY "/dev/tty1" /* Virtual console master */
|
#define VT_SECONDARY "/dev/tty1" /* Virtual console master */
|
||||||
#define VT_LOG "/dev/tty2" /* Virtual console master */
|
#define VT_LOG "/dev/tty2" /* Virtual console master */
|
||||||
#define SHELL "/bin/sh" /* Default shell */
|
#define SHELL "/bin/sh" /* Default shell */
|
||||||
#define INITSCRIPT "/etc/init.d/rcS" /* Initscript. */
|
//#define INITSCRIPT "/etc/init.d/rcS" /* Initscript. */
|
||||||
|
#define INITSCRIPT "/tmp/foo.sh"
|
||||||
#define PATH_DEFAULT "PATH=/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin"
|
#define PATH_DEFAULT "PATH=/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin"
|
||||||
|
|
||||||
static char *console = CONSOLE;
|
static char *console = CONSOLE;
|
||||||
@ -218,8 +219,9 @@ static int waitfor(int pid)
|
|||||||
static pid_t run(const char * const* command,
|
static pid_t run(const char * const* command,
|
||||||
char *terminal, int get_enter)
|
char *terminal, int get_enter)
|
||||||
{
|
{
|
||||||
int i, f;
|
int fd;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
const char * const* cmd = command;
|
||||||
static const char press_enter[] =
|
static const char press_enter[] =
|
||||||
"\nPlease press Enter to activate this console. ";
|
"\nPlease press Enter to activate this console. ";
|
||||||
|
|
||||||
@ -230,13 +232,22 @@ static pid_t run(const char * const* command,
|
|||||||
close(2);
|
close(2);
|
||||||
setsid();
|
setsid();
|
||||||
|
|
||||||
f=open(terminal, O_RDWR);
|
/* Reset signal handlers set for parent process */
|
||||||
dup(f);
|
signal(SIGUSR1, SIG_DFL);
|
||||||
dup(f);
|
signal(SIGUSR2, SIG_DFL);
|
||||||
|
signal(SIGINT, SIG_DFL);
|
||||||
|
signal(SIGTERM, SIG_DFL);
|
||||||
|
|
||||||
|
if ((fd = device_open(terminal, O_RDWR)) < 0) {
|
||||||
|
message(log, "Bummer, can't open %s\r\n", terminal);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
dup(fd);
|
||||||
|
dup(fd);
|
||||||
tcsetpgrp(0, getpgrp());
|
tcsetpgrp(0, getpgrp());
|
||||||
set_term(0);
|
set_term(0);
|
||||||
|
|
||||||
if (get_enter) {
|
if (get_enter==TRUE) {
|
||||||
/*
|
/*
|
||||||
* Save memory by not exec-ing anything large (like a shell)
|
* Save memory by not exec-ing anything large (like a shell)
|
||||||
* before the user wants it. This is critical if swap is not
|
* before the user wants it. This is critical if swap is not
|
||||||
@ -251,51 +262,45 @@ static pid_t run(const char * const* command,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Log the process name and args */
|
/* Log the process name and args */
|
||||||
|
message(log, "Executing pid(%d): '", getpid());
|
||||||
|
while ( *cmd) message(log, "%s ", *cmd++);
|
||||||
|
message(log, "'\r\n");
|
||||||
|
|
||||||
/* Now run it. The new program will take over this PID,
|
/* Now run it. The new program will take over this PID,
|
||||||
* so nothing further in init.c should be run. */
|
* so nothing further in init.c should be run. */
|
||||||
message(log, "Executing '%s', pid(%d)\r\n", *command, getpid());
|
|
||||||
execvp(*command, (char**)command+1);
|
execvp(*command, (char**)command+1);
|
||||||
|
|
||||||
message(log, "Hmm. Trying as a script.\r\n");
|
message(log, "Bummer, could not execute '%s'\n", command);
|
||||||
/* If shell scripts are not executed, force the issue */
|
|
||||||
if (errno == ENOEXEC) {
|
|
||||||
char * args[16];
|
|
||||||
args[0] = SHELL;
|
|
||||||
args[1] = "-c";
|
|
||||||
args[2] = "exec";
|
|
||||||
for( i=0 ; i<16 && command[i]; i++)
|
|
||||||
args[3+i] = (char*)command[i];
|
|
||||||
args[i] = NULL;
|
|
||||||
execvp(*args, (char**)args+1);
|
|
||||||
}
|
|
||||||
message(log, "Could not execute '%s'\n", command);
|
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
return pid;
|
return pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef DEBUG_INIT
|
|
||||||
static void shutdown_system(void)
|
static void shutdown_system(void)
|
||||||
{
|
{
|
||||||
const char* const swap_off_cmd[] = { "/bin/swapoff", "-a", 0};
|
const char* const swap_off_cmd[] = { "swapoff", "swapoff", "-a", 0};
|
||||||
const char* const umount_cmd[] = { "/bin/umount", "-a", "-n", 0};
|
const char* const umount_cmd[] = { "umount", "umount", "-a", "-n", 0};
|
||||||
|
|
||||||
message(console, "The system is going down NOW !!\r\n");
|
message(console, "The system is going down NOW !!\r\n");
|
||||||
sync();
|
sync();
|
||||||
|
#ifndef DEBUG_INIT
|
||||||
/* Allow Ctrl-Alt-Del to reboot system. */
|
/* Allow Ctrl-Alt-Del to reboot system. */
|
||||||
reboot(RB_ENABLE_CAD);
|
reboot(RB_ENABLE_CAD);
|
||||||
|
#endif
|
||||||
/* Send signals to every process _except_ pid 1 */
|
/* Send signals to every process _except_ pid 1 */
|
||||||
message(console, "Sending SIGHUP to all processes.\r\n");
|
message(console, "Sending SIGHUP to all processes.\r\n");
|
||||||
|
#ifndef DEBUG_INIT
|
||||||
kill(-1, SIGHUP);
|
kill(-1, SIGHUP);
|
||||||
|
#endif
|
||||||
sleep(2);
|
sleep(2);
|
||||||
sync();
|
sync();
|
||||||
message(console, "Sending SIGKILL to all processes.\r\n");
|
message(console, "Sending SIGKILL to all processes.\r\n");
|
||||||
|
#ifndef DEBUG_INIT
|
||||||
kill(-1, SIGKILL);
|
kill(-1, SIGKILL);
|
||||||
|
#endif
|
||||||
sleep(1);
|
sleep(1);
|
||||||
waitfor(run( swap_off_cmd, console, 0));
|
waitfor(run( swap_off_cmd, log, FALSE));
|
||||||
waitfor(run( umount_cmd, console, 0));
|
waitfor(run( umount_cmd, log, FALSE));
|
||||||
sync();
|
sync();
|
||||||
if (get_kernel_revision() <= 2 * 65536 + 2 * 256 + 11) {
|
if (get_kernel_revision() <= 2 * 65536 + 2 * 256 + 11) {
|
||||||
/* Removed bdflush call, kupdate in kernels >2.2.11 */
|
/* Removed bdflush call, kupdate in kernels >2.2.11 */
|
||||||
@ -309,7 +314,9 @@ static void halt_signal(int sig)
|
|||||||
shutdown_system();
|
shutdown_system();
|
||||||
message(console,
|
message(console,
|
||||||
"The system is halted. Press CTRL-ALT-DEL or turn off power\r\n");
|
"The system is halted. Press CTRL-ALT-DEL or turn off power\r\n");
|
||||||
|
#ifndef DEBUG_INIT
|
||||||
reboot(RB_POWER_OFF);
|
reboot(RB_POWER_OFF);
|
||||||
|
#endif
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,45 +324,44 @@ static void reboot_signal(int sig)
|
|||||||
{
|
{
|
||||||
shutdown_system();
|
shutdown_system();
|
||||||
message(console, "Please stand by while rebooting the system.\r\n");
|
message(console, "Please stand by while rebooting the system.\r\n");
|
||||||
|
#ifndef DEBUG_INIT
|
||||||
reboot(RB_AUTOBOOT);
|
reboot(RB_AUTOBOOT);
|
||||||
|
#endif
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
extern int init_main(int argc, char **argv)
|
extern int init_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int run_rc = TRUE;
|
int run_rc = TRUE;
|
||||||
|
int wait_for_enter = FALSE;
|
||||||
pid_t pid1 = 0;
|
pid_t pid1 = 0;
|
||||||
pid_t pid2 = 0;
|
pid_t pid2 = 0;
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
const char* const swap_on_cmd[] = { "/bin/swapon", " -a ", 0};
|
const char* const swap_on_cmd[] = { "/bin/swapon", "swapon", "-a", 0};
|
||||||
const char* const init_commands[] = { SHELL, " -c", " exec ", INITSCRIPT, 0};
|
const char* const init_commands[] = { INITSCRIPT, INITSCRIPT, 0};
|
||||||
const char* const shell_commands[] = { SHELL, " -", 0};
|
const char* const shell_commands[] = { SHELL, "-" SHELL, 0};
|
||||||
const char* const* tty0_commands = init_commands;
|
const char* const* tty0_commands = init_commands;
|
||||||
const char* const* tty1_commands = shell_commands;
|
const char* const* tty1_commands = shell_commands;
|
||||||
#ifndef DEBUG_INIT
|
#ifdef DEBUG_INIT
|
||||||
char *hello_msg_format =
|
|
||||||
"init started: BusyBox v%s (%s) multi-call binary\r\n";
|
|
||||||
#else
|
|
||||||
char *hello_msg_format =
|
char *hello_msg_format =
|
||||||
"init(%d) started: BusyBox v%s (%s) multi-call binary\r\n";
|
"init(%d) started: BusyBox v%s (%s) multi-call binary\r\n";
|
||||||
|
#else
|
||||||
|
char *hello_msg_format =
|
||||||
|
"init started: BusyBox v%s (%s) multi-call binary\r\n";
|
||||||
#endif
|
#endif
|
||||||
const char *no_memory =
|
const char *no_memory =
|
||||||
"Sorry, your computer does not have enough memory.\r\n";
|
"Sorry, your computer does not have enough memory.\r\n";
|
||||||
|
|
||||||
#ifndef DEBUG_INIT
|
/* Set up sig handlers -- be sure to
|
||||||
/* Set up sig handlers */
|
* clear all of these in run() */
|
||||||
signal(SIGUSR1, halt_signal);
|
signal(SIGUSR1, halt_signal);
|
||||||
signal(SIGSEGV, halt_signal);
|
|
||||||
signal(SIGPWR, halt_signal);
|
|
||||||
signal(SIGALRM, halt_signal);
|
|
||||||
signal(SIGHUP, halt_signal);
|
|
||||||
signal(SIGUSR2, reboot_signal);
|
signal(SIGUSR2, reboot_signal);
|
||||||
signal(SIGINT, reboot_signal);
|
signal(SIGINT, reboot_signal);
|
||||||
signal(SIGTERM, reboot_signal);
|
signal(SIGTERM, reboot_signal);
|
||||||
|
|
||||||
/* Turn off rebooting via CTL-ALT-DEL -- we get a
|
/* Turn off rebooting via CTL-ALT-DEL -- we get a
|
||||||
* SIGINT on CAD so we can shut things down gracefully... */
|
* SIGINT on CAD so we can shut things down gracefully... */
|
||||||
|
#ifndef DEBUG_INIT
|
||||||
reboot(RB_DISABLE_CAD);
|
reboot(RB_DISABLE_CAD);
|
||||||
#endif
|
#endif
|
||||||
/* Figure out where the default console should be */
|
/* Figure out where the default console should be */
|
||||||
@ -383,7 +389,7 @@ extern int init_main(int argc, char **argv)
|
|||||||
|
|
||||||
|
|
||||||
/* Mount /proc */
|
/* Mount /proc */
|
||||||
if (mount("/proc", "/proc", "proc", 0, 0) == 0) {
|
if (mount ("proc", "/proc", "proc", 0, 0) == 0) {
|
||||||
message(log, "Mounting /proc: done.\n");
|
message(log, "Mounting /proc: done.\n");
|
||||||
message(console, "Mounting /proc: done.\n");
|
message(console, "Mounting /proc: done.\n");
|
||||||
} else {
|
} else {
|
||||||
@ -403,7 +409,7 @@ extern int init_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Try to turn on swap */
|
/* Try to turn on swap */
|
||||||
waitfor(run(swap_on_cmd, console, 0));
|
waitfor(run(swap_on_cmd, log, FALSE));
|
||||||
if (mem_total() < 2000) {
|
if (mem_total() < 2000) {
|
||||||
message(console, "%s", no_memory);
|
message(console, "%s", no_memory);
|
||||||
while (1) {
|
while (1) {
|
||||||
@ -417,12 +423,14 @@ extern int init_main(int argc, char **argv)
|
|||||||
if ( argc > 1 && (!strcmp(argv[1], "single") ||
|
if ( argc > 1 && (!strcmp(argv[1], "single") ||
|
||||||
!strcmp(argv[1], "-s") || !strcmp(argv[1], "1"))) {
|
!strcmp(argv[1], "-s") || !strcmp(argv[1], "1"))) {
|
||||||
run_rc = FALSE;
|
run_rc = FALSE;
|
||||||
|
wait_for_enter = TRUE;
|
||||||
tty0_commands = shell_commands;
|
tty0_commands = shell_commands;
|
||||||
tty1_commands = shell_commands;
|
tty1_commands = shell_commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make sure an init script exists before trying to run it */
|
/* Make sure an init script exists before trying to run it */
|
||||||
if (run_rc == TRUE && stat(INITSCRIPT, &statbuf)) {
|
if (run_rc == TRUE && stat(INITSCRIPT, &statbuf)) {
|
||||||
|
wait_for_enter = TRUE;
|
||||||
tty0_commands = shell_commands;
|
tty0_commands = shell_commands;
|
||||||
tty1_commands = shell_commands;
|
tty1_commands = shell_commands;
|
||||||
}
|
}
|
||||||
@ -435,10 +443,10 @@ extern int init_main(int argc, char **argv)
|
|||||||
int status;
|
int status;
|
||||||
|
|
||||||
if (pid1 == 0 && tty0_commands) {
|
if (pid1 == 0 && tty0_commands) {
|
||||||
pid1 = run(tty0_commands, console, 1);
|
pid1 = run(tty0_commands, console, wait_for_enter);
|
||||||
}
|
}
|
||||||
if (pid2 == 0 && tty1_commands) {
|
if (pid2 == 0 && tty1_commands) {
|
||||||
pid2 = run(tty1_commands, second_terminal, 1);
|
pid2 = run(tty1_commands, second_terminal, TRUE);
|
||||||
}
|
}
|
||||||
wpid = wait(&status);
|
wpid = wait(&status);
|
||||||
if (wpid > 0 ) {
|
if (wpid > 0 ) {
|
||||||
|
100
init/init.c
100
init/init.c
@ -42,14 +42,15 @@
|
|||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
/* Turn this on to debug init so it won't reboot when killed */
|
/* Turn this on to debug init so it won't reboot when killed */
|
||||||
#define DEBUG_INIT
|
//#define DEBUG_INIT
|
||||||
|
|
||||||
#define CONSOLE "/dev/console" /* Logical system console */
|
#define CONSOLE "/dev/console" /* Logical system console */
|
||||||
#define VT_PRIMARY "/dev/tty0" /* Virtual console master */
|
#define VT_PRIMARY "/dev/tty0" /* Virtual console master */
|
||||||
#define VT_SECONDARY "/dev/tty1" /* Virtual console master */
|
#define VT_SECONDARY "/dev/tty1" /* Virtual console master */
|
||||||
#define VT_LOG "/dev/tty2" /* Virtual console master */
|
#define VT_LOG "/dev/tty2" /* Virtual console master */
|
||||||
#define SHELL "/bin/sh" /* Default shell */
|
#define SHELL "/bin/sh" /* Default shell */
|
||||||
#define INITSCRIPT "/etc/init.d/rcS" /* Initscript. */
|
//#define INITSCRIPT "/etc/init.d/rcS" /* Initscript. */
|
||||||
|
#define INITSCRIPT "/tmp/foo.sh"
|
||||||
#define PATH_DEFAULT "PATH=/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin"
|
#define PATH_DEFAULT "PATH=/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin"
|
||||||
|
|
||||||
static char *console = CONSOLE;
|
static char *console = CONSOLE;
|
||||||
@ -218,8 +219,9 @@ static int waitfor(int pid)
|
|||||||
static pid_t run(const char * const* command,
|
static pid_t run(const char * const* command,
|
||||||
char *terminal, int get_enter)
|
char *terminal, int get_enter)
|
||||||
{
|
{
|
||||||
int i, f;
|
int fd;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
const char * const* cmd = command;
|
||||||
static const char press_enter[] =
|
static const char press_enter[] =
|
||||||
"\nPlease press Enter to activate this console. ";
|
"\nPlease press Enter to activate this console. ";
|
||||||
|
|
||||||
@ -230,13 +232,22 @@ static pid_t run(const char * const* command,
|
|||||||
close(2);
|
close(2);
|
||||||
setsid();
|
setsid();
|
||||||
|
|
||||||
f=open(terminal, O_RDWR);
|
/* Reset signal handlers set for parent process */
|
||||||
dup(f);
|
signal(SIGUSR1, SIG_DFL);
|
||||||
dup(f);
|
signal(SIGUSR2, SIG_DFL);
|
||||||
|
signal(SIGINT, SIG_DFL);
|
||||||
|
signal(SIGTERM, SIG_DFL);
|
||||||
|
|
||||||
|
if ((fd = device_open(terminal, O_RDWR)) < 0) {
|
||||||
|
message(log, "Bummer, can't open %s\r\n", terminal);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
dup(fd);
|
||||||
|
dup(fd);
|
||||||
tcsetpgrp(0, getpgrp());
|
tcsetpgrp(0, getpgrp());
|
||||||
set_term(0);
|
set_term(0);
|
||||||
|
|
||||||
if (get_enter) {
|
if (get_enter==TRUE) {
|
||||||
/*
|
/*
|
||||||
* Save memory by not exec-ing anything large (like a shell)
|
* Save memory by not exec-ing anything large (like a shell)
|
||||||
* before the user wants it. This is critical if swap is not
|
* before the user wants it. This is critical if swap is not
|
||||||
@ -251,51 +262,45 @@ static pid_t run(const char * const* command,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Log the process name and args */
|
/* Log the process name and args */
|
||||||
|
message(log, "Executing pid(%d): '", getpid());
|
||||||
|
while ( *cmd) message(log, "%s ", *cmd++);
|
||||||
|
message(log, "'\r\n");
|
||||||
|
|
||||||
/* Now run it. The new program will take over this PID,
|
/* Now run it. The new program will take over this PID,
|
||||||
* so nothing further in init.c should be run. */
|
* so nothing further in init.c should be run. */
|
||||||
message(log, "Executing '%s', pid(%d)\r\n", *command, getpid());
|
|
||||||
execvp(*command, (char**)command+1);
|
execvp(*command, (char**)command+1);
|
||||||
|
|
||||||
message(log, "Hmm. Trying as a script.\r\n");
|
message(log, "Bummer, could not execute '%s'\n", command);
|
||||||
/* If shell scripts are not executed, force the issue */
|
|
||||||
if (errno == ENOEXEC) {
|
|
||||||
char * args[16];
|
|
||||||
args[0] = SHELL;
|
|
||||||
args[1] = "-c";
|
|
||||||
args[2] = "exec";
|
|
||||||
for( i=0 ; i<16 && command[i]; i++)
|
|
||||||
args[3+i] = (char*)command[i];
|
|
||||||
args[i] = NULL;
|
|
||||||
execvp(*args, (char**)args+1);
|
|
||||||
}
|
|
||||||
message(log, "Could not execute '%s'\n", command);
|
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
return pid;
|
return pid;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef DEBUG_INIT
|
|
||||||
static void shutdown_system(void)
|
static void shutdown_system(void)
|
||||||
{
|
{
|
||||||
const char* const swap_off_cmd[] = { "/bin/swapoff", "-a", 0};
|
const char* const swap_off_cmd[] = { "swapoff", "swapoff", "-a", 0};
|
||||||
const char* const umount_cmd[] = { "/bin/umount", "-a", "-n", 0};
|
const char* const umount_cmd[] = { "umount", "umount", "-a", "-n", 0};
|
||||||
|
|
||||||
message(console, "The system is going down NOW !!\r\n");
|
message(console, "The system is going down NOW !!\r\n");
|
||||||
sync();
|
sync();
|
||||||
|
#ifndef DEBUG_INIT
|
||||||
/* Allow Ctrl-Alt-Del to reboot system. */
|
/* Allow Ctrl-Alt-Del to reboot system. */
|
||||||
reboot(RB_ENABLE_CAD);
|
reboot(RB_ENABLE_CAD);
|
||||||
|
#endif
|
||||||
/* Send signals to every process _except_ pid 1 */
|
/* Send signals to every process _except_ pid 1 */
|
||||||
message(console, "Sending SIGHUP to all processes.\r\n");
|
message(console, "Sending SIGHUP to all processes.\r\n");
|
||||||
|
#ifndef DEBUG_INIT
|
||||||
kill(-1, SIGHUP);
|
kill(-1, SIGHUP);
|
||||||
|
#endif
|
||||||
sleep(2);
|
sleep(2);
|
||||||
sync();
|
sync();
|
||||||
message(console, "Sending SIGKILL to all processes.\r\n");
|
message(console, "Sending SIGKILL to all processes.\r\n");
|
||||||
|
#ifndef DEBUG_INIT
|
||||||
kill(-1, SIGKILL);
|
kill(-1, SIGKILL);
|
||||||
|
#endif
|
||||||
sleep(1);
|
sleep(1);
|
||||||
waitfor(run( swap_off_cmd, console, 0));
|
waitfor(run( swap_off_cmd, log, FALSE));
|
||||||
waitfor(run( umount_cmd, console, 0));
|
waitfor(run( umount_cmd, log, FALSE));
|
||||||
sync();
|
sync();
|
||||||
if (get_kernel_revision() <= 2 * 65536 + 2 * 256 + 11) {
|
if (get_kernel_revision() <= 2 * 65536 + 2 * 256 + 11) {
|
||||||
/* Removed bdflush call, kupdate in kernels >2.2.11 */
|
/* Removed bdflush call, kupdate in kernels >2.2.11 */
|
||||||
@ -309,7 +314,9 @@ static void halt_signal(int sig)
|
|||||||
shutdown_system();
|
shutdown_system();
|
||||||
message(console,
|
message(console,
|
||||||
"The system is halted. Press CTRL-ALT-DEL or turn off power\r\n");
|
"The system is halted. Press CTRL-ALT-DEL or turn off power\r\n");
|
||||||
|
#ifndef DEBUG_INIT
|
||||||
reboot(RB_POWER_OFF);
|
reboot(RB_POWER_OFF);
|
||||||
|
#endif
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,45 +324,44 @@ static void reboot_signal(int sig)
|
|||||||
{
|
{
|
||||||
shutdown_system();
|
shutdown_system();
|
||||||
message(console, "Please stand by while rebooting the system.\r\n");
|
message(console, "Please stand by while rebooting the system.\r\n");
|
||||||
|
#ifndef DEBUG_INIT
|
||||||
reboot(RB_AUTOBOOT);
|
reboot(RB_AUTOBOOT);
|
||||||
|
#endif
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
extern int init_main(int argc, char **argv)
|
extern int init_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int run_rc = TRUE;
|
int run_rc = TRUE;
|
||||||
|
int wait_for_enter = FALSE;
|
||||||
pid_t pid1 = 0;
|
pid_t pid1 = 0;
|
||||||
pid_t pid2 = 0;
|
pid_t pid2 = 0;
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
const char* const swap_on_cmd[] = { "/bin/swapon", " -a ", 0};
|
const char* const swap_on_cmd[] = { "/bin/swapon", "swapon", "-a", 0};
|
||||||
const char* const init_commands[] = { SHELL, " -c", " exec ", INITSCRIPT, 0};
|
const char* const init_commands[] = { INITSCRIPT, INITSCRIPT, 0};
|
||||||
const char* const shell_commands[] = { SHELL, " -", 0};
|
const char* const shell_commands[] = { SHELL, "-" SHELL, 0};
|
||||||
const char* const* tty0_commands = init_commands;
|
const char* const* tty0_commands = init_commands;
|
||||||
const char* const* tty1_commands = shell_commands;
|
const char* const* tty1_commands = shell_commands;
|
||||||
#ifndef DEBUG_INIT
|
#ifdef DEBUG_INIT
|
||||||
char *hello_msg_format =
|
|
||||||
"init started: BusyBox v%s (%s) multi-call binary\r\n";
|
|
||||||
#else
|
|
||||||
char *hello_msg_format =
|
char *hello_msg_format =
|
||||||
"init(%d) started: BusyBox v%s (%s) multi-call binary\r\n";
|
"init(%d) started: BusyBox v%s (%s) multi-call binary\r\n";
|
||||||
|
#else
|
||||||
|
char *hello_msg_format =
|
||||||
|
"init started: BusyBox v%s (%s) multi-call binary\r\n";
|
||||||
#endif
|
#endif
|
||||||
const char *no_memory =
|
const char *no_memory =
|
||||||
"Sorry, your computer does not have enough memory.\r\n";
|
"Sorry, your computer does not have enough memory.\r\n";
|
||||||
|
|
||||||
#ifndef DEBUG_INIT
|
/* Set up sig handlers -- be sure to
|
||||||
/* Set up sig handlers */
|
* clear all of these in run() */
|
||||||
signal(SIGUSR1, halt_signal);
|
signal(SIGUSR1, halt_signal);
|
||||||
signal(SIGSEGV, halt_signal);
|
|
||||||
signal(SIGPWR, halt_signal);
|
|
||||||
signal(SIGALRM, halt_signal);
|
|
||||||
signal(SIGHUP, halt_signal);
|
|
||||||
signal(SIGUSR2, reboot_signal);
|
signal(SIGUSR2, reboot_signal);
|
||||||
signal(SIGINT, reboot_signal);
|
signal(SIGINT, reboot_signal);
|
||||||
signal(SIGTERM, reboot_signal);
|
signal(SIGTERM, reboot_signal);
|
||||||
|
|
||||||
/* Turn off rebooting via CTL-ALT-DEL -- we get a
|
/* Turn off rebooting via CTL-ALT-DEL -- we get a
|
||||||
* SIGINT on CAD so we can shut things down gracefully... */
|
* SIGINT on CAD so we can shut things down gracefully... */
|
||||||
|
#ifndef DEBUG_INIT
|
||||||
reboot(RB_DISABLE_CAD);
|
reboot(RB_DISABLE_CAD);
|
||||||
#endif
|
#endif
|
||||||
/* Figure out where the default console should be */
|
/* Figure out where the default console should be */
|
||||||
@ -383,7 +389,7 @@ extern int init_main(int argc, char **argv)
|
|||||||
|
|
||||||
|
|
||||||
/* Mount /proc */
|
/* Mount /proc */
|
||||||
if (mount("/proc", "/proc", "proc", 0, 0) == 0) {
|
if (mount ("proc", "/proc", "proc", 0, 0) == 0) {
|
||||||
message(log, "Mounting /proc: done.\n");
|
message(log, "Mounting /proc: done.\n");
|
||||||
message(console, "Mounting /proc: done.\n");
|
message(console, "Mounting /proc: done.\n");
|
||||||
} else {
|
} else {
|
||||||
@ -403,7 +409,7 @@ extern int init_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Try to turn on swap */
|
/* Try to turn on swap */
|
||||||
waitfor(run(swap_on_cmd, console, 0));
|
waitfor(run(swap_on_cmd, log, FALSE));
|
||||||
if (mem_total() < 2000) {
|
if (mem_total() < 2000) {
|
||||||
message(console, "%s", no_memory);
|
message(console, "%s", no_memory);
|
||||||
while (1) {
|
while (1) {
|
||||||
@ -417,12 +423,14 @@ extern int init_main(int argc, char **argv)
|
|||||||
if ( argc > 1 && (!strcmp(argv[1], "single") ||
|
if ( argc > 1 && (!strcmp(argv[1], "single") ||
|
||||||
!strcmp(argv[1], "-s") || !strcmp(argv[1], "1"))) {
|
!strcmp(argv[1], "-s") || !strcmp(argv[1], "1"))) {
|
||||||
run_rc = FALSE;
|
run_rc = FALSE;
|
||||||
|
wait_for_enter = TRUE;
|
||||||
tty0_commands = shell_commands;
|
tty0_commands = shell_commands;
|
||||||
tty1_commands = shell_commands;
|
tty1_commands = shell_commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make sure an init script exists before trying to run it */
|
/* Make sure an init script exists before trying to run it */
|
||||||
if (run_rc == TRUE && stat(INITSCRIPT, &statbuf)) {
|
if (run_rc == TRUE && stat(INITSCRIPT, &statbuf)) {
|
||||||
|
wait_for_enter = TRUE;
|
||||||
tty0_commands = shell_commands;
|
tty0_commands = shell_commands;
|
||||||
tty1_commands = shell_commands;
|
tty1_commands = shell_commands;
|
||||||
}
|
}
|
||||||
@ -435,10 +443,10 @@ extern int init_main(int argc, char **argv)
|
|||||||
int status;
|
int status;
|
||||||
|
|
||||||
if (pid1 == 0 && tty0_commands) {
|
if (pid1 == 0 && tty0_commands) {
|
||||||
pid1 = run(tty0_commands, console, 1);
|
pid1 = run(tty0_commands, console, wait_for_enter);
|
||||||
}
|
}
|
||||||
if (pid2 == 0 && tty1_commands) {
|
if (pid2 == 0 && tty1_commands) {
|
||||||
pid2 = run(tty1_commands, second_terminal, 1);
|
pid2 = run(tty1_commands, second_terminal, TRUE);
|
||||||
}
|
}
|
||||||
wpid = wait(&status);
|
wpid = wait(&status);
|
||||||
if (wpid > 0 ) {
|
if (wpid > 0 ) {
|
||||||
|
@ -60,7 +60,7 @@ get_kernel_revision()
|
|||||||
|
|
||||||
file = fopen(filename,"r");
|
file = fopen(filename,"r");
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
perror(filename);
|
/* bummer, /proc must not be mounted... */
|
||||||
return( 0);
|
return( 0);
|
||||||
}
|
}
|
||||||
fscanf(file,"%d.%d.%d",&major,&minor,&patch);
|
fscanf(file,"%d.%d.%d",&major,&minor,&patch);
|
||||||
|
Loading…
Reference in New Issue
Block a user