live-session.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* vim: tabstop=4 shiftwidth=4 noexpandtab
  2. * This file is part of ToaruOS and is released under the terms
  3. * of the NCSA / University of Illinois License - see LICENSE.md
  4. * Copyright (C) 2018 K. Lange
  5. *
  6. * live-session - Run live CD user session.
  7. *
  8. * Launches the general session manager as 'local', waits for the
  9. * session to end, then launches the login manager.
  10. */
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13. #include <unistd.h>
  14. #include <errno.h>
  15. #include <sys/wait.h>
  16. #include <toaru/auth.h>
  17. #include <toaru/yutani.h>
  18. #include <toaru/trace.h>
  19. #define TRACE_APP_NAME "live-session"
  20. int main(int argc, char * argv[]) {
  21. int pid;
  22. if (geteuid() != 0) {
  23. return 1;
  24. }
  25. int _session_pid = fork();
  26. if (!_session_pid) {
  27. setuid(1000);
  28. toaru_auth_set_vars();
  29. char * args[] = {"/bin/session", NULL};
  30. execvp(args[0], args);
  31. return 1;
  32. }
  33. /* Dummy session for live-session prevents compositor from killing itself
  34. * when the main session dies the first time. */
  35. yutani_init();
  36. do {
  37. pid = wait(NULL);
  38. } while ((pid > 0 && pid != _session_pid) || (pid == -1 && errno == EINTR));
  39. TRACE("Live session has ended, launching graphical login.");
  40. int _glogin_pid = fork();
  41. if (!_glogin_pid) {
  42. char * args[] = {"/bin/glogin",NULL};
  43. execvp(args[0],args);
  44. system("reboot");
  45. }
  46. do {
  47. pid = wait(NULL);
  48. } while ((pid > 0 && pid != _glogin_pid) || (pid == -1 && errno == EINTR));
  49. return 0;
  50. }