From fd42d99803bd856c977e6fb3db6a4b12612ad6b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Fri, 4 Jul 2014 18:49:49 +0200 Subject: [PATCH] dispvm: close all windows after apps prerun (#872) Killing Xorg makes "unclean" termination of applications. Some apps (Firefox) complains about that at next startup. --- Makefile | 1 + misc/.gitignore | 1 + misc/Makefile | 4 +++- misc/close-window.c | 31 +++++++++++++++++++++++++++++++ misc/dispvm-prerun.sh | 4 ++++ rpm_spec/core-vm.spec | 1 + 6 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 misc/close-window.c diff --git a/Makefile b/Makefile index 9bc8ed8..3317043 100644 --- a/Makefile +++ b/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 diff --git a/misc/.gitignore b/misc/.gitignore index b87d6e1..b84ccbc 100644 --- a/misc/.gitignore +++ b/misc/.gitignore @@ -1,2 +1,3 @@ meminfo-writer xenstore-watch +close-window diff --git a/misc/Makefile b/misc/Makefile index 418c0fb..c9376ce 100644 --- a/misc/Makefile +++ b/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 . diff --git a/misc/close-window.c b/misc/close-window.c new file mode 100644 index 0000000..071527c --- /dev/null +++ b/misc/close-window.c @@ -0,0 +1,31 @@ +#include +#include +#include +#include + +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 /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 diff --git a/rpm_spec/core-vm.spec b/rpm_spec/core-vm.spec index e32c9e8..99394d9 100644 --- a/rpm_spec/core-vm.spec +++ b/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