init.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/mount.h>
  5. #include <sys/stat.h>
  6. #include <sys/wait.h>
  7. #include <fcntl.h>
  8. int main() {
  9. // Mount essential filesystems
  10. mkdir("/dev", 0755);
  11. mkdir("/proc", 0755);
  12. mkdir("/sys", 0755);
  13. mount("devtmpfs", "/dev", "devtmpfs", 0, NULL);
  14. mount("proc", "/proc", "proc", 0, NULL);
  15. mount("sysfs", "/sys", "sysfs", 0, NULL);
  16. // Set up standard file descriptors
  17. int fd = open("/dev/console", O_RDWR);
  18. if (fd >= 0) {
  19. dup2(fd, 0);
  20. dup2(fd, 1);
  21. dup2(fd, 2);
  22. if (fd > 2) close(fd);
  23. }
  24. printf("ArkOS C Init Wrapper: Environment mounted, launching Swift Splash...\n");
  25. // Launch the swift application
  26. pid_t pid = fork();
  27. if (pid == 0) {
  28. char *argv[] = { "/swift_splash", NULL };
  29. char *envp[] = { "PATH=/bin:/usr/bin:/sbin", NULL };
  30. execve("/swift_splash", argv, envp);
  31. printf("Execve failed!\n");
  32. exit(1);
  33. }
  34. // PID 1 must never exit
  35. int status;
  36. waitpid(pid, &status, 0);
  37. printf("Swift splash exited. Hanging system to prevent kernel panic...\n");
  38. while(1) sleep(1);
  39. return 0;
  40. }