BarryServer : Git

All the code for all my projects
// BarryServer : Git / OrionUserland / blob / master / init / main.c

// Related

OrionUserland

Barry Using POSIX names in structs 2e11092 (2 years, 4 months ago)
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/wait.h>

/* Main function */
int
main(int argc, char *argv[])
{
	if (getpid() != 1) {
		printf("init will not run except as PID#1\n");
		abort();
	}

	dbgprintf("Starting init");

	/* Open standard descriptors */
	open("/dev/tty", O_RDONLY);
	open("/dev/tty", O_WRONLY);
	dup(1);

	printf("Welcome to \033[1;32mOrion\033[0m!\n");

	int status;
	pid_t child;
	while (1) {
		child = fork();
		if (!child) {
			char *v[] = { "login", NULL };
			int err = execve("/bin/login", v, NULL);
			if (err < 0) {
				printf("init: %s: ", "/bin/login");
				perror(NULL);
				while (1);
			}
		} else {
			waitpid(child, &status, 0);
		}
		printf("\033[H\033[2J"); /* Clear screen */
	}
}