Exemple #1
0
int main(int argc, char *argv[])
{
	int fdtty1;

	signal(SIGINT, SIG_IGN);
	signal(SIGUSR1, sigusr1);

	/* remove any stale /etc/mtab file */

	unlink("/etc/mtab");

	/* clean up anything handed to us by the kernel */
	close(0);
	close(1);
	close(2);

	/* loop until we can open the first terminal */

	do {
		fdtty1 = open("/dev/tty1", O_RDWR|O_NOCTTY);
	} while (fdtty1 < 0);

	/* make stdin, stdout and stderr point to /dev/tty1 */

	if (fdtty1 != 0)
		close(0);
	dup(fdtty1);
	close(1);
	dup(fdtty1);
	close(2);
	dup(fdtty1);

	putstr("init version 0.9.0ac#1\n");

	close(open("/var/run/utmp", O_WRONLY | O_CREAT | O_TRUNC));

	membase = sbrk(0);

	load_inittab();
	parse_inittab();

	boot_runlevel();

	for (;;) {
		clear_zombies(0);
		if (dingdong) {
			uint8_t newrl;
			int fd = open("/var/run/intctl", O_RDONLY);
			if (fd != -1 && read(fd, &newrl, 1) == 1) {
				if (newrl != 'q') {
					exit_runlevel(1 << runlevel, 1 << newrl);
					runlevel = newrl;
					enter_runlevel(1 << runlevel);
				} else {
					/* Reload */
					reload_inittab();
					/* Prune anything running that should
					   not in fact be there */
					exit_runlevel(255, 1 << runlevel);
					/* Start anything added to the current
					   run level */
					enter_runlevel(1 << runlevel);
				}
			}
			close(fd);
			dingdong = 0;
		}
	}
}
Exemple #2
0
int main(int argc, char *argv[])
{
	int 	i;
	struct sigaction sa;

	/*
	 * setup all the signal handlers here
	 */

	memset(&sa, 0, sizeof(sa));
	/* sa.sa_flags = SA_RESETHAND we want to keep the handlers armed */

	sa.sa_handler = tstp_handler;
	sigaction(SIGTSTP, &sa, NULL);

	sa.sa_handler = cont_handler;
	sigaction(SIGCONT, &sa, NULL);

	sa.sa_handler = int_handler;
	sigaction(SIGINT, &sa, NULL);

	sa.sa_handler = respawn_children;
	sigaction(SIGALRM, &sa, NULL);

	sa.sa_handler = hup_handler;
	sigaction(SIGHUP, &sa, NULL);

#if defined(CONSOLE_BAUD_RATE) && LINUX_VERSION_CODE < 0x020100
	set_console_baud(CONSOLE_BAUD_RATE);
#endif

	/* 
	 * start up in single user mode if /etc/singleboot exists or if
	 * argv[1] is "single".
	 */
	if(boot_single(0, argc, argv)) enter_single();
#ifdef CONFIG_RTL865X
	for(i = 1; i < argc; i++) {
	    if(argv[i] && !strcmp(argv[i], "uart1"))
			boot_uart1=1;;
	}
#endif
#ifdef RUN_RC
	/* Register console if defined by boot */
#if LINUX_VERSION_CODE < 0x020100
	if ((console_device = getenv("CONSOLE"))) {
	char	*sp;
		unsetenv("CONSOLE");
		if ((sp = strchr(console_device, ','))) {
			*sp++ = 0;
			set_console_baud(atoi(sp));
		}
	}

	make_ascii_tty();
#else
{
	struct stat st;

	if (isatty(1)) {
		have_console = 1;
		make_ascii_tty();
	} else if (fstat(1, &st) == -1 && errno == EBADF) {
		close(0); close(1); close(2);
		open("/dev/null", O_RDWR);
		dup(0);
		dup(0);
	}
}
#endif

	/*If we get a SIGTSTP before multi-user mode, do nothing*/
	while(stopped)	
		pause();
	if(do_rc() != 0 && boot_single(1, argc, argv) && !stopped)
		enter_single();
	while(stopped)	/*Also if /etc/rc fails & we get SIGTSTP*/
		pause();
#endif

	write_wtmp();	/* write boottime record */
	read_inittab();

#ifdef DEBUGGING
	for(i = 0; i < numcmd; i++) {
	char **p;
		p = inittab[i].toks;
		printf("toks= %s %s %s %s\n",p[0], p[1], p[2], p[3]);
		printf("tty= %s\n", inittab[i].tty);
		printf("termcap= %s\n", inittab[i].termcap);
	}
	/*exit(0);*/
#endif

#if LINUX_VERSION_CODE < 0x020100
	for(i = 0; i < getdtablesize(); i++) close(i);
#else
	i = 0;
	if (have_console)
		i = 3;
	for(; i < getdtablesize(); i++) close(i);
#endif

	for (;;) {
		pid_t	pid;
		int	vec;

		if (run_sigint_processing) {
			run_sigint_processing = 0;
			sigint_processing();
		}

		respawn_children();

		if (reload) {
			reload = 0;
			reload_inittab();
			continue; /* process all reloads before waiting */
		}

		pid = wait(&vec);
		alarm(0);

		/* clear utmp entry, and append to wtmp if possible */
#if 0		/* DAVIDM */
		{
		    struct utmp *ut;
		    int ut_fd;

		    utmpname(_PATH_UTMP);
		    setutent();
		    while((ut = getutent())) {
			if(ut->ut_pid == pid) {
			    time(&ut->ut_time);
			    bzero(&ut->ut_user, UT_NAMESIZE);
			    bzero(&ut->ut_host, sizeof(ut->ut_host));
			    ut->ut_type = DEAD_PROCESS;
			    ut->ut_pid = 0;
			    ut->ut_addr = 0;
			    endutent();
			    pututline(ut);
			    if((ut_fd = open(_PATH_WTMP, O_APPEND|O_WRONLY)) >= 0) {
				flock(ut_fd, LOCK_EX|LOCK_NB);
				write(ut_fd, (const void *)ut, sizeof(struct utmp));
				flock(ut_fd, LOCK_UN|LOCK_NB);
				close(ut_fd);
			    }
			    break;
			}
		    }
		    endutent();
		}
#endif

		for(i = 0; i < numcmd; i++) {
			if(pid == inittab[i].pid) {
				inittab[i].pid = -1;
			}
		}
	}

}