コード例 #1
0
ファイル: init.c プロジェクト: aralbrec/FUZIX
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));

	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) {
				exit_runlevel(1 << runlevel, 1 << newrl);
				runlevel = newrl;
				enter_runlevel(1 << runlevel);
			}
			close(fd);
			dingdong = 0;
		}
	}
}
コード例 #2
0
ファイル: init.c プロジェクト: nori6001/FUZIX
/*
 *	Clear up the tasks that should not be running. Start with a HUP then
 *	probe them allowing up to 45 seconds, after which we send SIGKILL
 */
static void exit_runlevel(uint8_t oldmask, uint8_t newmask)
{
	uint8_t n = 0;
	if (cleanup_runlevel(oldmask, newmask, SIGHUP)) {
		while (n++ < 9) {
			sleep(5);
			clear_zombies(WNOHANG);
			if (cleanup_runlevel(oldmask, newmask, 0) == 0)
				return;
		}
		cleanup_runlevel(oldmask, newmask, SIGKILL);
	}
}