live-session.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 <signal.h>
  15. #include <errno.h>
  16. #include <sys/wait.h>
  17. #include <toaru/auth.h>
  18. #include <toaru/yutani.h>
  19. #include <toaru/trace.h>
  20. #define TRACE_APP_NAME "live-session"
  21. int main(int argc, char * argv[]) {
  22. int pid;
  23. if (getuid() != 0) {
  24. return 1;
  25. }
  26. int _session_pid = fork();
  27. if (!_session_pid) {
  28. setuid(1000);
  29. toaru_auth_set_vars();
  30. char * args[] = {"/bin/session", NULL};
  31. execvp(args[0], args);
  32. return 1;
  33. }
  34. /* Dummy session for live-session prevents compositor from killing itself
  35. * when the main session dies the first time. */
  36. yutani_init();
  37. do {
  38. pid = wait(NULL);
  39. } while ((pid > 0 && pid != _session_pid) || (pid == -1 && errno == EINTR));
  40. TRACE("Live session has ended, launching graphical login.");
  41. int _glogin_pid = fork();
  42. if (!_glogin_pid) {
  43. char * args[] = {"/bin/glogin",NULL};
  44. execvp(args[0],args);
  45. system("reboot");
  46. }
  47. do {
  48. pid = wait(NULL);
  49. } while ((pid > 0 && pid != _glogin_pid) || (pid == -1 && errno == EINTR));
  50. return 0;
  51. }