diff options
Diffstat (limited to 'src/spice-streaming-agent.cpp')
-rw-r--r-- | src/spice-streaming-agent.cpp | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/src/spice-streaming-agent.cpp b/src/spice-streaming-agent.cpp index 0cd90e6..1c3c4f9 100644 --- a/src/spice-streaming-agent.cpp +++ b/src/spice-streaming-agent.cpp @@ -11,6 +11,7 @@ #include "error.hpp" #include "xorg-utils.hpp" #include "eventfd.hpp" +#include "daemon.hpp" #include <spice/stream-device.h> #include <spice/enums.h> @@ -196,7 +197,7 @@ static void read_command(StreamPort &stream_port, bool blocking) update_fd.ack(); bool vt_active = ::vt_active.load(std::memory_order_relaxed); if (!vt_active) { - throw std::runtime_error("VT disabled"); + exit(0); } continue; } @@ -329,7 +330,12 @@ static void cursor_changes(StreamPort *stream_port, Display *display, int event_ if (vt_property == None || event.xproperty.atom != vt_property) continue; // update vt property, activate screen read if needed - vt_active.store(get_win_prop_int(display, rootwindow, vt_property) != 0, std::memory_order_relaxed); + bool vt_active = get_win_prop_int(display, rootwindow, vt_property) != 0; + if (!vt_active) { + // this is necessary as to avoid a clean exit that will hangs :( + _Exit(0); + } + ::vt_active.store(vt_active, std::memory_order_relaxed); std::atomic_thread_fence(std::memory_order_acquire); update_fd.signal(); continue; @@ -501,11 +507,6 @@ int main(int argc, char* argv[]) register_interrupts(); try { - // register built-in plugins - MjpegPlugin::Register(&agent); - - agent.LoadPlugins(pluginsdir); - FrameLog frame_log(log_filename, log_binary, log_frames); for (const std::string& arg: old_args) { @@ -513,6 +514,17 @@ int main(int argc, char* argv[]) } old_args.clear(); + int streamfd; + run_daemon(stream_port_name, streamfd); + + // this should be done after the fork to avoid duplicating + // resources + + // register built-in plugins + MjpegPlugin::Register(&agent); + + agent.LoadPlugins(pluginsdir); + Display *display = XOpenDisplay(NULL); if (display == NULL) { throw Error("Failed to open X display"); @@ -538,7 +550,7 @@ int main(int argc, char* argv[]) return EXIT_FAILURE; } - StreamPort stream_port(stream_port_name); + StreamPort stream_port(streamfd); std::thread cursor_th(cursor_changes, &stream_port, display, event_base); cursor_th.detach(); |