コード例 #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
static void reload_inittab(void)
{
	/* Save the old pid table */
	unsigned int size = sizeof(struct initpid) * initcount;
	struct initpid *p = (struct initpid *)membase;
	uint16_t i;

	memmove(membase, initpid, size);
	/* Throw everything else out */
	brk_warn(membase + size);
	/* Save the old pointer and size */
	oldpid = p;
	oldcount = initcount;
	/* Load the new table */
	load_inittab();
	parse_inittab();
	/* We now have the new initspaces all set up and the pointers
	   are valid. We have the old initpid table at membase and we
	   saved the old length in count. We can now transcribe the
	   pid entries and kill off anyone who doesn't belong */
	/* FIXME: we don't kill and restart an entry that has changed but
	   will respawn the new form. There isn't an easy way to fix that
	   without further major reworking */
	for (i = 0; i < oldcount; i++) {
		struct initpid *n = find_id(p->id);
		if (n == NULL && p->pid) {
			/* Deleted line - kill the process group */
			kill(-p->pid, SIGHUP);
			sleep(5);
			kill(-p->pid, SIGKILL);
		} else {
			n->pid = p->pid;
		}
	}
	/* We could shuffle all the pointers back down and free the old
	   pid table, but there is no point. If we do a further reload
	   we will move the current pid table right down and all will
	   be just as good */
}