#define DEBUG_INIT
*/
-#include "busybox.h"
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/mount.h>
#include <sys/types.h>
#include <sys/wait.h>
+#include "busybox.h"
+#define bb_need_full_version
+#define BB_DECLARE_EXTERN
+#include "messages.c"
#ifdef BB_SYSLOGD
# include <sys/syslog.h>
#endif
-#define bb_need_full_version
-#define BB_DECLARE_EXTERN
-#include "messages.c"
/* From <linux/vt.h> */
struct vt_stat {
#define INIT_SCRIPT "/etc/init.d/rcS" /* Default sysinit script. */
#endif
+#define MAXENV 16 /* Number of env. vars */
+//static const int MAXENV = 16; /* Number of env. vars */
static const int LOG = 0x1;
static const int CONSOLE = 0x2;
va_start(arguments, fmt);
vsnprintf(msg, sizeof(msg), fmt, arguments);
va_end(arguments);
- openlog("init", 0, LOG_USER);
+ openlog(applet_name, 0, LOG_USER);
syslog(LOG_USER|LOG_INFO, msg);
closelog();
}
} else if ((log_fd = device_open(log, O_RDWR|O_NDELAY)) < 0) {
log_fd = -2;
fprintf(stderr, "Bummer, can't write to log on %s!\r\n", log);
- fflush(stderr);
log = NULL;
device = CONSOLE;
}
fprintf(stderr, "Bummer, can't print: ");
va_start(arguments, fmt);
vfprintf(stderr, fmt, arguments);
- fflush(stderr);
va_end(arguments);
}
}
unsigned int result, u, s=10;
if (sysinfo(&info) != 0) {
- perror_msg("Error checking free memory: ");
+ perror_msg("Error checking free memory");
return -1;
}
static pid_t run(char *command, char *terminal, int get_enter)
{
- int i, fd;
+ int i=0, j=0;
+ int fd;
pid_t pid;
char *tmpCmd;
char *cmd[255], *cmdpath;
#endif
"\nPlease press Enter to activate this console. ";
- char *environment[] = {
+ char *environment[MAXENV+1] = {
"HOME=/",
"PATH=/usr/bin:/bin:/usr/sbin:/sbin",
"SHELL=/bin/sh",
termType,
- "USER=root",
- 0
+ "USER=root"
};
+ while (environment[i]) i++;
+ while ((environ[j]) && (i < MAXENV)) {
+ if (strncmp(environ[j], "TERM=", 5))
+ environment[i++] = environ[j];
+ j++;
+ }
+
if ((pid = fork()) == 0) {
/* Clean up */
ioctl(0, TIOCNOTTY, 0);
* specifies.
*/
#ifdef DEBUG_INIT
- pid_t shell_pgid = getpid();
message(LOG, "Waiting for enter to start '%s' (pid %d, console %s)\r\n",
- command, shell_pgid, terminal);
+ command, getpid(), terminal);
#endif
write(fileno(stdout), press_enter, sizeof(press_enter) - 1);
getc(stdin);
#ifdef DEBUG_INIT
/* Log the process name and args */
message(LOG, "Starting pid %d, console %s: '%s'\r\n",
- shell_pgid, terminal, command);
+ getpid(), terminal, command);
#endif
/* See if any special /bin/sh requiring characters are present */
exit(0);
}
-#if defined BB_FEATURE_INIT_CHROOT
-
-#warning BB_FEATURE_INIT_CHROOT is out of date and should be rewritten to us
-#warning pivot root instead. Do not even bother till this work is done...
-#warning You have been warned.
-
-#if ! defined BB_FEATURE_USE_PROCFS
-#error Sorry, I depend on the /proc filesystem right now.
-#endif
-
-static void check_chroot(int sig)
-{
- char *argv_init[2] = { "init", NULL, };
- char *envp_init[3] = { "HOME=/", "TERM=linux", NULL, };
- char rootpath[256], *tc;
- int fd;
-
- if ((fd = open("/proc/sys/kernel/init-chroot", O_RDONLY)) == -1) {
- message(CONSOLE,
- "SIGHUP recived, but could not open proc file\r\n");
- sleep(2);
- return;
- }
- if (read(fd, rootpath, sizeof(rootpath)) == -1) {
- message(CONSOLE,
- "SIGHUP recived, but could not read proc file\r\n");
- sleep(2);
- return;
- }
- close(fd);
-
- if (rootpath[0] == '\0') {
- message(CONSOLE,
- "SIGHUP recived, but new root is not valid: %s\r\n",
- rootpath);
- sleep(2);
- return;
- }
-
- tc = strrchr(rootpath, '\n');
- *tc = '\0';
-
- /* Ok, making it this far means we commit */
- message(CONSOLE, "Please stand by, changing root to `%s'.\r\n",
- rootpath);
-
- /* kill all other programs first */
- message(CONSOLE, "Sending SIGTERM to all processes.\r\n");
- kill(-1, SIGTERM);
- sleep(2);
- sync();
-
- message(CONSOLE, "Sending SIGKILL to all processes.\r\n");
- kill(-1, SIGKILL);
- sleep(2);
- sync();
-
- /* ok, we don't need /proc anymore. we also assume that the signaling
- * process left the rest of the filesystems alone for us */
- umount("/proc");
-
- /* Ok, now we chroot. Hopefully we only have two things mounted, the
- * new chroot'd mount point, and the old "/" mount. s,
- * we go ahead and unmount the old "/". This should trigger the kernel
- * to set things up the Right Way(tm). */
-
- if (!chroot(rootpath))
- umount("/dev/root");
-
- /* If the chroot fails, we are already too far to turn back, so we
- * continue and hope that executing init below will revive the system */
-
- /* close all of our descriptors and open new ones */
- close(0);
- close(1);
- close(2);
- open("/dev/console", O_RDWR, 0);
- dup(0);
- dup(0);
-
- message(CONSOLE, "Executing real init...\r\n");
- /* execute init in the (hopefully) new root */
- execve("/sbin/init", argv_init, envp_init);
-
- message(CONSOLE,
- "ERROR: Could not exec new init. Press %s to reboot.\r\n",
- (secondConsole == NULL) /* serial console */
- ? "Reset" : "CTRL-ALT-DEL");
- return;
-}
-#endif /* BB_FEATURE_INIT_CHROOT */
-
#endif /* ! DEBUG_INIT */
void new_initAction(initActionEnum action, char *process, char *cons)
#endif
)
{
- usage("init\n\nInit is the parent of all processes.\n\n"
- "This version of init is designed to be run only "
- "by the kernel.\n");
+ show_usage();
}
/* Set up sig handlers -- be sure to
* clear all of these in run() */
signal(SIGUSR2, halt_signal);
signal(SIGINT, reboot_signal);
signal(SIGTERM, reboot_signal);
-#if defined BB_FEATURE_INIT_CHROOT
- signal(SIGHUP, check_chroot);
-#endif
/* Turn off rebooting via CTL-ALT-DEL -- we get a
* SIGINT on CAD so we can shut things down gracefully... */
argv[0]="init";
if (argc > 1)
- strncpy(argv[1], "\0", strlen(argv[1])+1);
+ argv[1][0]=0;
/* Now run everything that needs to be run */