[Spice-devel] [PATCH spice-streaming-agent v2 5/5] Provide helper to give information to daemon

Frediano Ziglio fziglio at redhat.com
Mon May 21 10:45:31 UTC 2018


This is required so the daemon can manage the various sessions.
The helper is launched every time a graphic session is started.
It sends information to the daemon on how to connect to the given
display server.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 data/spice-streaming.desktop.in |  3 +--
 spice-streaming-agent.spec.in   |  1 +
 src/Makefile.am                 |  6 +++++
 src/spice-streaming-helper      | 40 +++++++++++++++++++++++++++++++++
 4 files changed, 48 insertions(+), 2 deletions(-)
 create mode 100755 src/spice-streaming-helper

diff --git a/data/spice-streaming.desktop.in b/data/spice-streaming.desktop.in
index dcb30a3..5e4e863 100644
--- a/data/spice-streaming.desktop.in
+++ b/data/spice-streaming.desktop.in
@@ -1,8 +1,7 @@
 [Desktop Entry]
 Name=SPICE Streaming Agent
 Comment=Agent for Streaming the framebuffer to Spice
-Exec=@BINDIR@/spice-streaming-agent
-#TryExec=/usr/bin/spice-streaming-agent
+Exec=@BINDIR@/spice-streaming-helper
 Terminal=false
 Type=Application
 Categories=
diff --git a/spice-streaming-agent.spec.in b/spice-streaming-agent.spec.in
index fd10270..5f4eec9 100644
--- a/spice-streaming-agent.spec.in
+++ b/spice-streaming-agent.spec.in
@@ -60,6 +60,7 @@ fi
 %doc COPYING ChangeLog README
 %{_udevrulesdir}/90-spice-guest-streaming.rules
 %{_bindir}/spice-streaming-agent
+%{_bindir}/spice-streaming-helper
 %{_sysconfdir}/xdg/autostart/spice-streaming.desktop
 %{_datadir}/gdm/greeter/autostart/spice-streaming.desktop
 /usr/lib/systemd/system/spice-streaming-agent.socket
diff --git a/src/Makefile.am b/src/Makefile.am
index 9b4bb30..5f11967 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -9,6 +9,8 @@ if ENABLE_TESTS
 SUBDIRS = . unittests
 endif
 
+EXTRA_DIST =
+
 AM_CPPFLAGS = \
 	-DSPICE_STREAMING_AGENT_PROGRAM \
 	-I$(top_srcdir)/include \
@@ -67,3 +69,7 @@ spice_streaming_agent_SOURCES = \
 	daemon.cpp \
 	daemon.hpp \
 	$(NULL)
+
+helperdir = $(bindir)
+helper_SCRIPTS = spice-streaming-helper
+EXTRA_DIST += spice-streaming-helper
diff --git a/src/spice-streaming-helper b/src/spice-streaming-helper
new file mode 100755
index 0000000..11a9128
--- /dev/null
+++ b/src/spice-streaming-helper
@@ -0,0 +1,40 @@
+#!/usr/bin/env python3
+
+"""This helper send session information to the daemon so the daemon can
+know how to connect to a given display server.
+Currently only X server display is used."""
+
+import os
+import socket
+import sys
+import struct
+
+# daemon address
+SERVER_ADDRESS = "\0spice-streaming-agent-daemon"
+
+def encode_auth():
+    """Encode authentication data to send to daemon"""
+    def encode_env(var, env_code):
+        """Encode a give environment"""
+        val = os.environ.get(var, '').encode('utf-8')
+        return struct.pack('BB', env_code, len(val)) + val
+    display = encode_env('DISPLAY', 1)
+    xauthority = encode_env('XAUTHORITY', 2)
+    return struct.pack('B', 1) + display + xauthority
+
+def main():
+    """Communicate authentication data to the daemon"""
+    try:
+        sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+        sock.connect(SERVER_ADDRESS)
+        sock.send(encode_auth())
+        # wait reply or disconnection from the daemon
+        # the daemon can do some check on this process so keep it up
+        # till we receive a disconnection
+        sock.recv(10)
+    except socket.error as msg:
+        print(msg, file=sys.stderr)
+        sys.exit(1)
+
+if __name__ == "__main__":
+    main()
-- 
2.17.0



More information about the Spice-devel mailing list