Browse Source

Exit compositor when last client exits

K. Lange 2 years ago
parent
commit
b524630bec
4 changed files with 28 additions and 6 deletions
  1. 5 0
      apps/compositor.c
  2. 2 0
      apps/glogin.c
  3. 16 6
      apps/live-session.c
  4. 5 0
      apps/login.c

+ 5 - 0
apps/compositor.c

@@ -2128,6 +2128,11 @@ int main(int argc, char * argv[]) {
 				free(client_list);
 			}
 
+			if (hashmap_is_empty(yg->clients_to_windows)) {
+				TRACE("Last compositor client disconnected, exiting.");
+				return 0;
+			}
+
 			free(p);
 			continue;
 		}

+ 2 - 0
apps/glogin.c

@@ -17,6 +17,7 @@
 
 #include <sys/wait.h>
 
+#include <toaru/yutani.h>
 #include <toaru/auth.h>
 #include <toaru/trace.h>
 #define TRACE_APP_NAME "glogin"
@@ -28,6 +29,7 @@ int main (int argc, char ** argv) {
 
 	/* Ensure a somewhat sane environment going in */
 	TRACE("Graphical login starting.");
+	yutani_init();
 
 	setenv("USER", "root", 1);
 	setenv("HOME", "/", 1);

+ 16 - 6
apps/live-session.c

@@ -5,10 +5,13 @@
 #include <errno.h>
 #include <sys/wait.h>
 #include <toaru/auth.h>
+#include <toaru/yutani.h>
 #include <toaru/trace.h>
 #define TRACE_APP_NAME "live-session"
 
 int main(int argc, char * argv[]) {
+	int pid;
+
 	if (getuid() != 0) {
 		return 1;
 	}
@@ -24,18 +27,25 @@ int main(int argc, char * argv[]) {
 		return 1;
 	}
 
-	int pid = 0;
+	/* Dummy session for live-session prevents compositor from killing itself
+	 * when the main session dies the first time. */
+	yutani_init();
+
 	do {
 		pid = wait(NULL);
 	} while ((pid > 0 && pid != _session_pid) || (pid == -1 && errno == EINTR));
 
 	TRACE("Live session has ended, launching graphical login.");
-	char * args[] = {"/bin/glogin",NULL};
-	execvp(args[0],args);
-
-	TRACE("failed to start glogin after log out, trying to reboot instead.");
-	system("reboot");
+	int _glogin_pid = fork();
+	if (!_glogin_pid) {
+		char * args[] = {"/bin/glogin",NULL};
+		execvp(args[0],args);
+		system("reboot");
+	}
 
+	do {
+		pid = wait(NULL);
+	} while ((pid > 0 && pid != _glogin_pid) || (pid == -1 && errno == EINTR));
 
 	return 0;
 }

+ 5 - 0
apps/login.c

@@ -74,6 +74,11 @@ int main(int argc, char ** argv) {
 		}
 		username[strlen(username)-1] = '\0';
 
+		if (!strcmp(username, "reboot")) {
+			/* Quick hack so vga text mode login can exit */
+			system("reboot");
+		}
+
 		fprintf(stdout, "password: ");
 		fflush(stdout);