#include "init_shared.h"
-#ifdef CONFIG_SYSLOGD
+#if ENABLE_SYSLOGD
# include <sys/syslog.h>
#endif
#define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin"
#endif
-#if defined CONFIG_FEATURE_INIT_COREDUMPS
+#if ENABLE_FEATURE_INIT_COREDUMPS
/*
* When a file named CORE_ENABLE_FLAG_FILE exists, setrlimit is called
* before processes are spawned to set core file size as unlimited.
static struct init_action *init_action_list = NULL;
static char console[CONSOLE_BUFF_SIZE] = CONSOLE_DEV;
-#ifndef CONFIG_SYSLOGD
+#if !ENABLE_SYSLOGD
static char *log_console = VC_5;
#endif
#if !ENABLE_DEBUG_INIT
LOG = 0x1,
CONSOLE = 0x2,
-#if defined CONFIG_FEATURE_EXTRA_QUIET
+#if ENABLE_FEATURE_EXTRA_QUIET
MAYBE_CONSOLE = 0x0,
#else
MAYBE_CONSOLE = CONSOLE,
static void shutdown_signal(int sig);
#endif
+#if !ENABLE_DEBUG_INIT
static void loop_forever(void)
{
while (1)
sleep(1);
}
+#endif
/* Print a message to the specified device.
* Device may be bitwise-or'd from LOG | CONSOLE */
va_list arguments;
int l;
RESERVE_CONFIG_BUFFER(msg, 1024);
-#ifndef CONFIG_SYSLOGD
+#if !ENABLE_SYSLOGD
static int log_fd = -1;
#endif
l = vsnprintf(msg + 1, 1024 - 2, fmt, arguments) + 1;
va_end(arguments);
-#ifdef CONFIG_SYSLOGD
+#if ENABLE_SYSLOGD
/* Log the message to syslogd */
if (device & LOG) {
/* don`t out "\r\n" */
}
if (fd < 0) {
/* Perhaps we should panic here? */
-#ifndef CONFIG_SYSLOGD
+#if !ENABLE_SYSLOGD
log_console =
#endif
safe_strncpy(console, bb_dev_null, sizeof(console));
* if TERM is set to linux (the default) */
if (s == NULL || strcmp(s, "linux") == 0)
putenv("TERM=vt102");
-#ifndef CONFIG_SYSLOGD
+#if !ENABLE_SYSLOGD
log_console = console;
#endif
} else {
cmd[0][0] = '-';
strcpy(cmd[0] + 1, s);
}
-#ifdef CONFIG_FEATURE_INIT_SCTTY
+#if ENABLE_FEATURE_INIT_SCTTY
/* Establish this process as session leader and
* (attempt) to make the tty (if any) a controlling tty.
*/
message(LOG, "Starting pid %d, console %s: '%s'",
getpid(), a->terminal, cmdpath);
-#if defined CONFIG_FEATURE_INIT_COREDUMPS
+#if ENABLE_FEATURE_INIT_COREDUMPS
{
struct stat sb;
if (stat(CORE_ENABLE_FLAG_FILE, &sb) == 0) {
/* We have to fork here, since the kernel calls do_exit(0) in
* linux/kernel/sys.c, which can cause the machine to panic when
* the init process is killed.... */
- if ((pid = fork()) == 0) {
+ pid = vfork();
+ if (pid == 0) { /* child */
reboot(magic);
_exit(0);
}
- waitpid (pid, NULL, 0);
+ waitpid(pid, NULL, 0);
}
static void shutdown_system(void)
sleep(2);
init_reboot(rb);
-
loop_forever();
}
if (strcmp(cons, bb_dev_null) == 0 && (action & ASKFIRST))
return;
- new_action = calloc((size_t) (1), sizeof(struct init_action));
- if (!new_action) {
- message(LOG | CONSOLE, "Memory allocation failure");
- loop_forever();
- }
+ new_action = xzalloc(sizeof(struct init_action));
/* Append to the end of the list */
for (a = last = init_action_list; a; a = a->next) {
*/
static void parse_inittab(void)
{
-#ifdef CONFIG_FEATURE_USE_INITTAB
+#if ENABLE_FEATURE_USE_INITTAB
FILE *file;
char buf[INIT_BUFFS_SIZE], lineAsRead[INIT_BUFFS_SIZE];
char tmpConsole[CONSOLE_BUFF_SIZE];
new_init_action(SYSINIT, INIT_SCRIPT, "");
return;
-#ifdef CONFIG_FEATURE_USE_INITTAB
+#if ENABLE_FEATURE_USE_INITTAB
}
while (fgets(buf, INIT_BUFFS_SIZE, file) != NULL) {
}
fclose(file);
return;
-#endif /* CONFIG_FEATURE_USE_INITTAB */
+#endif /* FEATURE_USE_INITTAB */
}
-#ifdef CONFIG_FEATURE_USE_INITTAB
+#if ENABLE_FEATURE_USE_INITTAB
static void reload_signal(int sig ATTRIBUTE_UNUSED)
{
struct init_action *a, *tmp;
run_actions(RESPAWN);
return;
}
-#endif /* CONFIG_FEATURE_USE_INITTAB */
+#endif /* FEATURE_USE_INITTAB */
int init_main(int argc, char **argv)
{
struct init_action *a;
pid_t wpid;
+ die_sleep = 30 * 24*60*60; /* if xmalloc will ever die... */
+
if (argc > 1 && !strcmp(argv[1], "-q")) {
return kill(1,SIGHUP);
}
parse_inittab();
}
-#ifdef CONFIG_SELINUX
+#if ENABLE_SELINUX
if (getenv("SELINUX_INIT") == NULL) {
int enforce = 0;
/* Next run anything to be run only once */
run_actions(ONCE);
-#ifdef CONFIG_FEATURE_USE_INITTAB
+#if ENABLE_FEATURE_USE_INITTAB
/* Redefine SIGHUP to reread /etc/inittab */
signal(SIGHUP, reload_signal);
#else
signal(SIGHUP, SIG_IGN);
-#endif /* CONFIG_FEATURE_USE_INITTAB */
+#endif /* FEATURE_USE_INITTAB */
/* Now run the looping stuff for the rest of forever */