BarryServer : Git

All the code for all my projects
// BarryServer : Git / OrionUserland / commit / 19aefaad8af9de8719ba1e5b5340e0a1b9c68853 / init

// Related

OrionUserland

Barry Importing existing Orion Userland 19aefaa (2 years, 4 months ago)
diff --git a/init/Makefile b/init/Makefile
new file mode 100644
index 0000000..5254c7c
--- /dev/null
+++ b/init/Makefile
@@ -0,0 +1,46 @@
+PRODUCT=$(notdir $(abspath $(CURDIR)))
+
+CC=i686-orion-gcc
+CFLAGS=
+
+AS=i686-orion-as
+AFLAGS=
+
+LD=i686-orion-gcc
+LFLAGS=
+
+AS_SOURCES := $(shell find . -name '*.S')
+OBJS = $(sort $(subst ./,build/,$(subst .S,.o,$(AS_SOURCES))))
+
+C_SOURCES := $(shell find . -name '*.c')
+OBJS += $(sort $(subst ./,build/,$(subst .c,.o,$(C_SOURCES))))
+
+.PHONY: clean all install
+
+all: $(PRODUCT)
+
+clean:
+	@echo "REMOVING OBJECT FILES"
+	@mkdir -p build
+	@rm -rf build
+	@touch $(PRODUCT)
+	@rm $(PRODUCT)
+
+install: $(PRODUCT)
+	@echo "INSTALLING $^"
+	@mkdir -p ${SYSROOT}/bin/
+	@install -Dm 755 $(PRODUCT) -t ${SYSROOT}/bin/
+
+$(PRODUCT): $(OBJS)
+	@echo "LINKING $@"
+	@$(LD) -o $@ $^ $(LFLAGS)
+
+build/%.o: %.c
+	@echo "COMPILING $<"
+	@mkdir -p $(@D)
+	@$(CC) -c $< -o $@ $(CFLAGS)
+
+build/%.o: %.S
+	@echo "ASSEMBLING $<"
+	@mkdir -p $(@D)
+	@$(AS) $< -o $@ $(AFLAGS)
diff --git a/init/init b/init/init
new file mode 100755
index 0000000..5b641ac
Binary files /dev/null and b/init/init differ
diff --git a/init/main.c b/init/main.c
new file mode 100644
index 0000000..0eb2b3b
--- /dev/null
+++ b/init/main.c
@@ -0,0 +1,42 @@
+#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");
+		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 */
+	}
+}