Browse Source

dispvm: close all windows after apps prerun (#872)

Killing Xorg makes "unclean" termination of applications. Some apps
(Firefox) complains about that at next startup.
Marek Marczykowski-Górecki 9 years ago
parent
commit
fd42d99803
6 changed files with 41 additions and 1 deletions
  1. 1 0
      Makefile
  2. 1 0
      misc/.gitignore
  3. 3 1
      misc/Makefile
  4. 31 0
      misc/close-window.c
  5. 4 0
      misc/dispvm-prerun.sh
  6. 1 0
      rpm_spec/core-vm.spec

+ 1 - 0
Makefile

@@ -64,6 +64,7 @@ install-vm:
 	install -d $(DESTDIR)/usr/lib/yum-plugins/
 	install -m 0644 misc/yum-qubes-hooks.py* $(DESTDIR)/usr/lib/yum-plugins/
 	install -D -m 0644 misc/yum-qubes-hooks.conf $(DESTDIR)/etc/yum/pluginconf.d/yum-qubes-hooks.conf
+	install -D misc/close-window $(DESTDIR)/usr/lib/qubes/close-window
 
 	install -d $(DESTDIR)/var/lib/qubes
 

+ 1 - 0
misc/.gitignore

@@ -1,2 +1,3 @@
 meminfo-writer
 xenstore-watch
+close-window

+ 3 - 1
misc/Makefile

@@ -1,8 +1,10 @@
 CC=gcc
 CFLAGS=-Wall -Wextra -Werror -g -O3
-all:	xenstore-watch python
+all:	xenstore-watch python close-window
 xenstore-watch: xenstore-watch.o
 	$(CC) -o xenstore-watch xenstore-watch.o -lxenstore
+close-window: close-window.c
+	$(CC) -lX11 -o $@ $<
 python:
 	python -m compileall .
 	python -O -m compileall .

+ 31 - 0
misc/close-window.c

@@ -0,0 +1,31 @@
+#include <X11/Xutil.h>
+#include <X11/Xlib.h>
+#include <string.h>
+#include <stdlib.h>
+
+int close_window(Display *d, XID window) {
+	XClientMessageEvent ev;
+	memset(&ev, 0, sizeof(ev));
+	ev.type = ClientMessage;
+	ev.display = d;
+	ev.window = window;
+	ev.format = 32;
+	ev.message_type = XInternAtom(d, "WM_PROTOCOLS", False);
+	ev.data.l[0] = XInternAtom(d, "WM_DELETE_WINDOW", False);;
+	return XSendEvent(ev.display, ev.window, True, 0, (XEvent *) & ev);
+}
+
+int main(int argc, char **argv) {
+	int i;
+	Display *d;
+
+	d = XOpenDisplay(NULL);
+	if (!d)
+		exit(1);
+	for (i=1; i<argc; i++) {
+		close_window(d, strtoul(argv[i], NULL, 0));
+	}
+	XSync(d, False);
+	XCloseDisplay(d);
+	return 0;
+}

+ 4 - 0
misc/dispvm-prerun.sh

@@ -27,6 +27,10 @@ done
 
 ps ax > /tmp/dispvm-prerun-proclist.log
 
+echo "Closing windows..."
+/usr/lib/qubes/close-window `xwininfo -root -children|tail -n +7 |awk '{print $1}'`
+sleep 1
+
 if [ -e /rw/home/user/.qubes-dispvm-customized ]; then
 	cp -af /rw/home/user /home/
 else

+ 1 - 0
rpm_spec/core-vm.spec

@@ -373,6 +373,7 @@ rm -f %{name}-%{version}
 /usr/lib/qubes/vm-file-editor
 /usr/lib/qubes/wrap-in-html-if-url.sh
 /usr/lib/qubes/iptables-yum-proxy
+/usr/lib/qubes/close-window
 /usr/lib/yum-plugins/yum-qubes-hooks.py*
 /usr/sbin/qubes-firewall
 /usr/sbin/qubes-netwatcher