Compare commits

...
Author SHA1 Message Date
osy b0b83b7f07 darwin: reopen the port when the VM is restored
Virtualization.framework does not restore the open state of the spice
port when it resumes a saved VM. The host then drops whatever the guest
writes to the port and never completes the write, which wedges the port
until the guest reboots: clipboard sharing stops working in both
directions and restarting the agents does not help.

The virtual RTC sends a message as soon as the VM is restored, so watch
for it and reopen the port before anything is written. Reopening tells
the host that the port is open again. Waiting for the clock change that
follows is too late: timed only steps the clock after an NTP round trip.

Resolves utmapp/UTM#7717

Assisted-by: Claude:claude-opus-5-5
2026-10-14 09:39:24 -07:00
osy 03ff810185 github: force universal archive build
xcodebuild does not read build settings from the shell environment, so
the ARCHS variable used to build GLib and gettext for both
architectures never reached the archive step. On the arm64 macos-15
runner this silently produced an arm64-only xcarchive/pkg instead of a
universal x86_64+arm64 binary.

Pass ARCHS and ONLY_ACTIVE_ARCH explicitly to xcodebuild archive so the
override takes effect regardless of the runner's host architecture.

Resolves #5

Assisted-by: Claude:claude-sonnet-5
2026-09-21 20:37:04 -05:00
osy 948db07d95 github: build on macos-15 runner
Newer Xcode versions only support deploying to macOS 12.0 and newer,
which breaks the project's 10.13 deployment target. Pin the runner to
macos-15, which defaults to Xcode 16.

Assisted-by: Claude:claude-opus-5
2026-09-21 19:37:41 -05:00
osy 7a9d859399 github: build GLib from source for arm64 and x86_64
Homebrew no longer supports x86_64, so installing it under Rosetta fails
in CI and the universal build has no x86_64 GLib to link against.

Build GLib and gettext (for libintl) from pinned upstream releases for
both architectures instead, based on Homebrew's glib formula. The
libraries target macOS 10.13 (11.0 on arm64) to match the project, and
availability errors are enabled to catch any use of newer APIs.

The Xcode project now takes the GLib locations from the
GLIB_ARM64_PREFIX and GLIB_X86_64_PREFIX build settings, which default
to the Homebrew paths so local builds are unchanged. The inputs of the
lipo phase are declared so they can be read with script sandboxing.

Assisted-by: Claude:claude-opus-5
2026-09-21 19:26:34 -05:00
osy 07005a1b0e Merge pull request #4 from pointum/fix-package-quarantine
Clear package quarantine
2026-09-21 17:51:12 -05:00
Maxim Ananov 37a74cf356 darwin: clear package quarantine 2026-08-16 16:13:19 -07:00
osy 15e4c3b63f data: update macOS package script to remove xattributes 2024-12-10 13:36:29 -08:00
osy 5ccfc993f4 readme: add notes for macOS 2024-11-18 01:59:26 -08:00
osy 9070c8ba4d darwin: add script to create installer 2024-11-18 01:48:31 -08:00
osy e4d0eea961 vdagentd: automatically switch session when security is disabled 2024-11-18 01:37:06 -08:00
osy c729770965 darwin: fix launch scripts 2024-11-17 22:34:41 -08:00
osy 38460ed519 darwin: fix build on Xcode 15.4 2024-11-17 20:05:32 -08:00
osy 684267abcb github: add CI 2024-11-17 20:05:32 -08:00
osy b788a2456c darwin: static link GLib, add LaunchDaemon 2024-11-17 13:41:51 -08:00
osy ee9ac60ad6 darwin: automatically download spice headers 2024-11-17 01:39:18 -08:00
osy 47e2539467 vdagent: support macOS NSPasteboard 2024-11-17 01:18:51 -08:00
osy 712c9ed7a6 vdagent: create new macOS agent 2024-11-16 17:45:12 -08:00
osy a395da3eeb vdagentd: add Xcode project for macOS build 2024-11-16 17:41:46 -08:00
Daniel Kahn Gillmor 553cb85f10 systemd services: add Documentation key (point to manpage) 2024-07-12 07:00:28 +00:00
Daniel Kahn Gillmor a3c361d829 Fix minor spelling errors.
This change was performed with:

```
codespell --ignore-words-list 'requestor' -w
```

("requestor" is part of the X11 API, and if we allow codespell to rewrite it it would fail to build)
2024-07-07 12:57:53 -04:00
Fabian Vogt aa08162f03 Switch to spice-vdagent.service by default
Add an [Install] section to the user unit and tell systemd to ignore the
.desktop file explicitly.

Also add missing ordering dependencies. Without this, the service fails if
it is started before e.g. $DISPLAY is set.
2023-02-09 10:22:01 +01:00
Victor Toso bcbbea34d9 vdagent: Remove watch event on vdagent_display_destroy()
To avoid main loop calling it when GIOChannel for x11 was already
destroyed.

Related: https://bugzilla.redhat.com/show_bug.cgi?id=2145004
Signed-off-by: Victor Toso <[email protected]>
2023-01-13 15:33:38 +01:00
Abderrahim Kitouni ed08813fcd Makefile.am: don't create /var/run/spice-vdagentd
/var/run is generally a symlink to /run, which is a tmpfs.
2022-09-28 07:38:52 +02:00
Victor Toso a9bb1752ce Release 0.22.1
Signed-off-by: Victor Toso <[email protected]>
2022-02-14 11:27:07 +01:00
Frediano Ziglio 0717474fec Do not process X11 events in vdagent_x11_create
Processing events requires some more initialisation between
VDAgentDisplay and vdagent_x11.
Postpone that after initialisation.
This fix a crash on Fedora 36, see
https://bugzilla.redhat.com/show_bug.cgi?id=2042877.

Signed-off-by: Frediano Ziglio <[email protected]>
2022-02-14 09:35:55 +00:00
Victor Toso 2289931e94 Release 0.22.0
Signed-off-by: Victor Toso <[email protected]>
2022-02-07 14:57:18 +01:00
Kevin PougetandJoan Bruguera 67090358b3 vdagentd/uinput: Handle side mouse buttons (BTN_SIDE and BTN_EXTRA)
Adds support for handling the side mouse buttons some mouses have, typically
used in web browsers for previous/next website in history.

spice-gtk requires a corresponding patch to capture and forward the buttons.

At the spice and protocol level, the required changes were previously merged:
* https://gitlab.freedesktop.org/spice/spice/-/issues/45
* https://gitlab.freedesktop.org/spice/spice/-/merge_requests/140
* https://gitlab.freedesktop.org/spice/spice-protocol/-/merge_requests/22

This commit is a rebased and revised version of the patch by Kevin Pouget:
https://www.spinics.net/lists/spice-devel/msg42582.html
(I have confirmed with him that it's OK that I submit the updated patches.)

Co-Authored-By: Kevin Pouget <[email protected]>
Co-Authored-By: Joan Bruguera <[email protected]>
2022-01-18 00:54:50 +01:00
Victor Toso 09de02fd5c udscs: udscs_connect: return error to caller
This way we can have the log in one place and avoid flooding the journal.

Signed-off-by: Victor Toso <[email protected]>
2021-12-20 19:09:48 +01:00
Victor Toso 1aa2c06015 vdagent: udscs: limit retry to connect to vdagentd
Related: https://bugzilla.redhat.com/show_bug.cgi?id=2005802
Related: https://bugzilla.redhat.com/show_bug.cgi?id=2028013
Signed-off-by: Victor Toso <[email protected]>
2021-12-20 19:09:48 +01:00
Adrian Bunk 8440e6010d configure.ac: autoconf 2.71 compatibility
"y" is not "set", but both have non-zero lengths.
2021-12-02 10:32:57 +00:00
Rex Dieter 3cd58713c9 Provide systemd user spice-vdagent.service 2021-07-16 11:07:39 -05:00
Maxim Cournoyer 67f3f3ed35 tests: Invoke ps in a way that does not truncate wide output.
By default, 'ps' truncates its output to about 100 characters.  The
test-termination test depends on finding the socket file name in the
output of the 'ps' command; it could fail depending on the file name
length of the directory where the test was run.

* tests/test-termination.c (get_daemon_pid) <ps>: Invoke with the -ww
option to preserve all the output.
2021-05-06 10:45:27 -04:00
Marc-André Lureau 8348ef3c61 Fix g_memdup deprecation warning with glib >= 2.68
Related to:
https://bugzilla.redhat.com/show_bug.cgi?id=1943059

Signed-off-by: Marc-André Lureau <[email protected]>
2021-05-04 13:20:51 +04:00
Chris Mayo 0105b280cb build: replace bashism in configuration for GTK 4
Else with dash as /bin/sh, GTK 4 support cannot be selected.
2021-03-25 19:31:44 +00:00
Julien Ropé 9306f18621 Release 0.21.0
Signed-off-by: Julien Ropé <[email protected]>
Acked-by: Frediano Ziglio <[email protected]>
2021-01-13 09:52:43 +01:00
Julien Ropé 58d97554e5 Use the Mutter API from display.c
Signed-off-by: Julien Ropé <[email protected]>
Acked-by: Jakub Janků <[email protected]>
2020-11-19 15:40:13 +01:00
Julien Ropé 73bf836726 Add implementation of the DBUS interface to Mutter.
This can be used to retrieve monitor resolutions directly from the
Mutter compositor under Wayland.
Under environments using a different compositor, the X11 lib will keep
being used.

Signed-off-by: Julien Ropé <[email protected]>
Acked-by: Jakub Janků <[email protected]>
2020-11-19 15:40:02 +01:00
Julien Ropé 21d355974f Move some reusable code at a higher level.
Adding disabled displays to the list is something that we will need to
do
with multiple backends, not just GTK.

Signed-off-by: Julien Ropé <[email protected]>
Acked-by: Jakub Janků <[email protected]>
2020-11-19 15:39:32 +01:00
Julien Ropé 9750013f0e Make the connector mappings available whatever the build options
Signed-off-by: Julien Ropé <[email protected]>
Acked-by: Jakub Janků <[email protected]>
2020-11-19 15:39:17 +01:00
Jakub Janků 1d40f0e967 ci: run checks only with --with-session-info=none
In the container environment, neither systemd nor
console kit is running, thus test-session-info fails.
To fix the pipeline, run "make distcheck" with the
aforementioned option, which disables this test.

Signed-off-by: Jakub Janků <[email protected]>
2020-11-15 16:59:02 +01:00
Jakub Janků aa792598ea build: test session info only with non-dummy implementation
The test, as it is written at the moment, only makes sense
with console-kit or systemd implementation. With the dummy one,
the test fails, but it's not an error in the vdagent code.

Signed-off-by: Jakub Janků <[email protected]>
2020-11-15 15:46:47 +01:00
Jakub Janků 396c2b2c7d build: test-session-info: include only what's necessary
The test doesn't depend on udscs.c in common_sources,
for example, so don't include it.

Signed-off-by: Jakub Janků <[email protected]>
2020-11-15 15:43:41 +01:00
Jakub Janků 8bffaaf3e5 test-session-info: rename misleading "ck_uid"
The source code refers to "console-kit uid",
but we have console-kit as well as systemd and
dummy implementation of session-info.

Signed-off-by: Jakub Janků <[email protected]>
2020-11-15 15:08:40 +01:00
Frediano Ziglio 5094d5cfe6 Add a test for session_info
Test from Uri, integrated in test suite.

Signed-off-by: Uri Lublin <[email protected]>
Signed-off-by: Frediano Ziglio <[email protected]>
2020-11-03 09:45:08 +00:00
Uri Lublin b7db1c20c9 vdagentd: do not allow to use an already used file-xfer id
Signed-off-by: Uri Lublin <[email protected]>
Acked-by: Frediano Ziglio <[email protected]>
2020-11-03 09:44:05 +00:00
Uri Lublin e4bfd1b632 cleanup active_xfers when the client disconnects
Signed-off-by: Uri Lublin <[email protected]>
Acked-by: Frediano Ziglio <[email protected]>
2020-11-03 09:43:32 +00:00
Frediano Ziglio 812ca77746 vdagentd: Limit number of agents per session to 1
Signed-off-by: Frediano Ziglio <[email protected]>
Acked-by: Uri Lublin <[email protected]>
2020-10-29 14:59:18 +00:00
Frediano Ziglio 5c50131797 Better check for sessions
Do not allow other users to hijack a session checking that
the process is launched by the owner of the session.

Signed-off-by: Frediano Ziglio <[email protected]>
Acked-by: Uri Lublin <[email protected]>
2020-10-29 14:59:18 +00:00
Frediano Ziglio 51c415df82 Avoids user session hijacking
Avoids user hijacking sessions by reusing PID.
In theory an attacker could:
- open a connection to the daemon;
- fork and exit the process but keep the file descriptor open
  (inheriting or duplicating it in forked process);
- force OS to recycle the initial PID, by creating many short lived
  processes.
Daemon would detect the old PID as having the new session.
Check the user to avoid such replacements.

This issue was reported by SUSE security team.

Signed-off-by: Frediano Ziglio <[email protected]>
Acked-by: Uri Lublin <[email protected]>
2020-10-29 14:59:18 +00:00
Frediano Ziglio 91caa92238 Avoids unlimited agent connections
Limit the number of agents that can be connected.
Avoids reaching the maximum number of files in a process.
Beside one file descriptor per agent the daemon open just some
other fixed number of files.

This issue was reported by SUSE security team.

Signed-off-by: Frediano Ziglio <[email protected]>
2020-10-29 14:59:18 +00:00
Frediano Ziglio 9d35d8a86f Avoids uncontrolled "active_xfers" allocations
Limit the number of active file transfers possibly causing DoSes
consuming memory in "active_xfers".

This issue was reported by SUSE security team.

Signed-off-by: Frediano Ziglio <[email protected]>
Acked-by: Uri Lublin <[email protected]>
2020-10-29 14:59:18 +00:00
Frediano Ziglio 1a8b93ca6a Avoids unchecked file transfer IDs allocation and usage
Avoid agents allocating file transfers.
The "active_xfers" entries are now inserted when client start sending
files.
Also different agents cannot mess with other agent transfers as a
transfer is bound to a single agent.

This issue was reported by SUSE security team.

Signed-off-by: Frediano Ziglio <[email protected]>
Acked-by: Uri Lublin <[email protected]>
2020-10-29 14:59:18 +00:00
Frediano Ziglio ce144335ff vdagentd: Avoid calling chmod
Create the socket with the right permissions using umask.
This also prevents possible symlink exploitation in case socket
path is not secure.

Signed-off-by: Frediano Ziglio <[email protected]>
Acked-by: Uri Lublin <[email protected]>
2020-10-29 14:59:18 +00:00
Jakub Janků 5a2471e24e x11-randr: fix leak on vdagent_x11 destroy
In vdagent_x11_destroy(), only x11->randr.failed_conf is freed
and x11->randr.{res, outputs, crtcs} are left allocated.

To fix it, create a new function vdagent_x11_randr_destroy()
that frees all randr resources, and call it from vdagent_x11_destroy().

Signed-off-by: Jakub Janků <[email protected]>
2020-10-28 17:07:21 +01:00
Julien Ropé 0c5b8fac09 CI: fix build failure
With latest fedora container using F33, we get gtk4 3.99, where vulkan is
enabled by default.
This require to get the vulkan headers as a dependency.

Signed-off-by: Julien Ropé <[email protected]>
2020-10-27 12:07:24 +01:00
Frediano Ziglio 8698e1e5cc vdagentd: Fix clipboard serial for big endian machines
The GUINT32_TO_LE in case of big endian machine can expand
the argument multiple times so avoid to pass argument that
could have side effects.

Signed-off-by: Frediano Ziglio <[email protected]>
Acked-by: Julien Ropé <[email protected]>
2020-10-21 16:19:47 +01:00
Frediano Ziglio aab670b3b7 vdagentd: Simplify handling VD_AGENT_GRAPHICS_DEVICE_INFO
g_free does nothing if pointer is NULL.
device_info and device_info_size will be overwritten in any case.

Signed-off-by: Frediano Ziglio <[email protected]>
Acked-by: Julien Ropé <[email protected]>
2020-10-21 16:08:22 +01:00
Frediano Ziglio e73e330e99 vdagentd: Constify vdagent_message_min_size
The array is not supposed to be changed.

Signed-off-by: Frediano Ziglio <[email protected]>
Acked-by: Julien Ropé <[email protected]>
2020-10-21 16:06:58 +01:00
Julien Ropé 9574a4299f When using GTK for monitors, we should not update the X11 structures.
X11 events are still used to notify the daemon of monitor resolution
changes, but the X11 structures themselves do not need to be updated,
because we will get all required informations from the GTK library.

Signed-off-by: Julien Ropé <[email protected]>
Acked-by: Frediano Ziglio <[email protected]>
2020-10-19 17:59:19 +02:00
Julien Ropé 5ab5fe3475 Using GTK, there is no way to modify the monitor resolution.
Since vdagent_x11_set_monitor_config() can work only under the X11
backend, make sure we don't call it when under Wayland - it will fail
anyway.

Signed-off-by: Julien Ropé <[email protected]>
Acked-by: Frediano Ziglio <[email protected]>
2020-10-19 17:59:11 +02:00
Julien Ropé 6c475b368d Send guest resolution using GDK functions.
- Implement the vdagent_gtk_get_resolutions() function.
  Use gdk_monitor_*() functions to retrieve the resolution of each
monitor. Associate them to the right display ID using the
connector_mapping hash

Signed-off-by: Julien Ropé <[email protected]>
Acked-by: Frediano Ziglio <[email protected]>
2020-10-19 17:59:03 +02:00
Julien Ropé 4c80090681 Split the "lookup_xrandr_output_for_device_info()" function to reuse
some of it with different backends.

Most display drivers will number their outputs starting with "1", but
some (like older QXL drivers) will start from 0.
As we need to map device names with SPICE display IDs, we need to know
what to expect.

The logic that finds whether we have a O-based index or not is
independent from the backend, and can be reused outside of the X11
implementation.

This commit separates this logic for that purpose, to prevent code
duplication.
- create the has_zero_based_display_id() function to call whatever the
  backend, and learn whether our IDs should be decremented or not.
  Its code is taken out of lookup_xrandr_output_for_device_info()
- keep the lookup_xrandr_output_for_device_info() for x11 implementation
- add parameters to some functions to give them the information that IDs
  should be decremented because of the 0-based index.

Signed-off-by: Julien Ropé <[email protected]>
Acked-by: Frediano Ziglio <[email protected]>
2020-10-19 17:58:54 +02:00
Julien Ropé d92f37ae06 Prepare mapping based on connector name.
Split the lookup_xrandr_output_for_device_info to access the part
retrieving the expected connector name.
Call that separate function in the "non-X11" part of the code, and use a
hashtable to map Spice display ID to its expected connector name.
This hashtable will later be used when we need to report resolution
changes to the daemon/server.

Signed-off-by: Julien Ropé <[email protected]>
Acked-by: Frediano Ziglio <[email protected]>
2020-10-19 17:58:43 +02:00
Julien Ropé f59192a021 Copy the 'debug' flag and 'vdagentd' socket into the VDAgentDisplay
structure.

Signed-off-by: Julien Ropé <[email protected]>
Acked-by: Frediano Ziglio <[email protected]>
2020-10-19 17:58:29 +02:00
Julien Ropé 6e5e6c2ca6 Add a non-X11 function to send the guest resolution to the
daemon/server.

The purpose here is to further separate X11-specific code, and have the
actual sending to the daemon to be out of X11 code, and reusable by
other APIs.

- Replace vdagent_x11_send_daemon_guest_res() with a function that
builds
  and returns the list of monitor resolutions.
- Create the vdagent_display_send_daemon_guest_res() that uses this to
  send the resolutions to the daemon.
- Call this function in place of vdagent_x11_send_daemon_guest_res()

In later commits, we will be able to use a different API to generate
the list of monitor resolution, without having to change the X11 code.

Signed-off-by: Julien Ropé <[email protected]>
Acked-by: Frediano Ziglio <[email protected]>
2020-10-19 17:58:12 +02:00
Frediano Ziglio 8c4137de70 ci: Upload test results in case of failure
Allows to see tests results in case "make check" fails.

Signed-off-by: Frediano Ziglio <[email protected]>
Acked-by: Jakub Janků <[email protected]>
2020-10-05 09:54:44 +01:00
Jakub Janků 09733a5c81 clipboard: enable copying files from client using webdav
When the user wants to copy files, new spice-gtk can share those
files using the existing phodav server. In that case, it advertises
the VD_AGENT_CLIPBOARD_FILE_LIST type in the clipboard grab message.

Upon request of the clipboard data in the mentioned type, spice-gtk
provides a list of absolute paths in the phodav server - these are
the files that are supposed to be copied/moved.

The role of the vdagent is to:
1) ensure that the phodav share is mounted,
2) adjust the provided paths given the mountpoint,
3) provide the uri list in various formats depending on which one
   was requested (different file managers use differenct formats)

The code that accomplishes these tasks is located in a new file
webdav-cb.c - the main reason for it is that vdagent currently
supports two clibpoard backends: x11, gtk+.

Implement this new feature only in the x11 backend since
the future of the gtk+ one is not clear.

Copy and move was tested with GNOME Nautilus, KDE Dolphin,
Cinnamon Nemo, Mate Caja, Xfce Thunar, LXDE PCManFM, Krusader.
The functionality with other file managers might be limited.

Copying files from the vdagnet side to the client is not
supported yet.

Signed-off-by: Jakub Janků <[email protected]>
Acked-by: Frediano Ziglio <[email protected]>
2020-09-28 10:46:09 +01:00
Jakub Janků 2e2feeb93b build: require spice-protocol 0.14.3
This adds the VD_AGENT_CLIPBOARD_FILE_LIST
necessary for the following commits.

Signed-off-by: Jakub Janků <[email protected]>
Acked-by: Frediano Ziglio <[email protected]>
2020-09-28 10:46:06 +01:00
Jakub Janků 0da3211f63 x11: move code to clipboard_data_send_to_requestor()
With the upcoming patch, clipboard data will be sent to the
requestor outside of vdagent_x11_clipboard_data() so
extract the necessary code into a new function to avoid
repetition.

The function takes "take_ownership" argument. If set to True,
the caller doesn't have to free the passed data which will
also be useful with the following changes.

Improve style by adding brackets to single-line if statements.

Signed-off-by: Jakub Janků <[email protected]>
Acked-by: Frediano Ziglio <[email protected]>
2020-09-28 10:46:03 +01:00
Frediano Ziglio 1f4a994ff1 audio: Change percentage formatting
Use XX% instead of %XX.

Signed-off-by: Frediano Ziglio <[email protected]>
Acked-by: Jakub Janků <[email protected]>
2020-09-25 16:01:21 +01:00
Frediano Ziglio 253539275a audio: Set range instead of reading and adjusting
Signed-off-by: Frediano Ziglio <[email protected]>
Acked-by: Jakub Janků <[email protected]>
2020-09-25 16:01:19 +01:00
Frediano Ziglio f30becd21f audio: Fix number rounding
Avoid truncation due to integer arithmetic.

Signed-off-by: Frediano Ziglio <[email protected]>
Acked-by: Jakub Janků <[email protected]>
2020-09-25 16:01:14 +01:00
Frediano Ziglio 7e924bcbf0 vdagentd: Better check for vdagent_connection_get_peer_pid results
The function can return -1 and leave "err" to NULL in some cases,
do not check only for "err".

Signed-off-by: Frediano Ziglio <[email protected]>
Acked-by: Julien Ropé <[email protected]>
2020-09-22 12:34:17 +01:00
Frediano Ziglio b894975bed vdagent-connection: Pass "err" to g_credentials_get_unix_pid
Allows to return detailed information if g_credentials_get_unix_pid
fails.

Signed-off-by: Frediano Ziglio <[email protected]>
Acked-by: Julien Ropé <[email protected]>
2020-09-22 12:34:04 +01:00
Frediano Ziglio b4479eb9b0 vdagentd: Automatically release "agent_data"
It's not guaranteed that agent_disconnect will release the connection
so avoid to have a dandling pointer.

Signed-off-by: Frediano Ziglio <[email protected]>
Acked-by: Jakub Janků <[email protected]>
2020-09-21 15:22:16 +01:00
Frediano Ziglio 9f768c6037 vdagentd: Make some agent_data variable constant
Signed-off-by: Frediano Ziglio <[email protected]>
Acked-by: Jakub Janků <[email protected]>
2020-09-21 15:22:14 +01:00
Frediano Ziglio 4983eb1f42 vdagentd: Make pidfilename a constant
No need to be a variable

Signed-off-by: Frediano Ziglio <[email protected]>
Acked-by: Jakub Janků <[email protected]>
2020-09-21 15:22:11 +01:00
Frediano Ziglio 7e37b05774 vdagentd: Use bool for agent_owns_clipboard and client_connected
More clear (instaed of 0/1) and save some bytes.

Signed-off-by: Frediano Ziglio <[email protected]>
Acked-by: Jakub Janků <[email protected]>
2020-09-21 15:22:09 +01:00
Frediano Ziglio 27805752fe console-kit: Do not mix GLib and libc memory allocations
Use always GLib functions for "seat" and "active_session" fields.

Signed-off-by: Frediano Ziglio <[email protected]>
Acked-by: Jakub Janků <[email protected]>
2020-09-21 15:22:04 +01:00
Julien Ropé ca4dd7e811 Enable GTK4 build with a specific configure option.
- Adding the "--with-gtk4" option to ask for GTK4, keeping it separate
from
  the default "--with-gtk" so that we can still build the agent with
GTK3.
  GTK4 will be used to solve several issues under Wayland related to
  multi-monitor situations.
- Change some calls to be compatible with modified API.
- Also add a build test to CI script.

Important note about the clipboard:
Using the Wayland backend in GTK is introducing new issues with
clipboard
that we can't fix for now.
So when building for GTK4, we will actually not use GTK for the
clipboard.

To achieve this, some build definitions are modified:
- WITH_GTK is kept, but is only used for GTK initialization and header
import
- WITH_GTK is replaced by USE_GTK_FOR_CLIPBOARD for all
clipboard-specific
  code. It is enabled when building with GTK3.
- USE_GTK_FOR_MONITORS is added, and will be used for monitor-specific
  code. It is enabled when building with GTK4.

Signed-off-by: Julien Ropé <[email protected]>
Acked-by: Frediano Ziglio <[email protected]>
2020-07-29 14:32:34 +02:00
Frediano Ziglio 65f64b805b vdagent-connection: Avoid leak if write callback is cancelled
g_object_unref is not called if out_stream_ready_cb source is
cancelled.

Signed-off-by: Frediano Ziglio <[email protected]>
Acked-by: Jakub Janku <[email protected]>
2020-07-25 14:36:28 +01:00
Frediano Ziglio 87c031a6a8 clipboard: Define "conn" field only using GTK
Not used anywhere else.

Signed-off-by: Frediano Ziglio <[email protected]>
Acked-by: Jakub Janků <[email protected]>
2020-07-22 11:58:32 +01:00
Frediano Ziglio ffba3a0e2d x11: Remove "fd" field
No much reason to cache it, used only in initialization

Signed-off-by: Frediano Ziglio <[email protected]>
Acked-by: Jakub Janků <[email protected]>
2020-07-22 11:58:29 +01:00
Frediano Ziglio a5932875c2 x11: Move "xrandr_event_base" inside "randr" structure
Signed-off-by: Frediano Ziglio <[email protected]>
Acked-by: Jakub Janků <[email protected]>
2020-07-22 11:58:27 +01:00
Frediano Ziglio a020b8e925 x11: Remove only written "has_xfixes" field
Signed-off-by: Frediano Ziglio <[email protected]>
Acked-by: Jakub Janků <[email protected]>
2020-07-22 11:58:21 +01:00
Julien Ropé ef54256abf Use RROutput directly in guest_output_map.
No need to allocate a separate variable - the RROutput value can be used
directly in the hashtable.

Signed-off-by: Julien Ropé <[email protected]>
Acked-by: Frediano Ziglio <[email protected]>
2020-07-15 10:33:38 +01:00
Julien Ropé 1601f4de95 Move more code from x11.c to display.c
Moving the non-X11 part of the code related to
"vdagent_x11_has_icon_on_desktop()".
Turns out most of it is disabled anyway when we build with GTK.

Signed-off-by: Julien Ropé <[email protected]>
Acked-by: Frediano Ziglio <[email protected]>
2020-07-15 10:33:36 +01:00
Julien Ropé aa75e9d792 Move handle_graphics_device_info code to generic display functions
Most of the code in vdagent_x11_handle_graphics_device_info() is dealing
with SPICE information, only a few of it is X11-specific.
Move that code away from x11-randr.c so that we can use it with Wayland.

Signed-off-by: Julien Ropé <[email protected]>
Acked-by: Frediano Ziglio <[email protected]>
2020-07-15 10:31:24 +01:00
Julien Ropé 2f025381f8 Split X11-specific code from the core agent code
This commit adds a set of functions (vdagent_display_*) that separates the
agent's code from the underlying backend used for handling monitor
events/settings.
Today, this does not change the behaviour of the agent, as those functions
will just call the existing X11 functions. But we will later add code to
them to support other means of dealing with monitors (i.e: Wayland
support).

Signed-off-by: Julien Ropé <[email protected]>
Acked-by: Frediano Ziglio <[email protected]>
2020-07-15 10:31:08 +01:00
Frediano Ziglio 98f05ec1fe ci: Add missing dependency
Code requires libdrm.
In Fedora 31 this was included by some dependent package, but
Fedora 32 requires explicit dependency.

Signed-off-by: Frediano Ziglio <[email protected]>
2020-07-10 09:51:48 +01:00
Jakub Janků 9721c99396 x11: cache atom names in vdagent_x11_get_atom_name()
XGetAtomName() returns a new string that should be freed,
when no longer needed, but the current impl doesn't do that.

To preserve the ease of use for debugging purposes,
cache the atom names and free them when the cache is full
and when the x11 struct is destroyed.

Fixes: https://gitlab.freedesktop.org/spice/linux/vd_agent/-/issues/22

Signed-off-by: Jakub Janků <[email protected]>
Acked-by: Frediano Ziglio <[email protected]>
2020-06-30 10:58:01 +01:00
Kevin Pouget 8adf50de9a vdagent: replace last call to g_debug(...) by syslog(LOG_DEBUG, ...)
Fixes #21 by avoiding to set `G_MESSAGES_DEBUG=all` to learn that the
vdagent failed to load because of missing virtio channel.

If the debug flag is not set, the vdagent remains silent, as defined
with 149bba9162 / #12.

Signed-off-by: Kevin Pouget <[email protected]>
2020-05-20 11:33:13 +02:00
Frediano Ziglio d0b5f80ada Fix possible compile error using former GLib2 version
We require GLib 2.50 but G_SOURCE_FUNC was introduced in version
2.58. Do the conversion instead of using G_SOURCE_FUNC macro.

Signed-off-by: Frediano Ziglio <[email protected]>
Acked-by: Victor Toso <[email protected]>
2020-05-11 16:46:10 +01:00
Frediano Ziglio 5654f4d2f9 systemd-login: Avoid a crash on container
On containers dbus could be not running.
In this case dbus.system_connection is NULL and calling
dbus_connection_close on it will cause a crash.
This happens also under Gitlab CI.

Signed-off-by: Frediano Ziglio <[email protected]>
Acked-by: Victor Toso <[email protected]>
2020-03-26 15:43:15 +00:00
Frediano Ziglio eeb5620260 test-termination: Check daemon terminates correctly sending SIGTERM
Check for https://gitlab.freedesktop.org/spice/linux/vd_agent/issues/18.

Signed-off-by: Frediano Ziglio <[email protected]>
Acked-by: Victor Toso <[email protected]>
2020-03-26 15:43:10 +00:00
Jakub Janků 7b0435ef66 vdagentd: init static uinput before fork
Otherwise the caller doesn't know that the init failed
because we're returning 0 in the parent and 1 in child.

Signed-off-by: Jakub Janků <[email protected]>
Acked-by: Frediano Ziglio <[email protected]>
2020-03-26 10:27:41 +00:00
Jakub Janků 9b8c0ebb9f vdagentd: work around GLib's fork issues
Creating threads is not compatible with forking as only the thread
that calls fork() is inherited.

Handlers registered with g_unix_signal_add() create a thread so
move these calls after fork.

Also call g_socket_service_start() after fork to avoid creation of
new threads before it is necessary.

Fixes: https://gitlab.freedesktop.org/spice/linux/vd_agent/issues/18

Also see: https://gitlab.gnome.org/GNOME/glib/issues/2073

Signed-off-by: Jakub Janků <[email protected]>
Acked-by: Frediano Ziglio <[email protected]>
2020-03-26 10:27:38 +00:00
Victor Toso bfbb63d3ae Release 0.20.0
Signed-off-by: Victor Toso <[email protected]>
2020-03-10 13:54:29 +01:00
Victor Toso 3b4b4d025d ci: Use meson instead of autotools in spice-protocol
It was dropped in git master.

Signed-off-by: Victor Toso <[email protected]>
2020-03-09 21:31:12 +01:00
Aral Balkan 70d57b3357 Add basic installation instructions to the readme
Acked-by: Victor Toso <[email protected]>
2020-03-09 20:19:22 +01:00
Jakub Janků e6c14d0ecc udscs-server: split initialization
Divide creation of udscs_server into 2 steps:

1) udscs_server_new()
 - allocates new udscs_server struct and inits it

2) udscs_server_listen_to_fd(), udscs_server_listen_to_address()
 - starts accepting new connections

Remove udscs_create_server() and udscs_create_server_for_fd().

This makes the code a bit shorter and nicer.

Signed-off-by: Jakub Janků <[email protected]>
Acked-by: Victor Toso <[email protected]>
2020-03-09 20:12:50 +01:00
Jakub Janků ab7901ced4 virtio: use GObject macro
Use G_DECLARE_FINAL_TYPE().

Rename
struct vdagent_virtio_port --> VirtioPort

Signed-off-by: Jakub Janků <[email protected]>
Acked-by: Victor Toso <[email protected]>
2020-03-09 20:12:47 +01:00
Jakub Janků 15f710dade udscs: use GObject macro
Use G_DECLARE_FINAL_TYPE().

Rename
struct udscs_connection --> UdscsConnection

Signed-off-by: Jakub Janků <[email protected]>
Acked-by: Victor Toso <[email protected]>
2020-03-09 20:12:44 +01:00
Jakub Janků 3257a1f732 introduce VDAgentConnection
1) VDAgentConnection

Add vdagent-connection.{c,h} files,
define a new derivable class VDAgentConnection.

VDAgentConnection uses GIO and therefore integrates well with GMainLoop.

Read messages must begin with a header of a fixed size.
Message body size can vary.

Note:
vdagent_connection_destroy() cancels ongoing I/O-ops
and closes the underlying FD.
However, the I/O-ops do not finish immediately,
but asynchronously in the next iteration of the main loop.
At the beginning of each op, VDAgentConnection is referenced,
so the object isn't finalized until the ops themselves finish.
To solve this, call g_main_context_iteration() before the agent exits.

2) udscs

Make udscs_connection a subclass of VDAgentConnection.

Rewrite udscs_server using GSocketService.
Use GList to store server's connections.

Drop support for select(), remove:
 * udscs_server_fill_fds()
 * udscs_server_handle_fds()

Remove udscs_{set,get}_user_data(). Custom data can be
associated with the GObject using g_object_set_data().

3) virtio_port

Make vdagent_virtio_port a subclass of VDAgentConnection.

Drop support for select(), remove:
 * vdagent_virtio_port_fill_fds()
 * vdagent_virtio_port_handle_fds()

4) vdagentd

Replace the main_loop() with a GMainLoop.

Use g_unix_signal_add() to handle SIGINT, SIGHUP, SIGTERM.
SIGQUIT handling is not supported by GLib.

Integrate the session_info into the loop using
GIOChannel and g_io_add_watch().

Signed-off-by: Jakub Janků <[email protected]>
Acked-by: Victor Toso <[email protected]>
2020-03-09 20:12:39 +01:00
Jakub Janků 5c136cb3a3 build: add GIO dependency
Require UNIX-specific GIO package to build spice-vdagent.

This package includes:

- GDBus which is going to be used instead of libdbus in
  console-kit.c and systemd-login.c

- I/O stream classes and networking APIs that are going to
  be used in VDAgentConnection

Version 2.44 is required because of the following definitions:
- g_input_stream_read_all_*
- g_output_stream_write_all_*
- GSimpleIOStream

GIO requires GLib and GObject, so we can depend solely on it.

GLib version across different distributions:
    Fedora 30:    2.60
    Fedora 29:    2.58
    Fedora 28:    2.56

    RHEL 7.6:     2.56
    RHEL 7.5:     2.54
    RHEL 7.4:     2.50

    Debian 10:    2.58
    Debian 9:     2.50
    Debian 8:     2.42

    Ubuntu 19.04: 2.60
    Ubuntu 18.04: 2.56
    Ubuntu 16.04: 2.48

Signed-off-by: Jakub Janků <[email protected]>
Acked-by: Victor Toso <[email protected]>
2020-03-09 20:12:34 +01:00
Marc-André Lureau a2fc33cbc7 clipboard: implement CAP_CLIPBOARD_GRAB_SERIAL
Implement the behaviour described in protocol "vdagent: introduce
VD_AGENT_CAP_CLIPBOARD_GRAB_SERIAL".

Signed-off-by: Marc-André Lureau <[email protected]>
Acked-by: Victor Toso <[email protected]>
2020-03-06 10:07:02 +01:00
Marc-André Lureau c9e806722b clipboard: only send release when no immediate grab
Do not send a release event between two grabs, this helps with window
manager interaction issues on peer side.

Advertise this behaviour via a capability introduced in spice-protocol
0.12.16, so the client doesn't need to do some time-based filtering.

(the capability shouldn't need to be negotiated, a client shouldn't
expect a release between two grabs)

Signed-off-by: Marc-André Lureau <[email protected]>
Acked-by: Victor Toso <[email protected]>
2020-03-06 10:06:50 +01:00
Marc-André Lureau 2ad6c158ff clipboard: filter out only our own events
Do not rely on internal state when receiving clipboard events, as this
may race with external events. Use gtk_clipboard_set_with_owner()

Signed-off-by: Marc-André Lureau <[email protected]>
Acked-by: Victor Toso <[email protected]>
2020-03-06 10:06:46 +01:00
Marc-André Lureau aa26d1d95b clipboard: gobject-ify VDAgentClipboards
This will allow easier lifecycle management,
and usage of gtk_clipboard_set_with_owner()

Signed-off-by: Marc-André Lureau <[email protected]>
Acked-by: Victor Toso <[email protected]>
2020-03-06 10:06:43 +01:00
Marc-André Lureau fb69a49828 vdagent: use G_OPTION_FLAG_NONE
Improve readability a bit, reindent slightly.

Signed-off-by: Marc-André Lureau <[email protected]>
Acked-by: Victor Toso <[email protected]>
2020-03-06 10:06:38 +01:00
Marc-André Lureau ff30f58701 configure: bump gobject >= 2.50
This is required for using the new GObject macros.

According to commit 61fc548fe1 ("Bump
GLib version to 2.34"), RHEL6 is no longer supported.

GLib version across some distributions, from repology:
- Debian Stable (9): 2.50.3
- CentOS 7: 2.56.1
- Fedora 26: 2.52.3 (fwiw, Fedora 30: 2.60.0)

Signed-off-by: Marc-André Lureau <[email protected]>
Acked-by: Victor Toso <[email protected]>
2020-03-06 10:06:34 +01:00
Marc-André Lureau 79d012503f configure: depend on gobject
The following patches are going to introduce GObject.  It's not a big
change, since usually glib comes installed with gobject on most systems.

Signed-off-by: Marc-André Lureau <[email protected]>
Acked-by: Victor Toso <[email protected]>
2020-03-06 10:06:31 +01:00
Marc-André Lureau 2c723788c0 clipboard: remove vdagent-selection-id usage
Modernize a bit the code, using gtk_clipboard_get_selection().

Signed-off-by: Marc-André Lureau <[email protected]>
Acked-by: Victor Toso <[email protected]>
2020-03-06 10:06:26 +01:00
Marc-André Lureau e0bfa678ae configure: bump gtk+ >= 3.22
According to repology,
- Debian Stable (9): 3.22.11
- CentOS 7: 3.22.30
- Fedora 26: 3.22.21 (fwiw, Fedora 30: 3.24.7)

Signed-off-by: Marc-André Lureau <[email protected]>
Acked-by: Victor Toso <[email protected]>
2020-03-06 10:06:22 +01:00
Benjamin Berg b67ff71f1b vdagentd: Fix session lookup for new GNOME versions
New GNOME versions have started to manage the session using the systemd
user instance. The effect of this is that the spice-vdagent running in
the user session is forked off (indirectly) from the systemd user
instance and does technically not belong to any session.

The correct way of handling this situation is to simply assume that the
process belongs to the users graphical session. Add a heuristic to find
the graphical session based on the UID, fixing spice-vdagent running on
GNOME 3.34 with systemd integration.

Acked-by: Victor Toso <[email protected]>
2019-10-17 11:53:51 +02:00
Uri Lublin f807e98bb6 virtio-port: handle_fds: make read and write code consistent
A comment and curly brackets for style were added.

Signed-off-by: Uri Lublin <[email protected]>
Acked-by: Frediano Ziglio <[email protected]>
2019-08-31 09:23:57 +01:00
Victor Toso 56a65ad1c6 covscan: add comment on false-positive on g_memdup()
Previous commit set last element of orig_argv array to NULL.
That's redundant as g_memdup() uses memcpy() and it would do
just that. Add a comment that the reason for this change is
to workaround clang's warning.

Suggested by Uri.

Signed-off-by: Victor Toso <[email protected]>
Acked-by: Uri Lublin <[email protected]>
2019-08-28 14:39:07 +02:00
Victor Toso cedab5fe0e covscan: initialize argv's copy
Otherwise we get a CLANG_WARNING due accessing garbage.

Covscan report:
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:471:9: warning: 1st function call argument is an uninitialized value
 > #        execvp(orig_argv[0], orig_argv);
 > #        ^      ~~~~~~~~~~~~
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:421:24: note: Storing uninitialized value
 > #    char **orig_argv = g_memdup(argv, sizeof(char*) * (argc+1));
 > #                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:434:9: note: Assuming 'error' is equal to NULL
 > #    if (error != NULL) {
 > #        ^~~~~~~~~~~~~
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:434:5: note: Taking false branch
 > #    if (error != NULL) {
 > #    ^
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:442:9: note: Assuming 'portdev' is not equal to NULL
 > #    if (portdev == NULL)
 > #        ^~~~~~~~~~~~~~~
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:442:5: note: Taking false branch
 > #    if (portdev == NULL)
 > #    ^
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:445:9: note: Assuming 'vdagentd_socket' is not equal to NULL
 > #    if (vdagentd_socket == NULL)
 > #        ^~~~~~~~~~~~~~~~~~~~~~~
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:445:5: note: Taking false branch
 > #    if (vdagentd_socket == NULL)
 > #    ^
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:448:30: note: Assuming 'do_daemonize' is 0
 > #    openlog("spice-vdagent", do_daemonize ? LOG_PID : (LOG_PID | LOG_PERROR),
 > #                             ^~~~~~~~~~~~
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:448:30: note: '?' condition is false
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:451:9: note: Assuming the condition is false
 > #    if (!g_file_test(portdev, G_FILE_TEST_EXISTS)) {
 > #        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:451:5: note: Taking false branch
 > #    if (!g_file_test(portdev, G_FILE_TEST_EXISTS)) {
 > #    ^
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:457:9: note: Assuming 'do_daemonize' is 0
 > #    if (do_daemonize)
 > #        ^~~~~~~~~~~~
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:457:5: note: Taking false branch
 > #    if (do_daemonize)
 > #    ^
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:468:9: note: Assuming 'version_mismatch' is not equal to 0
 > #    if (version_mismatch) {
 > #        ^~~~~~~~~~~~~~~~
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:468:5: note: Taking true branch
 > #    if (version_mismatch) {
 > #    ^
 > spice-vdagent-0.19.0/src/vdagent/vdagent.c:471:9: note: 1st function call argument is an uninitialized value
 > #        execvp(orig_argv[0], orig_argv);
 > #        ^      ~~~~~~~~~~~~
 > #  469|           syslog(LOG_INFO, "Version mismatch, restarting");
 > #  470|           sleep(1);
 > #  471|->         execvp(orig_argv[0], orig_argv);
 > #  472|       }
 > #  473|

Signed-off-by: Victor Toso <[email protected]>
Acked-by: Uri Lublin <[email protected]>
2019-08-27 16:09:07 +02:00
Victor Toso 83d2dbba24 covscan: avoid false positive on g_clear_pointer()
This is a CLANG_WARNING found by covscan. It is a false positive as
g_clear_pointer() does set vportp to NULL, meaning that the situation
described by covscan below should not be reached. Moving away from
g_clear_pointer() in this specific case just to make our tool happy.

Covscan report:
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:458:9: warning: Use of memory after it is freed
 > #    if (wbuf->write_pos != wbuf->size) {
 > #        ^
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:268:12: note: Assuming the condition is true
 > #    while (*vportp && (*vportp)->write_buf)
 > #           ^~~~~~~
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:268:12: note: Left side of '&&' is true
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:268:5: note: Loop condition is true.  Entering loop body
 > #    while (*vportp && (*vportp)->write_buf)
 > #    ^
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:269:9: note: Calling 'vdagent_virtio_port_do_write'
 > #        vdagent_virtio_port_do_write(vportp);
 > #        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:453:5: note: Taking false branch
 > #    if (!wbuf) {
 > #    ^
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:458:9: note: Assuming the condition is false
 > #    if (wbuf->write_pos != wbuf->size) {
 > #        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:458:5: note: Taking false branch
 > #    if (wbuf->write_pos != wbuf->size) {
 > #    ^
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:465:9: note: Assuming 'n' is < 0
 > #    if (n < 0) {
 > #        ^~~~~
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:465:5: note: Taking true branch
 > #    if (n < 0) {
 > #    ^
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:466:13: note: Assuming the condition is false
 > #        if (errno == EINTR)
 > #            ^~~~~~~~~~~~~~
 > /usr/include/errno.h:38:16: note: expanded from macro 'errno'
 > ## define errno (*__errno_location ())
 > #               ^
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:466:9: note: Taking false branch
 > #        if (errno == EINTR)
 > #        ^
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:469:9: note: Calling 'vdagent_virtio_port_destroy'
 > #        vdagent_virtio_port_destroy(vportp);
 > #        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:130:5: note: Taking false branch
 > #    if (!vport)
 > #    ^
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:133:9: note: Assuming the condition is false
 > #    if (vport->disconnect_callback)
 > #        ^~~~~~~~~~~~~~~~~~~~~~~~~~
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:133:5: note: Taking false branch
 > #    if (vport->disconnect_callback)
 > #    ^
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:137:5: note: Loop condition is true.  Entering loop body
 > #    while (wbuf) {
 > #    ^
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:140:9: note: Memory is released
 > #        g_free(wbuf);
 > #        ^~~~~~~~~~~~
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:137:5: note: Loop condition is false. Execution continues on line 144
 > #    while (wbuf) {
 > #    ^
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:144:5: note: Loop condition is true.  Entering loop body
 > #    for (i = 0; i < VDP_END_PORT; i++) {
 > #    ^
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:144:5: note: Loop condition is true.  Entering loop body
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:144:5: note: Loop condition is true.  Entering loop body
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:144:5: note: Loop condition is false. Execution continues on line 148
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:149:5: note: Assuming '_p' is null
 > #    g_clear_pointer(vportp, g_free);
 > #    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 > /usr/include/glib-2.0/glib/gmem.h:124:9: note: expanded from macro 'g_clear_pointer'
 > #    if (_p)                                                                    \
 > #        ^~
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:149:5: note: Taking false branch
 > /usr/include/glib-2.0/glib/gmem.h:124:5: note: expanded from macro 'g_clear_pointer'
 > #    if (_p)                                                                    \
 > #    ^
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:149:5: note: Loop condition is false.  Exiting loop
 > /usr/include/glib-2.0/glib/gmem.h:114:3: note: expanded from macro 'g_clear_pointer'
 > #  G_STMT_START {                                                               \
 > #  ^
 > /usr/include/glib-2.0/glib/gmacros.h:346:23: note: expanded from macro 'G_STMT_START'
 > ##define G_STMT_START  do
 > #                      ^
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:469:9: note: Returning; memory was released
 > #        vdagent_virtio_port_destroy(vportp);
 > #        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:269:9: note: Returning; memory was released
 > #        vdagent_virtio_port_do_write(vportp);
 > #        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:268:12: note: Left side of '&&' is true
 > #    while (*vportp && (*vportp)->write_buf)
 > #           ^
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:268:5: note: Loop condition is true.  Entering loop body
 > #    while (*vportp && (*vportp)->write_buf)
 > #    ^
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:269:9: note: Calling 'vdagent_virtio_port_do_write'
 > #        vdagent_virtio_port_do_write(vportp);
 > #        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:453:5: note: Taking false branch
 > #    if (!wbuf) {
 > #    ^
 > spice-vdagent-0.19.0/src/vdagentd/virtio-port.c:458:9: note: Use of memory after it is freed
 > #    if (wbuf->write_pos != wbuf->size) {
 > #        ^~~~~~~~~~~~~~~
 > #  456|       }
 > #  457|
 > #  458|->     if (wbuf->write_pos != wbuf->size) {
 > #  459|           syslog(LOG_ERR, "do_write: buffer is incomplete!!");
 > #  460|           return;

Signed-off-by: Victor Toso <[email protected]>
Acked-by: Frediano Ziglio <[email protected]>
2019-08-27 15:00:53 +02:00
Frediano Ziglio 0b94306d2c x11: Change check to make code scanners not giving warning
Some code scanners (both Coverity and clang one) report that
prev_sel/prev_cond could be unreferenced while NULL.
Change condition to make clear a NULL pointer is not used.

Signed-off-by: Frediano Ziglio <[email protected]>
Acked-by: Victor Toso <[email protected]>
2019-07-24 10:32:44 +01:00
Victor Toso 66935d134e device-info: remove g_list_length() on compare_addresses()
The g_list_length() function does iterate over both lists to compare
its length. Considering that we use this to check for true/false and
we will iterate again on both lists, we can do so once.

This also avoids covscan/clang warnings:

 | spice-vdagent-0.19.0/src/vdagent/device-info.c:216:27: warning: Access to field 'data' results in a dereference of a null pointer (loaded from variable 'lb')
 | #        PciDevice *devb = lb->data;
 | #                          ^
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:397:5: note: Taking false branch
 | #    if (!user_pci_addr) {
 | #    ^
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:407:22: note: Calling 'find_device_at_pci_address'
 | #    char *dev_path = find_device_at_pci_address(user_pci_addr, &vendor_id, &device_id);
 | #                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:329:5: note: Taking true branch
 | #    g_return_val_if_fail(pci_addr != NULL, NULL);
 | #    ^
 | /usr/include/glib-2.0/glib/gmessages.h:594:9: note: expanded from macro 'g_return_val_if_fail'
 | #     if G_LIKELY(expr) { } else                                         \
 | #        ^
 | /usr/include/glib-2.0/glib/gmacros.h:385:43: note: expanded from macro 'G_LIKELY'
 | ##define G_LIKELY(expr) (__builtin_expect (_G_BOOLEAN_EXPR((expr)), 1))
 | #                                          ^
 | /usr/include/glib-2.0/glib/gmacros.h:379:4: note: expanded from macro '_G_BOOLEAN_EXPR'
 | #   if (expr)                                    \
 | #   ^
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:329:5: note: Taking true branch
 | /usr/include/glib-2.0/glib/gmessages.h:594:6: note: expanded from macro 'g_return_val_if_fail'
 | #     if G_LIKELY(expr) { } else                                         \
 | #     ^
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:329:5: note: Loop condition is false.  Exiting loop
 | /usr/include/glib-2.0/glib/gmessages.h:593:40: note: expanded from macro 'g_return_val_if_fail'
 | ##define g_return_val_if_fail(expr,val)  G_STMT_START{                   \
 | #                                        ^
 | /usr/include/glib-2.0/glib/gmacros.h:346:23: note: expanded from macro 'G_STMT_START'
 | ##define G_STMT_START  do
 | #                      ^
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:330:5: note: Taking true branch
 | #    g_return_val_if_fail(device_id != NULL, NULL);
 | #    ^
 | /usr/include/glib-2.0/glib/gmessages.h:594:9: note: expanded from macro 'g_return_val_if_fail'
 | #     if G_LIKELY(expr) { } else                                         \
 | #        ^
 | /usr/include/glib-2.0/glib/gmacros.h:385:43: note: expanded from macro 'G_LIKELY'
 | ##define G_LIKELY(expr) (__builtin_expect (_G_BOOLEAN_EXPR((expr)), 1))
 | #                                          ^
 | /usr/include/glib-2.0/glib/gmacros.h:379:4: note: expanded from macro '_G_BOOLEAN_EXPR'
 | #   if (expr)                                    \
 | #   ^
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:330:5: note: Taking true branch
 | /usr/include/glib-2.0/glib/gmessages.h:594:6: note: expanded from macro 'g_return_val_if_fail'
 | #     if G_LIKELY(expr) { } else                                         \
 | #     ^
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:330:5: note: Loop condition is false.  Exiting loop
 | /usr/include/glib-2.0/glib/gmessages.h:593:40: note: expanded from macro 'g_return_val_if_fail'
 | ##define g_return_val_if_fail(expr,val)  G_STMT_START{                   \
 | #                                        ^
 | /usr/include/glib-2.0/glib/gmacros.h:346:23: note: expanded from macro 'G_STMT_START'
 | ##define G_STMT_START  do
 | #                      ^
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:331:5: note: Taking true branch
 | #    g_return_val_if_fail(vendor_id != NULL, NULL);
 | #    ^
 | /usr/include/glib-2.0/glib/gmessages.h:594:9: note: expanded from macro 'g_return_val_if_fail'
 | #     if G_LIKELY(expr) { } else                                         \
 | #        ^
 | /usr/include/glib-2.0/glib/gmacros.h:385:43: note: expanded from macro 'G_LIKELY'
 | ##define G_LIKELY(expr) (__builtin_expect (_G_BOOLEAN_EXPR((expr)), 1))
 | #                                          ^
 | /usr/include/glib-2.0/glib/gmacros.h:379:4: note: expanded from macro '_G_BOOLEAN_EXPR'
 | #   if (expr)                                    \
 | #   ^
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:331:5: note: Taking true branch
 | /usr/include/glib-2.0/glib/gmessages.h:594:6: note: expanded from macro 'g_return_val_if_fail'
 | #     if G_LIKELY(expr) { } else                                         \
 | #     ^
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:331:5: note: Loop condition is false.  Exiting loop
 | /usr/include/glib-2.0/glib/gmessages.h:593:40: note: expanded from macro 'g_return_val_if_fail'
 | ##define g_return_val_if_fail(expr,val)  G_STMT_START{                   \
 | #                                        ^
 | /usr/include/glib-2.0/glib/gmacros.h:346:23: note: expanded from macro 'G_STMT_START'
 | ##define G_STMT_START  do
 | #                      ^
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:334:5: note: Loop condition is true.  Entering loop body
 | #    for (int i = 0; i < 10; ++i) {
 | #    ^
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:340:13: note: Assuming the condition is false
 | #        if (stat(dev_path, &buf) != 0) {
 | #            ^~~~~~~~~~~~~~~~~~~~~~~~~
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:340:9: note: Taking false branch
 | #        if (stat(dev_path, &buf) != 0) {
 | #        ^
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:355:13: note: Assuming the condition is false
 | #        if (realpath(sys_path, device_link) == NULL) {
 | #            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:355:9: note: Taking false branch
 | #        if (realpath(sys_path, device_link) == NULL) {
 | #        ^
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:361:36: note: Calling 'parse_pci_address_from_sysfs_path'
 | #        PciAddress *drm_pci_addr = parse_pci_address_from_sysfs_path(device_link);
 | #                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:129:9: note: Assuming 'pos' is non-null
 | #    if (!pos) {
 | #        ^~~~
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:129:5: note: Taking false branch
 | #    if (!pos) {
 | #    ^
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:136:9: note: Assuming 'pos' is non-null
 | #    if (!pos) {
 | #        ^~~~
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:136:5: note: Taking false branch
 | #    if (!pos) {
 | #    ^
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:142:9: note: Assuming 'pos' is non-null
 | #    if (!pos) {
 | #        ^~~~
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:142:5: note: Taking false branch
 | #    if (!pos) {
 | #    ^
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:146:27: note: Calling 'pci_address_new'
 | #    PciAddress *address = pci_address_new();
 | #                          ^~~~~~~~~~~~~~~~~
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:61:12: note: Taking false branch
 | #    return g_new0(PciAddress, 1);
 | #           ^
 | /usr/include/glib-2.0/glib/gmem.h:279:42: note: expanded from macro 'g_new0'
 | ##define g_new0(struct_type, n_structs)                  _G_NEW (struct_type, n_structs, malloc0)
 | #                                                        ^
 | /usr/include/glib-2.0/glib/gmem.h:211:4: note: expanded from macro '_G_NEW'
 | #          if (__s == 1)                                         \
 | #          ^
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:61:12: note: Left side of '&&' is false
 | /usr/include/glib-2.0/glib/gmem.h:279:42: note: expanded from macro 'g_new0'
 | ##define g_new0(struct_type, n_structs)                  _G_NEW (struct_type, n_structs, malloc0)
 | #                                                        ^
 | /usr/include/glib-2.0/glib/gmem.h:213:40: note: expanded from macro '_G_NEW'
 | #          else if (__builtin_constant_p (__n) &&                \
 | #                                              ^
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:61:12: note: Null pointer value stored to field 'devices'
 | #    return g_new0(PciAddress, 1);
 | #           ^~~~~~~~~~~~~~~~~~~~~
 | /usr/include/glib-2.0/glib/gmem.h:279:42: note: expanded from macro 'g_new0'
 | ##define g_new0(struct_type, n_structs)                  _G_NEW (struct_type, n_structs, malloc0)
 | #                                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 | /usr/include/glib-2.0/glib/gmem.h:217:12: note: expanded from macro '_G_NEW'
 | #            __p = g_##func##_n (__n, __s);                      \
 | #                  ^~~~~~~~~~~~~~~~~~~~~~~
 | <scratch space>:76:1: note: expanded from here
 | #g_malloc0_n
 | #^
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:146:27: note: Returning from 'pci_address_new'
 | #    PciAddress *address = pci_address_new();
 | #                          ^~~~~~~~~~~~~~~~~
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:149:5: note: Loop condition is true.  Entering loop body
 | #    while (pos) {
 | #    ^
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:150:26: note: Taking false branch
 | #        PciDevice *dev = g_new0(PciDevice, 1);
 | #                         ^
 | /usr/include/glib-2.0/glib/gmem.h:279:42: note: expanded from macro 'g_new0'
 | ##define g_new0(struct_type, n_structs)                  _G_NEW (struct_type, n_structs, malloc0)
 | #                                                        ^
 | /usr/include/glib-2.0/glib/gmem.h:211:4: note: expanded from macro '_G_NEW'
 | #          if (__s == 1)                                         \
 | #          ^
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:150:26: note: Left side of '&&' is false
 | /usr/include/glib-2.0/glib/gmem.h:279:42: note: expanded from macro 'g_new0'
 | ##define g_new0(struct_type, n_structs)                  _G_NEW (struct_type, n_structs, malloc0)
 | #                                                        ^
 | /usr/include/glib-2.0/glib/gmem.h:213:40: note: expanded from macro '_G_NEW'
 | #          else if (__builtin_constant_p (__n) &&                \
 | #                                              ^
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:152:9: note: Taking true branch
 | #        if (!parse_pci_device(pos + 1, next, dev)) {
 | #        ^
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:154:13: note:  Execution continues on line 159
 | #            break;
 | #            ^
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:361:36: note: Returning from 'parse_pci_address_from_sysfs_path'
 | #        PciAddress *drm_pci_addr = parse_pci_address_from_sysfs_path(device_link);
 | #                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:362:9: note: Taking false branch
 | #        if (!drm_pci_addr) {
 | #        ^
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:367:14: note: Calling 'compare_addresses'
 | #        if (!compare_addresses(pci_addr, drm_pci_addr)) {
 | #             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:207:11: note: Assuming the condition is true
 | #    if (!(a->domain == b->domain
 | #          ^~~~~~~~~~~~~~~~~~~~~~
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:207:11: note: Left side of '&&' is true
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:208:12: note: Assuming the condition is true
 | #        && g_list_length(a->devices) == g_list_length(b->devices))) {
 | #           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:207:5: note: Taking false branch
 | #    if (!(a->domain == b->domain
 | #    ^
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:212:35: note: 'lb' initialized to a null pointer value
 | #    for (GList *la = a->devices, *lb = b->devices;
 | #                                  ^~
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:213:10: note: Assuming 'la' is not equal to NULL
 | #         la != NULL;
 | #         ^~~~~~~~~~
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:212:5: note: Loop condition is true.  Entering loop body
 | #    for (GList *la = a->devices, *lb = b->devices;
 | #    ^
 | spice-vdagent-0.19.0/src/vdagent/device-info.c:216:27: note: Access to field 'data' results in a dereference of a null pointer (loaded from variable 'lb')
 | #        PciDevice *devb = lb->data;
 | #                          ^~
 | #  214|            la = la->next, lb = lb->next) {
 | #  215|           PciDevice *deva = la->data;
 | #  216|->         PciDevice *devb = lb->data;
 | #  217|
 | #  218|           if (deva->slot != devb->slot

Signed-off-by: Victor Toso <[email protected]>
Acked-by: Frediano Ziglio <[email protected]>
2019-07-24 10:32:37 +01:00
Frediano Ziglio af8d1948b1 x11: Constify XEvent argument
No reasons to have it mutable.

Signed-off-by: Frediano Ziglio <[email protected]>
Acked-by: Victor Toso <[email protected]>
2019-07-24 10:32:35 +01:00
Frediano Ziglio 3522667bfa x11: Avoid passing XEvent as value
The structure is not that small and is not necessary to copy
the value.
This also removed a Coverity warning.

Signed-off-by: Frediano Ziglio <[email protected]>
Acked-by: Victor Toso <[email protected]>
2019-07-24 10:32:32 +01:00
Frediano Ziglio b6dfef73f2 x11-randr: Avoid passing XEvent as value
The structure is not that small and is not necessary to copy
the value.
This also removed a Coverity warning.

Signed-off-by: Frediano Ziglio <[email protected]>
Acked-by: Victor Toso <[email protected]>
2019-07-24 10:32:23 +01:00
Victor Toso 6bfbd03e83 vdagent: simple fix for address-of-packed-member
Seems to be a false positive but as this message only happens when user
client connects, we can copy this array to make compiling warn free.

 > src/vdagent/vdagent.c: In function ‘daemon_read_complete’:
 > src/vdagent/vdagent.c:226:71: error: taking address of packed member of
 >     ‘struct VDAgentAudioVolumeSync’ may result in an unaligned pointer
 >     value [-Werror=address-of-packed-member]
 >   226 |             vdagent_audio_playback_sync(avs->mute, avs->nchannels, avs->volume);
 >       |                                                                    ~~~^~~~~~~~
 > src/vdagent/vdagent.c:228:69: error: taking address of packed member of
 >     ‘struct VDAgentAudioVolumeSync’ may result in an unaligned pointer
 >     value [-Werror=address-of-packed-member]
 >   228 |             vdagent_audio_record_sync(avs->mute, avs->nchannels, avs->volume);
 >       |                                                                  ~~~^~~~~~~~

Signed-off-by: Victor Toso <[email protected]>
Acked-by: Frediano Ziglio <[email protected]>
2019-07-19 12:13:42 +01:00
Victor Toso 7976dc31af x11-randr: simplest fix for address-of-packed-member
The struct type for width/height is uint32_t while we are trying to
access and change it with int* - code can be improved a bit in following
patches but this one fixes the warning by copying the value from the
struct and copying back new value afterwards.

Also:
- Moved variables to internal scope;
- Added braces to inner if;

 > src/vdagent/x11-randr.c: In function ‘zero_base_monitors’:
 >     src/vdagent/x11-randr.c:621:28: error: taking address of packed member of
 >     ‘struct VDAgentMonConfig’ may result in an unaligned pointer value
 > [-Werror=address-of-packed-member]
 >   621 |         mon_width = (int *)&mon_config->monitors[i].width;
 >       |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 > src/vdagent/x11-randr.c:622:29: error: taking address of packed member of
 >     ‘struct VDAgentMonConfig’ may result in an unaligned pointer value
 >     [-Werror=address-of-packed-member]
 >   622 |         mon_height = (int *)&mon_config->monitors[i].height;
 >       |                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Victor Toso <[email protected]>
Acked-by: Frediano Ziglio <[email protected]>
2019-07-19 11:49:32 +01:00
Victor Toso 70c5908f8c x11-randr: use glib's MAX and MIN
Since 2861868 "randr: remove monitors.xml on auto-configuration" in
2015-04-10 by Marc-Andre Lureau <[email protected]> this
file includes glib.h and can remove those helpers.

Signed-off-by: Victor Toso <[email protected]>
Acked-by: Frediano Ziglio <[email protected]>
2019-07-19 11:38:19 +01:00
Victor Toso b6fde1641a vdagent: fix memory leak of g_memdup()
Found by covscan:

 | spice-vdagent-0.19.0/src/vdagent/vdagent.c:432:9: warning: Potential leak of memory pointed to by 'orig_argv'
 | #        g_printerr("Invalid arguments, %s\n", error->message);
 | #        ^
 | spice-vdagent-0.19.0/src/vdagent/vdagent.c:418:24: note: Memory is allocated
 | #    char **orig_argv = g_memdup(argv, sizeof(char*) * (argc+1));
 | #                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 | spice-vdagent-0.19.0/src/vdagent/vdagent.c:431:9: note: Assuming 'error' is not equal to NULL
 | #    if (error != NULL) {
 | #        ^~~~~~~~~~~~~
 | spice-vdagent-0.19.0/src/vdagent/vdagent.c:431:5: note: Taking true branch
 | #    if (error != NULL) {
 | #    ^
 | spice-vdagent-0.19.0/src/vdagent/vdagent.c:432:9: note: Potential leak of memory pointed to by 'orig_argv'
 | #        g_printerr("Invalid arguments, %s\n", error->message);
 | #        ^
 | #  430|
 | #  431|       if (error != NULL) {
 | #  432|->         g_printerr("Invalid arguments, %s\n", error->message);
 | #  433|           g_clear_error(&error);
 | #  434|           return -1;

Signed-off-by: Victor Toso <[email protected]>
Acked-by: Frediano Ziglio <[email protected]>
2019-07-19 11:37:54 +01:00
54 changed files with 5848 additions and 1583 deletions

No files matched your search

+144
View File
@@ -0,0 +1,144 @@
name: Build
on:
push:
pull_request:
jobs:
build-macos:
name: Build macOS
runs-on: macos-15
env:
GLIB_VERSION: "2.90.0"
GLIB_SHA256: 17d15cac2af80a33271127408e0abc2748eb297c595c2a26409e81e14e7d1b8f
GETTEXT_VERSION: "1.0"
GETTEXT_SHA256: 71132a3fb71e68245b8f2ac4e9e97137d3e5c02f415636eb508ae607bc01add7
# must be <= the project's deployment target
MACOSX_DEPLOYMENT_TARGET: "10.13"
ARCHS: arm64 x86_64
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Install build tools
run: |
brew install meson ninja pkgconf
echo "GLIB_PREFIX=$RUNNER_TEMP/glib" >> "$GITHUB_ENV"
- name: Cache GLib
id: cache
uses: actions/cache@v4
with:
path: ${{ runner.temp }}/glib
key: glib-${{ env.GLIB_VERSION }}-gettext-${{ env.GETTEXT_VERSION }}-${{ hashFiles('.github/workflows/build.yaml') }}
- name: Build gettext
if: steps.cache.outputs.cache-hit != 'true'
working-directory: ${{ runner.temp }}
run: |
curl -fsSLO "https://ftp.gnu.org/gnu/gettext/gettext-$GETTEXT_VERSION.tar.xz"
echo "$GETTEXT_SHA256 gettext-$GETTEXT_VERSION.tar.xz" | shasum -a 256 -c -
for arch in $ARCHS; do
rm -rf "gettext-$GETTEXT_VERSION"
tar xf "gettext-$GETTEXT_VERSION.tar.xz"
pushd "gettext-$GETTEXT_VERSION/gettext-runtime"
./configure --host="${arch/arm64/aarch64}-apple-darwin" \
--prefix="$GLIB_PREFIX/$arch" \
--enable-static \
--disable-shared \
--with-included-gettext \
--disable-java \
--disable-csharp \
--disable-libasprintf \
--without-libintl-prefix \
--without-libiconv-prefix \
CC="clang -arch $arch"
make -C intl -j"$(sysctl -n hw.ncpu)"
make -C intl install
popd
done
- name: Build GLib
if: steps.cache.outputs.cache-hit != 'true'
working-directory: ${{ runner.temp }}
run: |
curl -fsSLO "https://download.gnome.org/sources/glib/${GLIB_VERSION%.*}/glib-$GLIB_VERSION.tar.xz"
echo "$GLIB_SHA256 glib-$GLIB_VERSION.tar.xz" | shasum -a 256 -c -
tar xf "glib-$GLIB_VERSION.tar.xz"
# girepository is unused and requires macOS 10.15
sed -i '' "/^subdir('girepository')$/d" "glib-$GLIB_VERSION/meson.build"
sdk="$(xcrun --sdk macosx --show-sdk-path)"
for arch in $ARCHS; do
prefix="$GLIB_PREFIX/$arch"
mkdir -p "$prefix/lib/pkgconfig"
cat > "$prefix/lib/pkgconfig/libffi.pc" <<EOF
Name: libffi
Description: Library supporting Foreign Function Interfaces
Version: 3.4
Cflags: -I$sdk/usr/include/ffi
Libs: -lffi
EOF
# don't depend on Rosetta
[ "$arch" = "$(uname -m)" ] && needs_exe_wrapper=false || needs_exe_wrapper=true
cat > "cross-$arch.ini" <<EOF
[binaries]
c = ['clang', '-arch', '$arch']
cpp = ['clang++', '-arch', '$arch']
objc = ['clang', '-arch', '$arch']
ar = 'ar'
strip = 'strip'
pkg-config = 'pkg-config'
[built-in options]
c_args = ['-I$prefix/include', '-Werror=unguarded-availability-new']
cpp_args = ['-I$prefix/include']
objc_args = ['-I$prefix/include', '-Werror=unguarded-availability-new']
c_link_args = ['-L$prefix/lib']
cpp_link_args = ['-L$prefix/lib']
objc_link_args = ['-L$prefix/lib']
[properties]
needs_exe_wrapper = $needs_exe_wrapper
pkg_config_libdir = ['$prefix/lib/pkgconfig']
# macOS 27+, meson's check ignores availability
has_function_pipe2 = false
[host_machine]
system = 'darwin'
subsystem = 'macos'
kernel = 'xnu'
cpu_family = '${arch/arm64/aarch64}'
cpu = '${arch/arm64/aarch64}'
endian = 'little'
EOF
# SDK has no pcre2 headers; other fallbacks would silently stub out deps (e.g. libintl)
meson setup "build-$arch" "glib-$GLIB_VERSION" \
--cross-file "cross-$arch.ini" \
--prefix="$prefix" \
--buildtype=release \
--default-library=static \
--wrap-mode=nofallback \
--force-fallback-for=libpcre2-8 \
-Dbsymbolic_functions=false \
-Ddtrace=disabled \
-Dintrospection=disabled \
-Dnls=disabled \
-Dman-pages=disabled \
-Ddocumentation=false \
-Dtests=false
meson compile -C "build-$arch"
meson install -C "build-$arch"
done
- name: Build
run: |
xcodebuild archive -scheme vd_agent -archivePath vd_agent.xcarchive \
ARCHS="$ARCHS" ONLY_ACTIVE_ARCH=NO \
GLIB_ARM64_PREFIX="$GLIB_PREFIX/arm64" \
GLIB_X86_64_PREFIX="$GLIB_PREFIX/x86_64"
- name: Archive
run: tar -acf vd_agent.xcarchive.tgz vd_agent.xcarchive
- name: Upload
uses: actions/upload-artifact@v4
with:
name: vd_agent-macOS
path: vd_agent.xcarchive.tgz
+23 -4
View File
@@ -5,19 +5,25 @@ variables:
bzip2 python3-pyparsing meson ninja-build gtk-doc glib2-devel
gettext gettext-devel libpciaccess-devel alsa-lib-devel
libXfixes-devel libX11-devel libXrandr-devel libXinerama-devel
gtk3-devel dbus-devel systemd-devel
gtk3-devel dbus-devel systemd-devel procps-ng libdrm-devel gtk4-devel
vulkan-headers
DISTCHECK_CONFIGURE_FLAGS:
--with-session-info=none
before_script:
- dnf install -y $DEPS_COMMON
- git clone https://gitlab.freedesktop.org/spice/spice-protocol.git
- (cd spice-protocol && ./autogen.sh --prefix=/usr && make install)
- meson --buildtype=release spice-protocol build-spice-protocol --prefix=/usr --werror
- ninja -C build-spice-protocol install
fedora-autotools:
script:
- ./autogen.sh
- make
- make check
- make distcheck
- git clean -xfd
- ./autogen.sh --with-session-info=none
- make distcheck --environment-overrides
- git clean -xfd
- ./autogen.sh --with-session-info=systemd --with-init-script=systemd+redhat
@@ -37,3 +43,16 @@ fedora-autotools:
- make install
- make uninstall
- git clean -xfd
- ./autogen.sh --with-gtk4
- make
- make install
- make uninstall
- git clean -xfd
artifacts:
expire_in: '1 week'
when: on_failure
paths:
- test-suite.log
- tests/test*.log
+43 -6
View File
@@ -1,3 +1,40 @@
Gitlab markdown format support linking to Issues (#) and Merge requests (!) and more, see below:
https://gitlab.freedesktop.org/spice/linux/vd_agent/-/blob/master/CHANGELOG.md
News in spice-vdagent 0.22.1
===========================
* !42 - Fix crash on startup of session agent
News in spice-vdagent 0.22.0
===========================
* !40 - Handle side mouse buttons
* !39 - Set retry limit to connect to vdagentd and improve logging error
* !35 - Fix deprecation warning
* !37 - Provide systemd spice-vdagent.service
News in spice-vdagent 0.21.0
============================
* Security fixes:
CVE-2020-25650, CVE-2020-25651, CVE-2020-25652, CVE-2020-25653
* Fix shutdown issue due to incompatible thread/fork uses with GLib
* Fix mouse pointer issues under Wayland
* Fix a crash when running without dbus (e.g: within containers)
* !9 - Introduce optional GTK4 support for monitor management
* !13 - Enable copying files from client using webdav
* Bump spice-protocol dependency to v0.14.3
News in spice-vdagent 0.20.0
============================
* Add gio-unix and gobject dependency >= 2.50
* Bump gtk+ >= 3.22 (optional dependency)
* Last release with gtk+ being optional
* !4 - Race fixes between client and guest clipboard
* !2 - Fix session lookup for new GNOME versions
* !3 - Now using GMainLoop and GIO to handle I/O of messages
* Several minor covscan fixes
News in spice-vdagent 0.19.0
============================
@@ -56,7 +93,7 @@ News in spice-vdagent 0.17.0
* Set exit code to 1 instead of 0 when virtio device cannot be opened
* Fix double-free on uinput->screen_info (rhbz#1262635)
* Code improvement over unix domain client server support (udcs)
* Fix build compatiblity with different libsystemd versions (fdo#94209)
* Fix build compatibility with different libsystemd versions (fdo#94209)
News in spice-vdagent 0.16.0
============================
@@ -80,7 +117,7 @@ News in spice-vdagent 0.15.0
News in spice-vdagent 0.14.0
============================
* More multi-monitor and arbritary resolution support bugfixes
* More multi-monitor and arbitrary resolution support bugfixes
* Add support for file transfers from client to guest
* Add support for setups with multiple Screens (multiple qxl devices each
mapped to their own screen), limitations:
@@ -94,16 +131,16 @@ News in spice-vdagent 0.14.0
News in spice-vdagent 0.12.1
============================
* Various bugfixes for multi-monitor and arbritary resolution support
* Various bugfixes for multi-monitor and arbitrary resolution support
* Requires libXrandr >= 1.3, Note 0.12.0 also required this, but did not
check for it. For older distributions use 0.10.1
News in spice-vdagent 0.12.0
============================
* Full multi-monitor and arbritary resolution support, this requires a new
* Full multi-monitor and arbitrary resolution support, this requires a new
enough xorg-x11-drv-qxl driver, as well as a new enough host
* systemd service support, using systemd hardware acivation
* systemd service support, using systemd hardware activation
* Use syslog for logging, rather then logging to private log files
News in spice-vdagent 0.10.1
@@ -128,7 +165,7 @@ News in spice-vdagent 0.8.1
* In daemon mode the session vdagent now retries connecting to the system
vdagentd every second, once a connection is made a version check is done,
if the version differs (which only happens on an upgrade from one version
to the next) the sesion vdagent re-execs itself (Marc-André Lureau)
to the next) the session vdagent re-execs itself (Marc-André Lureau)
News in spice-vdagent 0.8.0
===========================
+44 -9
View File
@@ -9,6 +9,8 @@ TESTS = $(check_PROGRAMS)
common_sources = \
src/udscs.c \
src/udscs.h \
src/vdagent-connection.c \
src/vdagent-connection.h \
src/vdagentd-proto-strings.h \
src/vdagentd-proto.h \
$(NULL)
@@ -17,7 +19,7 @@ src_spice_vdagent_CFLAGS = \
$(DRM_CFLAGS) \
$(X_CFLAGS) \
$(SPICE_CFLAGS) \
$(GLIB2_CFLAGS) \
$(GIO2_CFLAGS) \
$(GTK_CFLAGS) \
$(ALSA_CFLAGS) \
-I$(srcdir)/src \
@@ -28,7 +30,7 @@ src_spice_vdagent_LDADD = \
$(DRM_LIBS) \
$(X_LIBS) \
$(SPICE_LIBS) \
$(GLIB2_LIBS) \
$(GIO2_LIBS) \
$(GTK_LIBS) \
$(ALSA_LIBS) \
$(NULL)
@@ -39,10 +41,16 @@ src_spice_vdagent_SOURCES = \
src/vdagent/audio.h \
src/vdagent/clipboard.c \
src/vdagent/clipboard.h \
src/vdagent/webdav-cb.c \
src/vdagent/webdav-cb.h \
src/vdagent/device-info.c \
src/vdagent/device-info.h \
src/vdagent/display.c \
src/vdagent/display.h \
src/vdagent/file-xfers.c \
src/vdagent/file-xfers.h \
src/vdagent/mutter.c \
src/vdagent/mutter.h \
src/vdagent/x11-priv.h \
src/vdagent/x11-randr.c \
src/vdagent/x11.c \
@@ -52,7 +60,7 @@ src_spice_vdagent_SOURCES = \
tests_test_file_xfers_CFLAGS = \
$(SPICE_CFLAGS) \
$(GLIB2_CFLAGS) \
$(GIO2_CFLAGS) \
-I$(srcdir)/src \
-I$(srcdir)/src/vdagent \
-DUDSCS_NO_SERVER \
@@ -60,7 +68,7 @@ tests_test_file_xfers_CFLAGS = \
tests_test_file_xfers_LDADD = \
$(SPICE_LIBS) \
$(GLIB2_LIBS) \
$(GIO2_LIBS) \
$(NULL)
tests_test_file_xfers_SOURCES = \
@@ -76,7 +84,7 @@ src_spice_vdagentd_CFLAGS = \
$(LIBSYSTEMD_LOGIN_CFLAGS) \
$(PCIACCESS_CFLAGS) \
$(SPICE_CFLAGS) \
$(GLIB2_CFLAGS) \
$(GIO2_CFLAGS) \
$(PIE_CFLAGS) \
-I$(srcdir)/src \
$(NULL)
@@ -87,7 +95,7 @@ src_spice_vdagentd_LDADD = \
$(LIBSYSTEMD_LOGIN_LIBS) \
$(PCIACCESS_LIBS) \
$(SPICE_LIBS) \
$(GLIB2_LIBS) \
$(GIO2_LIBS) \
$(PIE_LDFLAGS) \
$(NULL)
@@ -103,11 +111,34 @@ src_spice_vdagentd_SOURCES = \
src/vdagentd/virtio-port.h \
$(NULL)
tests_test_session_info_CFLAGS = \
$(DBUS_CFLAGS) \
$(GIO2_CFLAGS) \
-I$(srcdir)/src \
-I$(srcdir)/src/vdagentd \
$(NULL)
tests_test_session_info_LDADD = \
$(DBUS_LIBS) \
$(GIO2_LIBS) \
$(NULL)
tests_test_session_info_SOURCES = \
src/vdagentd/session-info.h \
tests/test-session-info.c \
$(NULL)
if HAVE_CONSOLE_KIT
src_spice_vdagentd_SOURCES += src/vdagentd/console-kit.c
tests_test_session_info_SOURCES += src/vdagentd/console-kit.c
check_PROGRAMS += tests/test-session-info
else
if HAVE_LIBSYSTEMD_LOGIN
src_spice_vdagentd_SOURCES += src/vdagentd/systemd-login.c
tests_test_session_info_CFLAGS += $(LIBSYSTEMD_LOGIN_CFLAGS)
tests_test_session_info_LDADD += $(LIBSYSTEMD_LOGIN_LIBS)
tests_test_session_info_SOURCES += src/vdagentd/systemd-login.c
check_PROGRAMS += tests/test-session-info
else
src_spice_vdagentd_SOURCES += src/vdagentd/dummy-session-info.c
endif
@@ -122,9 +153,6 @@ gdmautostart_DATA = $(top_srcdir)/data/spice-vdagent.desktop
gdmautostart2dir = $(datadir)/gdm/autostart/LoginWindow
gdmautostart2_DATA = $(top_srcdir)/data/spice-vdagent.desktop
install-data-local:
$(mkdir_p) $(DESTDIR)$(localstatedir)/run/spice-vdagentd
if INIT_SCRIPT_RED_HAT
initdir = $(sysconfdir)/rc.d/init.d
init_SCRIPTS = $(top_srcdir)/data/spice-vdagentd
@@ -136,6 +164,10 @@ systemdunit_DATA = \
$(top_srcdir)/data/spice-vdagentd.service \
$(top_srcdir)/data/spice-vdagentd.socket
userunitdir = $(SYSTEMDUSERUNITDIR)
userunit_DATA = \
$(top_srcdir)/data/spice-vdagent.service
udevrulesdir = $(udevdir)/rules.d
udevrules_DATA = $(top_srcdir)/data/70-spice-vdagentd.rules
@@ -154,6 +186,7 @@ EXTRA_DIST = \
CHANGELOG.md \
data/70-spice-vdagentd.rules \
data/spice-vdagent.desktop \
data/spice-vdagent.service \
data/spice-vdagentd \
data/spice-vdagentd.service \
data/spice-vdagentd.socket \
@@ -169,3 +202,5 @@ tests_test_device_info_LDADD = $(src_spice_vdagent_LDADD)
tests_test_device_info_CFLAGS = $(src_spice_vdagent_CFLAGS)
check_PROGRAMS += tests/test-device-info
check_PROGRAMS += tests/test-termination
+62 -2
View File
@@ -1,5 +1,7 @@
Spice agent for Linux
=====================
Spice agent for Linux and macOS
===============================
### Linux
The spice agent for Linux consists of 2 parts, a daemon spice-vdagentd and
a per X-session process spice-vdagent. The daemon gets started in Spice guests
@@ -27,6 +29,59 @@ Features:
* Limited support for setups with multiple Screens (multiple qxl devices each
mapped to their own screen)
### macOS
Similar to Linux, the SPICE agent has a LaunchDaemon spice-vdagentd which
handles communication with the console port and a LaunchAgent spice-vdagent
that runs for each logged in user. Note that there is no protection against
one logged in user from snooping another user's clipboard when this is running.
The macOS agent currently only supports clipboard features.
## Install (Linux)
From inside your virtual machine (e.g., GNOME Boxes), use your guest system’s
package manager to install.
For example, if you’re running a Debian/Ubuntu derivative in a VM, use:
```shell
sudo apt install spice-vdagent
```
## Build (macOS)
Currently, you can only build on Apple Silicon Macs with Homebrew installed in
both native and Rosetta. This is because we require GLib installed in both
architectures at the default location.
>>>
$ /opt/homebrew/bin/brew install glib # arm64
$ /usr/local/bin/brew install glib # x86_64
>>>
Alternatively, GLib can be built from source for each architecture (see
`.github/workflows/build.yaml`) and the install prefixes passed to Xcode
with `GLIB_ARM64_PREFIX=... GLIB_X86_64_PREFIX=...`.
Then, you can build the project with Xcode or `xcodebuild`
>>>
$ xcodebuild archive -scheme vd_agent -archivePath vd_agent.xcarchive
>>>
Afterwards, you can sign the output and create an installer package with a paid
Apple Developer certificate (Developer ID Application and Developer ID
Installer are both needed).
>>>
$ ./package_macos.sh vd_agent.xcarchive spice-vdagent-x.yy.pkg
>>>
You may then wish to notarize it before distributing.
## How it works
All vdagent communications on the guest side run over a single pipe which
gets presented to the guest os as a virtio serial port.
@@ -40,6 +95,11 @@ Under Linux this virtio serial port has the following name:
/dev/virtio-ports/com.redhat.spice.0
>>>
Under macOS this virtio serial port has the following name:
>>>
/dev/tty.com.redhat.spice.0
>>>
To enable the virtio serial port you need to pass the following params on
the qemu cmdline:
+33 -7
View File
@@ -1,5 +1,5 @@
AC_PREREQ(2.59)
AC_INIT([spice-vdagent], [0.19.0])
AC_INIT([spice-vdagent], [0.22.1])
AC_CONFIG_SRCDIR([configure.ac])
AM_CONFIG_HEADER([src/config.h])
@@ -64,7 +64,9 @@ AC_MSG_RESULT($with_init_script)
if test "x$init_systemd" = "xyes"; then
SYSTEMDSYSTEMUNITDIR=`${PKG_CONFIG} systemd --variable=systemdsystemunitdir`
SYSTEMDUSERUNITDIR=`${PKG_CONFIG} systemd --variable=systemduserunitdir`
AC_SUBST(SYSTEMDSYSTEMUNITDIR)
AC_SUBST(SYSTEMDUSERUNITDIR)
# earlier versions of systemd require a separate libsystemd-daemon library
PKG_CHECK_MODULES([LIBSYSTEMD_DAEMON],
[libsystemd >= 209],
@@ -81,13 +83,30 @@ AC_ARG_WITH([gtk],
[Use GTK+ instead of Xlib @<:@default=auto@:>@])],
[],
[with_gtk="auto"])
if test "x$with_gtk" != "xno"; then
PKG_CHECK_MODULES([GTK], [gtk+-3.0 >= 3.10], [
AC_DEFINE([WITH_GTK], [1], [If defined, vdagent will favor GTK+ over Xlib])
AC_ARG_WITH([gtk4],
[AS_HELP_STRING(
[--with-gtk4=@<:@yes/no@:>@],
[Use GTK4 instead of Xlib @<:@default=no@:>@])],
[],
[with_gtk4="no"])
if test "x$with_gtk4" = "xyes"; then
PKG_CHECK_MODULES([GTK], [gtk4 >= 3.98], [
AC_DEFINE([WITH_GTK], [1], [If defined, load GTK+ libraries])
AC_DEFINE([USE_GTK_FOR_MONITORS], [1], [If defined, use GTK for monitor resolution instead of XRandr])
with_gtk="yes"
], [
AC_MSG_ERROR([GTK4 requested but not found])
with_gtk="no"])
else
if test "x$with_gtk" != "xno"; then
PKG_CHECK_MODULES([GTK], [gtk+-3.0 >= 3.22], [
AC_DEFINE([WITH_GTK], [1], [If defined, load GTK+ libraries])
AC_DEFINE([USE_GTK_FOR_CLIPBOARD], [1], [If defined, use GTK for clipboard features])
with_gtk="yes"
], [
AS_IF([test "x$with_gtk" = "xyes"], [AC_MSG_ERROR([GTK+ requested but not found])])
with_gtk="no"])
fi
fi
AC_ARG_ENABLE([pciaccess],
@@ -100,13 +119,17 @@ AC_ARG_ENABLE([static-uinput],
[enable_static_uinput="$enableval"],
[enable_static_uinput="no"])
PKG_CHECK_MODULES([GLIB2], [glib-2.0 >= 2.34])
PKG_CHECK_MODULES([GIO2], [gio-unix-2.0 >= 2.50])
PKG_CHECK_MODULES(X, [xfixes xrandr >= 1.3 xinerama x11])
PKG_CHECK_MODULES(SPICE, [spice-protocol >= 0.14.0])
PKG_CHECK_MODULES(SPICE, [spice-protocol >= 0.14.3])
PKG_CHECK_MODULES(ALSA, [alsa >= 1.0.22])
PKG_CHECK_MODULES([DBUS], [dbus-1])
PKG_CHECK_MODULES([DRM], [libdrm])
PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.68], [], [
AC_DEFINE(g_memdup2, g_memdup, [GLib2 < 2.68 compatibility])
])
if test "$with_session_info" = "auto" || test "$with_session_info" = "systemd"; then
PKG_CHECK_MODULES([LIBSYSTEMD_LOGIN],
[libsystemd >= 209],
@@ -155,7 +178,7 @@ if test x"$enable_static_uinput" = "xyes" ; then
fi
# If no CFLAGS are set, set some sane default CFLAGS
if test "$ac_test_CFLAGS" != set; then
if test -z "$ac_test_CFLAGS"; then
DEFAULT_CFLAGS="-Wall -Werror -Wp,-D_FORTIFY_SOURCE=2 -fno-strict-aliasing -fstack-protector --param=ssp-buffer-size=4"
for F in $DEFAULT_CFLAGS; do
AC_MSG_CHECKING([whether $CC supports $F])
@@ -169,6 +192,9 @@ if test "$ac_test_CFLAGS" != set; then
done
fi
# Always enabled for autoconf targets
AC_DEFINE([WITH_SESSION_SECURITY], [1], [If undefined and there is no session info, only one session agent is allowed] )
AC_ARG_ENABLE([pie],
AS_HELP_STRING([--enable-pie=@<:@auto/yes/no@:>@],
[Enable position-independent-executable support (for spice-vdagentd)@<:@default=auto@:>@]),
+22
View File
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<dict>
<key>Crashed</key>
<false/>
</dict>
<key>Label</key>
<string>com.redhat.spice.vdagent</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/spice-vdagent</string>
<string>-x</string>
<string>-S</string>
<string>/var/run/spice-vdagent-sock</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
+28
View File
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<dict>
<key>Crashed</key>
<false/>
</dict>
<key>Label</key>
<string>com.redhat.spice.vdagentd</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/spice-vdagentd</string>
<string>-x</string>
<string>-s</string>
<string>/dev/tty.com.redhat.spice.0</string>
<string>-S</string>
<string>/var/run/spice-vdagent-sock</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/var/log/spice-vdagentd.stderr.log</string>
<key>StandardOutPath</key>
<string>/var/log/spice-vdagentd.stdout.log</string>
</dict>
</plist>
+12
View File
@@ -0,0 +1,12 @@
#!/bin/sh
set -e
GUI_USER=$(stat -f%Su /dev/console)
GUI_UID=$(id -u $GUI_USER)
/bin/launchctl load /Library/LaunchDaemons/com.redhat.spice.vdagentd.plist
if [ "$GUI_USER" != "root" ]; then
/bin/launchctl asuser $GUI_UID /bin/launchctl load /Library/LaunchAgents/com.redhat.spice.vdagent.plist
fi
+1
View File
@@ -7,3 +7,4 @@ Type=Application
Categories=
X-GNOME-Autostart-Phase=WindowManager
NoDisplay=true
X-systemd-skip=true
+11
View File
@@ -0,0 +1,11 @@
[Unit]
Description=Spice guest session agent
Documentation=man:spice-vdagent(1)
# Make sure the display is reachable
After=graphical-session.target
[Service]
ExecStart=/usr/bin/spice-vdagent -x
[Install]
WantedBy=graphical-session.target
+1
View File
@@ -1,5 +1,6 @@
[Unit]
Description=Agent daemon for Spice guests
Documentation=man:spice-vdagentd(1)
After=dbus.target
Requires=spice-vdagentd.socket
+49
View File
@@ -0,0 +1,49 @@
#!/bin/sh
set -e
VERSION="0.22.1"
INPUT_ARCHIVE="$1"
OUTPUT_PKG="$2"
TMP_ROOT="/tmp/package.$$"
TMP_COMPONENT="/tmp/Vdagent.pkg"
command -v realpath >/dev/null 2>&1 || realpath() {
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
}
BASEDIR="$(dirname "$(realpath $0)")"
cp -a "$INPUT_ARCHIVE/Products" "$TMP_ROOT"
xattr -cr "$TMP_ROOT"
codesign --sign "Developer ID Application" \
--force \
--identifier com.redhat.spice.vdagentd \
--preserve-metadata=entitlements,requirements,flags,runtime \
--timestamp \
"$TMP_ROOT/usr/local/bin/spice-vdagentd"
codesign --sign "Developer ID Application" \
--force \
--identifier com.redhat.spice.vdagent \
--preserve-metadata=entitlements,requirements,flags,runtime \
--timestamp \
"$TMP_ROOT/usr/local/bin/spice-vdagent"
pkgbuild --root "$TMP_ROOT" \
--identifier com.redhat.spice.vdagent \
--version "$VERSION" \
--install-location / \
--scripts "$BASEDIR/data/install_scripts" \
"$TMP_COMPONENT"
productbuild --package "$TMP_COMPONENT" \
--identifier com.redhat.spice.vdagent \
--version "$VERSION" \
--sign "Developer ID Installer" \
"$OUTPUT_PKG"
rm "$TMP_COMPONENT"
rm -r "$TMP_ROOT"
+320
View File
@@ -0,0 +1,320 @@
/*
* Copyright (C) 2024 osy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import AppKit
import ArgumentParser
import ObjectiveC
let DEFAULT_VDAGENTD_SOCKET = "/run/spice-vdagentd/spice-vdagent-sock"
typealias VdagentConnection = OpaquePointer
@main
struct Vdagent: ParsableCommand {
static var configuration = CommandConfiguration(
commandName: "spice-vdagent")
@Flag(name: .shortAndLong, help: "Enable debug")
var debug = false
@Option(name: [.customLong("vdagentd-socket"), .customShort("S")], help: ArgumentHelp("Set spice-vdagentd socket", valueName: "path"))
var socketPath = DEFAULT_VDAGENTD_SOCKET
@Flag(name: [.customLong("foreground"), .customShort("x")], help: "Do not daemonize the agent")
var foreground = false
func startVdagent() throws {
let cb = vdagent_cb_t(clipboard_request: host_clipboard_request,
clipboard_grab: host_clipboard_grab,
clipboard_data: host_clipboard_data,
clipboard_release: host_clipboard_release,
client_disconnected: host_client_disconnected,
agent_connected: host_agent_connected,
agent_disconnected: host_agent_disconnected)
let host = VdagentHost()
if debug {
vdagent_set_debug(1)
}
if !foreground {
throw VdagentError.unimplementedDaemon
}
let ctx = Unmanaged.passRetained(host)
defer {
ctx.release()
}
withUnsafePointer(to: cb) { cb in
_ = vdagent_start(socketPath, cb, ctx.toOpaque())
}
}
func run() {
let vdagentQueue = DispatchQueue(label: "SPICE vdagent main loop", qos: .userInteractive)
vdagentQueue.async {
do {
try self.startVdagent()
Self.exit()
} catch {
Self.exit(withError: error)
}
}
RunLoop.current.run()
}
}
private class VdagentHost: NSObject {
typealias Item = (lock: DispatchSemaphore, item: NSPasteboardItem)
private var lastItem: Item?
private var lastUpdateCount: Int = -1
private var updateTimer: Timer?
private var lastAgent: VdagentConnection? {
willSet {
if let agent = lastAgent {
vdagent_unref(agent)
}
}
}
func clipboardRequest(_ agent: VdagentConnection, sel: vdagent_clipboard_select_t, type: vdagent_clipboard_type_t) throws {
let pasteboard = try pasteboard(for: sel)
let pasteboardType = try pasteboardType(for: type)
guard let data = pasteboard.data(forType: pasteboardType) else {
throw VdagentError.dataNotAvailable
}
try data.withUnsafeBytes<Void> { buffer in
vdagent_clipboard_data(agent, sel, type, buffer.baseAddress, UInt32(data.count))
}
}
func clipboardGrab(_ agent: VdagentConnection, sel: vdagent_clipboard_select_t, types: [vdagent_clipboard_type_t]) throws {
let pasteboard = try pasteboard(for: sel)
let pasteboardTypes = types.compactMap { try? pasteboardType(for: $0) }
let item = NSPasteboardItem()
item.setDataProvider(self, forTypes: pasteboardTypes)
item.connectionAgent = agent
lastUpdateCount = pasteboard.changeCount + 1
pasteboard.prepareForNewContents(with: .currentHostOnly)
pasteboard.writeObjects([item])
}
func clipboardData(_ agent: VdagentConnection, sel: vdagent_clipboard_select_t, type: vdagent_clipboard_type_t, data: Data) throws {
let pasteboard = try pasteboard(for: sel)
let pasteboardType = try pasteboardType(for: type)
let success: Bool
if let (lock, item) = lastItem {
lastItem = nil
if item.types.contains(pasteboardType) {
success = item.setData(data, forType: pasteboardType)
} else {
success = false
}
lock.signal()
} else {
// unsolicited clipboard data
lastUpdateCount = pasteboard.changeCount + 1
success = pasteboard.setData(data, forType: pasteboardType)
}
if !success {
throw VdagentError.failedToWritePasteboard
}
}
func clipboardRelease(_ agent: VdagentConnection, sel: vdagent_clipboard_select_t) throws {
}
func guestUpdate(_ agent: VdagentConnection) {
let pasteboard = NSPasteboard.general
let newCount = pasteboard.changeCount
if newCount != lastUpdateCount, let pasteboardTypes = pasteboard.types {
lastUpdateCount = newCount
let types = pasteboardTypes.compactMap { clipboardType(for: $0) }
if !types.isEmpty {
vdagent_clipboard_grab(agent, VDAgentClipboardSelectClipboard, types, Int32(types.count))
}
}
}
func clientDisconnected(_ agent: VdagentConnection) {
}
func agentConnected(_ agent: VdagentConnection) {
let agent = vdagent_ref(agent)!
// need to synchronize with RunLoop
RunLoop.main.perform {
self.lastAgent = agent
let timer = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true) { [weak self] _ in
self?.guestUpdate(agent)
}
self.updateTimer = timer
RunLoop.main.add(timer, forMode: .default)
}
}
func agentDisconnected(_ agent: VdagentConnection) {
updateTimer?.invalidate()
// need to synchronize with RunLoop
RunLoop.main.perform {
self.updateTimer = nil
self.lastAgent = nil
}
}
}
private extension VdagentHost {
private func pasteboard(for sel: vdagent_clipboard_select_t) throws -> NSPasteboard {
switch sel {
case VDAgentClipboardSelectClipboard: return .general
default: throw VdagentError.unsupportedClipboardSelection(sel)
}
}
private func pasteboardType(for type: vdagent_clipboard_type_t) throws -> NSPasteboard.PasteboardType {
switch type {
case VDAgentClipboardTypeImageTIFF: return .tiff
case VDAgentClipboardTypeImagePNG: return .png
case VDAgentClipboardTypeUTF8Text: return .string
default: throw VdagentError.unsupportedDataType(type)
}
}
private func clipboardType(for type: NSPasteboard.PasteboardType) -> vdagent_clipboard_type_t? {
switch type {
case .tiff: return VDAgentClipboardTypeImageTIFF
case .png: return VDAgentClipboardTypeImagePNG
case .string: return VDAgentClipboardTypeUTF8Text
default: return nil
}
}
}
extension VdagentHost: NSPasteboardItemDataProvider {
func pasteboard(_ pasteboard: NSPasteboard?, item: NSPasteboardItem, provideDataForType type: NSPasteboard.PasteboardType) {
guard let type = clipboardType(for: type) else {
print("Error: unsupported pasteboard type \(type)")
return
}
lastItem = (DispatchSemaphore(value: 0), item)
vdagent_clipboard_request(item.connectionAgent, VDAgentClipboardSelectClipboard, type)
guard lastItem!.lock.wait(timeout: .now() + .seconds(5)) == .success else {
lastItem = nil
print("Error: timed out waiting for clipboard data")
return
}
}
}
private enum VdagentError: Error {
case unimplementedDaemon
case unsupportedClipboardSelection(vdagent_clipboard_select_t)
case unsupportedDataType(vdagent_clipboard_type_t)
case dataNotAvailable
case failedToWritePasteboard
}
extension VdagentError: LocalizedError {
var errorDescription: String? {
switch self {
case .unimplementedDaemon:
return "Daemon mode is not implemented, please run with '-x'."
case .unsupportedClipboardSelection(let sel):
return "Unsupported clipboard selection: \(sel)"
case .unsupportedDataType(let type):
return "Unsupported clipboard data type: \(type)"
case .dataNotAvailable:
return "Data not available"
case .failedToWritePasteboard:
return "Failed to write to pasteboard"
}
}
}
private var AssociatedAgentConnection: UInt8 = 0
extension NSPasteboardItem {
var connectionAgent: VdagentConnection? {
get {
return objc_getAssociatedObject(self, &AssociatedAgentConnection) as? VdagentConnection
}
set {
objc_setAssociatedObject(self, &AssociatedAgentConnection, newValue,
objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
}
}
private func withError(_ callback: () throws -> Void) -> Bool {
do {
try callback()
return true
} catch {
print("Error: \(error.localizedDescription)")
return false
}
}
private func host_clipboard_request(_ agent: VdagentConnection!, ctx: UnsafeMutableRawPointer!, sel: vdagent_clipboard_select_t, type: vdagent_clipboard_type_t) -> Bool {
withError {
let host = Unmanaged<VdagentHost>.fromOpaque(ctx).takeUnretainedValue()
try host.clipboardRequest(agent, sel: sel, type: type)
}
}
private func host_clipboard_grab(_ agent: VdagentConnection!, ctx: UnsafeMutableRawPointer!, sel: vdagent_clipboard_select_t, types: UnsafePointer<vdagent_clipboard_type_t>?, n_types: UInt32) -> Bool {
withError {
let host = Unmanaged<VdagentHost>.fromOpaque(ctx).takeUnretainedValue()
let _types = Array(UnsafeBufferPointer(start: types!, count: Int(n_types)))
try host.clipboardGrab(agent, sel: sel, types: _types)
}
}
private func host_clipboard_data(_ agent: VdagentConnection!, ctx: UnsafeMutableRawPointer!, sel: vdagent_clipboard_select_t, type: vdagent_clipboard_type_t, data: UnsafePointer<UInt8>?, size: UInt32) -> Bool {
withError {
let host = Unmanaged<VdagentHost>.fromOpaque(ctx).takeUnretainedValue()
let _data: Data
if let data = data {
_data = Data(bytes: data, count: Int(size))
} else {
_data = Data()
}
try host.clipboardData(agent, sel: sel, type: type, data: _data)
}
}
private func host_clipboard_release(_ agent: VdagentConnection!, ctx: UnsafeMutableRawPointer!, sel: vdagent_clipboard_select_t) -> Bool {
withError {
let host = Unmanaged<VdagentHost>.fromOpaque(ctx).takeUnretainedValue()
try host.clipboardRelease(agent, sel: sel)
}
}
private func host_client_disconnected(_ agent: VdagentConnection!, ctx: UnsafeMutableRawPointer!) {
let host = Unmanaged<VdagentHost>.fromOpaque(ctx).takeUnretainedValue()
host.clientDisconnected(agent)
}
private func host_agent_connected(_ agent: VdagentConnection!, ctx: UnsafeMutableRawPointer!) {
let host = Unmanaged<VdagentHost>.fromOpaque(ctx).takeUnretainedValue()
host.agentConnected(agent)
}
private func host_agent_disconnected(_ agent: VdagentConnection!, ctx: UnsafeMutableRawPointer!) {
let host = Unmanaged<VdagentHost>.fromOpaque(ctx).takeUnretainedValue()
host.agentDisconnected(agent)
}
+103
View File
@@ -0,0 +1,103 @@
/* src/config.h.in. Generated from configure.ac by autoheader. */
/* If defined, vdagentd will be compiled with ConsoleKit support */
#undef HAVE_CONSOLE_KIT
/* Define to 1 if you have the <inttypes.h> header file. */
#define HAVE_INTTYPES_H 1
/* If defined, vdagentd will be compiled with libsystemd-login support */
#undef HAVE_LIBSYSTEMD_LOGIN
/* If defined, vdagentd will be compiled with pciaccess support */
#undef HAVE_PCIACCESS
/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1
/* Define to 1 if you have the <stdio.h> header file. */
#define HAVE_STDIO_H 1
/* Define to 1 if you have the <stdlib.h> header file. */
#define HAVE_STDLIB_H 1
/* Define to 1 if you have the <strings.h> header file. */
#define HAVE_STRINGS_H 1
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
/* Define to 1 if you have the <sys/stat.h> header file. */
#define HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
/* Define to 1 if you have the <unistd.h> header file. */
#define HAVE_UNISTD_H 1
/* Name of package */
#define PACKAGE "spice-vdagent"
/* Define to the address where bug reports for this package should be sent. */
#define PACKAGE_BUGREPORT ""
/* Define to the full name of this package. */
#define PACKAGE_NAME "spice-vdagent"
/* Define to the full name and version of this package. */
#define PACKAGE_STRING "spice-vdagent 0.22.1"
/* Define to the one symbol short name of this package. */
#define PACKAGE_TARNAME "spice-vdagent"
/* Define to the home page for this package. */
#define PACKAGE_URL ""
/* Define to the version of this package. */
#define PACKAGE_VERSION "0.22.1"
/* Define to 1 if all of the C89 standard headers exist (not just the ones
required in a freestanding environment). This macro is provided for
backward compatibility; new code need not use it. */
#define STDC_HEADERS 1
/* If defined, use GTK for clipboard features */
#undef USE_GTK_FOR_CLIPBOARD
/* If defined, use GTK for monitor resolution instead of XRandr */
#undef USE_GTK_FOR_MONITORS
/* Version number of package */
#define VERSION "0.22.1"
/* If defined, load GTK+ libraries */
#undef WITH_GTK
/* If undefined and there is no session info, only one session agent is
allowed */
#undef WITH_SESSION_SECURITY
/* If defined, vdagentd will use a static uinput device */
#undef WITH_STATIC_UINPUT
/* If defined, vdagentd will support socket activation with systemd */
#undef WITH_SYSTEMD_SOCKET_ACTIVATION
/* Number of bits in a file offset, on hosts where this is settable. */
#define _FILE_OFFSET_BITS 64
/* Enable GNU extensions */
#define _GNU_SOURCE 1
/* Define to 1 on platforms where this makes off_t a 64-bit type. */
#define _LARGE_FILES 1
/* Number of bits in time_t, on hosts where this is settable. */
#define _TIME_BITS 64
/* Define to 1 on platforms where this makes time_t a 64-bit type. */
#undef __MINGW_USE_VC2005_COMPAT
/* GLib2 < 2.68 compatibility */
#undef g_memdup2
+477
View File
@@ -0,0 +1,477 @@
/*
* Copyright (C) 2024 osy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <stdio.h>
#include <syslog.h>
#include <sys/socket.h>
#include <glib-unix.h>
#include <spice/vd_agent.h>
#include "udscs.h"
#include "vdagentd-proto.h"
#include "vdagent.h"
#define MAX_RETRY_CONNECT_SYSTEM_AGENT 60
G_BEGIN_DECLS
#define VDAGENT_TYPE_VDAGENT (vdagent_get_type())
G_DECLARE_FINAL_TYPE(VDAgent, vdagent, VDAGENT, VDAGENT, GObject)
struct _VDAgent {
GObject parent_instance;
UdscsConnection *conn;
gint udscs_num_retry;
const vdagent_cb_t *cb;
void *ctx;
GMainLoop *loop;
};
G_END_DECLS
G_DEFINE_TYPE(VDAgent, vdagent, G_TYPE_OBJECT)
static int quit = 0;
static int parent_socket = -1;
static int version_mismatch = 0;
/* Command line options */
static gboolean debug = FALSE;
static gchar *vdagentd_socket = NULL;
static void vdagent_quit_loop(VDAgent *agent)
{
if (agent->cb && agent->cb->agent_disconnected) {
agent->cb->agent_disconnected(agent, agent->ctx);
}
if (agent->loop) {
g_main_loop_quit(agent->loop);
}
}
static gboolean vdagent_signal_handler(gpointer user_data)
{
VDAgent *agent = user_data;
quit = TRUE;
vdagent_quit_loop(agent);
return G_SOURCE_REMOVE;
}
static void vdagent_dispose(GObject *object)
{
VDAgent *agent = VDAGENT_VDAGENT(object);
g_clear_pointer(&agent->conn, vdagent_connection_destroy);
while (g_source_remove_by_user_data(agent))
continue;
g_clear_pointer(&agent->loop, g_main_loop_unref);
G_OBJECT_CLASS(vdagent_parent_class)->dispose(object);
}
static void vdagent_class_init(VDAgentClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS(klass);
object_class->dispose = vdagent_dispose;
}
static void vdagent_init(VDAgent *self)
{
self->loop = g_main_loop_new(NULL, FALSE);
}
static VDAgent *vdagent_new(const vdagent_cb_t *cb, void *ctx)
{
VDAgent *agent = g_object_new(VDAGENT_TYPE_VDAGENT, NULL);
agent->cb = cb;
agent->ctx = ctx;
g_unix_signal_add(SIGINT, vdagent_signal_handler, agent);
g_unix_signal_add(SIGHUP, vdagent_signal_handler, agent);
g_unix_signal_add(SIGTERM, vdagent_signal_handler, agent);
return agent;
}
void vdagent_set_debug(int debugOption)
{
debug = debugOption;
}
static guint32 convert_clipboard_type_to_raw(vdagent_clipboard_type_t type)
{
switch (type) {
case VDAgentClipboardTypeUTF8Text: return VD_AGENT_CLIPBOARD_UTF8_TEXT;
case VDAgentClipboardTypeImagePNG: return VD_AGENT_CLIPBOARD_IMAGE_PNG;
case VDAgentClipboardTypeImageBMP: return VD_AGENT_CLIPBOARD_IMAGE_BMP;
case VDAgentClipboardTypeImageTIFF: return VD_AGENT_CLIPBOARD_IMAGE_TIFF;
case VDAgentClipboardTypeImageJPG: return VD_AGENT_CLIPBOARD_IMAGE_JPG;
case VDAgentClipboardTypeNone:
default: return VD_AGENT_CLIPBOARD_NONE;
}
}
static vdagent_clipboard_type_t convert_raw_to_clipboard_type(guint32 type)
{
switch (type) {
case VD_AGENT_CLIPBOARD_UTF8_TEXT: return VDAgentClipboardTypeUTF8Text;
case VD_AGENT_CLIPBOARD_IMAGE_PNG: return VDAgentClipboardTypeImagePNG;
case VD_AGENT_CLIPBOARD_IMAGE_BMP: return VDAgentClipboardTypeImageBMP;
case VD_AGENT_CLIPBOARD_IMAGE_TIFF: return VDAgentClipboardTypeImageTIFF;
case VD_AGENT_CLIPBOARD_IMAGE_JPG: return VDAgentClipboardTypeImageJPG;
case VD_AGENT_CLIPBOARD_NONE:
default: return VDAgentClipboardTypeNone;
}
}
static guint32 convert_clipboard_select_to_raw(vdagent_clipboard_select_t sel)
{
switch (sel) {
case VDAgentClipboardSelectPrimary: return VD_AGENT_CLIPBOARD_SELECTION_PRIMARY;
case VDAgentClipboardSelectSecondary: return VD_AGENT_CLIPBOARD_SELECTION_SECONDARY;
case VDAgentClipboardSelectClipboard:
default: return VD_AGENT_CLIPBOARD_SELECTION_CLIPBOARD;
}
}
static vdagent_clipboard_select_t convert_raw_to_clipboard_select(guint32 sel)
{
switch (sel) {
case VD_AGENT_CLIPBOARD_SELECTION_PRIMARY: return VDAgentClipboardSelectPrimary;
case VD_AGENT_CLIPBOARD_SELECTION_SECONDARY: return VDAgentClipboardSelectSecondary;
case VD_AGENT_CLIPBOARD_SELECTION_CLIPBOARD:
default: return VDAgentClipboardSelectClipboard;
}
}
static void daemon_clipboard_request(VDAgent *agent,
guint sel_id, guint type)
{
if (agent->cb && agent->cb->clipboard_request) {
if (!agent->cb->clipboard_request(agent, agent->ctx,
convert_raw_to_clipboard_select(sel_id),
convert_raw_to_clipboard_type(type))) {
udscs_write(agent->conn, VDAGENTD_CLIPBOARD_DATA, sel_id,
VD_AGENT_CLIPBOARD_NONE, NULL, 0);
}
} else {
syslog(LOG_WARNING, "%s: no callback installed", __func__);
}
}
static void daemon_clipboard_grab(VDAgent *agent,
guint sel_id, guint32 *types, guint n_types)
{
if (agent->cb && agent->cb->clipboard_grab) {
vdagent_clipboard_type_t *_types = calloc(n_types, sizeof(*_types));
if (_types) {
for (int i = 0; i < n_types; i++) {
_types[i] = convert_raw_to_clipboard_type(types[i]);
}
agent->cb->clipboard_grab(agent, agent->ctx,
convert_raw_to_clipboard_select(sel_id),
_types, n_types);
free(_types);
}
} else {
syslog(LOG_WARNING, "%s: no callback installed", __func__);
}
}
static void daemon_clipboard_data(VDAgent *agent,
guint sel_id, guint32 type,
guchar *data, guint size)
{
if (agent->cb && agent->cb->clipboard_data) {
agent->cb->clipboard_data(agent, agent->ctx,
convert_raw_to_clipboard_select(sel_id),
convert_raw_to_clipboard_type(type),
data, size);
} else {
syslog(LOG_WARNING, "%s: no callback installed", __func__);
}
}
static void daemon_clipboard_release(VDAgent *agent, guint sel_id)
{
if (agent->cb && agent->cb->clipboard_release) {
agent->cb->clipboard_release(agent, agent->ctx,
convert_raw_to_clipboard_select(sel_id));
} else {
syslog(LOG_WARNING, "%s: no callback installed", __func__);
}
}
static void daemon_read_complete(UdscsConnection *conn,
struct udscs_message_header *header, uint8_t *data)
{
VDAgent *agent = g_object_get_data(G_OBJECT(conn), "agent");
switch (header->type) {
case VDAGENTD_CLIPBOARD_REQUEST:
daemon_clipboard_request(agent, header->arg1, header->arg2);
break;
case VDAGENTD_CLIPBOARD_GRAB:
daemon_clipboard_grab(agent, header->arg1, (guint32 *)data, header->size / sizeof(guint32));
break;
case VDAGENTD_CLIPBOARD_DATA:
daemon_clipboard_data(agent, header->arg1, header->arg2, data, header->size);
break;
case VDAGENTD_CLIPBOARD_RELEASE:
daemon_clipboard_release(agent, header->arg1);
break;
case VDAGENTD_VERSION:
if (strcmp((char *)data, VERSION) != 0) {
syslog(LOG_INFO, "vdagentd version mismatch: got %s expected %s",
data, VERSION);
vdagent_quit_loop(agent);
version_mismatch = 1;
}
break;
case VDAGENTD_CLIENT_DISCONNECTED:
if (agent->cb && agent->cb->client_disconnected) {
agent->cb->client_disconnected(agent, agent->ctx);
}
break;
default:
syslog(LOG_ERR, "Unknown message from vdagentd type: %d, ignoring",
header->type);
}
}
static void daemon_error_cb(VDAgentConnection *conn, GError *err)
{
VDAgent *agent = g_object_get_data(G_OBJECT(conn), "agent");
if (err) {
syslog(LOG_ERR, "%s", err->message);
g_error_free(err);
}
g_clear_pointer(&conn, vdagent_connection_destroy);
vdagent_quit_loop(agent);
}
static gboolean vdagent_init_async_cb(gpointer user_data)
{
VDAgent *agent = user_data;
GError *err = NULL;
agent->conn = udscs_connect(vdagentd_socket,
daemon_read_complete,
daemon_error_cb,
debug,
&err);
if (agent->conn == NULL) {
if (agent->udscs_num_retry == MAX_RETRY_CONNECT_SYSTEM_AGENT) {
syslog(LOG_WARNING,
"Failed to connect to spice-vdagentd at %s (tried %d times)",
vdagentd_socket, agent->udscs_num_retry);
g_error_free(err);
goto err_init;
}
if (agent->udscs_num_retry == 0) {
/* Log only when it fails and at the end */
syslog(LOG_DEBUG,
"Failed to connect with spice-vdagentd due '%s'. Trying again in 1s",
err->message);
}
g_error_free(err);
agent->udscs_num_retry++;
g_timeout_add_seconds(1, vdagent_init_async_cb, agent);
return G_SOURCE_REMOVE;
}
if (agent->udscs_num_retry != 0) {
syslog(LOG_DEBUG,
"Connected with spice-vdagentd after %d attempts",
agent->udscs_num_retry);
}
agent->udscs_num_retry = 0;
g_object_set_data(G_OBJECT(agent->conn), "agent", agent);
if (agent->cb && agent->cb->agent_connected) {
agent->cb->agent_connected(agent, agent->ctx);
}
return G_SOURCE_REMOVE;
err_init:
vdagent_quit_loop(agent);
quit = TRUE;
return G_SOURCE_REMOVE;
}
int vdagent_start(const char *socketPath, const vdagent_cb_t *cb, void *ctx)
{
VDAgent *agent;
if (socketPath == NULL)
vdagentd_socket = g_strdup(VDAGENTD_SOCKET);
else
vdagentd_socket = g_strdup(socketPath);
openlog("spice-vdagent", LOG_PID | LOG_PERROR, LOG_USER);
syslog(LOG_INFO, "vdagent started");
reconnect:
if (version_mismatch) {
syslog(LOG_INFO, "Version mismatch, restarting");
sleep(1);
}
agent = vdagent_new(cb, ctx);
g_timeout_add(0, vdagent_init_async_cb, agent);
g_main_loop_run(agent->loop);
g_clear_object(&agent);
/* allow the VDAgentConnection to finalize properly */
g_main_context_iteration(NULL, FALSE);
if (!quit)
goto reconnect;
g_free(vdagentd_socket);
return 0;
}
VDAgent *vdagent_ref(VDAgent *agent)
{
return VDAGENT_VDAGENT(g_object_ref(agent));
}
void vdagent_unref(VDAgent *agent)
{
g_object_unref(agent);
}
typedef struct {
UdscsConnection *conn;
struct udscs_message_header hdr;
const uint8_t *data;
GMutex mutex;
GCond cond;
gboolean is_done;
} vdagent_write_params_t;
static gboolean _vdagent_write_cb(gpointer user_data)
{
vdagent_write_params_t *params = (vdagent_write_params_t *)user_data;
udscs_write(params->conn,
params->hdr.type,
params->hdr.arg1,
params->hdr.arg2,
params->data,
params->hdr.size);
g_mutex_lock(&params->mutex);
params->is_done = TRUE;
g_cond_signal(&params->cond);
g_mutex_unlock(&params->mutex);
return G_SOURCE_REMOVE;
}
// write can happen from any thread so we need to synchronize it with the main context
static void vdagent_write(VDAgent *agent, uint32_t type, uint32_t arg1,
uint32_t arg2, const uint8_t *data, uint32_t size)
{
vdagent_write_params_t params = {
.conn = agent->conn,
.hdr.type = type,
.hdr.arg1 = arg1,
.hdr.arg2 = arg2,
.hdr.size = size,
.data = data,
};
// if we have the main context
if (g_main_context_acquire(NULL)) {
// we can call udscs_write directly
udscs_write(agent->conn, type,
arg1, arg2, data, size);
g_main_context_release(NULL);
} else {
// we have to synchronize with main context
g_mutex_init(&params.mutex);
g_cond_init(&params.cond);
g_mutex_lock(&params.mutex);
g_main_context_invoke(NULL, _vdagent_write_cb, &params);
while (!params.is_done) {
g_cond_wait(&params.cond, &params.mutex);
}
g_mutex_unlock(&params.mutex);
}
}
void vdagent_clipboard_request(VDAgent *agent, vdagent_clipboard_select_t sel, vdagent_clipboard_type_t type)
{
vdagent_write(agent,
VDAGENTD_CLIPBOARD_REQUEST,
convert_clipboard_select_to_raw(sel),
convert_clipboard_type_to_raw(type),
NULL, 0);
}
void vdagent_clipboard_grab(VDAgent *agent, vdagent_clipboard_select_t sel,
const vdagent_clipboard_type_t *types, int n_types)
{
guint32 *_types = calloc(n_types, sizeof(*_types));
if (!_types) {
syslog(LOG_ERR, "out of memory");
return;
}
for (int i = 0; i < n_types; i++) {
_types[i] = convert_clipboard_type_to_raw(types[i]);
}
vdagent_write(agent,
VDAGENTD_CLIPBOARD_GRAB,
convert_clipboard_select_to_raw(sel),
0,
(uint8_t *)_types, n_types * sizeof(guint32));
free(_types);
}
void vdagent_clipboard_data(VDAgent *agent, vdagent_clipboard_select_t sel,
vdagent_clipboard_type_t type, const unsigned char *data, unsigned int size)
{
vdagent_write(agent,
VDAGENTD_CLIPBOARD_DATA,
convert_clipboard_select_to_raw(sel),
convert_clipboard_type_to_raw(type),
data, size);
}
void vdagent_clipboard_release(VDAgent *agent, vdagent_clipboard_select_t sel)
{
vdagent_write(agent,
VDAGENTD_CLIPBOARD_RELEASE,
convert_clipboard_select_to_raw(sel),
0,
NULL, 0);
}
+73
View File
@@ -0,0 +1,73 @@
/*
* Copyright (C) 2024 osy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef vddagent_h
#define vddagent_h
#include <stdbool.h>
typedef struct _VDAgent VDAgent;
typedef enum {
VDAgentClipboardTypeNone,
VDAgentClipboardTypeUTF8Text,
VDAgentClipboardTypeImagePNG,
VDAgentClipboardTypeImageBMP,
VDAgentClipboardTypeImageTIFF,
VDAgentClipboardTypeImageJPG,
} vdagent_clipboard_type_t;
typedef enum {
VDAgentClipboardSelectClipboard,
VDAgentClipboardSelectPrimary,
VDAgentClipboardSelectSecondary,
} vdagent_clipboard_select_t;
typedef bool (*vdagent_clipboard_request_cb)(VDAgent *agent, void *ctx, vdagent_clipboard_select_t sel, vdagent_clipboard_type_t type);
typedef bool (*vdagent_clipboard_grab_cb)(VDAgent *agent, void *ctx, vdagent_clipboard_select_t sel,
const vdagent_clipboard_type_t *types, unsigned int n_types);
typedef bool (*vdagent_clipboard_data_cb)(VDAgent *agent, void *ctx, vdagent_clipboard_select_t sel,
vdagent_clipboard_type_t type, const unsigned char *data, unsigned int size);
typedef bool (*vdagent_clipboard_release_cb)(VDAgent *agent, void *ctx, vdagent_clipboard_select_t sel);
typedef void (*vdagent_client_disconnected_cb)(VDAgent *agent, void *ctx);
typedef void (*vdagent_agent_connected_cb)(VDAgent *agent, void *ctx);
typedef void (*vdagent_agent_disconnected_cb)(VDAgent *agent, void *ctx);
typedef struct {
vdagent_clipboard_request_cb clipboard_request;
vdagent_clipboard_grab_cb clipboard_grab;
vdagent_clipboard_data_cb clipboard_data;
vdagent_clipboard_release_cb clipboard_release;
vdagent_client_disconnected_cb client_disconnected;
vdagent_agent_connected_cb agent_connected;
vdagent_agent_disconnected_cb agent_disconnected;
} vdagent_cb_t;
void vdagent_set_debug(int debugOption);
int vdagent_start(const char *socketPath, const vdagent_cb_t *cb, void *ctx);
VDAgent *vdagent_ref(VDAgent *agent);
void vdagent_unref(VDAgent *agent);
void vdagent_clipboard_request(VDAgent *agent, vdagent_clipboard_select_t sel, vdagent_clipboard_type_t type);
void vdagent_clipboard_grab(VDAgent *agent, vdagent_clipboard_select_t sel,
const vdagent_clipboard_type_t *types, int n_types);
void vdagent_clipboard_data(VDAgent *agent, vdagent_clipboard_select_t sel,
vdagent_clipboard_type_t type, const unsigned char *data, unsigned int size);
void vdagent_clipboard_release(VDAgent *agent, vdagent_clipboard_select_t sel);
#endif /* vddagent_h */
+164 -443
View File
@@ -22,60 +22,29 @@
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>
#include <unistd.h>
#include <errno.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <glib.h>
#include <glib-unix.h>
#include <gio/gunixsocketaddress.h>
#include "udscs.h"
#include "vdagentd-proto-strings.h"
#include "vdagent-connection.h"
struct udscs_buf {
uint8_t *buf;
size_t pos;
size_t size;
// Maximum number of connected agents.
// Avoid DoS from agents.
// As each connection end up taking a file descriptor is good to have a limit
// less than the number of file descriptors in the process (by default 1024).
#define MAX_CONNECTED_AGENTS 128
struct udscs_buf *next;
};
struct udscs_connection {
int fd;
struct _UdscsConnection {
VDAgentConnection parent_instance;
int debug;
void *user_data;
#ifndef UDSCS_NO_SERVER
struct ucred peer_cred;
#endif
/* Read stuff, single buffer, separate header and data buffer */
int header_read;
struct udscs_message_header header;
struct udscs_buf data;
/* Writes are stored in a linked list of buffers, with both the header
+ data for a single message in 1 buffer. */
struct udscs_buf *write_buf;
/* Callbacks */
udscs_read_callback read_callback;
udscs_disconnect_callback disconnect_callback;
struct udscs_connection *next;
struct udscs_connection *prev;
GIOChannel *io_channel;
guint write_watch_id;
guint read_watch_id;
};
static gboolean udscs_io_channel_cb(GIOChannel *source,
GIOCondition condition,
gpointer data);
G_DEFINE_TYPE(UdscsConnection, udscs_connection, VDAGENT_TYPE_CONNECTION)
static void debug_print_message_header(struct udscs_connection *conn,
static void debug_print_message_header(UdscsConnection *conn,
struct udscs_message_header *header,
const gchar *direction)
{
@@ -91,485 +60,238 @@ static void debug_print_message_header(struct udscs_connection *conn,
conn, direction, type, header->arg1, header->arg2, header->size);
}
struct udscs_connection *udscs_connect(const char *socketname,
udscs_read_callback read_callback,
udscs_disconnect_callback disconnect_callback,
int debug)
static gsize conn_handle_header(VDAgentConnection *conn,
gpointer header_buf)
{
int c;
struct sockaddr_un address;
struct udscs_connection *conn;
return ((struct udscs_message_header *)header_buf)->size;
}
conn = g_new0(struct udscs_connection, 1);
static void conn_handle_message(VDAgentConnection *conn,
gpointer header_buf,
gpointer data)
{
UdscsConnection *self = UDSCS_CONNECTION(conn);
struct udscs_message_header *header = header_buf;
debug_print_message_header(self, header, "received");
self->read_callback(self, header, data);
}
static void udscs_connection_init(UdscsConnection *self)
{
}
static void udscs_connection_finalize(GObject *obj)
{
UdscsConnection *self = UDSCS_CONNECTION(obj);
if (self->debug) {
syslog(LOG_DEBUG, "%p disconnected", self);
}
G_OBJECT_CLASS(udscs_connection_parent_class)->finalize(obj);
}
static void udscs_connection_class_init(UdscsConnectionClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
VDAgentConnectionClass *conn_class = VDAGENT_CONNECTION_CLASS(klass);
gobject_class->finalize = udscs_connection_finalize;
conn_class->handle_header = conn_handle_header;
conn_class->handle_message = conn_handle_message;
}
UdscsConnection *udscs_connect(const char *socketname,
udscs_read_callback read_callback,
VDAgentConnErrorCb error_cb,
int debug,
GError **err)
{
GIOStream *io_stream;
UdscsConnection *conn;
io_stream = vdagent_socket_connect(socketname, err);
if (*err) {
return NULL;
}
conn = g_object_new(UDSCS_TYPE_CONNECTION, NULL);
conn->debug = debug;
conn->fd = socket(PF_UNIX, SOCK_STREAM, 0);
if (conn->fd == -1) {
syslog(LOG_ERR, "creating unix domain socket: %m");
g_free(conn);
return NULL;
}
address.sun_family = AF_UNIX;
snprintf(address.sun_path, sizeof(address.sun_path), "%s", socketname);
c = connect(conn->fd, (struct sockaddr *)&address, sizeof(address));
if (c != 0) {
if (conn->debug) {
syslog(LOG_DEBUG, "connect %s: %m", socketname);
}
close(conn->fd);
g_free(conn);
return NULL;
}
conn->io_channel = g_io_channel_unix_new(conn->fd);
if (!conn->io_channel) {
udscs_destroy_connection(&conn);
return NULL;
}
conn->read_watch_id =
g_io_add_watch(conn->io_channel,
G_IO_IN | G_IO_ERR | G_IO_NVAL,
udscs_io_channel_cb,
conn);
conn->read_callback = read_callback;
conn->disconnect_callback = disconnect_callback;
vdagent_connection_setup(VDAGENT_CONNECTION(conn),
io_stream,
FALSE,
sizeof(struct udscs_message_header),
error_cb);
if (conn->debug)
if (conn->debug) {
syslog(LOG_DEBUG, "%p connected to %s", conn, socketname);
}
return conn;
}
void udscs_destroy_connection(struct udscs_connection **connp)
{
struct udscs_buf *wbuf, *next_wbuf;
struct udscs_connection *conn = *connp;
if (!conn)
return;
if (conn->disconnect_callback)
conn->disconnect_callback(conn);
wbuf = conn->write_buf;
while (wbuf) {
next_wbuf = wbuf->next;
g_free(wbuf->buf);
g_free(wbuf);
wbuf = next_wbuf;
}
g_clear_pointer(&conn->data.buf, g_free);
if (conn->next)
conn->next->prev = conn->prev;
if (conn->prev)
conn->prev->next = conn->next;
close(conn->fd);
if (conn->write_watch_id != 0)
g_source_remove(conn->write_watch_id);
if (conn->read_watch_id != 0)
g_source_remove(conn->read_watch_id);
g_clear_pointer(&conn->io_channel, g_io_channel_unref);
if (conn->debug)
syslog(LOG_DEBUG, "%p disconnected", conn);
g_clear_pointer(connp, g_free);
}
void udscs_set_user_data(struct udscs_connection *conn, void *data)
{
conn->user_data = data;
}
void *udscs_get_user_data(struct udscs_connection *conn)
{
if (!conn)
return NULL;
return conn->user_data;
}
void udscs_write(struct udscs_connection *conn, uint32_t type, uint32_t arg1,
void udscs_write(UdscsConnection *conn, uint32_t type, uint32_t arg1,
uint32_t arg2, const uint8_t *data, uint32_t size)
{
struct udscs_buf *wbuf, *new_wbuf;
gpointer buf;
guint buf_size;
struct udscs_message_header header;
new_wbuf = g_new(struct udscs_buf, 1);
new_wbuf->pos = 0;
new_wbuf->size = sizeof(header) + size;
new_wbuf->next = NULL;
new_wbuf->buf = g_malloc(new_wbuf->size);
buf_size = sizeof(header) + size;
buf = g_malloc(buf_size);
header.type = type;
header.arg1 = arg1;
header.arg2 = arg2;
header.size = size;
memcpy(new_wbuf->buf, &header, sizeof(header));
memcpy(new_wbuf->buf + sizeof(header), data, size);
memcpy(buf, &header, sizeof(header));
memcpy(buf + sizeof(header), data, size);
debug_print_message_header(conn, &header, "sent");
if (conn->io_channel && conn->write_watch_id == 0)
conn->write_watch_id =
g_io_add_watch(conn->io_channel,
G_IO_OUT | G_IO_ERR | G_IO_NVAL,
udscs_io_channel_cb,
conn);
if (!conn->write_buf) {
conn->write_buf = new_wbuf;
return;
}
/* maybe we should limit the write_buf stack depth ? */
wbuf = conn->write_buf;
while (wbuf->next)
wbuf = wbuf->next;
wbuf->next = new_wbuf;
vdagent_connection_write(VDAGENT_CONNECTION(conn), buf, buf_size);
}
/* A helper for udscs_do_read() */
static void udscs_read_complete(struct udscs_connection **connp)
{
struct udscs_connection *conn = *connp;
debug_print_message_header(conn, &conn->header, "received");
if (conn->read_callback) {
conn->read_callback(connp, &conn->header, conn->data.buf);
if (!*connp) /* Was the connection disconnected by the callback ? */
return;
}
g_free(conn->data.buf);
memset(&conn->data, 0, sizeof(conn->data)); /* data.buf = NULL */
conn->header_read = 0;
}
static void udscs_do_read(struct udscs_connection **connp)
{
ssize_t n;
size_t to_read;
uint8_t *dest;
struct udscs_connection *conn = *connp;
if (conn->header_read < sizeof(conn->header)) {
to_read = sizeof(conn->header) - conn->header_read;
dest = (uint8_t *)&conn->header + conn->header_read;
} else {
to_read = conn->data.size - conn->data.pos;
dest = conn->data.buf + conn->data.pos;
}
n = read(conn->fd, dest, to_read);
if (n < 0) {
if (errno == EINTR)
return;
syslog(LOG_ERR, "reading unix domain socket: %m, disconnecting %p",
conn);
}
if (n <= 0) {
udscs_destroy_connection(connp);
return;
}
if (conn->header_read < sizeof(conn->header)) {
conn->header_read += n;
if (conn->header_read == sizeof(conn->header)) {
if (conn->header.size == 0) {
udscs_read_complete(connp);
return;
}
conn->data.pos = 0;
conn->data.size = conn->header.size;
conn->data.buf = g_malloc(conn->data.size);
}
} else {
conn->data.pos += n;
if (conn->data.pos == conn->data.size)
udscs_read_complete(connp);
}
}
static void udscs_do_write(struct udscs_connection **connp)
{
ssize_t n;
size_t to_write;
struct udscs_connection *conn = *connp;
struct udscs_buf* wbuf = conn->write_buf;
if (!wbuf) {
syslog(LOG_ERR,
"%p do_write called on a connection without a write buf ?!",
conn);
return;
}
to_write = wbuf->size - wbuf->pos;
n = write(conn->fd, wbuf->buf + wbuf->pos, to_write);
if (n < 0) {
if (errno == EINTR)
return;
syslog(LOG_ERR, "writing to unix domain socket: %m, disconnecting %p",
conn);
udscs_destroy_connection(connp);
return;
}
wbuf->pos += n;
if (wbuf->pos == wbuf->size) {
conn->write_buf = wbuf->next;
g_free(wbuf->buf);
g_free(wbuf);
}
}
static gboolean udscs_io_channel_cb(GIOChannel *source,
GIOCondition condition,
gpointer data)
{
struct udscs_connection *conn = data;
if (condition & G_IO_IN) {
udscs_do_read(&conn);
// coverity[check_after_deref] previous function can change conn
if (conn == NULL)
return G_SOURCE_REMOVE;
return G_SOURCE_CONTINUE;
}
if (condition & G_IO_OUT) {
udscs_do_write(&conn);
// coverity[check_after_deref] previous function can change conn
if (conn == NULL)
return G_SOURCE_REMOVE;
if (conn->write_buf)
return G_SOURCE_CONTINUE;
conn->write_watch_id = 0;
return G_SOURCE_REMOVE;
}
udscs_destroy_connection(&conn);
return G_SOURCE_REMOVE;
}
#ifndef UDSCS_NO_SERVER
/* ---------- Server-side implementation ---------- */
struct udscs_server {
int fd;
GSocketService *service;
GList *connections;
int debug;
struct udscs_connection connections_head;
udscs_connect_callback connect_callback;
udscs_read_callback read_callback;
udscs_disconnect_callback disconnect_callback;
VDAgentConnErrorCb error_cb;
};
struct udscs_server *udscs_create_server_for_fd(int fd,
static gboolean udscs_server_accept_cb(GSocketService *service,
GSocketConnection *socket_conn,
GObject *source_object,
gpointer user_data);
struct udscs_server *udscs_server_new(
udscs_connect_callback connect_callback,
udscs_read_callback read_callback,
udscs_disconnect_callback disconnect_callback,
VDAgentConnErrorCb error_cb,
int debug)
{
struct udscs_server *server;
if (fd <= 0) {
syslog(LOG_ERR, "Invalid file descriptor: %i", fd);
return NULL;
}
server = g_new0(struct udscs_server, 1);
server->debug = debug;
server->fd = fd;
server->connect_callback = connect_callback;
server->read_callback = read_callback;
server->disconnect_callback = disconnect_callback;
server->error_cb = error_cb;
server->service = g_socket_service_new();
g_socket_service_stop(server->service);
g_signal_connect(server->service, "incoming",
G_CALLBACK(udscs_server_accept_cb), server);
return server;
}
struct udscs_server *udscs_create_server(const char *socketname,
udscs_connect_callback connect_callback,
udscs_read_callback read_callback,
udscs_disconnect_callback disconnect_callback,
int debug)
void udscs_server_listen_to_socket(struct udscs_server *server,
gint fd,
GError **err)
{
int c;
int fd;
struct sockaddr_un address;
struct udscs_server *server;
GSocket *socket;
fd = socket(PF_UNIX, SOCK_STREAM, 0);
if (fd == -1) {
syslog(LOG_ERR, "creating unix domain socket: %m");
return NULL;
socket = g_socket_new_from_fd(fd, err);
if (socket == NULL) {
return;
}
g_socket_listener_add_socket(G_SOCKET_LISTENER(server->service),
socket, NULL, err);
g_object_unref(socket);
}
address.sun_family = AF_UNIX;
snprintf(address.sun_path, sizeof(address.sun_path), "%s", socketname);
c = bind(fd, (struct sockaddr *)&address, sizeof(address));
if (c != 0) {
syslog(LOG_ERR, "bind %s: %m", socketname);
close(fd);
return NULL;
}
void udscs_server_listen_to_address(struct udscs_server *server,
const gchar *addr,
GError **err)
{
GSocketAddress *sock_addr;
c = listen(fd, 5);
if (c != 0) {
syslog(LOG_ERR, "listen: %m");
close(fd);
return NULL;
}
sock_addr = g_unix_socket_address_new(addr);
g_socket_listener_add_address(G_SOCKET_LISTENER(server->service),
sock_addr,
G_SOCKET_TYPE_STREAM,
G_SOCKET_PROTOCOL_DEFAULT,
NULL, NULL, err);
g_object_unref(sock_addr);
}
server = udscs_create_server_for_fd(fd, connect_callback, read_callback,
disconnect_callback, debug);
void udscs_server_start(struct udscs_server *server)
{
g_socket_service_start(server->service);
}
if (!server) {
close(fd);
}
return server;
void udscs_server_destroy_connection(struct udscs_server *server,
UdscsConnection *conn)
{
server->connections = g_list_remove(server->connections, conn);
vdagent_connection_destroy(conn);
}
void udscs_destroy_server(struct udscs_server *server)
{
struct udscs_connection *conn, *next_conn;
if (!server)
return;
conn = server->connections_head.next;
while (conn) {
next_conn = conn->next;
udscs_destroy_connection(&conn);
conn = next_conn;
}
close(server->fd);
g_list_free_full(server->connections, vdagent_connection_destroy);
g_object_unref(server->service);
g_free(server);
}
int udscs_get_peer_pid(struct udscs_connection *conn)
static gboolean udscs_server_accept_cb(GSocketService *service,
GSocketConnection *socket_conn,
GObject *source_object,
gpointer user_data)
{
return (int)conn->peer_cred.pid;
}
struct udscs_server *server = user_data;
UdscsConnection *new_conn;
static void udscs_server_accept(struct udscs_server *server) {
struct udscs_connection *new_conn, *conn;
struct sockaddr_un address;
socklen_t length = sizeof(address);
int r, fd;
fd = accept(server->fd, (struct sockaddr *)&address, &length);
if (fd == -1) {
if (errno == EINTR)
return;
syslog(LOG_ERR, "accept: %m");
return;
/* prevents DoS having too many agents attached */
if (g_list_length(server->connections) >= MAX_CONNECTED_AGENTS) {
syslog(LOG_ERR, "Too many agents connected");
return TRUE;
}
new_conn = g_new0(struct udscs_connection, 1);
new_conn->fd = fd;
new_conn = g_object_new(UDSCS_TYPE_CONNECTION, NULL);
new_conn->debug = server->debug;
new_conn->read_callback = server->read_callback;
new_conn->disconnect_callback = server->disconnect_callback;
g_object_ref(socket_conn);
vdagent_connection_setup(VDAGENT_CONNECTION(new_conn),
G_IO_STREAM(socket_conn),
FALSE,
sizeof(struct udscs_message_header),
server->error_cb);
length = sizeof(new_conn->peer_cred);
r = getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &new_conn->peer_cred, &length);
if (r != 0) {
syslog(LOG_ERR, "Could not get peercred, disconnecting new client");
close(fd);
g_free(new_conn);
return;
}
conn = &server->connections_head;
while (conn->next)
conn = conn->next;
new_conn->prev = conn;
conn->next = new_conn;
server->connections = g_list_prepend(server->connections, new_conn);
if (server->debug)
syslog(LOG_DEBUG, "new client accepted: %p, pid: %d",
new_conn, udscs_get_peer_pid(new_conn));
syslog(LOG_DEBUG, "new client accepted: %p", new_conn);
if (server->connect_callback)
server->connect_callback(new_conn);
}
int udscs_server_fill_fds(struct udscs_server *server, fd_set *readfds,
fd_set *writefds)
{
struct udscs_connection *conn;
int nfds;
if (!server)
return -1;
nfds = server->fd + 1;
FD_SET(server->fd, readfds);
conn = server->connections_head.next;
while (conn) {
FD_SET(conn->fd, readfds);
if (conn->write_buf)
FD_SET(conn->fd, writefds);
if (conn->fd >= nfds)
nfds = conn->fd + 1;
conn = conn->next;
}
return nfds;
}
void udscs_server_handle_fds(struct udscs_server *server, fd_set *readfds,
fd_set *writefds)
{
struct udscs_connection *conn, *next_conn;
if (!server)
return;
if (FD_ISSET(server->fd, readfds))
udscs_server_accept(server);
conn = server->connections_head.next;
while (conn) {
/* conn may be destroyed by udscs_do_read() or udscs_do_write()
* (when disconnected), so get the next connection first. */
next_conn = conn->next;
if (FD_ISSET(conn->fd, readfds))
udscs_do_read(&conn);
if (conn && FD_ISSET(conn->fd, writefds))
udscs_do_write(&conn);
conn = next_conn;
}
return TRUE;
}
void udscs_server_write_all(struct udscs_server *server,
uint32_t type, uint32_t arg1, uint32_t arg2,
const uint8_t *data, uint32_t size)
{
struct udscs_connection *conn;
conn = server->connections_head.next;
while (conn) {
udscs_write(conn, type, arg1, arg2, data, size);
conn = conn->next;
GList *l;
for (l = server->connections; l; l = l->next) {
udscs_write(UDSCS_CONNECTION(l->data), type, arg1, arg2, data, size);
}
}
@@ -577,17 +299,16 @@ int udscs_server_for_all_clients(struct udscs_server *server,
udscs_for_all_clients_callback func, void *priv)
{
int r = 0;
struct udscs_connection *conn, *next_conn;
GList *l, *next;
if (!server)
return 0;
conn = server->connections_head.next;
while (conn) {
/* Get next conn as func may destroy the current conn */
next_conn = conn->next;
r += func(&conn, priv);
conn = next_conn;
l = server->connections;
while (l) {
next = l->next;
r += func(l->data, priv);
l = next;
}
return r;
}
+37 -70
View File
@@ -22,15 +22,18 @@
#ifndef __UDSCS_H
#define __UDSCS_H
#include <stdio.h>
#include <stdint.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <glib-object.h>
#include "vdagent-connection.h"
G_BEGIN_DECLS
#define UDSCS_TYPE_CONNECTION udscs_connection_get_type()
G_DECLARE_FINAL_TYPE(UdscsConnection, udscs_connection, UDSCS, CONNECTION, VDAgentConnection)
/* ---------- Generic bits and client-side API ---------- */
struct udscs_connection;
struct udscs_message_header {
uint32_t type;
uint32_t arg1;
@@ -41,54 +44,29 @@ struct udscs_message_header {
/* Callbacks with this type will be called when a complete message has been
* received. The callback does not own the data buffer and should not free it.
* The data buffer will be freed shortly after the read callback returns.
* The callback may call udscs_destroy_connection, in which case *connp must be
* made NULL (which udscs_destroy_connection takes care of).
*/
typedef void (*udscs_read_callback)(struct udscs_connection **connp,
typedef void (*udscs_read_callback)(UdscsConnection *conn,
struct udscs_message_header *header, uint8_t *data);
/* Callbacks with this type will be called when the connection is disconnected.
* Note:
* 1) udscs will destroy the connection in question itself after
* this callback has completed!
* 2) This callback is always called, even if the disconnect is initiated
* by the udscs user through returning -1 from a read callback, or
* by explicitly calling udscs_destroy_connection.
*/
typedef void (*udscs_disconnect_callback)(struct udscs_connection *conn);
/* Connect to the unix domain socket specified by socketname.
* Only sockets bound to a pathname are supported.
*
* If debug is true then the events on this connection will be traced.
* This includes the incoming and outgoing message names.
*/
struct udscs_connection *udscs_connect(const char *socketname,
udscs_read_callback read_callback,
udscs_disconnect_callback disconnect_callback,
int debug);
/* Close the connection, releases the corresponding resources and
* sets *connp to NULL.
*
* Does nothing if *connp is NULL.
* In case of failure, returns NULL and set @err with reason.
*/
void udscs_destroy_connection(struct udscs_connection **connp);
UdscsConnection *udscs_connect(const char *socketname,
udscs_read_callback read_callback,
VDAgentConnErrorCb error_cb,
int debug,
GError **err);
/* Queue a message for delivery to the client connected through conn.
*/
void udscs_write(struct udscs_connection *conn, uint32_t type, uint32_t arg1,
void udscs_write(UdscsConnection *conn, uint32_t type, uint32_t arg1,
uint32_t arg2, const uint8_t *data, uint32_t size);
/* Associates the specified user data with the connection. */
void udscs_set_user_data(struct udscs_connection *conn, void *data);
/* Return value: the connection's associated user data,
* NULL if conn is NULL.
*/
void *udscs_get_user_data(struct udscs_connection *conn);
#ifndef UDSCS_NO_SERVER
/* ---------- Server-side API ---------- */
@@ -98,33 +76,36 @@ struct udscs_server;
/* Callbacks with this type will be called when a new connection to a
* server is accepted.
*/
typedef void (*udscs_connect_callback)(struct udscs_connection *conn);
typedef void (*udscs_connect_callback)(UdscsConnection *conn);
/* Create a server for the given file descriptor. This allows us to use
* pre-configured sockets for use with systemd socket activation, etc.
*
* See udscs_create_server() for more information
*/
struct udscs_server *udscs_create_server_for_fd(int fd,
udscs_connect_callback connect_callback,
udscs_read_callback read_callback,
udscs_disconnect_callback disconnect_callback,
int debug);
/* Create the unix domain socket specified by socketname and
* start listening on it.
* Only sockets bound to a pathname are supported.
/* Initialize a new udscs_server struct.
*
* If debug is true then the events on this socket and related individual
* connections will be traced.
* This includes the incoming and outgoing message names.
*/
struct udscs_server *udscs_create_server(const char *socketname,
struct udscs_server *udscs_server_new(
udscs_connect_callback connect_callback,
udscs_read_callback read_callback,
udscs_disconnect_callback disconnect_callback,
VDAgentConnErrorCb error_cb,
int debug);
/* Start listening on a pre-configured socket specified by the given @fd.
* This can be used with systemd socket activation, etc. */
void udscs_server_listen_to_socket(struct udscs_server *server,
gint fd,
GError **err);
/* Create a new socket, bind it to @address and start listening on it. */
void udscs_server_listen_to_address(struct udscs_server *server,
const gchar *addr,
GError **err);
void udscs_server_start(struct udscs_server *server);
void udscs_server_destroy_connection(struct udscs_server *server,
UdscsConnection *conn);
/* Close all the server's connections and releases the corresponding
* resources.
* Does nothing if server is NULL.
@@ -141,7 +122,7 @@ void udscs_server_write_all(struct udscs_server *server,
/* Callback type for udscs_server_for_all_clients. Clients can be disconnected
* from this callback just like with a read callback.
*/
typedef int (*udscs_for_all_clients_callback)(struct udscs_connection **connp,
typedef int (*udscs_for_all_clients_callback)(UdscsConnection *conn,
void *priv);
/* Call func for all clients connected to the server, passing through
@@ -151,22 +132,8 @@ typedef int (*udscs_for_all_clients_callback)(struct udscs_connection **connp,
int udscs_server_for_all_clients(struct udscs_server *server,
udscs_for_all_clients_callback func, void *priv);
/* Given a udscs server, fill the fd_sets pointed to by readfds and
* writefds for select() usage.
* Return value: value of the highest fd + 1 or -1 if server is NULL
*/
int udscs_server_fill_fds(struct udscs_server *server, fd_set *readfds,
fd_set *writefds);
/* Handle any events flagged by select for the given udscs server.
* Does nothing if server is NULL.
*/
void udscs_server_handle_fds(struct udscs_server *server, fd_set *readfds,
fd_set *writefds);
/* Returns the peer's PID. */
int udscs_get_peer_pid(struct udscs_connection *conn);
#endif
G_END_DECLS
#endif
+319
View File
@@ -0,0 +1,319 @@
/* vdagent-connection.c
Copyright 2019 Red Hat, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <syslog.h>
#include <fcntl.h>
#include <errno.h>
#include <glib/gstdio.h>
#include <gio/gunixinputstream.h>
#include <gio/gunixoutputstream.h>
#include <gio/gunixsocketaddress.h>
#include "vdagent-connection.h"
typedef struct {
GIOStream *io_stream;
gboolean opening;
VDAgentConnErrorCb error_cb;
GCancellable *cancellable;
GQueue *write_queue;
gsize bytes_written;
gsize header_size;
gpointer header_buf;
gpointer data_buf;
} VDAgentConnectionPrivate;
G_DEFINE_TYPE_WITH_PRIVATE(VDAgentConnection, vdagent_connection, G_TYPE_OBJECT)
static void read_next_message(VDAgentConnection *self);
GIOStream *vdagent_file_open(const gchar *path, GError **err)
{
gint fd, errsv;
fd = g_open(path, O_RDWR);
if (fd == -1) {
errsv = errno;
g_set_error_literal(err, G_FILE_ERROR,
g_file_error_from_errno(errsv),
g_strerror(errsv));
return NULL;
}
return g_simple_io_stream_new(g_unix_input_stream_new(fd, TRUE),
g_unix_output_stream_new(fd, TRUE));
}
GIOStream *vdagent_socket_connect(const gchar *path, GError **err)
{
GSocketConnection *conn;
GSocketAddress *addr;
GSocketClient *client;
addr = g_unix_socket_address_new(path);
client = g_object_new(G_TYPE_SOCKET_CLIENT,
"family", G_SOCKET_FAMILY_UNIX,
"type", G_SOCKET_TYPE_STREAM,
NULL);
conn = g_socket_client_connect(client, G_SOCKET_CONNECTABLE(addr), NULL, err);
g_object_unref(client);
g_object_unref(addr);
return G_IO_STREAM(conn);
}
static void vdagent_connection_init(VDAgentConnection *self)
{
VDAgentConnectionPrivate *priv = vdagent_connection_get_instance_private(self);
priv->cancellable = g_cancellable_new();
priv->write_queue = g_queue_new();
}
static void vdagent_connection_dispose(GObject *obj)
{
VDAgentConnection *self = VDAGENT_CONNECTION(obj);
VDAgentConnectionPrivate *priv = vdagent_connection_get_instance_private(self);
g_clear_object(&priv->cancellable);
g_clear_object(&priv->io_stream);
G_OBJECT_CLASS(vdagent_connection_parent_class)->dispose(obj);
}
static void vdagent_connection_finalize(GObject *obj)
{
VDAgentConnection *self = VDAGENT_CONNECTION(obj);
VDAgentConnectionPrivate *priv = vdagent_connection_get_instance_private(self);
g_queue_free_full(priv->write_queue, (GDestroyNotify)g_bytes_unref);
g_free(priv->header_buf);
g_free(priv->data_buf);
G_OBJECT_CLASS(vdagent_connection_parent_class)->finalize(obj);
}
static void vdagent_connection_class_init(VDAgentConnectionClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
gobject_class->dispose = vdagent_connection_dispose;
gobject_class->finalize = vdagent_connection_finalize;
}
void vdagent_connection_setup(VDAgentConnection *self,
GIOStream *io_stream,
gboolean wait_on_opening,
gsize header_size,
VDAgentConnErrorCb error_cb)
{
VDAgentConnectionPrivate *priv = vdagent_connection_get_instance_private(self);
priv->io_stream = io_stream;
priv->opening = wait_on_opening;
priv->header_size = header_size;
priv->header_buf = g_malloc(header_size);
priv->error_cb = error_cb;
read_next_message(self);
}
void vdagent_connection_destroy(gpointer p)
{
g_return_if_fail(VDAGENT_IS_CONNECTION(p));
VDAgentConnection *self = VDAGENT_CONNECTION(p);
VDAgentConnectionPrivate *priv = vdagent_connection_get_instance_private(self);
g_cancellable_cancel(priv->cancellable);
g_io_stream_close(priv->io_stream, NULL, NULL);
g_object_unref(self);
}
PidUid vdagent_connection_get_peer_pid_uid(VDAgentConnection *self,
GError **err)
{
VDAgentConnectionPrivate *priv = vdagent_connection_get_instance_private(self);
GSocket *sock;
GCredentials *cred;
PidUid pid_uid = { -1, -1 };
g_return_val_if_fail(G_IS_SOCKET_CONNECTION(priv->io_stream), pid_uid);
sock = g_socket_connection_get_socket(G_SOCKET_CONNECTION(priv->io_stream));
cred = g_socket_get_credentials(sock, err);
if (cred) {
pid_uid.pid = g_credentials_get_unix_pid(cred, err);
pid_uid.uid = g_credentials_get_unix_user(cred, err);
g_object_unref(cred);
}
return pid_uid;
}
/* Performs single write operation,
* returns TRUE if there's still data to be written, otherwise FALSE. */
static gboolean do_write(VDAgentConnection *self, gboolean block)
{
VDAgentConnectionPrivate *priv = vdagent_connection_get_instance_private(self);
GOutputStream *out;
GBytes *msg;
gssize res;
GError *err = NULL;
msg = g_queue_peek_head(priv->write_queue);
out = g_io_stream_get_output_stream(priv->io_stream);
if (!msg) {
return FALSE;
}
res = g_pollable_stream_write(out,
g_bytes_get_data(msg, NULL) + priv->bytes_written,
g_bytes_get_size(msg) - priv->bytes_written,
block, priv->cancellable, &err);
if (err) {
if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) {
g_error_free(err);
return TRUE;
} else if (g_error_matches(err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
g_error_free(err);
return FALSE;
} else {
priv->error_cb(self, err);
return FALSE;
}
}
priv->bytes_written += res;
if (priv->bytes_written == g_bytes_get_size(msg)) {
g_bytes_unref(g_queue_pop_head(priv->write_queue));
priv->bytes_written = 0;
}
return !g_queue_is_empty(priv->write_queue);
}
static gboolean out_stream_ready_cb(GObject *pollable_stream,
gpointer user_data)
{
return do_write(user_data, FALSE);
}
void vdagent_connection_write(VDAgentConnection *self,
gpointer data,
gsize size)
{
VDAgentConnectionPrivate *priv = vdagent_connection_get_instance_private(self);
GPollableOutputStream *out;
GSource *source;
g_queue_push_tail(priv->write_queue, g_bytes_new_take(data, size));
if (g_queue_get_length(priv->write_queue) == 1) {
out = G_POLLABLE_OUTPUT_STREAM(g_io_stream_get_output_stream(priv->io_stream));
source = g_pollable_output_stream_create_source(out, priv->cancellable);
g_source_set_callback(source, (GSourceFunc) out_stream_ready_cb,
g_object_ref(self), g_object_unref);
g_source_attach(source, NULL);
g_source_unref(source);
}
}
void vdagent_connection_flush(VDAgentConnection *self)
{
while (do_write(self, TRUE));
}
static void message_read_cb(GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
VDAgentConnection *self = user_data;
VDAgentConnectionPrivate *priv = vdagent_connection_get_instance_private(self);
GInputStream *in = G_INPUT_STREAM(source_object);
GError *err = NULL;
gsize bytes_read, data_size;
g_input_stream_read_all_finish(in, res, &bytes_read, &err);
if (err) {
if (g_error_matches(err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
g_error_free(err);
} else {
priv->error_cb(self, err);
}
goto unref;
}
if (bytes_read == 0) {
/* see virtio-port.c for the rationale behind this */
if (priv->opening) {
g_usleep(10000);
read_next_message(self);
} else {
priv->error_cb(self, NULL);
}
goto unref;
}
priv->opening = FALSE;
if (!priv->data_buf) {
/* we've read the message header, now let's read its body */
data_size = VDAGENT_CONNECTION_GET_CLASS(self)->handle_header(
self, priv->header_buf);
if (g_cancellable_is_cancelled(priv->cancellable)) {
goto unref;
}
if (data_size > 0) {
priv->data_buf = g_malloc(data_size);
g_input_stream_read_all_async(in,
priv->data_buf, data_size,
G_PRIORITY_DEFAULT, priv->cancellable,
message_read_cb, g_object_ref(self));
goto unref;
}
}
VDAGENT_CONNECTION_GET_CLASS(self)->handle_message(
self, priv->header_buf, priv->data_buf);
g_clear_pointer(&priv->data_buf, g_free);
read_next_message(self);
unref:
g_object_unref(self);
}
static void read_next_message(VDAgentConnection *self)
{
VDAgentConnectionPrivate *priv = vdagent_connection_get_instance_private(self);
GInputStream *in;
if (g_cancellable_is_cancelled(priv->cancellable)) {
return;
}
in = g_io_stream_get_input_stream(priv->io_stream);
g_input_stream_read_all_async(in,
priv->header_buf, priv->header_size,
G_PRIORITY_DEFAULT, priv->cancellable,
message_read_cb, g_object_ref(self));
}
+107
View File
@@ -0,0 +1,107 @@
/* vdagent-connection.h
Copyright 2019 Red Hat, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __VDAGENT_CONNECTION_H
#define __VDAGENT_CONNECTION_H
#include <glib.h>
#include <gio/gio.h>
#include <glib-object.h>
G_BEGIN_DECLS
#define VDAGENT_TYPE_CONNECTION vdagent_connection_get_type()
G_DECLARE_DERIVABLE_TYPE(VDAgentConnection, vdagent_connection, VDAGENT, CONNECTION, GObject)
/* Subclasses of VDAgentConnection must implement
* handle_header and handle_message. */
struct _VDAgentConnectionClass {
GObjectClass parent_class;
/* Called when a message header has been read.
*
* Handler must parse the @header_buf and
* return the size of message's body.
*
* @header_buf must not be freed. */
gsize (*handle_header) (VDAgentConnection *self,
gpointer header_buf);
/* Called when a full message has been read.
*
* @header, @data must not be freed. */
void (*handle_message) (VDAgentConnection *self,
gpointer header_buf,
gpointer data_buf);
};
/* Invoked when an error occurs during read or write.
*
* If @err is NULL, the connection was closed by the remote side,
* otherwise the handler must free @err using g_error_free().
*
* VDAgentConnection will not continue with the given I/O-op that failed. */
typedef void (*VDAgentConnErrorCb)(VDAgentConnection *self, GError *err);
/* Open a file in @path for read and write.
* Returns a new GIOStream to the given file or NULL when @err is set. */
GIOStream *vdagent_file_open(const gchar *path, GError **err);
/* Create a socket and initiate a new connection to the socket in @path.
* Returns a new GIOStream or NULL when @err is set. */
GIOStream *vdagent_socket_connect(const gchar *path, GError **err);
/* Set up @self to use @io_stream and start reading from it.
*
* If @wait_on_opening is set to TRUE, EOF won't be treated as an error
* until the first message is successfully read or written to the @io_stream. */
void vdagent_connection_setup(VDAgentConnection *self,
GIOStream *io_stream,
gboolean wait_on_opening,
gsize header_size,
VDAgentConnErrorCb error_cb);
/* Cancel running I/O-operations, close the underlying FD and
* unref the VDAgentConnection object. */
void vdagent_connection_destroy(gpointer p);
/* Append a message to the write queue.
*
* VDAgentConnection takes ownership of @data
* and frees it once the message is flushed. */
void vdagent_connection_write(VDAgentConnection *self,
gpointer data,
gsize size);
/* Synchronously write all queued messages to the output stream. */
void vdagent_connection_flush(VDAgentConnection *self);
typedef struct PidUid {
pid_t pid;
uid_t uid;
} PidUid;
/* Returns the PID and UID of the foreign process connected to the socket
* or fill @err set. */
PidUid vdagent_connection_get_peer_pid_uid(VDAgentConnection *self,
GError **err);
G_END_DECLS
#endif
+22 -22
View File
@@ -60,7 +60,7 @@ static bool set_alsa_capture(uint8_t mute, uint8_t nchannels, uint16_t *volume)
{
snd_mixer_t *handle = NULL;
snd_mixer_elem_t *e;
long min, max, vol;
long vol;
bool ret = true;
int alsa_mute;
@@ -74,23 +74,23 @@ static bool set_alsa_capture(uint8_t mute, uint8_t nchannels, uint16_t *volume)
alsa_mute = (mute) ? ALSA_MUTE : ALSA_UNMUTE;
snd_mixer_selem_set_capture_switch_all(e, alsa_mute);
snd_mixer_selem_get_capture_volume_range(e, &min, &max);
snd_mixer_selem_set_capture_volume_range(e, 0, UINT16_MAX);
switch (nchannels) {
case 1: /* MONO */
vol = CLAMP(volume[0], min, max);
vol = volume[0];
snd_mixer_selem_set_capture_volume(e, SND_MIXER_SCHN_MONO, vol);
syslog(LOG_DEBUG, "vdagent-audio: (capture-mono) %lu (%%%0.2f)",
vol, (float) (100*vol/max));
syslog(LOG_DEBUG, "vdagent-audio: (capture-mono) %lu (%0.2f%%)",
vol, 100.0 * vol / UINT16_MAX);
break;
case 2: /* LEFT-RIGHT */
vol = CLAMP(volume[0], min, max);
vol = volume[0];
snd_mixer_selem_set_capture_volume(e, SND_MIXER_SCHN_FRONT_LEFT, vol);
syslog(LOG_DEBUG, "vdagent-audio: (capture-left) %lu (%%%0.2f)",
vol, (float) (100*vol/max));
vol = CLAMP(volume[1], min, max);
syslog(LOG_DEBUG, "vdagent-audio: (capture-left) %lu (%0.2f%%)",
vol, 100.0 * vol / UINT16_MAX);
vol = volume[1];
snd_mixer_selem_set_capture_volume(e, SND_MIXER_SCHN_FRONT_RIGHT, vol);
syslog(LOG_DEBUG, "vdagent-audio: (capture-right) %lu (%%%0.2f)",
vol, (float) (100*vol/max));
syslog(LOG_DEBUG, "vdagent-audio: (capture-right) %lu (%0.2f%%)",
vol, 100.0 * vol / UINT16_MAX);
break;
default:
syslog(LOG_WARNING, "vdagent-audio: number of channels not supported");
@@ -106,7 +106,7 @@ static bool set_alsa_playback (uint8_t mute, uint8_t nchannels, uint16_t *volume
{
snd_mixer_t *handle = NULL;
snd_mixer_elem_t* e;
long min, max, vol;
long vol;
bool ret = true;
int alsa_mute;
@@ -120,23 +120,23 @@ static bool set_alsa_playback (uint8_t mute, uint8_t nchannels, uint16_t *volume
alsa_mute = (mute) ? ALSA_MUTE : ALSA_UNMUTE;
snd_mixer_selem_set_playback_switch_all(e, alsa_mute);
snd_mixer_selem_get_playback_volume_range(e, &min, &max);
snd_mixer_selem_set_playback_volume_range(e, 0, UINT16_MAX);
switch (nchannels) {
case 1: /* MONO */
vol = CLAMP(volume[0], min, max);
vol = volume[0];
snd_mixer_selem_set_playback_volume(e, SND_MIXER_SCHN_MONO, vol);
syslog(LOG_DEBUG, "vdagent-audio: (playback-mono) %lu (%%%0.2f)",
vol, (float) (100*vol/max));
syslog(LOG_DEBUG, "vdagent-audio: (playback-mono) %lu (%0.2f%%)",
vol, 100.0 * vol / UINT16_MAX);
break;
case 2: /* LEFT-RIGHT */
vol = CLAMP(volume[0], min, max);
vol = volume[0];
snd_mixer_selem_set_playback_volume(e, SND_MIXER_SCHN_FRONT_LEFT, vol);
syslog(LOG_DEBUG, "vdagent-audio: (playback-left) %lu (%%%0.2f)",
vol, (float) (100*vol/max));
vol = CLAMP(volume[1], min, max);
syslog(LOG_DEBUG, "vdagent-audio: (playback-left) %lu (%0.2f%%)",
vol, 100.0 * vol / UINT16_MAX);
vol = volume[1];
snd_mixer_selem_set_playback_volume(e, SND_MIXER_SCHN_FRONT_RIGHT, vol);
syslog(LOG_DEBUG, "vdagent-audio: (playback-right) %lu (%%%0.2f)",
vol, (float) (100*vol/max));
syslog(LOG_DEBUG, "vdagent-audio: (playback-right) %lu (%0.2f%%)",
vol, 100.0 * vol / UINT16_MAX);
break;
default:
syslog(LOG_WARNING, "vdagent-audio: number of channels not supported");
+93 -55
View File
@@ -17,7 +17,7 @@
*/
#include <config.h>
#ifdef WITH_GTK
#ifdef USE_GTK_FOR_CLIPBOARD
# include <gtk/gtk.h>
# include <syslog.h>
@@ -27,13 +27,31 @@
#include "clipboard.h"
#ifdef WITH_GTK
#ifdef USE_GTK_FOR_CLIPBOARD
/* 2 selections supported - _SELECTION_CLIPBOARD = 0, _SELECTION_PRIMARY = 1 */
#define SELECTION_COUNT (VD_AGENT_CLIPBOARD_SELECTION_PRIMARY + 1)
#define TYPE_COUNT (VD_AGENT_CLIPBOARD_IMAGE_JPG + 1)
#define sel_id_from_clip(clipboard) \
GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(clipboard), "vdagent-selection-id"))
static const GdkAtom sel_atom[] = {
[VD_AGENT_CLIPBOARD_SELECTION_CLIPBOARD] = GDK_SELECTION_CLIPBOARD,
[VD_AGENT_CLIPBOARD_SELECTION_PRIMARY] = GDK_SELECTION_PRIMARY,
};
G_STATIC_ASSERT(G_N_ELEMENTS(sel_atom) == SELECTION_COUNT);
static gint sel_id_from_clip(GtkClipboard *clipboard)
{
GdkAtom sel = gtk_clipboard_get_selection(clipboard);
int i;
for (i = 0; i < G_N_ELEMENTS(sel_atom); i++) {
if (sel == sel_atom[i]) {
return i;
}
}
g_return_val_if_reached(0);
}
enum {
OWNER_NONE,
@@ -58,16 +76,26 @@ typedef struct {
} Selection;
#endif
struct VDAgentClipboards {
#ifdef WITH_GTK
struct udscs_connection *conn;
Selection selections[SELECTION_COUNT];
struct _VDAgentClipboards {
GObject parent;
#ifdef USE_GTK_FOR_CLIPBOARD
UdscsConnection *conn;
Selection selections[SELECTION_COUNT];
#else
struct vdagent_x11 *x11;
#endif
};
#ifdef WITH_GTK
struct _VDAgentClipboardsClass
{
GObjectClass parent;
};
G_DEFINE_TYPE(VDAgentClipboards, vdagent_clipboards, G_TYPE_OBJECT)
#ifdef USE_GTK_FOR_CLIPBOARD
static const struct {
guint type;
const gchar *atom_name;
@@ -210,16 +238,17 @@ static void clipboard_owner_change_cb(GtkClipboard *clipboard,
Selection *sel = &c->selections[sel_id];
/* if the event was caused by gtk_clipboard_set_with_data(), ignore it */
if (sel->owner == OWNER_CLIENT)
if (gtk_clipboard_get_owner(clipboard) == G_OBJECT(c)) {
return;
if (sel->owner == OWNER_GUEST) {
clipboard_new_owner(c, sel_id, OWNER_NONE);
udscs_write(c->conn, VDAGENTD_CLIPBOARD_RELEASE, sel_id, 0, NULL, 0);
}
if (event->reason != GDK_OWNER_CHANGE_NEW_OWNER)
if (event->reason != GDK_OWNER_CHANGE_NEW_OWNER) {
if (sel->owner == OWNER_GUEST) {
clipboard_new_owner(c, sel_id, OWNER_NONE);
udscs_write(c->conn, VDAGENTD_CLIPBOARD_RELEASE, sel_id, 0, NULL, 0);
}
return;
}
/* if there's a pending request for clipboard targets, cancel it */
if (sel->last_targets_req)
@@ -252,7 +281,7 @@ static void clipboard_contents_received_cb(GtkClipboard *clipboard,
gtk_selection_data_get_data(sel_data),
gtk_selection_data_get_length(sel_data));
} else {
syslog(LOG_WARNING, "%s: sel_id=%u: expected type %u, recieved %u, "
syslog(LOG_WARNING, "%s: sel_id=%u: expected type %u, received %u, "
"skipping", __func__, sel_id, target, type);
udscs_write(c->conn, VDAGENTD_CLIPBOARD_DATA, sel_id,
VD_AGENT_CLIPBOARD_NONE, NULL, 0);
@@ -300,7 +329,7 @@ static void clipboard_clear_cb(GtkClipboard *clipboard, gpointer user_data)
void vdagent_clipboard_grab(VDAgentClipboards *c, guint sel_id,
guint32 *types, guint n_types)
{
#ifndef WITH_GTK
#ifndef USE_GTK_FOR_CLIPBOARD
vdagent_x11_clipboard_grab(c->x11, sel_id, types, n_types);
#else
GtkTargetEntry targets[G_N_ELEMENTS(atom2agent)];
@@ -329,9 +358,10 @@ void vdagent_clipboard_grab(VDAgentClipboards *c, guint sel_id,
g_clear_pointer(&sel->last_targets_req, request_ref_cancel);
}
if (gtk_clipboard_set_with_data(sel->clipboard,
targets, n_targets,
clipboard_get_cb, clipboard_clear_cb, c))
if (gtk_clipboard_set_with_owner(sel->clipboard,
targets, n_targets,
clipboard_get_cb, clipboard_clear_cb,
G_OBJECT(c)))
clipboard_new_owner(c, sel_id, OWNER_CLIENT);
else {
syslog(LOG_ERR, "%s: sel_id=%u: clipboard grab failed", __func__, sel_id);
@@ -343,7 +373,7 @@ void vdagent_clipboard_grab(VDAgentClipboards *c, guint sel_id,
void vdagent_clipboard_data(VDAgentClipboards *c, guint sel_id,
guint type, guchar *data, guint size)
{
#ifndef WITH_GTK
#ifndef USE_GTK_FOR_CLIPBOARD
vdagent_x11_clipboard_data(c->x11, sel_id, type, data, size);
#else
g_return_if_fail(sel_id < SELECTION_COUNT);
@@ -373,7 +403,7 @@ void vdagent_clipboard_data(VDAgentClipboards *c, guint sel_id,
void vdagent_clipboard_release(VDAgentClipboards *c, guint sel_id)
{
#ifndef WITH_GTK
#ifndef USE_GTK_FOR_CLIPBOARD
vdagent_x11_clipboard_release(c->x11, sel_id);
#else
g_return_if_fail(sel_id < SELECTION_COUNT);
@@ -387,7 +417,7 @@ void vdagent_clipboard_release(VDAgentClipboards *c, guint sel_id)
void vdagent_clipboards_release_all(VDAgentClipboards *c)
{
#ifndef WITH_GTK
#ifndef USE_GTK_FOR_CLIPBOARD
vdagent_x11_client_disconnected(c->x11);
#else
guint sel_id, owner;
@@ -405,7 +435,7 @@ void vdagent_clipboards_release_all(VDAgentClipboards *c)
void vdagent_clipboard_request(VDAgentClipboards *c, guint sel_id, guint type)
{
#ifndef WITH_GTK
#ifndef USE_GTK_FOR_CLIPBOARD
vdagent_x11_clipboard_request(c->x11, sel_id, type);
#else
Selection *sel;
@@ -435,50 +465,58 @@ err:
#endif
}
VDAgentClipboards *vdagent_clipboards_init(struct vdagent_x11 *x11,
struct udscs_connection *conn)
static void
vdagent_clipboards_init(VDAgentClipboards *self)
{
#ifdef WITH_GTK
guint sel_id;
const GdkAtom sel_atom[SELECTION_COUNT] = {
GDK_SELECTION_CLIPBOARD, /* VD_AGENT_CLIPBOARD_SELECTION_CLIPBOARD */
GDK_SELECTION_PRIMARY, /* VD_AGENT_CLIPBOARD_SELECTION_PRIMARY */
};
#endif
}
VDAgentClipboards *c;
c = g_new0(VDAgentClipboards, 1);
#ifndef WITH_GTK
c->x11 = x11;
VDAgentClipboards *vdagent_clipboards_new(struct vdagent_x11 *x11)
{
VDAgentClipboards *self = g_object_new(VDAGENT_TYPE_CLIPBOARDS, NULL);
#ifndef USE_GTK_FOR_CLIPBOARD
self->x11 = x11;
#else
c->conn = conn;
guint sel_id;
for (sel_id = 0; sel_id < SELECTION_COUNT; sel_id++) {
GtkClipboard *clipboard = gtk_clipboard_get(sel_atom[sel_id]);
c->selections[sel_id].clipboard = clipboard;
/* enables the use of sel_id_from_clipboard(clipboard) macro */
g_object_set_data(G_OBJECT(clipboard), "vdagent-selection-id",
GUINT_TO_POINTER(sel_id));
self->selections[sel_id].clipboard = clipboard;
g_signal_connect(G_OBJECT(clipboard), "owner-change",
G_CALLBACK(clipboard_owner_change_cb), c);
G_CALLBACK(clipboard_owner_change_cb), self);
}
#endif
return c;
return self;
}
void vdagent_clipboards_finalize(VDAgentClipboards *c, gboolean conn_alive)
void
vdagent_clipboards_set_conn(VDAgentClipboards *self, UdscsConnection *conn)
{
#ifdef WITH_GTK
guint sel_id;
for (sel_id = 0; sel_id < SELECTION_COUNT; sel_id++)
g_signal_handlers_disconnect_by_func(c->selections[sel_id].clipboard,
G_CALLBACK(clipboard_owner_change_cb), c);
if (conn_alive == FALSE)
c->conn = NULL;
vdagent_clipboards_release_all(c);
#ifdef USE_GTK_FOR_CLIPBOARD
self->conn = conn;
#endif
}
g_free(c);
static void vdagent_clipboards_dispose(GObject *obj)
{
#ifdef USE_GTK_FOR_CLIPBOARD
VDAgentClipboards *self = VDAGENT_CLIPBOARDS(obj);
guint sel_id;
for (sel_id = 0; sel_id < SELECTION_COUNT; sel_id++)
g_signal_handlers_disconnect_by_func(self->selections[sel_id].clipboard,
G_CALLBACK(clipboard_owner_change_cb), self);
if (self->conn)
vdagent_clipboards_release_all(self);
#endif
}
static void
vdagent_clipboards_class_init(VDAgentClipboardsClass *klass)
{
GObjectClass *oclass = G_OBJECT_CLASS(klass);
oclass->dispose = vdagent_clipboards_dispose;
}
+6 -5
View File
@@ -19,16 +19,17 @@
#ifndef __VDAGENT_CLIPBOARD_H
#define __VDAGENT_CLIPBOARD_H
#include <glib.h>
#include <glib-object.h>
#include "x11.h"
#include "udscs.h"
typedef struct VDAgentClipboards VDAgentClipboards;
#define VDAGENT_TYPE_CLIPBOARDS vdagent_clipboards_get_type()
G_DECLARE_FINAL_TYPE(VDAgentClipboards, vdagent_clipboards, VDAGENT, CLIPBOARDS, GObject)
VDAgentClipboards *vdagent_clipboards_init(struct vdagent_x11 *x11,
struct udscs_connection *conn);
void vdagent_clipboards_finalize(VDAgentClipboards *c, gboolean conn_alive);
VDAgentClipboards *vdagent_clipboards_new(struct vdagent_x11 *x11);
void vdagent_clipboards_set_conn(VDAgentClipboards *self, UdscsConnection *conn);
void vdagent_clipboard_request(VDAgentClipboards *c, guint sel_id, guint type);
+92 -75
View File
@@ -204,13 +204,13 @@ static PciAddress* parse_pci_address_from_spice(char *input)
static bool compare_addresses(PciAddress *a, PciAddress *b)
{
// only check domain, slot, and function
if (!(a->domain == b->domain
&& g_list_length(a->devices) == g_list_length(b->devices))) {
if (a->domain != b->domain) {
return false;
}
for (GList *la = a->devices, *lb = b->devices;
la != NULL;
const GList *la, *lb;
for (la = a->devices, lb = b->devices;
la != NULL && lb != NULL;
la = la->next, lb = lb->next) {
PciDevice *deva = la->data;
PciDevice *devb = lb->data;
@@ -220,7 +220,9 @@ static bool compare_addresses(PciAddress *a, PciAddress *b)
return false;
}
}
return true;
/* True only if both have the same length */
return (la == NULL && lb == NULL);
}
// Connector type names from xorg modesetting driver
@@ -330,7 +332,7 @@ static char* find_device_at_pci_address(PciAddress *pci_addr, int *vendor_id, in
g_return_val_if_fail(device_id != NULL, NULL);
g_return_val_if_fail(vendor_id != NULL, NULL);
// Look for a device that matches the PCI address parsed above. Loop
// through the list of cards reported by the DRM subsytem
// through the list of cards reported by the DRM subsystem
for (int i = 0; i < 10; ++i) {
char dev_path[64];
struct stat buf;
@@ -386,12 +388,14 @@ static char* find_device_at_pci_address(PciAddress *pci_addr, int *vendor_id, in
return NULL;
}
// PCI address should be in the following format:
// pci/$domain/$slot.$fn/$slot.$fn
bool lookup_xrandr_output_for_device_info(VDAgentDeviceDisplayInfo *device_info,
Display *xdisplay,
XRRScreenResources *xres,
RROutput *output_id)
/**
* Look up DRM info for the device, and retrieve the expected connector name.
* This name will later be compared to the monitor names found at the display manager level.
*/
int get_connector_name_for_device_info(VDAgentDeviceDisplayInfo *device_info,
char *expected_name, size_t name_size,
bool has_virtual_zero_display)
{
PciAddress *user_pci_addr = parse_pci_address_from_spice((char*)device_info->device_address);
if (!user_pci_addr) {
@@ -399,7 +403,7 @@ bool lookup_xrandr_output_for_device_info(VDAgentDeviceDisplayInfo *device_info,
"Couldn't parse PCI address '%s'. "
"Address should be the form 'pci/$domain/$slot.$fn/$slot.fn...",
device_info->device_address);
return false;
return -1;
}
int vendor_id = 0;
@@ -410,68 +414,86 @@ bool lookup_xrandr_output_for_device_info(VDAgentDeviceDisplayInfo *device_info,
int drm_fd = open(dev_path, O_RDWR);
if (drm_fd < 0) {
syslog(LOG_WARNING, "Unable to open file %s", dev_path);
return false;
g_free(dev_path);
return -1;
}
drmModeResPtr res = drmModeGetResources(drm_fd);
if (res) {
// find the drm output that is equal to device_display_id
if (device_info->device_display_id >= res->count_connectors) {
syslog(LOG_WARNING,
"Specified display id %i is higher than the maximum display id "
"provided by this device (%i)",
device_info->device_display_id, res->count_connectors - 1);
close(drm_fd);
return false;
}
drmModeConnectorPtr conn =
drmModeGetConnector(drm_fd, res->connectors[device_info->device_display_id]);
drmModeFreeResources(res);
res = NULL;
if (res == NULL) {
syslog(LOG_WARNING,
"Unable to get DRM resources for card %s. "
"Falling back to using xrandr output index.",
dev_path);
close(drm_fd);
g_free(dev_path);
return 1; // error out - actual handling is deferred to the caller
}
if (conn == NULL) {
syslog(LOG_WARNING, "Unable to get drm connector for display id %i",
device_info->device_display_id);
return false;
}
// no need for dev_path anymore
g_free(dev_path);
bool decrement_name = false;
if (vendor_id == PCI_VENDOR_ID_REDHAT && device_id == PCI_DEVICE_ID_QXL) {
// Older QXL drivers numbered their outputs starting with
// 0. This contrasts with most drivers who start numbering
// outputs with 1. In this case, the expected drm connector
// name will need to be decremented before comparing to the
// xrandr output name
for (int i = 0; i < xres->noutput; ++i) {
XRROutputInfo *oinfo = XRRGetOutputInfo(xdisplay, xres, xres->outputs[i]);
if (!oinfo) {
syslog(LOG_WARNING, "Unable to lookup XRandr output info for output %li",
xres->outputs[i]);
return false;
}
if (strcmp(oinfo->name, "Virtual-0") == 0) {
decrement_name = true;
XRRFreeOutputInfo(oinfo);
break;
}
XRRFreeOutputInfo(oinfo);
}
}
// Compare the name of the xrandr output against what we would
// expect based on the drm connection type. The xrandr names
// are driver-specific, so we need to special-case some
// drivers. Most hardware these days uses the 'modesetting'
// driver, but the QXL device uses its own driver which has
// different naming conventions
char expected_name[100];
if (vendor_id == PCI_VENDOR_ID_REDHAT && device_id == PCI_DEVICE_ID_QXL) {
drm_conn_name_qxl(conn, expected_name, sizeof(expected_name), decrement_name);
} else {
drm_conn_name_modesetting(conn, expected_name, sizeof(expected_name));
}
// find the drm output that is equal to device_display_id
if (device_info->device_display_id >= res->count_connectors) {
syslog(LOG_WARNING,
"Specified display id %i is higher than the maximum display id "
"provided by this device (%i)",
device_info->device_display_id, res->count_connectors - 1);
close(drm_fd);
return -1;
}
drmModeConnectorPtr conn =
drmModeGetConnector(drm_fd, res->connectors[device_info->device_display_id]);
drmModeFreeResources(res);
res = NULL;
close(drm_fd);
if (conn == NULL) {
syslog(LOG_WARNING, "Unable to get drm connector for display id %i",
device_info->device_display_id);
return -1;
}
bool decrement_name = false;
if (vendor_id == PCI_VENDOR_ID_REDHAT && device_id == PCI_DEVICE_ID_QXL
&& has_virtual_zero_display) {
decrement_name = true;
}
// Compare the name of the xrandr output against what we would
// expect based on the drm connection type. The xrandr names
// are driver-specific, so we need to special-case some
// drivers. Most hardware these days uses the 'modesetting'
// driver, but the QXL device uses its own driver which has
// different naming conventions
if (vendor_id == PCI_VENDOR_ID_REDHAT && device_id == PCI_DEVICE_ID_QXL) {
drm_conn_name_qxl(conn, expected_name, name_size, decrement_name);
} else {
drm_conn_name_modesetting(conn, expected_name, name_size);
}
drmModeFreeConnector(conn);
return 0;
}
// PCI address should be in the following format:
// pci/$domain/$slot.$fn/$slot.$fn
bool lookup_xrandr_output_for_device_info(VDAgentDeviceDisplayInfo *device_info,
Display *xdisplay,
XRRScreenResources *xres,
RROutput *output_id,
bool has_virtual_zero_display)
{
char expected_name[100];
int ret;
ret = get_connector_name_for_device_info(device_info, expected_name, sizeof(expected_name),
has_virtual_zero_display);
switch (ret) {
case -1: // generic error => exit
return false;
case 0:
// Loop through xrandr outputs and check whether the xrandr
// output name matches the drm connector name
for (int i = 0; i < xres->noutput; ++i) {
@@ -491,13 +513,8 @@ bool lookup_xrandr_output_for_device_info(VDAgentDeviceDisplayInfo *device_info,
}
XRRFreeOutputInfo(oinfo);
}
drmModeFreeConnector(conn);
} else {
close(drm_fd);
syslog(LOG_WARNING,
"Unable to get DRM resources for card %s. "
"Falling back to using xrandr output index.",
dev_path);
break;
case 1: // no DRM info found
// This is probably a proprietary driver (e.g. Nvidia) that does
// not provide outputs via drm, so the only thing we can do is just
// assume that it is the only device assigned to X, and use the
+6 -1
View File
@@ -27,4 +27,9 @@ struct vdagent_x11;
bool lookup_xrandr_output_for_device_info(VDAgentDeviceDisplayInfo *device_info,
Display *xdisplay,
XRRScreenResources *xres,
RROutput *output_id);
RROutput *output_id,
bool has_virtual_zero_display);
int get_connector_name_for_device_info(VDAgentDeviceDisplayInfo *device_info,
char *expected_name, size_t name_size,
bool has_virtual_zero_display);
+491
View File
@@ -0,0 +1,491 @@
/* display.c vdagent display source code
Copyright 2020 Red Hat, Inc.
Red Hat Authors:
Julien Ropé <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <glib.h>
#ifdef WITH_GTK
#include <gdk/gdk.h>
#include <gtk/gtk.h> // for GTK_CHECK_VERSION
#if GTK_CHECK_VERSION(3, 98, 0)
#include <gdk/wayland/gdkwayland.h>
#include <gdk/x11/gdkx.h>
#else
#ifdef GDK_WINDOWING_X11
#include <gdk/gdkx.h>
#endif
#endif
#endif
#include <syslog.h>
#include "x11.h"
#include "x11-priv.h"
#include "device-info.h"
#include "vdagentd-proto.h"
#include "mutter.h"
#include "display.h"
/**
* VDAgentDisplay and the vdagent_display_*() functions are used as wrappers for display-related
* operations.
* They allow vdagent code to call generic display functions that are independent from the underlying
* API (X11/GTK/etc).
*
* The display.c file contains the actual implementation and chooses what API will be called.
* The x11.c and x11-randr.c files contains the x11-specific functions.
*/
struct VDAgentDisplay {
// association between SPICE display ID and expected connector name
GHashTable *connector_mapping;
struct vdagent_x11 *x11;
UdscsConnection *vdagentd;
int debug;
GIOChannel *x11_channel;
guint io_watch_source_id;
VDAgentMutterDBus *mutter;
};
static gint vdagent_guest_xorg_resolution_compare(gconstpointer a, gconstpointer b)
{
struct vdagentd_guest_xorg_resolution *ptr_a, *ptr_b;
ptr_a = (struct vdagentd_guest_xorg_resolution *)a;
ptr_b = (struct vdagentd_guest_xorg_resolution *)b;
return ptr_a->display_id - ptr_b->display_id;
}
static GArray *vdagent_gtk_get_resolutions(VDAgentDisplay *display,
int *width, int *height, int *screen_count)
{
#ifdef USE_GTK_FOR_MONITORS
if (!GDK_IS_WAYLAND_DISPLAY(gdk_display_get_default())) {
return NULL;
}
GArray *res_array = g_array_new(FALSE, FALSE, sizeof(struct vdagentd_guest_xorg_resolution));
int i;
GListModel *monitors = NULL;
GdkDisplay *gdk_display = gdk_display_get_default();
// Make sure GDK is aware of the changes we want to send.
// TODO: This may be removed if we get a notification of change from GDK itself,
// but with X11 notification, we end up sending obsolete information.
gdk_display_sync(gdk_display);
monitors = gdk_display_get_monitors(gdk_display);
*screen_count = g_list_model_get_n_items(monitors);
for (i = 0; i < *screen_count; i++) {
struct vdagentd_guest_xorg_resolution curr;
GdkMonitor *monitor = (GdkMonitor*)g_list_model_get_item(monitors, i);
GdkRectangle geometry;
gdk_monitor_get_geometry(monitor, &geometry);
curr.x = geometry.x;
curr.y = geometry.y;
curr.height = geometry.height;
curr.width = geometry.width;
// compute the size of the desktop based on the dimension of the monitors
// TODO: check for a specific API giving us that information (not found in GTK ?)
if (curr.x + curr.width > *width) {
*width = curr.x + curr.width;
}
if (curr.y + curr.height > *height) {
*height = curr.y + curr.height;
}
// retrieve the Spice Display ID based on the connector name
const char *name = gdk_monitor_get_connector(monitor);
if (!name) {
syslog(LOG_WARNING, "Unknown connector for monitor %d", i);
continue;
}
gpointer value;
if (g_hash_table_lookup_extended(display->connector_mapping, name, NULL, &value)) {
curr.display_id = GPOINTER_TO_UINT(value);
syslog(LOG_DEBUG, "Found monitor %s with geometry %dx%d+%d-%d - associating it to SPICE display #%d",
name, curr.width, curr.height, curr.x, curr.y, curr.display_id);
g_array_append_val(res_array, curr);
} else {
syslog(LOG_DEBUG, "No SPICE display found for connector %s", name);
}
}
if (res_array->len == 0) {
syslog(LOG_DEBUG, "No Spice display ID matching - assuming display ID == Monitor index");
for (i = 0; i < *screen_count; i++) {
struct vdagentd_guest_xorg_resolution res;
GdkMonitor *monitor = (GdkMonitor*)g_list_model_get_item(monitors, i);
GdkRectangle geometry;
gdk_monitor_get_geometry(monitor, &geometry);
res.x = geometry.x;
res.y = geometry.y;
res.height = geometry.height;
res.width = geometry.width;
res.display_id = i;
g_array_append_val(res_array, res);
}
}
return res_array;
#else
return NULL;
#endif
}
void vdagent_display_send_daemon_guest_res(VDAgentDisplay *display, gboolean update)
{
GArray *res_array;
int width = 0, height = 0, screen_count = 0;
// Try various backends one after the other.
// We try Mutter first, because it has a bigger probability of being available.
// Second GTK, because if/when we build with GTK4, this is the one that will work best.
// Finally we try X11. This is the default, and should work OK in most circumstances.
res_array = vdagent_mutter_get_resolutions(display->mutter, &width, &height, &screen_count);
if (res_array == NULL) {
res_array = vdagent_gtk_get_resolutions(display, &width, &height, &screen_count);
}
if (res_array == NULL) {
res_array = vdagent_x11_get_resolutions(display->x11, update, &width, &height, &screen_count);
}
if (res_array == NULL) {
return;
}
if (res_array->len < g_hash_table_size(display->connector_mapping)) {
// Complete the array with disabled displays.
// We need to send 0x0 resolution to let the daemon know the display is not there anymore.
syslog(LOG_DEBUG, "%d/%d displays found - completing with disabled displays.",
res_array->len, g_hash_table_size(display->connector_mapping));
GHashTableIter iter;
gpointer key, value;
g_hash_table_iter_init(&iter, display->connector_mapping);
while (g_hash_table_iter_next(&iter, &key, &value)) {
bool found = false;
int display_id = GPOINTER_TO_INT(value);
for (int i = 0; i < res_array->len; i++) {
struct vdagentd_guest_xorg_resolution *res =
(struct vdagentd_guest_xorg_resolution*)res_array->data;
if (res[i].display_id == display_id) {
found = true;
break;
}
}
if (!found) {
struct vdagentd_guest_xorg_resolution res;
res.x = 0;
res.y = 0;
res.height = 0;
res.width = 0;
res.display_id = display_id;
g_array_append_val(res_array, res);
}
}
}
// sort the list to make sure we send them in the display_id order
g_array_sort(res_array, vdagent_guest_xorg_resolution_compare);
if (display->debug) {
syslog(LOG_DEBUG, "Sending guest screen resolutions to vdagentd:");
if (res_array->len > screen_count) {
syslog(LOG_DEBUG, "(NOTE: list may contain overlapping areas when "
"multiple spice displays show the same guest output)");
}
struct vdagentd_guest_xorg_resolution *res =
(struct vdagentd_guest_xorg_resolution*)res_array->data;
for (int i = 0; i < res_array->len; i++) {
syslog(LOG_DEBUG, " display_id=%d - %dx%d%+d%+d",
res[i].display_id, res[i].width, res[i].height, res[i].x, res[i].y);
}
}
udscs_write(display->vdagentd, VDAGENTD_GUEST_XORG_RESOLUTION, width, height,
(uint8_t *)res_array->data,
res_array->len * sizeof(struct vdagentd_guest_xorg_resolution));
g_array_free(res_array, TRUE);
}
static gchar *vdagent_display_get_wm_name(VDAgentDisplay *display)
{
#ifdef GDK_WINDOWING_X11
// With GTK4, screen have disappear, and with it the access to the window manager name
// Use the X11 call instead.
#if ! GTK_CHECK_VERSION(3, 98, 0)
GdkDisplay *gdk_display = gdk_display_get_default();
if (GDK_IS_X11_DISPLAY(gdk_display))
return g_strdup(gdk_x11_screen_get_window_manager_name(
gdk_display_get_default_screen(gdk_display)));
return g_strdup("unsupported");
#endif
#endif
return vdagent_x11_get_wm_name(display->x11);
}
struct vdagent_x11* vdagent_display_get_x11(VDAgentDisplay *display)
{
return display->x11;
}
static gboolean x11_io_channel_cb(GIOChannel *source, GIOCondition condition, gpointer data)
{
VDAgentDisplay *display = data;
vdagent_x11_do_read(display->x11);
return G_SOURCE_CONTINUE;
}
VDAgentDisplay* vdagent_display_create(UdscsConnection *vdagentd, int debug, int sync)
{
VDAgentDisplay *display;
gchar *net_wm_name = NULL;
display = g_new0(VDAgentDisplay, 1);
display->vdagentd = vdagentd;
display->debug = debug;
display->x11 = vdagent_x11_create(vdagentd, debug, sync);
if (display->x11 == NULL) {
g_free(display);
return NULL;
}
display->x11->vdagent_display = display;
display->connector_mapping = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
display->mutter = vdagent_mutter_create(display->connector_mapping);
display->x11_channel = g_io_channel_unix_new(vdagent_x11_get_fd(display->x11));
if (display->x11_channel == NULL) {
vdagent_x11_destroy(display->x11, TRUE);
g_free(display);
return NULL;
}
display->io_watch_source_id =
g_io_add_watch(display->x11_channel, G_IO_IN, x11_io_channel_cb, display);
/* Since we are started at the same time as the wm,
sometimes we need to wait a bit for the _NET_WM_NAME to show up. */
for (int i = 0; i < 9; i++) {
g_free(net_wm_name);
net_wm_name = vdagent_display_get_wm_name(display);
if (strcmp(net_wm_name, "unknown"))
break;
usleep(100000);
}
if (display->debug)
syslog(LOG_DEBUG, "%s: net_wm_name=\"%s\", has icons=%d",
__func__, net_wm_name, vdagent_display_has_icons_on_desktop(display));
g_free(net_wm_name);
vdagent_display_send_daemon_guest_res(display, TRUE);
return display;
}
void vdagent_display_destroy(VDAgentDisplay *display, int vdagentd_disconnected)
{
if (!display) {
return;
}
g_source_remove(display->io_watch_source_id);
g_clear_pointer(&display->x11_channel, g_io_channel_unref);
vdagent_x11_destroy(display->x11, vdagentd_disconnected);
vdagent_mutter_destroy(display->mutter);
g_hash_table_destroy(display->connector_mapping);
g_free(display);
}
/* Function used to determine the default location to save file-xfers,
xdg desktop dir or xdg download dir. We err on the safe side and use a
whitelist approach, so any unknown desktop will end up with saving
file-xfers to the xdg download dir, and opening the xdg download dir with
xdg-open when the file-xfer completes. */
gboolean vdagent_display_has_icons_on_desktop(VDAgentDisplay *display)
{
static const char * const wms_with_icons_on_desktop[] = {
"Metacity", /* GNOME-2 or GNOME-3 fallback */
"Xfwm4", /* Xfce */
"Marco", /* Mate */
"Metacity (Marco)", /* Mate, newer */
NULL
};
gchar *net_wm_name = vdagent_display_get_wm_name(display);
int i;
for (i = 0; wms_with_icons_on_desktop[i]; i++)
if (!strcmp(net_wm_name, wms_with_icons_on_desktop[i])) {
g_free(net_wm_name);
return TRUE;
}
g_free(net_wm_name);
return FALSE;
}
static bool has_zero_based_display_id(VDAgentDisplay *display)
{
// Older QXL drivers numbered their outputs starting with
// 0. This contrasts with most drivers who start numbering
// outputs with 1. In this case, the expected drm connector
// name will need to be decremented before comparing to the
// display manager output name
bool ret = false;
#ifdef USE_GTK_FOR_MONITORS
GdkDisplay *gdk_display = gdk_display_get_default();
if (GDK_IS_WAYLAND_DISPLAY(gdk_display)) {
gdk_display_sync(gdk_display);
GListModel *monitors = gdk_display_get_monitors(gdk_display);
int screen_count = g_list_model_get_n_items(monitors);
for (int i = 0; i < screen_count; i++) {
GdkMonitor *monitor = (GdkMonitor *)g_list_model_get_item(monitors, i);
const char *name = gdk_monitor_get_connector(monitor);
if (!name) {
continue;
}
if (strcmp(name, "Virtual-0") == 0) {
ret = true;
break;
}
}
}
else // otherwise, use the X11 code (below)
#endif
{
XRRScreenResources *xres = display->x11->randr.res;
Display *xdisplay = display->x11->display;
for (int i = 0; i < xres->noutput; ++i) {
XRROutputInfo *oinfo = XRRGetOutputInfo(xdisplay, xres, xres->outputs[i]);
if (!oinfo) {
syslog(LOG_WARNING, "Unable to lookup XRandr output info for output %li",
xres->outputs[i]);
return false;
}
if (strcmp(oinfo->name, "Virtual-0") == 0) {
ret = true;
XRRFreeOutputInfo(oinfo);
break;
}
XRRFreeOutputInfo(oinfo);
}
}
return ret;
}
// handle the device info message from the server. This will allow us to
// maintain a mapping from spice display id to xrandr output
void vdagent_display_handle_graphics_device_info(VDAgentDisplay *display, uint8_t *data,
size_t size)
{
VDAgentGraphicsDeviceInfo *graphics_device_info = (VDAgentGraphicsDeviceInfo *)data;
VDAgentDeviceDisplayInfo *device_display_info = graphics_device_info->display_info;
void *buffer_end = data + size;
bool decrement_id = has_zero_based_display_id(display);
syslog(LOG_INFO, "Received Graphics Device Info:");
for (size_t i = 0; i < graphics_device_info->count; ++i) {
if ((void*) device_display_info > buffer_end ||
(void*) (&device_display_info->device_address +
device_display_info->device_address_len) > buffer_end) {
syslog(LOG_ERR, "Malformed graphics_display_info message, "
"extends beyond the end of the buffer");
break;
}
// make sure the string is terminated:
if (device_display_info->device_address_len > 0) {
device_display_info->device_address[device_display_info->device_address_len - 1] = '\0';
} else {
syslog(LOG_WARNING, "Zero length device_address received for channel_id: %u, monitor_id: %u",
device_display_info->channel_id, device_display_info->monitor_id);
}
// Get the expected connector name from hardware info. Store it with the SPICE display ID.
char expected_name[100];
int ret = get_connector_name_for_device_info(device_display_info, expected_name,
sizeof(expected_name), decrement_id);
if (ret == 0) {
g_hash_table_insert(display->connector_mapping,
g_strdup(expected_name),
GUINT_TO_POINTER(device_display_info->channel_id + device_display_info->monitor_id));
syslog(LOG_DEBUG, "Mapping connector %s to display #%d", expected_name,
(device_display_info->channel_id + device_display_info->monitor_id));
}
// Also map the SPICE display ID to the corresponding X server object.
vdagent_x11_handle_device_display_info(display->x11, device_display_info, decrement_id);
device_display_info = (VDAgentDeviceDisplayInfo*) ((char*) device_display_info +
sizeof(VDAgentDeviceDisplayInfo) + device_display_info->device_address_len);
}
// make sure daemon is up-to-date with (possibly updated) device IDs
vdagent_display_send_daemon_guest_res(display, TRUE);
}
/*
* Set monitor configuration according to client request.
*
* On exit send current configuration to client, regardless of error.
*
* Errors:
* screen size too large for driver to handle. (we set the largest/smallest possible)
* no randr support in X server.
* invalid configuration request from client.
*/
void vdagent_display_set_monitor_config(VDAgentDisplay *display, VDAgentMonitorsConfig *mon_config,
int fallback)
{
#ifdef USE_GTK_FOR_MONITORS
if (GDK_IS_WAYLAND_DISPLAY(gdk_display_get_default())) {
// FIXME: there is no equivalent call to set the monitor config under wayland
// Send the configuration back - the client need to know the resolution was not taken into account.
vdagent_display_send_daemon_guest_res(display, TRUE);
return;
}
#endif
vdagent_x11_set_monitor_config(display->x11, mon_config, fallback);
}
+39
View File
@@ -0,0 +1,39 @@
/*
* display.h- vdagent display handling header
Copyright 2020 Red Hat, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SRC_VDAGENT_DISPLAY_H_
#define SRC_VDAGENT_DISPLAY_H_
typedef struct VDAgentDisplay VDAgentDisplay;
VDAgentDisplay *vdagent_display_create(UdscsConnection *vdagentd, int debug, int sync);
void vdagent_display_destroy(VDAgentDisplay *display, int vdagentd_disconnected);
gboolean vdagent_display_has_icons_on_desktop(VDAgentDisplay *display);
void vdagent_display_handle_graphics_device_info(VDAgentDisplay *display, uint8_t *data, size_t size);
void vdagent_display_set_monitor_config(VDAgentDisplay *display,
VDAgentMonitorsConfig *mon_config,
int fallback);
struct vdagent_x11 *vdagent_display_get_x11(VDAgentDisplay *display);
void vdagent_display_send_daemon_guest_res(VDAgentDisplay *display, gboolean update);
#endif /* SRC_VDAGENT_DISPLAY_H_ */
+3 -3
View File
@@ -39,7 +39,7 @@
struct vdagent_file_xfers {
GHashTable *xfers;
struct udscs_connection *vdagentd;
UdscsConnection *vdagentd;
char *save_dir;
int open_save_dir;
int debug;
@@ -76,7 +76,7 @@ static void vdagent_file_xfer_task_free(gpointer data)
}
struct vdagent_file_xfers *vdagent_file_xfers_create(
struct udscs_connection *vdagentd, const char *save_dir,
UdscsConnection *vdagentd, const char *save_dir,
int open_save_dir, int debug)
{
struct vdagent_file_xfers *xfers;
@@ -373,7 +373,7 @@ void vdagent_file_xfers_data(struct vdagent_file_xfers *xfers,
}
}
void vdagent_file_xfers_error_disabled(struct udscs_connection *vdagentd, uint32_t msg_id)
void vdagent_file_xfers_error_disabled(UdscsConnection *vdagentd, uint32_t msg_id)
{
g_return_if_fail(vdagentd != NULL);
+2 -2
View File
@@ -27,7 +27,7 @@
struct vdagent_file_xfers;
struct vdagent_file_xfers *vdagent_file_xfers_create(
struct udscs_connection *vdagentd, const char *save_dir,
UdscsConnection *vdagentd, const char *save_dir,
int open_save_dir, int debug);
void vdagent_file_xfers_destroy(struct vdagent_file_xfers *xfer);
@@ -37,7 +37,7 @@ void vdagent_file_xfers_status(struct vdagent_file_xfers *xfers,
VDAgentFileXferStatusMessage *msg);
void vdagent_file_xfers_data(struct vdagent_file_xfers *xfers,
VDAgentFileXferDataMessage *msg);
void vdagent_file_xfers_error_disabled(struct udscs_connection *vdagentd,
void vdagent_file_xfers_error_disabled(UdscsConnection *vdagentd,
uint32_t msg_id);
int vdagent_file_xfers_create_file(const char *save_dir, char **file_name_p);
+276
View File
@@ -0,0 +1,276 @@
/* mutter.c - implements the DBUS interface to mutter
Copyright 2020 Red Hat, Inc.
Red Hat Authors:
Julien Ropé <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <glib.h>
#include <gio/gio.h>
#include <syslog.h>
#include "vdagentd-proto.h"
#include "mutter.h"
// MUTTER DBUS FORMAT STRINGS
#define MODE_BASE_FORMAT "siiddad"
#define MODE_FORMAT "(" MODE_BASE_FORMAT "a{sv})"
#define MODES_FORMAT "a" MODE_FORMAT
#define MONITOR_SPEC_FORMAT "(ssss)"
#define MONITOR_FORMAT "(" MONITOR_SPEC_FORMAT MODES_FORMAT "a{sv})"
#define MONITORS_FORMAT "a" MONITOR_FORMAT
#define LOGICAL_MONITOR_MONITORS_FORMAT "a" MONITOR_SPEC_FORMAT
#define LOGICAL_MONITOR_FORMAT "(iidub" LOGICAL_MONITOR_MONITORS_FORMAT "a{sv})"
#define LOGICAL_MONITORS_FORMAT "a" LOGICAL_MONITOR_FORMAT
#define CURRENT_STATE_FORMAT "(u" MONITORS_FORMAT LOGICAL_MONITORS_FORMAT "a{sv})"
struct VDAgentMutterDBus {
GDBusProxy *dbus_proxy;
GHashTable *connector_mapping;
};
/**
* Initialise a communication to Mutter through its DBUS interface.
*
* Errors can indicate that another compositor is used. This is not a blocker, and we should default
* to use a different API then.
*
* Returns:
* An initialise VDAgentMutterDBus structure if successful.
* NULL if an error occurred.
*/
VDAgentMutterDBus *vdagent_mutter_create(GHashTable *connector_mapping)
{
GError *error = NULL;
VDAgentMutterDBus *mutter = g_new0(VDAgentMutterDBus, 1);
mutter->connector_mapping = g_hash_table_ref(connector_mapping);
GDBusProxyFlags flags = (G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START
| G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES
| G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS);
mutter->dbus_proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION,
flags,
NULL,
"org.gnome.Mutter.DisplayConfig",
"/org/gnome/Mutter/DisplayConfig",
"org.gnome.Mutter.DisplayConfig",
NULL,
&error);
if (!mutter->dbus_proxy) {
syslog(LOG_WARNING, "display: failed to create dbus proxy: %s", error->message);
g_clear_error(&error);
vdagent_mutter_destroy(mutter);
return NULL;
}
return mutter;
}
void vdagent_mutter_destroy(VDAgentMutterDBus *mutter)
{
g_clear_object(&mutter->dbus_proxy);
g_hash_table_unref(mutter->connector_mapping);
g_free(mutter);
}
/** Look through a list of logical monitor to find the one provided.
* Returns the corresponding x and y position of the monitor on the desktop.
* This function is a helper to vdagent_mutter_get_resolution().
*
* Parameters:
* logical_monitor: initialized GVariant iterator. It will be copied to look through the items
* so that its original position is not modified.
* connector: name of the connector that must be found
* x and y: will received the found position
*
*/
static void vdagent_mutter_get_monitor_position(GVariantIter *logical_monitors,
const gchar *connector, int *x, int *y)
{
GVariant *logical_monitor = NULL;
GVariantIter *logical_monitor_iterator = g_variant_iter_copy(logical_monitors);
while (g_variant_iter_next(logical_monitor_iterator, "@"LOGICAL_MONITOR_FORMAT,
&logical_monitor)) {
GVariantIter *tmp_monitors = NULL;
g_variant_get_child(logical_monitor, 0, "i", x);
g_variant_get_child(logical_monitor, 1, "i", y);
g_variant_get_child(logical_monitor, 5, LOGICAL_MONITOR_MONITORS_FORMAT, &tmp_monitors);
g_variant_unref(logical_monitor);
GVariant *tmp_monitor = NULL;
gboolean found = FALSE;
while (!found && g_variant_iter_next(tmp_monitors, "@"MONITOR_SPEC_FORMAT, &tmp_monitor)) {
const gchar *tmp_connector;
g_variant_get_child(tmp_monitor, 0, "&s", &tmp_connector);
if (g_strcmp0(connector, tmp_connector) == 0) {
found = TRUE;
}
g_variant_unref(tmp_monitor);
}
g_variant_iter_free(tmp_monitors);
if (found) {
break;
}
*x = *y = 0;
}
g_variant_iter_free(logical_monitor_iterator);
}
GArray *vdagent_mutter_get_resolutions(VDAgentMutterDBus *mutter,
int *desktop_width, int *desktop_height, int *screen_count)
{
GError *error = NULL;
GArray *res_array = NULL;
// keep track of monitors we find and are not mapped to SPICE displays
// we will map them back later (assuming display ID == monitor index)
// this prevents the need from looping twice on all DBUS items
GArray *not_found_array = NULL;
if (!mutter) {
return res_array;
}
GVariant *values = g_dbus_proxy_call_sync(mutter->dbus_proxy,
"GetCurrentState",
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1, // use proxy default timeout
NULL,
&error);
if (!values) {
syslog(LOG_WARNING, "display: failed to call GetCurrentState from mutter over DBUS");
if (error != NULL) {
syslog(LOG_WARNING, " error message: %s", error->message);
g_clear_error(&error);
}
return res_array;
}
res_array = g_array_new(FALSE, FALSE, sizeof(struct vdagentd_guest_xorg_resolution));
not_found_array = g_array_new(FALSE, FALSE, sizeof(struct vdagentd_guest_xorg_resolution));
GVariantIter *monitors = NULL;
GVariantIter *logical_monitors = NULL;
g_variant_get_child(values, 1, MONITORS_FORMAT, &monitors);
g_variant_get_child(values, 2, LOGICAL_MONITORS_FORMAT, &logical_monitors);
// list monitors
GVariant *monitor = NULL;
*screen_count = g_variant_iter_n_children(monitors);
while (g_variant_iter_next(monitors, "@"MONITOR_FORMAT, &monitor)) {
const gchar *connector = NULL;
GVariantIter *modes = NULL;
GVariant *monitor_specs = NULL;
g_variant_get_child(monitor, 0, "@"MONITOR_SPEC_FORMAT, &monitor_specs);
g_variant_get_child(monitor_specs, 0, "&s", &connector);
g_variant_get_child(monitor, 1, MODES_FORMAT, &modes);
g_variant_unref(monitor_specs);
g_variant_unref(monitor);
// list modes
GVariant *mode = NULL;
while (g_variant_iter_next(modes, "@"MODE_FORMAT, &mode)) {
GVariant *properties = NULL;
gboolean is_current;
g_variant_get_child(mode, 6, "@a{sv}", &properties);
if (!g_variant_lookup(properties, "is-current", "b", &is_current)) {
is_current = FALSE;
}
g_variant_unref(properties);
if (!is_current) {
g_variant_unref(mode);
continue;
}
struct vdagentd_guest_xorg_resolution curr;
vdagent_mutter_get_monitor_position(logical_monitors, connector, &curr.x, &curr.y);
g_variant_get_child(mode, 1, "i", &curr.width);
g_variant_get_child(mode, 2, "i", &curr.height);
g_variant_unref(mode);
// compute the size of the desktop based on the dimension of the monitors
if (curr.x + curr.width > *desktop_width) {
*desktop_width = curr.x + curr.width;
}
if (curr.y + curr.height > *desktop_height) {
*desktop_height = curr.y + curr.height;
}
gpointer value;
if (g_hash_table_lookup_extended(mutter->connector_mapping, connector, NULL, &value)) {
curr.display_id = GPOINTER_TO_UINT(value);
syslog(LOG_DEBUG,
"Found monitor %s with geometry %dx%d+%d-%d - associating it to SPICE display #%d",
connector, curr.width, curr.height, curr.x, curr.y, curr.display_id);
g_array_append_val(res_array, curr);
} else {
syslog(LOG_DEBUG, "No SPICE display found for connector %s", connector);
g_array_append_val(not_found_array, curr);
}
break;
}
g_variant_iter_free(modes);
}
g_variant_iter_free(logical_monitors);
g_variant_iter_free(monitors);
int i;
if (res_array->len == 0) {
syslog(LOG_DEBUG, "%s: No Spice display ID matching - assuming display ID == Monitor index",
__FUNCTION__);
g_array_free(res_array, TRUE);
res_array = not_found_array;
struct vdagentd_guest_xorg_resolution *res;
res = (struct vdagentd_guest_xorg_resolution*)res_array->data;
for (i = 0; i < res_array->len; i++) {
res[i].display_id = i;
}
}
else {
g_array_free(not_found_array, TRUE);
}
g_variant_unref(values);
return res_array;
}
+33
View File
@@ -0,0 +1,33 @@
/* mutter.h - implements the DBUS interface to mutter
Copyright 2020 Red Hat, Inc.
Red Hat Authors:
Julien Ropé <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SRC_VDAGENT_MUTTER_H_
#define SRC_VDAGENT_MUTTER_H_
typedef struct VDAgentMutterDBus VDAgentMutterDBus;
VDAgentMutterDBus *vdagent_mutter_create(GHashTable *connector_mapping);
void vdagent_mutter_destroy(VDAgentMutterDBus *mutter);
GArray *vdagent_mutter_get_resolutions(VDAgentMutterDBus *mutter, int *width, int *height, int *screen_count);
#endif /* SRC_VDAGENT_MUTTER_H_ */
+102 -61
View File
@@ -38,16 +38,18 @@
#include "udscs.h"
#include "vdagentd-proto.h"
#include "audio.h"
#include "x11.h"
#include "file-xfers.h"
#include "clipboard.h"
#include "display.h"
#define MAX_RETRY_CONNECT_SYSTEM_AGENT 60
typedef struct VDAgent {
VDAgentClipboards *clipboards;
struct vdagent_x11 *x11;
VDAgentDisplay *display;
struct vdagent_file_xfers *xfers;
struct udscs_connection *conn;
GIOChannel *x11_channel;
UdscsConnection *conn;
gint udscs_num_retry;
GMainLoop *loop;
} VDAgent;
@@ -66,25 +68,32 @@ static gchar *portdev = NULL;
static gchar *vdagentd_socket = NULL;
static GOptionEntry entries[] = {
{ "debug", 'd', 0,
G_OPTION_ARG_NONE, &debug,
"Enable debug", NULL },
{ "virtio-serial-port-path", 's', 0,
{ "debug", 'd',
G_OPTION_FLAG_NONE,
G_OPTION_ARG_NONE, &debug,
"Enable debug", NULL },
{ "virtio-serial-port-path", 's',
G_OPTION_FLAG_NONE,
G_OPTION_ARG_STRING, &portdev,
"Set virtio-serial path (" DEFAULT_VIRTIO_PORT_PATH ")", NULL },
{ "vdagentd-socket", 'S', 0, G_OPTION_ARG_STRING,
&vdagentd_socket,
"Set spice-vdagentd socket (" VDAGENTD_SOCKET ")", NULL },
{ "foreground", 'x', G_OPTION_FLAG_REVERSE,
G_OPTION_ARG_NONE, &do_daemonize,
"Do not daemonize the agent", NULL },
{ "file-xfer-save-dir", 'f', 0,
{ "vdagentd-socket", 'S',
G_OPTION_FLAG_NONE,
G_OPTION_ARG_STRING, &vdagentd_socket,
"Set spice-vdagentd socket (" VDAGENTD_SOCKET ")", NULL },
{ "foreground", 'x',
G_OPTION_FLAG_REVERSE,
G_OPTION_ARG_NONE, &do_daemonize,
"Do not daemonize the agent", NULL },
{ "file-xfer-save-dir", 'f',
G_OPTION_FLAG_NONE,
G_OPTION_ARG_STRING, &fx_dir,
"Set directory to file transfers files", "<dir|xdg-desktop|xdg-download>"},
{ "file-xfer-open-dir", 'o', 0,
G_OPTION_ARG_INT, &fx_open_dir,
"Open directory after completing file transfer", "<0|1>" },
{ "x11-abort-on-error", 'y', G_OPTION_FLAG_HIDDEN,
{ "file-xfer-open-dir", 'o',
G_OPTION_FLAG_NONE,
G_OPTION_ARG_INT, &fx_open_dir,
"Open directory after completing file transfer", "<0|1>" },
{ "x11-abort-on-error", 'y',
G_OPTION_FLAG_HIDDEN,
G_OPTION_ARG_NONE, &x11_sync,
"Aborts on errors from X11", NULL },
{ NULL }
@@ -107,7 +116,7 @@ static const gchar *xfer_get_download_directory(VDAgent *agent)
return fx_dir;
}
return g_get_user_special_dir(vdagent_x11_has_icons_on_desktop(agent->x11) ?
return g_get_user_special_dir(vdagent_display_has_icons_on_desktop(agent->display) ?
G_USER_DIRECTORY_DESKTOP :
G_USER_DIRECTORY_DOWNLOAD);
}
@@ -137,7 +146,7 @@ static gboolean vdagent_init_file_xfer(VDAgent *agent)
}
open_dir = fx_open_dir == -1 ?
!vdagent_x11_has_icons_on_desktop(agent->x11) :
!vdagent_display_has_icons_on_desktop(agent->display) :
fx_open_dir;
agent->xfers = vdagent_file_xfers_create(agent->conn, xfer_dir,
@@ -158,21 +167,21 @@ static void vdagent_quit_loop(VDAgent *agent)
{
/* other GMainLoop(s) might be running, quit them before agent->loop */
if (agent->clipboards) {
vdagent_clipboards_finalize(agent->clipboards, agent->conn != NULL);
agent->clipboards = NULL;
vdagent_clipboards_set_conn(agent->clipboards, agent->conn);
g_clear_object(&agent->clipboards);
}
if (agent->loop)
g_main_loop_quit(agent->loop);
}
static void daemon_read_complete(struct udscs_connection **connp,
static void daemon_read_complete(UdscsConnection *conn,
struct udscs_message_header *header, uint8_t *data)
{
VDAgent *agent = udscs_get_user_data(*connp);
VDAgent *agent = g_object_get_data(G_OBJECT(conn), "agent");
switch (header->type) {
case VDAGENTD_MONITORS_CONFIG:
vdagent_x11_set_monitor_config(agent->x11, (VDAgentMonitorsConfig *)data, 0);
vdagent_display_set_monitor_config(agent->display, (VDAgentMonitorsConfig *)data, 0);
break;
case VDAGENTD_CLIPBOARD_REQUEST:
vdagent_clipboard_request(agent->clipboards, header->arg1, header->arg2);
@@ -201,7 +210,7 @@ static void daemon_read_complete(struct udscs_connection **connp,
vdagent_file_xfers_start(agent->xfers,
(VDAgentFileXferStartMessage *)data);
} else {
vdagent_file_xfers_error_disabled(*connp,
vdagent_file_xfers_error_disabled(conn,
((VDAgentFileXferStartMessage *)data)->id);
}
break;
@@ -210,7 +219,7 @@ static void daemon_read_complete(struct udscs_connection **connp,
vdagent_file_xfers_status(agent->xfers,
(VDAgentFileXferStatusMessage *)data);
} else {
vdagent_file_xfers_error_disabled(*connp,
vdagent_file_xfers_error_disabled(conn,
((VDAgentFileXferStatusMessage *)data)->id);
}
break;
@@ -222,11 +231,14 @@ static void daemon_read_complete(struct udscs_connection **connp,
break;
case VDAGENTD_AUDIO_VOLUME_SYNC: {
VDAgentAudioVolumeSync *avs = (VDAgentAudioVolumeSync *)data;
uint16_t *volume = g_memdup2(avs->volume, sizeof(uint16_t) * avs->nchannels);
if (avs->is_playback) {
vdagent_audio_playback_sync(avs->mute, avs->nchannels, avs->volume);
vdagent_audio_playback_sync(avs->mute, avs->nchannels, volume);
} else {
vdagent_audio_record_sync(avs->mute, avs->nchannels, avs->volume);
vdagent_audio_record_sync(avs->mute, avs->nchannels, volume);
}
g_free(volume);
break;
}
case VDAGENTD_FILE_XFER_DATA:
@@ -234,12 +246,12 @@ static void daemon_read_complete(struct udscs_connection **connp,
vdagent_file_xfers_data(agent->xfers,
(VDAgentFileXferDataMessage *)data);
} else {
vdagent_file_xfers_error_disabled(*connp,
vdagent_file_xfers_error_disabled(conn,
((VDAgentFileXferDataMessage *)data)->id);
}
break;
case VDAGENTD_GRAPHICS_DEVICE_INFO:
vdagent_x11_handle_graphics_device_info(agent->x11, data, header->size);
vdagent_display_handle_graphics_device_info(agent->display, data, header->size);
break;
case VDAGENTD_CLIENT_DISCONNECTED:
vdagent_clipboards_release_all(agent->clipboards);
@@ -253,10 +265,15 @@ static void daemon_read_complete(struct udscs_connection **connp,
}
}
static void daemon_disconnect_cb(struct udscs_connection *conn)
static void daemon_error_cb(VDAgentConnection *conn, GError *err)
{
VDAgent *agent = udscs_get_user_data(conn);
agent->conn = NULL;
VDAgent *agent = g_object_get_data(G_OBJECT(conn), "agent");
if (err) {
syslog(LOG_ERR, "%s", err->message);
g_error_free(err);
}
g_clear_pointer(&agent->conn, vdagent_connection_destroy);
vdagent_quit_loop(agent);
}
@@ -320,15 +337,7 @@ static int daemonize(void)
return 0;
}
static gboolean x11_io_channel_cb(GIOChannel *source,
GIOCondition condition,
gpointer data)
{
VDAgent *agent = data;
vdagent_x11_do_read(agent->x11);
return G_SOURCE_CONTINUE;
}
gboolean vdagent_signal_handler(gpointer user_data)
{
@@ -354,13 +363,12 @@ static VDAgent *vdagent_new(void)
static void vdagent_destroy(VDAgent *agent)
{
vdagent_finalize_file_xfer(agent);
vdagent_x11_destroy(agent->x11, agent->conn == NULL);
udscs_destroy_connection(&agent->conn);
vdagent_display_destroy(agent->display, agent->conn == NULL);
g_clear_pointer(&agent->conn, vdagent_connection_destroy);
while (g_source_remove_by_user_data(agent))
continue;
g_clear_pointer(&agent->x11_channel, g_io_channel_unref);
g_clear_pointer(&agent->loop, g_main_loop_unref);
g_free(agent);
}
@@ -368,32 +376,50 @@ static void vdagent_destroy(VDAgent *agent)
static gboolean vdagent_init_async_cb(gpointer user_data)
{
VDAgent *agent = user_data;
GError *err = NULL;
agent->conn = udscs_connect(vdagentd_socket,
daemon_read_complete, daemon_disconnect_cb,
debug);
daemon_read_complete,
daemon_error_cb,
debug,
&err);
if (agent->conn == NULL) {
if (agent->udscs_num_retry == MAX_RETRY_CONNECT_SYSTEM_AGENT) {
syslog(LOG_WARNING,
"Failed to connect to spice-vdagentd at %s (tried %d times)",
vdagentd_socket, agent->udscs_num_retry);
g_error_free(err);
goto err_init;
}
if (agent->udscs_num_retry == 0) {
/* Log only when it fails and at the end */
syslog(LOG_DEBUG,
"Failed to connect with spice-vdagentd due '%s'. Trying again in 1s",
err->message);
}
g_error_free(err);
agent->udscs_num_retry++;
g_timeout_add_seconds(1, vdagent_init_async_cb, agent);
return G_SOURCE_REMOVE;
}
udscs_set_user_data(agent->conn, agent);
if (agent->udscs_num_retry != 0) {
syslog(LOG_DEBUG,
"Connected with spice-vdagentd after %d attempts",
agent->udscs_num_retry);
}
agent->udscs_num_retry = 0;
g_object_set_data(G_OBJECT(agent->conn), "agent", agent);
agent->x11 = vdagent_x11_create(agent->conn, debug, x11_sync);
if (agent->x11 == NULL)
goto err_init;
agent->x11_channel = g_io_channel_unix_new(vdagent_x11_get_fd(agent->x11));
if (agent->x11_channel == NULL)
agent->display = vdagent_display_create(agent->conn, debug, x11_sync);
if (agent->display == NULL)
goto err_init;
g_io_add_watch(agent->x11_channel,
G_IO_IN,
x11_io_channel_cb,
agent);
if (!vdagent_init_file_xfer(agent))
syslog(LOG_WARNING, "File transfer is disabled");
agent->clipboards = vdagent_clipboards_init(agent->x11, agent->conn);
agent->clipboards = vdagent_clipboards_new(vdagent_display_get_x11(agent->display));
vdagent_clipboards_set_conn(agent->clipboards, agent->conn);
if (parent_socket != -1) {
if (write(parent_socket, "OK", 2) != 2)
@@ -415,7 +441,8 @@ int main(int argc, char *argv[])
GOptionContext *context;
GError *error = NULL;
VDAgent *agent;
char **orig_argv = g_memdup(argv, sizeof(char*) * (argc+1));
char **orig_argv = g_memdup2(argv, sizeof(char*) * (argc+1));
orig_argv[argc] = NULL; /* To avoid clang analyzer false-positive */
context = g_option_context_new(NULL);
g_option_context_add_main_entries(context, entries, NULL);
@@ -423,7 +450,9 @@ int main(int argc, char *argv[])
"\tSpice session guest agent: X11\n"
"\tVersion: " VERSION);
#ifdef WITH_GTK
#if ! GTK_CHECK_VERSION(3, 98, 0) // not with GTK4 - option parsing is gone
g_option_context_add_group(context, gtk_get_option_group(FALSE));
#endif
#endif
g_option_context_parse(context, &argc, &argv, &error);
g_option_context_free(context);
@@ -431,6 +460,7 @@ int main(int argc, char *argv[])
if (error != NULL) {
g_printerr("Invalid arguments, %s\n", error->message);
g_clear_error(&error);
g_free(orig_argv);
return -1;
}
@@ -445,7 +475,8 @@ int main(int argc, char *argv[])
LOG_USER);
if (!g_file_test(portdev, G_FILE_TEST_EXISTS)) {
g_debug("vdagent virtio channel %s does not exist, exiting", portdev);
syslog(LOG_DEBUG, "vdagent virtio channel %s does not exist, exiting", portdev);
g_free(orig_argv);
return 0;
}
@@ -455,9 +486,16 @@ int main(int argc, char *argv[])
syslog(LOG_INFO, "vdagent started");
#ifdef WITH_GTK
#if GTK_CHECK_VERSION(3, 98, 0)
// GTK4: use Wayland if possible, otherwise use X11
gdk_set_allowed_backends("wayland,x11");
gtk_init();
#else
// GTK3: need to use X11 as talking to Wayland will cause bugs
gdk_set_allowed_backends("x11");
gtk_init(NULL, NULL);
#endif
#endif
reconnect:
if (version_mismatch) {
@@ -475,6 +513,9 @@ reconnect:
vdagent_destroy(agent);
agent = NULL;
/* allow the VDAgentConnection to finalize properly */
g_main_context_iteration(NULL, FALSE);
if (!quit && do_daemonize)
goto reconnect;
+292
View File
@@ -0,0 +1,292 @@
/* webdav-cb.c - common code for x11 and GTK+ backend handling webdav copy&paste
Copyright 2020 Red Hat, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <syslog.h>
#include "webdav-cb.h"
/* FIXME:
* From my testing, gvfs-dav with avahi doesn't seem stable enough,
* so let's simply use the usual port 9843 when mounting the shared folder for now.
*
* This is a bit unfortunate because the port can be customized with the -p option,
* while the service name "Spice client folder" is hardcoded.
*
* Issues with gvfs-dav and avahi:
* - https://bugzilla.redhat.com/show_bug.cgi?id=1843035
* - similar to https://bugzilla.redhat.com/show_bug.cgi?id=1773219
* - https://gitlab.gnome.org/GNOME/gvfs/-/issues/498
* - hence the %2520 in CLIPBOARD_WEBDAV_URI below
* - fixed recently
* - https://gitlab.gnome.org/GNOME/gvfs/-/issues/449
*/
// #define CLIPBOARD_WEBDAV_URI "dav+sd://Spice%2520client%2520folder._webdav._tcp.local"
#define CLIPBOARD_WEBDAV_URI "dav://localhost:9843"
typedef enum clipboard_action {
CLIPBOARD_ACTION_COPY,
CLIPBOARD_ACTION_CUT,
} clipboard_action;
static GMount *webdav_mount;
static GVolumeMonitor *monitor;
static GCancellable *cancellable;
static gchar *clipboard_data_to_uris(const gchar *target, const gchar *mount_uri,
const gchar *data, gsize size, GError **err)
{
if (!data || size < 1) {
/* this is valid input */
return NULL;
}
if (data[size-1]) {
g_set_error_literal(err, G_IO_ERROR, G_IO_ERROR_PARTIAL_INPUT,
"received list of uris that is not null-terminated");
return NULL;
}
clipboard_action action;
if (!g_strcmp0(data, "copy")) {
action = CLIPBOARD_ACTION_COPY;
} else if (!g_strcmp0(data, "cut")) {
action = CLIPBOARD_ACTION_CUT;
} else {
g_set_error_literal(err, G_IO_ERROR, G_IO_ERROR_INVALID_DATA,
"first line of uri list must specify clipboard action");
return NULL;
}
/* skip the action line, since we're only interested in
* the actual uris from this point forward */
gsize action_len = strlen(data) + 1;
data += action_len;
size -= action_len;
if (size < 1) {
return NULL;
}
GString *str = g_string_new(NULL);
const gchar *delimiter = "\n";
gboolean end_with_delimiter = FALSE;
/* TODO: add support for more file managers
* (and then update clipboard_format_tmpl in x11-priv.h) */
if (!g_strcmp0(target, "text/uri-list")) {
delimiter = "\r\n";
if (action == CLIPBOARD_ACTION_CUT) {
syslog(LOG_WARNING, "cutting is not supported with 'text/uri-list' target");
}
} else if (!g_strcmp0(target, "text/plain;charset=utf-8")) {
/* Nautilus uses text clipboard since
* https://gitlab.gnome.org/GNOME/nautilus/commit/1f77023b5769c773dd9261e5294c0738bf6a3115 */
end_with_delimiter = TRUE;
g_string_append(str, "x-special/nautilus-clipboard\n");
g_string_append (str, action == CLIPBOARD_ACTION_CUT ? "cut\n" : "copy\n");
} else if (!g_strcmp0(target, "application/x-kde-cutselection")) {
/* KDE Dolphin handles text/uri-list just fine,
* but this atom is needed to distinguish between copy and move */
g_string_append(str, action == CLIPBOARD_ACTION_CUT ? "1" : "0");
return g_string_free(str, FALSE);
} else if (!g_strcmp0(target, "x-special/gnome-copied-files") ||
!g_strcmp0(target, "x-special/mate-copied-files")) {
/* Nautilus moved away from this approach,
* but there's a bunch of other file managers that do use it, such as:
* Nemo (Cinnamon), Thunar (Xfce), Deepin File Manager (Deepin), Xfe; Caja (Mate) */
g_string_append(str, action == CLIPBOARD_ACTION_CUT ? "cut\n" : "copy\n");
} else {
g_set_error(err, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
"conversion to uri target %s is not supported", target);
return g_string_free(str, TRUE);
}
for (const gchar *item = data; item < data + size; item += strlen(item) + 1) {
gchar *escaped = g_uri_escape_string(item, G_URI_RESERVED_CHARS_ALLOWED_IN_PATH, TRUE);
gchar *uri = g_build_filename(mount_uri, escaped, NULL);
g_string_append(str, uri);
g_string_append(str, delimiter);
g_free(escaped);
g_free(uri);
}
if (!end_with_delimiter) {
g_string_truncate(str, str->len - strlen(delimiter));
}
return g_string_free(str, FALSE);
}
static gchar *clipboard_webdav_mount_get_uri(GMount *mount, GError **err)
{
GFile *root;
gchar *path, *uri;
root = g_mount_get_root(mount);
path = g_file_get_path(root);
if (path) {
/* gvfs-fuse is running, so we get path as follows:
* "/run/user/<UID>/gvfs/dav+sd:host=SpiceClipboard._webdav._tcp.local"
* but we still need to convert it to uri */
uri = g_filename_to_uri(path, NULL, err);
g_free(path);
} else {
/* gvfs-fuse is not running, let's return the CLIPBOARD_WEBDAV_URI ("dav+sd://..."),
* so that at least gio apps can access the shared files */
uri = g_file_get_uri(root);
syslog(LOG_WARNING, "gvfs-fuse doesn't seem to be running, "
"file copy functionality may be limited");
}
g_object_unref(root);
return uri;
}
static void resolve_task(GTask *task, const gchar *target, GBytes *data)
{
GError *err = NULL;
gchar *mount_uri, *uris;
mount_uri = clipboard_webdav_mount_get_uri(webdav_mount, &err);
if (!mount_uri) {
g_task_return_error(task, err);
g_object_unref(task);
return;
}
uris = clipboard_data_to_uris(target, mount_uri,
g_bytes_get_data(data, NULL), g_bytes_get_size(data), &err);
g_free(mount_uri);
if (err) {
g_task_return_error(task, err);
g_object_unref(task);
return;
}
g_task_return_pointer(task, uris, g_free);
g_object_unref(task);
}
static void unmounted_cb(GMount *mount, gpointer user_data)
{
syslog(LOG_DEBUG, "%s unmounted", CLIPBOARD_WEBDAV_URI);
g_clear_object(&webdav_mount);
}
static void mount_found_cb(GObject *source, GAsyncResult *res, gpointer user_data)
{
GTask *task = user_data;
GError *err = NULL;
webdav_mount = g_file_find_enclosing_mount_finish(G_FILE(source), res, &err);
if (err) {
g_task_return_error(task, err);
g_object_unref(task);
}
syslog(LOG_DEBUG, "mount %s found", CLIPBOARD_WEBDAV_URI);
g_signal_connect(webdav_mount, "unmounted", G_CALLBACK(unmounted_cb), NULL);
gchar *target = g_object_get_data(G_OBJECT(task), "target");
GBytes *data = g_task_get_task_data(task);
resolve_task(task, target, data);
}
static void mounted_cb(GObject *source, GAsyncResult *res, gpointer user_data)
{
GFile *f = G_FILE(source);
GTask *task = user_data;
GError *err = NULL;
g_file_mount_enclosing_volume_finish(f, res, &err);
if (g_error_matches(err, G_IO_ERROR, G_IO_ERROR_ALREADY_MOUNTED)) {
g_clear_error(&err);
} else if (err) {
g_task_return_error(task, err);
g_object_unref(task);
return;
}
syslog(LOG_DEBUG, "%s mounted successfully", CLIPBOARD_WEBDAV_URI);
g_file_find_enclosing_mount_async(f, G_PRIORITY_DEFAULT, cancellable, mount_found_cb, task);
}
static void clipboard_webdav_mount_async(GTask *task)
{
g_return_if_fail(webdav_mount == NULL);
syslog(LOG_DEBUG, "mounting %s", CLIPBOARD_WEBDAV_URI);
GFile *f = g_file_new_for_uri(CLIPBOARD_WEBDAV_URI);
g_file_mount_enclosing_volume(f,
G_MOUNT_MOUNT_NONE,
NULL, /* GMountOperation */
cancellable,
mounted_cb,
task);
g_object_unref(f);
}
gchar *clipboard_data_translate_to_uris_finish(GObject *source,
GAsyncResult *res, gsize *size, GError **err)
{
*size = 0;
g_return_val_if_fail(g_task_is_valid(res, source), NULL);
gchar *uris = g_task_propagate_pointer(G_TASK(res), err);
if (uris) {
*size = strlen(uris);
}
return uris;
}
void clipboard_data_translate_to_uris_async(const gchar *target, GBytes *data,
GCancellable *cancel, GAsyncReadyCallback callback, gpointer user_data)
{
GTask *task = g_task_new(NULL, cancel, callback, user_data);
if (!webdav_mount) {
g_task_set_task_data(task, g_bytes_ref(data), (GDestroyNotify)g_bytes_unref);
g_object_set_data_full(G_OBJECT(task), "target", g_strdup(target), g_free);
clipboard_webdav_mount_async(task);
return;
}
resolve_task(task, target, data);
}
void clipboard_webdav_init()
{
/* we listen to the "unmounted" signal,
* but without the GVolumeMonitor, the signal is not emitted,
* although the docs don't seem to mention it!
* https://gitlab.gnome.org/GNOME/gvfs/-/issues/494 */
monitor = g_volume_monitor_get();
webdav_mount = NULL;
cancellable = g_cancellable_new();
}
void clipboard_webdav_finalize()
{
g_cancellable_cancel(cancellable);
g_clear_object(&cancellable);
g_clear_object(&webdav_mount);
g_clear_object(&monitor);
}
+38
View File
@@ -0,0 +1,38 @@
/* webdav-cb.h
Copyright 2020 Red Hat, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <gio/gio.h>
void clipboard_webdav_init();
void clipboard_webdav_finalize();
/* converts the @data received from spice-gtk to the given @target;
* supported targets are:
* - "text/uri-list"
* - "text/plain;charset=utf-8"
* - "application/x-kde-cutselection"
* - "x-special/gnome-copied-files"
* - "x-special/mate-copied-files"
*/
void clipboard_data_translate_to_uris_async(const gchar *target, GBytes *data,
GCancellable *cancel, GAsyncReadyCallback callback, gpointer user_data);
gchar *clipboard_data_translate_to_uris_finish(GObject *source,
GAsyncResult *res, gsize *size, GError **err);
+28 -9
View File
@@ -7,8 +7,12 @@
#include <spice/vd_agent.h>
#include <X11/extensions/Xrandr.h>
#include "display.h"
#ifndef USE_GTK_FOR_CLIPBOARD
#include "webdav-cb.h"
#ifndef WITH_GTK
/* Macros to print a message to the logfile prefixed by the selection */
#define SELPRINTF(format, ...) \
syslog(LOG_ERR, "%s: " format, \
@@ -63,9 +67,18 @@ static const struct clipboard_format_tmpl clipboard_format_templates[] = {
"image/x-MS-bmp", "image/x-win-bitmap", NULL }, },
{ VD_AGENT_CLIPBOARD_IMAGE_TIFF, { "image/tiff", NULL }, },
{ VD_AGENT_CLIPBOARD_IMAGE_JPG, { "image/jpeg", NULL }, },
{ VD_AGENT_CLIPBOARD_FILE_LIST, { "text/uri-list",
"text/plain;charset=utf-8", "application/x-kde-cutselection",
"x-special/gnome-copied-files", "x-special/mate-copied-files", NULL } },
};
#define clipboard_format_count (sizeof(clipboard_format_templates)/sizeof(clipboard_format_templates[0]))
#define ATOM_NAME_CACHE_SIZE 16
struct atom_name_cache_item {
Atom atom;
char *name;
};
#endif
#define MAX_SCREENS 16
@@ -79,7 +92,7 @@ struct monitor_size {
struct vdagent_x11 {
Display *display;
#ifndef WITH_GTK
#ifndef USE_GTK_FOR_CLIPBOARD
struct clipboard_format_info clipboard_formats[clipboard_format_count];
Atom clipboard_atom;
Atom clipboard_primary_atom;
@@ -87,8 +100,9 @@ struct vdagent_x11 {
Atom incr_atom;
Atom multiple_atom;
Atom timestamp_atom;
struct atom_name_cache_item atom_name_cache[ATOM_NAME_CACHE_SIZE];
int atom_name_cache_next;
Window selection_window;
int has_xfixes;
int xfixes_event_base;
int max_prop_size;
int expected_targets_notifies[256];
@@ -96,6 +110,7 @@ struct vdagent_x11 {
int clipboard_owner[256];
int clipboard_type_count[256];
uint32_t clipboard_agent_types[256][256];
Bool clipboard_has_files[256];
Atom clipboard_x11_targets[256][256];
/* Data for conversion_req which is currently being processed */
struct vdagent_x11_conversion_request *conversion_req;
@@ -108,21 +123,21 @@ struct vdagent_x11 {
uint8_t *selection_req_data;
uint32_t selection_req_data_pos;
uint32_t selection_req_data_size;
GBytes *file_list_data[256];
Atom selection_req_atom;
#endif
Window root_window[MAX_SCREENS];
struct udscs_connection *vdagentd;
UdscsConnection *vdagentd;
int debug;
int fd;
int screen_count;
int width[MAX_SCREENS];
int height[MAX_SCREENS];
int xrandr_event_base;
/* resolution change state */
struct {
XRRScreenResources *res;
XRROutputInfo **outputs;
XRRCrtcInfo **crtcs;
int event_base;
int min_width;
int max_width;
int min_height;
@@ -141,18 +156,22 @@ struct vdagent_x11 {
int has_xinerama;
int dont_send_guest_xorg_res;
GHashTable *guest_output_map;
VDAgentDisplay *vdagent_display;
};
extern int (*vdagent_x11_prev_error_handler)(Display *, XErrorEvent *);
extern int vdagent_x11_caught_error;
void vdagent_x11_randr_init(struct vdagent_x11 *x11);
void vdagent_x11_send_daemon_guest_xorg_res(struct vdagent_x11 *x11,
int update);
void vdagent_x11_randr_destroy(struct vdagent_x11 *x11);
GArray *vdagent_x11_get_resolutions(struct vdagent_x11 *x11, gboolean update,
int *width, int *height, int *system_screen_count);
void vdagent_x11_randr_handle_root_size_change(struct vdagent_x11 *x11,
int screen, int width, int height);
int vdagent_x11_randr_handle_event(struct vdagent_x11 *x11,
XEvent event);
const XEvent *event);
void vdagent_x11_set_error_handler(struct vdagent_x11 *x11,
int (*handler)(Display *, XErrorEvent *));
int vdagent_x11_restore_error_handler(struct vdagent_x11 *x11);
+101 -115
View File
@@ -136,7 +136,7 @@ void vdagent_x11_randr_init(struct vdagent_x11 *x11)
return;
}
if (XRRQueryExtension(x11->display, &x11->xrandr_event_base, &i)) {
if (XRRQueryExtension(x11->display, &x11->randr.event_base, &i)) {
XRRQueryVersion(x11->display, &x11->xrandr_major, &x11->xrandr_minor);
if (x11->xrandr_major == 1 && x11->xrandr_minor >= 3)
x11->has_xrandr = 1;
@@ -171,6 +171,12 @@ void vdagent_x11_randr_init(struct vdagent_x11 *x11)
}
}
void vdagent_x11_randr_destroy(struct vdagent_x11 *x11)
{
free_randr_resources(x11);
g_free(x11->randr.failed_conf);
}
static XRRModeInfo *
find_mode_by_name (struct vdagent_x11 *x11, char *name)
{
@@ -414,7 +420,7 @@ static RROutput get_xrandr_output_for_display_id(struct vdagent_x11 *x11, int di
gpointer value;
if (g_hash_table_lookup_extended(x11->guest_output_map, GINT_TO_POINTER(display_id),
NULL, &value)) {
return *(gint64*)value;
return (RROutput)value;
}
}
@@ -511,6 +517,7 @@ static int set_screen_to_best_size(struct vdagent_x11 *x11, int width, int heigh
void vdagent_x11_randr_handle_root_size_change(struct vdagent_x11 *x11,
int screen, int width, int height)
{
#ifndef USE_GTK_FOR_MONITORS
update_randr_res(x11, 0);
if (width == x11->width[screen] && height == x11->height[screen]) {
@@ -523,28 +530,31 @@ void vdagent_x11_randr_handle_root_size_change(struct vdagent_x11 *x11,
x11->width[screen] = width;
x11->height[screen] = height;
#endif
if (!x11->dont_send_guest_xorg_res) {
vdagent_x11_send_daemon_guest_xorg_res(x11, 1);
vdagent_display_send_daemon_guest_res(x11->vdagent_display, TRUE);
}
}
int vdagent_x11_randr_handle_event(struct vdagent_x11 *x11,
XEvent event)
const XEvent *event)
{
int handled = TRUE;
switch (event.type - x11->xrandr_event_base) {
switch (event->type - x11->randr.event_base) {
case RRScreenChangeNotify: {
XRRScreenChangeNotifyEvent *sce =
(XRRScreenChangeNotifyEvent *) &event;
const XRRScreenChangeNotifyEvent *sce =
(const XRRScreenChangeNotifyEvent *) event;
vdagent_x11_randr_handle_root_size_change(x11, 0,
sce->width, sce->height);
break;
}
case RRNotify: {
#ifndef USE_GTK_FOR_MONITORS
update_randr_res(x11, 0);
#endif
if (!x11->dont_send_guest_xorg_res)
vdagent_x11_send_daemon_guest_xorg_res(x11, 1);
vdagent_display_send_daemon_guest_res(x11->vdagent_display, TRUE);
break;
}
default:
@@ -555,16 +565,6 @@ int vdagent_x11_randr_handle_event(struct vdagent_x11 *x11,
return handled;
}
static int min_int(int x, int y)
{
return x > y ? y : x;
}
static int max_int(int x, int y)
{
return x > y ? x : y;
}
static int constrain_to_range(int low, int *val, int high)
{
if (low <= *val && *val <= high) {
@@ -621,20 +621,24 @@ static void zero_base_monitors(struct vdagent_x11 *x11,
int *width, int *height)
{
int i, min_x = INT_MAX, min_y = INT_MAX, max_x = INT_MIN, max_y = INT_MIN;
int *mon_height, *mon_width;
for (i = 0; i < mon_config->num_of_monitors; i++) {
if (!monitor_enabled(&mon_config->monitors[i]))
int mon_height, mon_width;
if (!monitor_enabled(&mon_config->monitors[i])) {
continue;
}
mon_config->monitors[i].x &= ~7;
mon_config->monitors[i].width &= ~7;
mon_width = (int *)&mon_config->monitors[i].width;
mon_height = (int *)&mon_config->monitors[i].height;
constrain_to_screen(x11, mon_width, mon_height);
min_x = min_int(mon_config->monitors[i].x, min_x);
min_y = min_int(mon_config->monitors[i].y, min_y);
max_x = max_int(mon_config->monitors[i].x + *mon_width, max_x);
max_y = max_int(mon_config->monitors[i].y + *mon_height, max_y);
mon_width = mon_config->monitors[i].width;
mon_height = mon_config->monitors[i].height;
constrain_to_screen(x11, &mon_width, &mon_height);
min_x = MIN(mon_config->monitors[i].x, min_x);
min_y = MIN(mon_config->monitors[i].y, min_y);
max_x = MAX(mon_config->monitors[i].x + mon_width, max_x);
max_y = MAX(mon_config->monitors[i].y + mon_height, max_y);
mon_config->monitors[i].width = mon_width;
mon_config->monitors[i].height = mon_height;
}
if (min_x != 0 || min_y != 0) {
syslog(LOG_ERR, "%s: agent config %d,%d rooted, adjusting to 0,0.",
@@ -784,64 +788,32 @@ static void dump_monitors_config(struct vdagent_x11 *x11,
// handle the device info message from the server. This will allow us to
// maintain a mapping from spice display id to xrandr output
void vdagent_x11_handle_graphics_device_info(struct vdagent_x11 *x11, uint8_t *data, size_t size)
void vdagent_x11_handle_device_display_info(struct vdagent_x11 *x11,
VDAgentDeviceDisplayInfo *device_display_info,
gboolean has_virtual_zero_display)
{
VDAgentGraphicsDeviceInfo *graphics_device_info = (VDAgentGraphicsDeviceInfo *)data;
VDAgentDeviceDisplayInfo *device_display_info = graphics_device_info->display_info;
RROutput x_output;
if (lookup_xrandr_output_for_device_info(device_display_info, x11->display,
x11->randr.res, &x_output, has_virtual_zero_display)) {
syslog(LOG_INFO, "Adding graphics device info: channel_id: %u monitor_id: "
"%u device_address: %s, device_display_id: %u xrandr output ID: %lu",
device_display_info->channel_id,
device_display_info->monitor_id,
device_display_info->device_address,
device_display_info->device_display_id,
x_output);
void *buffer_end = data + size;
syslog(LOG_INFO, "Received Graphics Device Info:");
for (size_t i = 0; i < graphics_device_info->count; ++i) {
if ((void*) device_display_info > buffer_end ||
(void*) (&device_display_info->device_address +
device_display_info->device_address_len) > buffer_end) {
syslog(LOG_ERR, "Malformed graphics_display_info message, "
"extends beyond the end of the buffer");
break;
}
// make sure the string is terminated:
if (device_display_info->device_address_len > 0) {
device_display_info->device_address[device_display_info->device_address_len - 1] = '\0';
} else {
syslog(LOG_WARNING, "Zero length device_address received for channel_id: %u, monitor_id: %u",
device_display_info->channel_id, device_display_info->monitor_id);
}
RROutput x_output;
if (lookup_xrandr_output_for_device_info(device_display_info, x11->display,
x11->randr.res, &x_output)) {
gint64 *value = g_new(gint64, 1);
*value = x_output;
syslog(LOG_INFO, "Adding graphics device info: channel_id: %u monitor_id: "
"%u device_address: %s, device_display_id: %u xrandr output ID: %lu",
device_display_info->channel_id,
device_display_info->monitor_id,
device_display_info->device_address,
device_display_info->device_display_id,
x_output);
g_hash_table_insert(x11->guest_output_map,
GUINT_TO_POINTER(device_display_info->channel_id + device_display_info->monitor_id),
value);
} else {
syslog(LOG_INFO, "channel_id: %u monitor_id: %u device_address: %s, "
"device_display_id: %u xrandr output ID NOT FOUND",
device_display_info->channel_id,
device_display_info->monitor_id,
device_display_info->device_address,
device_display_info->device_display_id);
}
device_display_info = (VDAgentDeviceDisplayInfo*) ((char*) device_display_info +
sizeof(VDAgentDeviceDisplayInfo) + device_display_info->device_address_len);
g_hash_table_insert(x11->guest_output_map,
GUINT_TO_POINTER(device_display_info->channel_id + device_display_info->monitor_id),
(gpointer)x_output);
} else {
syslog(LOG_INFO, "channel_id: %u monitor_id: %u device_address: %s, "
"device_display_id: %u xrandr output ID NOT FOUND",
device_display_info->channel_id,
device_display_info->monitor_id,
device_display_info->device_address,
device_display_info->device_display_id);
}
// make sure daemon is up-to-date with (possibly updated) device IDs
vdagent_x11_send_daemon_guest_xorg_res(x11, 1);
}
static int get_output_index_for_display_id(struct vdagent_x11 *x11, int display_id)
@@ -1010,7 +982,7 @@ void vdagent_x11_set_monitor_config(struct vdagent_x11 *x11,
fullscreen it will keep sending the failing config. */
g_free(x11->randr.failed_conf);
x11->randr.failed_conf =
g_memdup(mon_config, config_size(mon_config->num_of_monitors));
g_memdup2(mon_config, config_size(mon_config->num_of_monitors));
return;
}
}
@@ -1060,18 +1032,45 @@ void vdagent_x11_set_monitor_config(struct vdagent_x11 *x11,
x11->dont_send_guest_xorg_res = 0;
exit:
vdagent_x11_send_daemon_guest_xorg_res(x11, 0);
vdagent_display_send_daemon_guest_res(x11->vdagent_display, FALSE);
/* Flush output buffers and consume any pending events */
vdagent_x11_do_read(x11);
g_free(curr);
}
void vdagent_x11_send_daemon_guest_xorg_res(struct vdagent_x11 *x11, int update)
/**
* Builds a list of available monitors, associated with their resolutions.
*
* This function will use the x11->guest_output_map hashtable to map the SPICE display ID to the
* XRandr display ID, and make sure we get the right resolution for each SPICE display.
* See vdagent_x11_handle_device_display_info() for how this hashtable is populated.
*
* If the ID can't be matched (which happens when running under XWayland for instance), a default
* mapping is made, which assumes the list of X displays are in the same order as the SPICE displays.
* This will cause issues if some SPICE displays are not enabled (for instance: display 2 is
* enabled, but not display 1, causing a mismatch of IDs).
*
* Parameters:
* x11 - pointer to the X11 structure
* update - TRUE if the cached resolutions need to be updated before building the list
* width - full width of the desktop area (containing all the displays)
* height - full height of the desktop area (containing all the displays)
* system_screen_count - number of displays found on the system. In some situations, this may be
* different than the number of SPICE displays (for instance: multiple displays
* overlapping the same area of the desktop).
* Used for logging/troubleshooting purposes.
*
* Returns: a GArray of vdagentd_guest_xorg_resolution elements, to be sent to the vdagent daemon.
* NULL if an error occurs.
*/
GArray *vdagent_x11_get_resolutions(struct vdagent_x11 *x11, gboolean update,
int *width, int *height, int *system_screen_count)
{
GArray *res_array = g_array_new(FALSE, FALSE, sizeof(struct vdagentd_guest_xorg_resolution));
int i, width = 0, height = 0, screen_count = 0;
int i, screen_count = 0;
*width = *height = 0;
if (x11->has_xrandr) {
if (update)
update_randr_res(x11, 0);
@@ -1094,12 +1093,11 @@ void vdagent_x11_send_daemon_guest_xorg_res(struct vdagent_x11 *x11, int update)
// all down.
RROutput output_id = x11->randr.res->outputs[i];
GHashTableIter iter;
gpointer key, value;
gpointer key, other_id;
g_hash_table_iter_init(&iter, x11->guest_output_map);
bool found = false;
while (g_hash_table_iter_next(&iter, &key, &value)) {
gint64 *other_id = value;
if (*other_id == output_id) {
while (g_hash_table_iter_next(&iter, &key, &other_id)) {
if ((RROutput)other_id == output_id) {
curr.display_id = GPOINTER_TO_INT(key);
g_array_append_val(res_array, curr);
found = true;
@@ -1110,8 +1108,8 @@ void vdagent_x11_send_daemon_guest_xorg_res(struct vdagent_x11 *x11, int update)
}
}
}
width = x11->width[0];
height = x11->height[0];
*width = x11->width[0];
*height = x11->height[0];
} else if (x11->has_xinerama) {
XineramaScreenInfo *screen_info = NULL;
@@ -1125,7 +1123,7 @@ void vdagent_x11_send_daemon_guest_xorg_res(struct vdagent_x11 *x11, int update)
screen_info[i].screen_number, screen_count);
XFree(screen_info);
g_array_free(res_array, true);
return;
return NULL;
}
struct vdagentd_guest_xorg_resolution *curr = &g_array_index(res_array,
struct vdagentd_guest_xorg_resolution,
@@ -1136,8 +1134,8 @@ void vdagent_x11_send_daemon_guest_xorg_res(struct vdagent_x11 *x11, int update)
curr->y = screen_info[i].y_org;
}
XFree(screen_info);
width = x11->width[0];
height = x11->height[0];
*width = x11->width[0];
*height = x11->height[0];
} else {
no_info:
for (i = 0; i < screen_count; i++) {
@@ -1145,11 +1143,12 @@ no_info:
res.width = x11->width[i];
res.height = x11->height[i];
/* No way to get screen coordinates, assume rtl order */
res.x = width;
res.x = *width;
res.y = 0;
width += x11->width[i];
if (x11->height[i] > height)
height = x11->height[i];
*width += x11->width[i];
if (x11->height[i] > *height) {
*height = x11->height[i];
}
g_array_append_val(res_array, res);
}
}
@@ -1157,22 +1156,9 @@ no_info:
if (screen_count == 0) {
syslog(LOG_DEBUG, "Screen count is zero, are we on wayland?");
g_array_free(res_array, TRUE);
return;
return NULL;
}
if (x11->debug) {
syslog(LOG_DEBUG, "Sending guest screen resolutions to vdagentd:");
if (res_array->len > screen_count) {
syslog(LOG_DEBUG, "(NOTE: list may contain overlapping areas when multiple spice displays show the same guest output)");
}
for (i = 0; i < res_array->len; i++) {
struct vdagentd_guest_xorg_resolution *res = (struct vdagentd_guest_xorg_resolution*)res_array->data;
syslog(LOG_DEBUG, " screen %d %dx%d%+d%+d, display_id=%d", i,
res[i].width, res[i].height, res[i].x, res[i].y, res[i].display_id);
}
}
udscs_write(x11->vdagentd, VDAGENTD_GUEST_XORG_RESOLUTION, width, height,
(uint8_t *)res_array->data, res_array->len * sizeof(struct vdagentd_guest_xorg_resolution));
g_array_free(res_array, TRUE);
*system_screen_count = screen_count;
return res_array;
}
+220 -150
View File
@@ -36,8 +36,13 @@
#include <glib.h>
#ifdef WITH_GTK
#include <gdk/gdk.h>
#include <gtk/gtk.h> // for GTK_CHECK_VERSION
#ifdef GDK_WINDOWING_X11
#include <gdk/gdkx.h>
#if GTK_CHECK_VERSION(3, 98, 0)
#include <gdk/x11/gdkx.h>
#else
#include <gdk/gdkx.h>
#endif
#endif
#endif
#include <stdlib.h>
@@ -57,18 +62,19 @@
int (*vdagent_x11_prev_error_handler)(Display *, XErrorEvent *);
int vdagent_x11_caught_error;
#ifndef WITH_GTK
#ifndef USE_GTK_FOR_CLIPBOARD
static void vdagent_x11_handle_selection_notify(struct vdagent_x11 *x11,
XEvent *event, int incr);
const XEvent *event, int incr);
static void vdagent_x11_handle_selection_request(struct vdagent_x11 *x11);
static void vdagent_x11_handle_targets_notify(struct vdagent_x11 *x11,
XEvent *event);
const XEvent *event);
static void vdagent_x11_handle_property_delete_notify(struct vdagent_x11 *x11,
XEvent *del_event);
const XEvent *del_event);
static void vdagent_x11_send_selection_notify(struct vdagent_x11 *x11,
Atom prop, struct vdagent_x11_selection_request *request);
static void vdagent_x11_set_clipboard_owner(struct vdagent_x11 *x11,
uint8_t selection, int new_owner);
static void uris_ready_cb(GObject *source, GAsyncResult *res, gpointer user_data);
static const char *vdagent_x11_sel_to_str(uint8_t selection) {
switch (selection) {
@@ -90,7 +96,6 @@ static int vdagent_x11_debug_error_handler(
abort();
}
#ifndef WITH_GTK
/* With the clipboard we're sometimes dealing with Properties on another apps
Window. which can go away at any time. */
static int vdagent_x11_ignore_bad_window_handler(
@@ -101,7 +106,6 @@ static int vdagent_x11_ignore_bad_window_handler(
return vdagent_x11_prev_error_handler(display, error);
}
#endif
void vdagent_x11_set_error_handler(struct vdagent_x11 *x11,
int (*handler)(Display *, XErrorEvent *))
@@ -123,15 +127,8 @@ int vdagent_x11_restore_error_handler(struct vdagent_x11 *x11)
return error;
}
static gchar *vdagent_x11_get_wm_name(struct vdagent_x11 *x11)
gchar *vdagent_x11_get_wm_name(struct vdagent_x11 *x11)
{
#ifdef GDK_WINDOWING_X11
GdkDisplay *display = gdk_display_get_default();
if (GDK_IS_X11_DISPLAY(display))
return g_strdup(gdk_x11_screen_get_window_manager_name(
gdk_display_get_default_screen(display)));
return g_strdup("unsupported");
#else
Atom type_ret;
int format_ret;
unsigned long len, remain;
@@ -193,20 +190,18 @@ static gchar *vdagent_x11_get_wm_name(struct vdagent_x11 *x11)
if (net_wm_name == NULL)
return g_strdup("unknown");
return net_wm_name;
#endif
}
struct vdagent_x11 *vdagent_x11_create(struct udscs_connection *vdagentd,
int debug, int sync)
struct vdagent_x11 *vdagent_x11_create(UdscsConnection *vdagentd,
int debug, int sync)
{
struct vdagent_x11 *x11;
XWindowAttributes attrib;
#ifdef WITH_GTK
#ifdef USE_GTK_FOR_CLIPBOARD
int i;
#else
int i, j, major, minor;
#endif
gchar *net_wm_name = NULL;
x11 = g_new0(struct vdagent_x11, 1);
x11->vdagentd = vdagentd;
@@ -215,7 +210,7 @@ struct vdagent_x11 *vdagent_x11_create(struct udscs_connection *vdagentd,
x11->guest_output_map = g_hash_table_new_full(&g_direct_hash,
&g_direct_equal,
NULL,
&g_free);
NULL);
x11->display = XOpenDisplay(NULL);
@@ -241,8 +236,7 @@ struct vdagent_x11 *vdagent_x11_create(struct udscs_connection *vdagentd,
for (i = 0; i < x11->screen_count; i++)
x11->root_window[i] = RootWindow(x11->display, i);
x11->fd = ConnectionNumber(x11->display);
#ifndef WITH_GTK
#ifndef USE_GTK_FOR_CLIPBOARD
x11->clipboard_atom = XInternAtom(x11->display, "CLIPBOARD", False);
x11->clipboard_primary_atom = XInternAtom(x11->display, "PRIMARY", False);
x11->targets_atom = XInternAtom(x11->display, "TARGETS", False);
@@ -269,10 +263,9 @@ struct vdagent_x11 *vdagent_x11_create(struct udscs_connection *vdagentd,
vdagent_x11_randr_init(x11);
#ifndef WITH_GTK
#ifndef USE_GTK_FOR_CLIPBOARD
if (XFixesQueryExtension(x11->display, &x11->xfixes_event_base, &i) &&
XFixesQueryVersion(x11->display, &major, &minor) && major >= 1) {
x11->has_xfixes = 1;
XFixesSelectSelectionInput(x11->display, x11->root_window[0],
x11->clipboard_atom,
XFixesSetSelectionOwnerNotifyMask|
@@ -295,6 +288,8 @@ struct vdagent_x11 *vdagent_x11_create(struct udscs_connection *vdagentd,
/* Be a good X11 citizen and maximize the amount of data we send at once */
if (x11->max_prop_size > 262144)
x11->max_prop_size = 262144;
clipboard_webdav_init();
#endif
for (i = 0; i < x11->screen_count; i++) {
@@ -306,24 +301,6 @@ struct vdagent_x11 *vdagent_x11_create(struct udscs_connection *vdagentd,
x11->width[i] = attrib.width;
x11->height[i] = attrib.height;
}
vdagent_x11_send_daemon_guest_xorg_res(x11, 1);
/* Since we are started at the same time as the wm,
sometimes we need to wait a bit for the _NET_WM_NAME to show up. */
for (i = 0; i < 9; i++) {
g_free(net_wm_name);
net_wm_name = vdagent_x11_get_wm_name(x11);
if (strcmp(net_wm_name, "unknown"))
break;
usleep(100000);
}
if (x11->debug)
syslog(LOG_DEBUG, "%s: net_wm_name=\"%s\", has icons=%d",
__func__, net_wm_name, vdagent_x11_has_icons_on_desktop(x11));
g_free(net_wm_name);
/* Flush output buffers and consume any pending events */
vdagent_x11_do_read(x11);
return x11;
}
@@ -333,7 +310,7 @@ void vdagent_x11_destroy(struct vdagent_x11 *x11, int vdagentd_disconnected)
if (!x11)
return;
#ifndef WITH_GTK
#ifndef USE_GTK_FOR_CLIPBOARD
if (vdagentd_disconnected)
x11->vdagentd = NULL;
@@ -341,20 +318,28 @@ void vdagent_x11_destroy(struct vdagent_x11 *x11, int vdagentd_disconnected)
for (sel = 0; sel < VD_AGENT_CLIPBOARD_SELECTION_SECONDARY; ++sel) {
vdagent_x11_set_clipboard_owner(x11, sel, owner_none);
}
for (int i = 0; i < ATOM_NAME_CACHE_SIZE; i++) {
if (x11->atom_name_cache[i].name) {
XFree(x11->atom_name_cache[i].name);
}
}
clipboard_webdav_finalize();
#endif
g_hash_table_destroy(x11->guest_output_map);
XCloseDisplay(x11->display);
g_free(x11->randr.failed_conf);
vdagent_x11_randr_destroy(x11);
g_free(x11);
}
int vdagent_x11_get_fd(struct vdagent_x11 *x11)
{
return x11->fd;
return ConnectionNumber(x11->display);
}
#ifndef WITH_GTK
#ifndef USE_GTK_FOR_CLIPBOARD
static void vdagent_x11_next_selection_request(struct vdagent_x11 *x11)
{
struct vdagent_x11_selection_request *selection_request;
@@ -392,7 +377,7 @@ static void vdagent_x11_set_clipboard_owner(struct vdagent_x11 *x11,
once = 0;
}
vdagent_x11_send_selection_notify(x11, None, curr_sel);
if (curr_sel == x11->selection_req) {
if (prev_sel == NULL) {
x11->selection_req = next_sel;
free(x11->selection_req_data);
x11->selection_req_data = NULL;
@@ -400,7 +385,6 @@ static void vdagent_x11_set_clipboard_owner(struct vdagent_x11 *x11,
x11->selection_req_data_size = 0;
x11->selection_req_atom = None;
} else {
// coverity[var_deref_op] if it is not the first there's a previous
prev_sel->next = next_sel;
}
free(curr_sel);
@@ -424,12 +408,11 @@ static void vdagent_x11_set_clipboard_owner(struct vdagent_x11 *x11,
if (x11->vdagentd)
udscs_write(x11->vdagentd, VDAGENTD_CLIPBOARD_DATA, selection,
VD_AGENT_CLIPBOARD_NONE, NULL, 0);
if (curr_conv == x11->conversion_req) {
if (prev_conv == NULL) {
x11->conversion_req = next_conv;
x11->clipboard_data_size = 0;
x11->expect_property_notify = 0;
} else {
// coverity[var_deref_op] if it is not the first there's a previous
prev_conv->next = next_conv;
}
free(curr_conv);
@@ -438,6 +421,9 @@ static void vdagent_x11_set_clipboard_owner(struct vdagent_x11 *x11,
}
}
x11->clipboard_has_files[selection] = False;
g_clear_pointer(&x11->file_list_data[selection], g_bytes_unref);
if (new_owner == owner_none) {
/* When going from owner_guest to owner_none we need to send a
clipboard release message to the client */
@@ -465,12 +451,13 @@ static int vdagent_x11_get_clipboard_atom(struct vdagent_x11 *x11, uint8_t selec
}
static int vdagent_x11_get_clipboard_selection(struct vdagent_x11 *x11,
XEvent *event, uint8_t *selection)
const XEvent *event, uint8_t *selection)
{
Atom atom;
if (event->type == x11->xfixes_event_base) {
XFixesSelectionNotifyEvent *xfev = (XFixesSelectionNotifyEvent *)event;
const XFixesSelectionNotifyEvent *xfev =
(const XFixesSelectionNotifyEvent *)event;
atom = xfev->selection;
} else if (event->type == SelectionNotify) {
atom = event->xselection.selection;
@@ -494,23 +481,23 @@ static int vdagent_x11_get_clipboard_selection(struct vdagent_x11 *x11,
}
#endif
static void vdagent_x11_handle_event(struct vdagent_x11 *x11, XEvent event)
static void vdagent_x11_handle_event(struct vdagent_x11 *x11, const XEvent *event)
{
int i, handled = 0;
#ifndef WITH_GTK
#ifndef USE_GTK_FOR_CLIPBOARD
uint8_t selection;
if (event.type == x11->xfixes_event_base) {
if (event->type == x11->xfixes_event_base) {
union {
XEvent ev;
XFixesSelectionNotifyEvent xfev;
} ev;
if (vdagent_x11_get_clipboard_selection(x11, &event, &selection)) {
if (vdagent_x11_get_clipboard_selection(x11, event, &selection)) {
return;
}
ev.ev = event;
ev.ev = *event;
switch (ev.xfev.subtype) {
case XFixesSetSelectionOwnerNotify:
break;
@@ -521,7 +508,7 @@ static void vdagent_x11_handle_event(struct vdagent_x11 *x11, XEvent event)
break;
default:
VSELPRINTF("unexpected xfix event subtype %d window %d",
(int)ev.xfev.subtype, (int)event.xany.window);
(int)ev.xfev.subtype, (int)event->xany.window);
return;
}
VSELPRINTF("New selection owner: %u", (unsigned int)ev.xfev.owner);
@@ -530,11 +517,10 @@ static void vdagent_x11_handle_event(struct vdagent_x11 *x11, XEvent event)
if (ev.xfev.owner == x11->selection_window)
return;
/* If the clipboard owner is changed we no longer own it */
vdagent_x11_set_clipboard_owner(x11, selection, owner_none);
if (ev.xfev.owner == None)
if (ev.xfev.owner == None) {
vdagent_x11_set_clipboard_owner(x11, selection, owner_none);
return;
}
/* Request the supported targets from the new owner */
XConvertSelection(x11->display, ev.xfev.selection, x11->targets_atom,
@@ -548,39 +534,39 @@ static void vdagent_x11_handle_event(struct vdagent_x11 *x11, XEvent event)
if (vdagent_x11_randr_handle_event(x11, event))
return;
switch (event.type) {
switch (event->type) {
case ConfigureNotify:
for (i = 0; i < x11->screen_count; i++)
if (event.xconfigure.window == x11->root_window[i])
if (event->xconfigure.window == x11->root_window[i])
break;
if (i == x11->screen_count)
break;
handled = 1;
vdagent_x11_randr_handle_root_size_change(x11, i,
event.xconfigure.width, event.xconfigure.height);
event->xconfigure.width, event->xconfigure.height);
break;
case MappingNotify:
/* These are uninteresting */
handled = 1;
break;
#ifndef WITH_GTK
#ifndef USE_GTK_FOR_CLIPBOARD
case SelectionNotify:
if (event.xselection.target == x11->targets_atom)
vdagent_x11_handle_targets_notify(x11, &event);
if (event->xselection.target == x11->targets_atom)
vdagent_x11_handle_targets_notify(x11, event);
else
vdagent_x11_handle_selection_notify(x11, &event, 0);
vdagent_x11_handle_selection_notify(x11, event, 0);
handled = 1;
break;
case PropertyNotify:
if (x11->expect_property_notify &&
event.xproperty.state == PropertyNewValue) {
vdagent_x11_handle_selection_notify(x11, &event, 1);
event->xproperty.state == PropertyNewValue) {
vdagent_x11_handle_selection_notify(x11, event, 1);
}
if (x11->selection_req_data &&
event.xproperty.state == PropertyDelete) {
vdagent_x11_handle_property_delete_notify(x11, &event);
event->xproperty.state == PropertyDelete) {
vdagent_x11_handle_property_delete_notify(x11, event);
}
/* Always mark as handled, since we cannot unselect input for property
notifications once we are done with handling the incr transfer. */
@@ -594,7 +580,7 @@ static void vdagent_x11_handle_event(struct vdagent_x11 *x11, XEvent event)
case SelectionRequest: {
struct vdagent_x11_selection_request *req, *new_req;
if (vdagent_x11_get_clipboard_selection(x11, &event, &selection)) {
if (vdagent_x11_get_clipboard_selection(x11, event, &selection)) {
return;
}
@@ -606,7 +592,7 @@ static void vdagent_x11_handle_event(struct vdagent_x11 *x11, XEvent event)
handled = 1;
new_req->event = event;
new_req->event = *event;
new_req->selection = selection;
new_req->next = NULL;
@@ -628,7 +614,7 @@ static void vdagent_x11_handle_event(struct vdagent_x11 *x11, XEvent event)
}
if (!handled && x11->debug)
syslog(LOG_DEBUG, "unhandled x11 event, type %d, window %d",
(int)event.type, (int)event.xany.window);
(int)event->type, (int)event->xany.window);
}
void vdagent_x11_do_read(struct vdagent_x11 *x11)
@@ -637,20 +623,34 @@ void vdagent_x11_do_read(struct vdagent_x11 *x11)
while (XPending(x11->display)) {
XNextEvent(x11->display, &event);
vdagent_x11_handle_event(x11, event);
vdagent_x11_handle_event(x11, &event);
}
}
#ifndef WITH_GTK
#ifndef USE_GTK_FOR_CLIPBOARD
static const char *vdagent_x11_get_atom_name(struct vdagent_x11 *x11, Atom a)
{
if (a == None)
return "None";
return XGetAtomName(x11->display, a);
for (int i = 0; i < ATOM_NAME_CACHE_SIZE; i++) {
if (x11->atom_name_cache[i].atom == a) {
return x11->atom_name_cache[i].name;
}
}
struct atom_name_cache_item *cch;
cch = &x11->atom_name_cache[x11->atom_name_cache_next];
if (cch->name) {
XFree(cch->name);
}
cch->atom = a;
cch->name = XGetAtomName(x11->display, a);
x11->atom_name_cache_next = (x11->atom_name_cache_next + 1) % ATOM_NAME_CACHE_SIZE;
return cch->name;
}
static int vdagent_x11_get_selection(struct vdagent_x11 *x11, XEvent *event,
static int vdagent_x11_get_selection(struct vdagent_x11 *x11, const XEvent *event,
uint8_t selection, Atom type, Atom prop, int format,
unsigned char **data_ret, int incr)
{
@@ -802,6 +802,17 @@ static uint32_t vdagent_x11_target_to_type(struct vdagent_x11 *x11,
int i, j;
for (i = 0; i < clipboard_format_count; i++) {
/* targets for VD_AGENT_CLIPBOARD_FILE_LIST overlap with the text targets */
if (x11->clipboard_has_files[selection]) {
if (x11->clipboard_formats[i].type == VD_AGENT_CLIPBOARD_UTF8_TEXT) {
continue;
}
} else {
if (x11->clipboard_formats[i].type == VD_AGENT_CLIPBOARD_FILE_LIST) {
continue;
}
}
for (j = 0; j < x11->clipboard_formats[i].atom_count; j++) {
if (x11->clipboard_formats[i].atoms[j] == target) {
return x11->clipboard_formats[i].type;
@@ -842,7 +853,7 @@ static void vdagent_x11_handle_conversion_request(struct vdagent_x11 *x11)
}
static void vdagent_x11_handle_selection_notify(struct vdagent_x11 *x11,
XEvent *event, int incr)
const XEvent *event, int incr)
{
int len = 0;
unsigned char *data = NULL;
@@ -927,7 +938,7 @@ static void vdagent_x11_print_targets(struct vdagent_x11 *x11,
}
static void vdagent_x11_handle_targets_notify(struct vdagent_x11 *x11,
XEvent *event)
const XEvent *event)
{
int i, len;
Atom atom, *atoms = NULL;
@@ -971,6 +982,11 @@ static void vdagent_x11_handle_targets_notify(struct vdagent_x11 *x11,
type_count = &x11->clipboard_type_count[selection];
*type_count = 0;
for (i = 0; i < clipboard_format_count; i++) {
if (x11->clipboard_formats[i].type == VD_AGENT_CLIPBOARD_FILE_LIST) {
/* we don't support file copying in this direction yet */
continue;
}
atom = atom_lists_overlap(x11->clipboard_formats[i].atoms, atoms,
x11->clipboard_formats[i].atom_count, len);
if (atom) {
@@ -1026,12 +1042,17 @@ static void vdagent_x11_send_selection_notify(struct vdagent_x11 *x11,
}
static void vdagent_x11_send_targets(struct vdagent_x11 *x11,
uint8_t selection, XEvent *event)
uint8_t selection, const XEvent *event)
{
Atom prop, targets[256] = { x11->targets_atom, };
int i, j, k, target_count = 1;
for (i = 0; i < x11->clipboard_type_count[selection]; i++) {
if (x11->clipboard_agent_types[selection][i] == VD_AGENT_CLIPBOARD_UTF8_TEXT &&
x11->clipboard_has_files[selection]) {
continue;
}
for (j = 0; j < clipboard_format_count; j++) {
if (x11->clipboard_formats[j].type !=
x11->clipboard_agent_types[selection][i])
@@ -1118,12 +1139,23 @@ static void vdagent_x11_handle_selection_request(struct vdagent_x11 *x11)
return;
}
if (type == VD_AGENT_CLIPBOARD_FILE_LIST && x11->file_list_data[selection]) {
VSELPRINTF("setting file list from cache");
clipboard_data_translate_to_uris_async(
vdagent_x11_get_atom_name(x11, event->xselectionrequest.target),
x11->file_list_data[selection],
NULL, uris_ready_cb, x11
);
return;
}
udscs_write(x11->vdagentd, VDAGENTD_CLIPBOARD_REQUEST, selection, type,
NULL, 0);
}
static void vdagent_x11_handle_property_delete_notify(struct vdagent_x11 *x11,
XEvent *del_event)
const XEvent *del_event)
{
XEvent *sel_event;
int len;
@@ -1252,6 +1284,13 @@ void vdagent_x11_clipboard_grab(struct vdagent_x11 *x11, uint8_t selection,
x11->selection_window, CurrentTime);
vdagent_x11_set_clipboard_owner(x11, selection, owner_client);
for (int i = 0; i < x11->clipboard_type_count[selection]; i++) {
if (x11->clipboard_agent_types[selection][i] == VD_AGENT_CLIPBOARD_FILE_LIST) {
x11->clipboard_has_files[selection] = True;
break;
}
}
/* If there're pending requests for targets, ignore the returned
* targets as the XSetSelectionOwner() call above made them invalid */
x11->ignore_targets_notifies[selection] =
@@ -1261,10 +1300,95 @@ void vdagent_x11_clipboard_grab(struct vdagent_x11 *x11, uint8_t selection,
vdagent_x11_do_read(x11);
}
static void clipboard_data_send_to_requestor(struct vdagent_x11 *x11,
uint8_t selection, uint8_t *data, uint32_t size, Bool take_ownership)
{
XEvent *event;
Atom prop;
event = &x11->selection_req->event;
prop = event->xselectionrequest.property;
if (prop == None) {
prop = event->xselectionrequest.target;
}
if (size > x11->max_prop_size) {
unsigned long len = size;
VSELPRINTF("Starting incr send of clipboard data");
vdagent_x11_set_error_handler(x11, vdagent_x11_ignore_bad_window_handler);
XSelectInput(x11->display, event->xselectionrequest.requestor,
PropertyChangeMask);
XChangeProperty(x11->display, event->xselectionrequest.requestor, prop,
x11->incr_atom, 32, PropModeReplace,
(unsigned char*)&len, 1);
if (vdagent_x11_restore_error_handler(x11) == 0) {
if (take_ownership) {
x11->selection_req_data = data;
} else {
/* duplicate data */
x11->selection_req_data = malloc(size);
if (x11->selection_req_data == NULL) {
SELPRINTF("out of memory allocating selection buffer");
return;
}
memcpy(x11->selection_req_data, data, size);
}
x11->selection_req_data_pos = 0;
x11->selection_req_data_size = size;
x11->selection_req_atom = prop;
vdagent_x11_send_selection_notify(x11, prop, x11->selection_req);
} else {
SELPRINTF("clipboard data sent failed, requestor window gone");
}
} else {
vdagent_x11_set_error_handler(x11, vdagent_x11_ignore_bad_window_handler);
XChangeProperty(x11->display, event->xselectionrequest.requestor, prop,
event->xselectionrequest.target, 8, PropModeReplace,
data, size);
if (vdagent_x11_restore_error_handler(x11) == 0) {
vdagent_x11_send_selection_notify(x11, prop, NULL);
} else {
SELPRINTF("clipboard data sent failed, requestor window gone");
}
if (take_ownership) {
g_free(data);
}
}
}
static void uris_ready_cb(GObject *source, GAsyncResult *res, gpointer user_data)
{
struct vdagent_x11 *x11 = user_data;
GError *err = NULL;
size_t size;
char *uris = clipboard_data_translate_to_uris_finish(source, res, &size, &err);
if (g_error_matches(err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
g_error_free(err);
return;
}
if (!x11->selection_req) {
return;
}
uint8_t selection = x11->selection_req->selection;
if (err) {
SELPRINTF("failed to translate data to uris %s", err->message);
g_error_free(err);
}
clipboard_data_send_to_requestor(x11, selection, (uint8_t *)uris, size, True);
/* Flush output buffers and consume any pending events */
vdagent_x11_do_read(x11);
}
void vdagent_x11_clipboard_data(struct vdagent_x11 *x11, uint8_t selection,
uint32_t type, uint8_t *data, uint32_t size)
{
Atom prop;
XEvent *event;
uint32_t type_from_event;
@@ -1305,44 +1429,17 @@ void vdagent_x11_clipboard_data(struct vdagent_x11 *x11, uint8_t selection,
return;
}
prop = event->xselectionrequest.property;
if (prop == None)
prop = event->xselectionrequest.target;
if (type == VD_AGENT_CLIPBOARD_FILE_LIST) {
g_clear_pointer(&x11->file_list_data[selection], g_bytes_unref);
x11->file_list_data[selection] = g_bytes_new(data, size);
if (size > x11->max_prop_size) {
unsigned long len = size;
VSELPRINTF("Starting incr send of clipboard data");
vdagent_x11_set_error_handler(x11, vdagent_x11_ignore_bad_window_handler);
XSelectInput(x11->display, event->xselectionrequest.requestor,
PropertyChangeMask);
XChangeProperty(x11->display, event->xselectionrequest.requestor, prop,
x11->incr_atom, 32, PropModeReplace,
(unsigned char*)&len, 1);
if (vdagent_x11_restore_error_handler(x11) == 0) {
/* duplicate data */
x11->selection_req_data = malloc(size);
if (x11->selection_req_data != NULL) {
memcpy(x11->selection_req_data, data, size);
x11->selection_req_data_pos = 0;
x11->selection_req_data_size = size;
x11->selection_req_atom = prop;
vdagent_x11_send_selection_notify(x11, prop, x11->selection_req);
} else {
SELPRINTF("out of memory allocating selection buffer");
}
} else {
SELPRINTF("clipboard data sent failed, requestor window gone");
}
clipboard_data_translate_to_uris_async(
vdagent_x11_get_atom_name(x11, event->xselectionrequest.target),
x11->file_list_data[selection], NULL, uris_ready_cb, x11
);
return;
} else {
vdagent_x11_set_error_handler(x11, vdagent_x11_ignore_bad_window_handler);
XChangeProperty(x11->display, event->xselectionrequest.requestor, prop,
event->xselectionrequest.target, 8, PropModeReplace,
data, size);
if (vdagent_x11_restore_error_handler(x11) == 0)
vdagent_x11_send_selection_notify(x11, prop, NULL);
else
SELPRINTF("clipboard data sent failed, requestor window gone");
clipboard_data_send_to_requestor(x11, selection, data, size, False);
}
/* Flush output buffers and consume any pending events */
@@ -1370,7 +1467,7 @@ void vdagent_x11_clipboard_release(struct vdagent_x11 *x11, uint8_t selection)
XSync(x11->display, False);
while (XCheckTypedEvent(x11->display, x11->xfixes_event_base,
&event))
vdagent_x11_handle_event(x11, event);
vdagent_x11_handle_event(x11, &event);
/* Note no need to do a set_clipboard_owner(owner_none) here, as that is
already done by processing the XFixesSetSelectionOwnerNotify event. */
@@ -1389,30 +1486,3 @@ void vdagent_x11_client_disconnected(struct vdagent_x11 *x11)
}
}
#endif
/* Function used to determine the default location to save file-xfers,
xdg desktop dir or xdg download dir. We err on the safe side and use a
whitelist approach, so any unknown desktop will end up with saving
file-xfers to the xdg download dir, and opening the xdg download dir with
xdg-open when the file-xfer completes. */
int vdagent_x11_has_icons_on_desktop(struct vdagent_x11 *x11)
{
const char * const wms_with_icons_on_desktop[] = {
"Metacity", /* GNOME-2 or GNOME-3 fallback */
"Xfwm4", /* Xfce */
"Marco", /* Mate */
"Metacity (Marco)", /* Mate, newer */
NULL
};
gchar *net_wm_name = vdagent_x11_get_wm_name(x11);
int i;
for (i = 0; wms_with_icons_on_desktop[i]; i++)
if (!strcmp(net_wm_name, wms_with_icons_on_desktop[i])) {
g_free(net_wm_name);
return 1;
}
g_free(net_wm_name);
return 0;
}
+7 -4
View File
@@ -28,7 +28,7 @@
struct vdagent_x11;
struct vdagent_x11 *vdagent_x11_create(struct udscs_connection *vdagentd,
struct vdagent_x11 *vdagent_x11_create(UdscsConnection *vdagentd,
int debug, int sync);
void vdagent_x11_destroy(struct vdagent_x11 *x11, int vdagentd_disconnected);
@@ -38,7 +38,7 @@ void vdagent_x11_do_read(struct vdagent_x11 *x11);
void vdagent_x11_set_monitor_config(struct vdagent_x11 *x11,
VDAgentMonitorsConfig *mon_config, int fallback);
#ifndef WITH_GTK
#ifndef USE_GTK_FOR_CLIPBOARD
void vdagent_x11_clipboard_grab(struct vdagent_x11 *x11, uint8_t selection,
uint32_t *types, uint32_t type_count);
void vdagent_x11_clipboard_request(struct vdagent_x11 *x11,
@@ -50,7 +50,10 @@ void vdagent_x11_clipboard_release(struct vdagent_x11 *x11, uint8_t selection);
void vdagent_x11_client_disconnected(struct vdagent_x11 *x11);
#endif
int vdagent_x11_has_icons_on_desktop(struct vdagent_x11 *x11);
void vdagent_x11_handle_graphics_device_info(struct vdagent_x11 *x11, uint8_t *data, size_t size);
gchar *vdagent_x11_get_wm_name(struct vdagent_x11 *x11);
void vdagent_x11_handle_device_display_info(struct vdagent_x11 *x11,
VDAgentDeviceDisplayInfo *device_display_info,
gboolean has_virtual_zero_display);
#endif
+69 -2
View File
@@ -318,7 +318,7 @@ static char *console_kit_get_first_seat(struct session_info *info)
}
dbus_message_iter_get_basic(&subiter, &seat);
info->seat = strdup(seat);
info->seat = g_strdup(seat);
exit:
if (reply != NULL) {
@@ -383,7 +383,7 @@ const char *session_info_get_active_session(struct session_info *info)
goto exit;
}
info->active_session = strdup(session);
info->active_session = g_strdup(session);
si_dbus_match_rule_update(info);
exit:
@@ -568,3 +568,70 @@ exit:
}
return ret;
}
uid_t session_info_uid_for_session(struct session_info *info, const char *session)
{
DBusError error;
DBusMessage *message = NULL;
DBusMessage *reply = NULL;
uint32_t uid;
uid_t ret = -1;
const char *err_msg;
g_return_val_if_fail(info != NULL, ret);
g_return_val_if_fail(info->connection != NULL, ret);
g_return_val_if_fail(info->active_session != NULL, ret);
dbus_error_init(&error);
err_msg = "(console-kit) Unable to create dbus message for GetUnixUser";
message = dbus_message_new_method_call(INTERFACE_CONSOLE_KIT,
session,
INTERFACE_CONSOLE_KIT_SESSION,
"GetUnixUser");
if (message == NULL) {
goto exit;
}
err_msg = "(console-kit) GetUnixUser failed";
reply = dbus_connection_send_with_reply_and_block(info->connection,
message,
-1,
&error);
if (reply == NULL || dbus_error_is_set(&error)) {
goto exit;
}
dbus_error_init(&error);
err_msg = "(console-kit) fail to get session-type from reply";
if (!dbus_message_get_args(reply,
&error,
DBUS_TYPE_UINT32, &uid,
DBUS_TYPE_INVALID)) {
goto exit;
}
if (info->verbose) {
syslog(LOG_DEBUG, "(console-kit) unix user is '%u'", (unsigned) uid);
}
err_msg = NULL;
ret = uid;
exit:
if (err_msg) {
if (dbus_error_is_set(&error)) {
syslog(LOG_ERR, "%s: %s", err_msg, error.message);
dbus_error_free(&error);
} else {
syslog(LOG_ERR, "%s", err_msg);
}
}
if (reply != NULL) {
dbus_message_unref(reply);
}
if (message != NULL) {
dbus_message_unref(message);
}
return ret;
}
+5
View File
@@ -55,3 +55,8 @@ gboolean session_info_session_is_locked(G_GNUC_UNUSED struct session_info *si)
{
return FALSE;
}
uid_t session_info_uid_for_session(struct session_info *si, const char *session)
{
return -1;
}
+3
View File
@@ -40,4 +40,7 @@ char *session_info_session_for_pid(struct session_info *ck, uint32_t pid);
gboolean session_info_session_is_locked(struct session_info *si);
gboolean session_info_is_user(struct session_info *si);
/* get owner of a given session */
uid_t session_info_uid_for_session(struct session_info *si, const char *session);
#endif
+67 -5
View File
@@ -250,7 +250,9 @@ void session_info_destroy(struct session_info *si)
return;
si_dbus_match_remove(si);
dbus_connection_close(si->dbus.system_connection);
if (si->dbus.system_connection) {
dbus_connection_close(si->dbus.system_connection);
}
sd_login_monitor_unref(si->mon);
g_free(si->session);
g_free(si);
@@ -286,15 +288,66 @@ const char *session_info_get_active_session(struct session_info *si)
char *session_info_session_for_pid(struct session_info *si, uint32_t pid)
{
int i;
int r;
GStrv sessions = NULL;
char *session = NULL;
uid_t uid;
r = sd_pid_get_session(pid, &session);
if (r < 0)
syslog(LOG_ERR, "Error getting session for pid %u: %s",
pid, strerror(-r));
else if (si->verbose)
if (r >= 0) {
goto out;
}
/* If we could not get a session for the pid then the agent is probably
* running in a systemd managed session. In that case we simply assume
* it is actually part of the newest graphical session we can find. */
r = sd_pid_get_owner_uid(pid, &uid);
if (r < 0) {
syslog(LOG_ERR, "Error getting owner UID for pid %u: %s",
pid, strerror(-r));
goto out;
}
r = sd_uid_get_sessions(uid, 0, &sessions);
if (r < 0) {
syslog(LOG_ERR, "Error getting sessions for UID %d: %s",
(int) uid, strerror(-r));
goto out;
}
for (i = 0; sessions[i] != NULL; i++) {
char *session_type = NULL;
r = sd_session_get_type(sessions[i], &session_type);
if (r < 0) {
syslog(LOG_ERR, "Error getting session type for session %s: %s",
sessions[i], strerror(-r));
continue;
}
if (g_strcmp0(session_type, "wayland") == 0 ||
g_strcmp0(session_type, "x11") == 0 ||
g_strcmp0(session_type, "mir") == 0) {
/* We prefer the newest session (i.e. last entry) from the
* user, assuming that any old session that still exist has
* just not yet died properly. */
if (session != NULL)
free (session);
session = g_strdup(sessions[i]);
}
free(session_type);
}
g_strfreev(sessions);
out:
if (session != NULL && si->verbose) {
syslog(LOG_INFO, "Session for pid %u: %s", pid, session);
}
return session;
}
@@ -341,3 +394,12 @@ gboolean session_info_is_user(struct session_info *si)
return ret;
}
uid_t session_info_uid_for_session(struct session_info *si, const char *session)
{
uid_t ret = -1;
if (sd_session_get_uid(session, &ret) < 0) {
return -1;
}
return ret;
}
+4
View File
@@ -140,6 +140,8 @@ void vdagentd_uinput_update_size(struct vdagentd_uinput **uinputp,
ioctl(uinput->fd, UI_SET_KEYBIT, BTN_LEFT);
ioctl(uinput->fd, UI_SET_KEYBIT, BTN_MIDDLE);
ioctl(uinput->fd, UI_SET_KEYBIT, BTN_RIGHT);
ioctl(uinput->fd, UI_SET_KEYBIT, BTN_SIDE);
ioctl(uinput->fd, UI_SET_KEYBIT, BTN_EXTRA);
/* wheel */
ioctl(uinput->fd, UI_SET_EVBIT, EV_REL);
@@ -200,6 +202,8 @@ void vdagentd_uinput_do_mouse(struct vdagentd_uinput **uinputp,
{ .name = "left", .mask = VD_AGENT_LBUTTON_MASK, .btn = BTN_LEFT },
{ .name = "middle", .mask = VD_AGENT_MBUTTON_MASK, .btn = BTN_MIDDLE },
{ .name = "right", .mask = VD_AGENT_RBUTTON_MASK, .btn = BTN_RIGHT },
{ .name = "side" , .mask = VD_AGENT_SBUTTON_MASK, .btn = BTN_SIDE },
{ .name = "extra" , .mask = VD_AGENT_EBUTTON_MASK, .btn = BTN_EXTRA },
};
static const struct button_s wheel[] = {
{ .name = "up", .mask = VD_AGENT_UBUTTON_MASK, .btn = 1 },
+438 -201
View File
File diff suppressed because it is too large. Load diff
+127 -286
View File
@@ -20,27 +20,20 @@
*/
#include <config.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <glib.h>
#include <gio/gio.h>
#include <glib-unix.h>
#include "vdagent-connection.h"
#include "virtio-port.h"
struct vdagent_virtio_port_buf {
uint8_t *buf;
size_t pos;
size_t size;
size_t write_pos;
struct vdagent_virtio_port_buf *next;
};
/* Data to keep track of the assembling of vdagent messages per chunk port,
@@ -52,160 +45,150 @@ struct vdagent_virtio_port_chunk_port_data {
uint8_t *message_data;
};
struct vdagent_virtio_port {
int fd;
int opening;
int is_uds;
/* Chunk read stuff, single buffer, separate header and data buffer */
int chunk_header_read;
int chunk_data_pos;
VDIChunkHeader chunk_header;
uint8_t chunk_data[VD_AGENT_MAX_DATA_SIZE];
struct _VirtioPort {
VDAgentConnection parent_instance;
/* Per chunk port data */
struct vdagent_virtio_port_chunk_port_data port_data[VDP_END_PORT];
/* Writes are stored in a linked list of buffers, with both the header
+ data for a single message in 1 buffer. */
struct vdagent_virtio_port_buf *write_buf;
struct vdagent_virtio_port_buf write_buf;
/* Callbacks */
vdagent_virtio_port_read_callback read_callback;
vdagent_virtio_port_disconnect_callback disconnect_callback;
VDAgentConnErrorCb error_cb;
};
static void vdagent_virtio_port_do_write(struct vdagent_virtio_port **vportp);
static void vdagent_virtio_port_do_read(struct vdagent_virtio_port **vportp);
G_DEFINE_TYPE(VirtioPort, virtio_port, VDAGENT_TYPE_CONNECTION)
struct vdagent_virtio_port *vdagent_virtio_port_create(const char *portname,
vdagent_virtio_port_read_callback read_callback,
vdagent_virtio_port_disconnect_callback disconnect_callback)
static void vdagent_virtio_port_do_chunk(VDAgentConnection *conn,
gpointer header_data,
gpointer chunk_data);
static gsize conn_handle_header(VDAgentConnection *conn,
gpointer header_buf)
{
struct vdagent_virtio_port *vport;
struct sockaddr_un address;
int c;
VirtioPort *self = VIRTIO_PORT(conn);
VDIChunkHeader *header = header_buf;
GError *err;
vport = g_new0(struct vdagent_virtio_port, 1);
header->size = GUINT32_FROM_LE(header->size);
header->port = GUINT32_FROM_LE(header->port);
vport->fd = open(portname, O_RDWR);
if (vport->fd == -1) {
vport->fd = socket(PF_UNIX, SOCK_STREAM, 0);
if (vport->fd == -1) {
goto error;
}
address.sun_family = AF_UNIX;
snprintf(address.sun_path, sizeof(address.sun_path), "%s", portname);
c = connect(vport->fd, (struct sockaddr *)&address, sizeof(address));
if (c == 0) {
vport->is_uds = 1;
} else {
goto error;
}
} else {
vport->is_uds = 0;
if (header->size > VD_AGENT_MAX_DATA_SIZE) {
err = g_error_new(G_IO_ERROR, G_IO_ERROR_FAILED,
"chunk size %u too large", header->size);
self->error_cb(conn, err);
return 0;
}
vport->opening = 1;
vport->read_callback = read_callback;
vport->disconnect_callback = disconnect_callback;
return vport;
error:
syslog(LOG_ERR, "open %s: %m", portname);
if (vport->fd != -1) {
close(vport->fd);
if (header->port >= VDP_END_PORT) {
err = g_error_new(G_IO_ERROR, G_IO_ERROR_FAILED,
"chunk port %u out of range", header->port);
self->error_cb(conn, err);
return 0;
}
g_free(vport);
return NULL;
return header->size;
}
void vdagent_virtio_port_destroy(struct vdagent_virtio_port **vportp)
static void virtio_port_init(VirtioPort *self)
{
struct vdagent_virtio_port_buf *wbuf, *next_wbuf;
struct vdagent_virtio_port *vport = *vportp;
int i;
}
if (!vport)
return;
static void virtio_port_finalize(GObject *obj)
{
VirtioPort *self = VIRTIO_PORT(obj);
guint i;
if (vport->disconnect_callback)
vport->disconnect_callback(vport);
wbuf = vport->write_buf;
while (wbuf) {
next_wbuf = wbuf->next;
g_free(wbuf->buf);
g_free(wbuf);
wbuf = next_wbuf;
}
g_free(self->write_buf.buf);
for (i = 0; i < VDP_END_PORT; i++) {
g_free(vport->port_data[i].message_data);
g_free(self->port_data[i].message_data);
}
close(vport->fd);
g_clear_pointer(vportp, g_free);
G_OBJECT_CLASS(virtio_port_parent_class)->finalize(obj);
}
int vdagent_virtio_port_fill_fds(struct vdagent_virtio_port *vport,
fd_set *readfds, fd_set *writefds)
static void virtio_port_class_init(VirtioPortClass *klass)
{
if (!vport)
return -1;
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
VDAgentConnectionClass *conn_class = VDAGENT_CONNECTION_CLASS(klass);
FD_SET(vport->fd, readfds);
if (vport->write_buf)
FD_SET(vport->fd, writefds);
gobject_class->finalize = virtio_port_finalize;
return vport->fd + 1;
conn_class->handle_header = conn_handle_header;
conn_class->handle_message = vdagent_virtio_port_do_chunk;
}
void vdagent_virtio_port_handle_fds(struct vdagent_virtio_port **vportp,
fd_set *readfds, fd_set *writefds)
VirtioPort *vdagent_virtio_port_create(const char *portname,
vdagent_virtio_port_read_callback read_callback,
VDAgentConnErrorCb error_cb)
{
if (!*vportp)
return;
VirtioPort *vport;
GIOStream *io_stream;
GError *err = NULL;
if (FD_ISSET((*vportp)->fd, readfds))
vdagent_virtio_port_do_read(vportp);
io_stream = vdagent_file_open(portname, &err);
if (err) {
syslog(LOG_ERR, "%s: %s", __func__, err->message);
g_clear_error(&err);
io_stream = vdagent_socket_connect(portname, &err);
if (err) {
syslog(LOG_ERR, "%s: %s", __func__, err->message);
g_error_free(err);
return NULL;
}
}
if (*vportp && FD_ISSET((*vportp)->fd, writefds))
vdagent_virtio_port_do_write(vportp);
}
vport = g_object_new(VIRTIO_TYPE_PORT, NULL);
static struct vdagent_virtio_port_buf* vdagent_virtio_port_get_last_wbuf(
struct vdagent_virtio_port *vport)
{
struct vdagent_virtio_port_buf *wbuf;
/* When calling vdagent_connection_new(),
* @wait_on_opening MUST be set to TRUE:
*
* When we open the virtio serial port, the following happens:
* 1) The linux kernel virtio_console driver sends a
* VIRTIO_CONSOLE_PORT_OPEN message to qemu
* 2) qemu's spicevmc chardev driver calls qemu_spice_add_interface to
* register the agent chardev with the spice-server
* 3) spice-server then calls the spicevmc chardev driver's state
* callback to let it know it is ready to receive data
* 4) The state callback sends a CHR_EVENT_OPENED to the virtio-console
* chardev backend
* 5) The virtio-console chardev backend sends VIRTIO_CONSOLE_PORT_OPEN
* to the linux kernel virtio_console driver
*
* Until steps 1 - 5 have completed the linux kernel virtio_console
* driver sees the virtio serial port as being in a disconnected state
* and read will return 0 ! So if we blindly assume that a read 0 means
* that the channel is closed we will hit a race here.
*/
vdagent_connection_setup(VDAGENT_CONNECTION(vport),
io_stream,
TRUE,
sizeof(VDIChunkHeader),
error_cb);
wbuf = vport->write_buf;
if (!wbuf)
return NULL;
vport->read_callback = read_callback;
vport->error_cb = error_cb;
while (wbuf->next)
wbuf = wbuf->next;
return wbuf;
return vport;
}
void vdagent_virtio_port_write_start(
struct vdagent_virtio_port *vport,
VirtioPort *vport,
uint32_t port_nr,
uint32_t message_type,
uint32_t message_opaque,
uint32_t data_size)
{
struct vdagent_virtio_port_buf *wbuf, *new_wbuf;
struct vdagent_virtio_port_buf *new_wbuf;
VDIChunkHeader *chunk_header;
VDAgentMessage *message_header;
new_wbuf = g_new(struct vdagent_virtio_port_buf, 1);
new_wbuf->pos = 0;
g_return_if_fail(vport->write_buf.buf == NULL);
new_wbuf = &vport->write_buf;
new_wbuf->write_pos = 0;
new_wbuf->size = sizeof(*chunk_header) + sizeof(*message_header) + data_size;
new_wbuf->next = NULL;
new_wbuf->buf = g_malloc(new_wbuf->size);
chunk_header = (VDIChunkHeader *) (new_wbuf->buf + new_wbuf->write_pos);
@@ -219,23 +202,19 @@ void vdagent_virtio_port_write_start(
message_header->opaque = GUINT64_TO_LE(message_opaque);
message_header->size = GUINT32_TO_LE(data_size);
new_wbuf->write_pos += sizeof(*message_header);
if (!vport->write_buf) {
vport->write_buf = new_wbuf;
return;
}
wbuf = vdagent_virtio_port_get_last_wbuf(vport);
wbuf->next = new_wbuf;
}
int vdagent_virtio_port_write_append(struct vdagent_virtio_port *vport,
int vdagent_virtio_port_write_append(VirtioPort *vport,
const uint8_t *data, uint32_t size)
{
struct vdagent_virtio_port_buf *wbuf;
wbuf = vdagent_virtio_port_get_last_wbuf(vport);
if (!wbuf) {
if (size == 0) {
return 0;
}
wbuf = &vport->write_buf;
if (!wbuf->buf) {
syslog(LOG_ERR, "can't append without a buffer");
return -1;
}
@@ -247,11 +226,16 @@ int vdagent_virtio_port_write_append(struct vdagent_virtio_port *vport,
memcpy(wbuf->buf + wbuf->write_pos, data, size);
wbuf->write_pos += size;
if (wbuf->write_pos == wbuf->size) {
vdagent_connection_write(VDAGENT_CONNECTION(vport), wbuf->buf, wbuf->size);
wbuf->buf = NULL;
}
return 0;
}
void vdagent_virtio_port_write(
struct vdagent_virtio_port *vport,
VirtioPort *vport,
uint32_t port_nr,
uint32_t message_type,
uint32_t message_opaque,
@@ -263,13 +247,7 @@ void vdagent_virtio_port_write(
vdagent_virtio_port_write_append(vport, data, data_size);
}
void vdagent_virtio_port_flush(struct vdagent_virtio_port **vportp)
{
while (*vportp && (*vportp)->write_buf)
vdagent_virtio_port_do_write(vportp);
}
void vdagent_virtio_port_reset(struct vdagent_virtio_port *vport, int port)
void vdagent_virtio_port_reset(VirtioPort *vport, int port)
{
if (port >= VDP_END_PORT) {
syslog(LOG_ERR, "vdagent_virtio_port_reset port out of range");
@@ -279,20 +257,23 @@ void vdagent_virtio_port_reset(struct vdagent_virtio_port *vport, int port)
memset(&vport->port_data[port], 0, sizeof(vport->port_data[0]));
}
static void vdagent_virtio_port_do_chunk(struct vdagent_virtio_port **vportp)
static void vdagent_virtio_port_do_chunk(VDAgentConnection *conn,
gpointer header_data,
gpointer chunk_data)
{
int avail, read, pos = 0;
struct vdagent_virtio_port *vport = *vportp;
VirtioPort *vport = VIRTIO_PORT(conn);
VDIChunkHeader *chunk_header = header_data;
struct vdagent_virtio_port_chunk_port_data *port =
&vport->port_data[vport->chunk_header.port];
&vport->port_data[chunk_header->port];
if (port->message_header_read < sizeof(port->message_header)) {
read = sizeof(port->message_header) - port->message_header_read;
if (read > vport->chunk_header.size) {
read = vport->chunk_header.size;
if (read > chunk_header->size) {
read = chunk_header->size;
}
memcpy((uint8_t *)&port->message_header + port->message_header_read,
vport->chunk_data, read);
chunk_data, read);
port->message_header_read += read;
if (port->message_header_read == sizeof(port->message_header)) {
@@ -310,11 +291,12 @@ static void vdagent_virtio_port_do_chunk(struct vdagent_virtio_port **vportp)
if (port->message_header_read == sizeof(port->message_header)) {
read = port->message_header.size - port->message_data_pos;
avail = vport->chunk_header.size - pos;
avail = chunk_header->size - pos;
if (avail > read) {
syslog(LOG_ERR, "chunk larger than message, lost sync?");
vdagent_virtio_port_destroy(vportp);
GError *err = g_error_new(G_IO_ERROR, G_IO_ERROR_FAILED,
"chunk larger than message, lost sync?");
vport->error_cb(VDAGENT_CONNECTION(vport), err);
return;
}
@@ -323,18 +305,14 @@ static void vdagent_virtio_port_do_chunk(struct vdagent_virtio_port **vportp)
if (read) {
memcpy(port->message_data + port->message_data_pos,
vport->chunk_data + pos, read);
chunk_data + pos, read);
port->message_data_pos += read;
}
if (port->message_data_pos == port->message_header.size) {
if (vport->read_callback) {
int r = vport->read_callback(vport, vport->chunk_header.port,
&port->message_header, port->message_data);
if (r == -1) {
vdagent_virtio_port_destroy(vportp);
return;
}
vport->read_callback(vport, chunk_header->port,
&port->message_header, port->message_data);
}
port->message_header_read = 0;
port->message_data_pos = 0;
@@ -342,140 +320,3 @@ static void vdagent_virtio_port_do_chunk(struct vdagent_virtio_port **vportp)
}
}
}
static int vport_read(struct vdagent_virtio_port *vport, uint8_t *buf, int len)
{
if (vport->is_uds) {
return recv(vport->fd, buf, len, 0);
} else {
return read(vport->fd, buf, len);
}
}
static void vdagent_virtio_port_do_read(struct vdagent_virtio_port **vportp)
{
ssize_t n;
size_t to_read;
uint8_t *dest;
struct vdagent_virtio_port *vport = *vportp;
if (vport->chunk_header_read < sizeof(vport->chunk_header)) {
to_read = sizeof(vport->chunk_header) - vport->chunk_header_read;
dest = (uint8_t *)&vport->chunk_header + vport->chunk_header_read;
} else {
to_read = vport->chunk_header.size - vport->chunk_data_pos;
dest = vport->chunk_data + vport->chunk_data_pos;
}
n = vport_read(vport, dest, to_read);
if (n < 0) {
if (errno == EINTR)
return;
syslog(LOG_ERR, "reading from vdagent virtio port: %m");
}
if (n == 0 && vport->opening) {
/* When we open the virtio serial port, the following happens:
1) The linux kernel virtio_console driver sends a
VIRTIO_CONSOLE_PORT_OPEN message to qemu
2) qemu's spicevmc chardev driver calls qemu_spice_add_interface to
register the agent chardev with the spice-server
3) spice-server then calls the spicevmc chardev driver's state
callback to let it know it is ready to receive data
4) The state callback sends a CHR_EVENT_OPENED to the virtio-console
chardev backend
5) The virtio-console chardev backend sends VIRTIO_CONSOLE_PORT_OPEN
to the linux kernel virtio_console driver
Until steps 1 - 5 have completed the linux kernel virtio_console
driver sees the virtio serial port as being in a disconnected state
and read will return 0 ! So if we blindly assume that a read 0 means
that the channel is closed we will hit a race here.
Therefore we ignore read returning 0 until we've successfully read
or written some data. If we hit this race we also sleep a bit here
to avoid busy waiting until the above steps complete */
usleep(10000);
return;
}
if (n <= 0) {
vdagent_virtio_port_destroy(vportp);
return;
}
vport->opening = 0;
if (vport->chunk_header_read < sizeof(vport->chunk_header)) {
vport->chunk_header_read += n;
if (vport->chunk_header_read == sizeof(vport->chunk_header)) {
vport->chunk_header.size = GUINT32_FROM_LE(vport->chunk_header.size);
vport->chunk_header.port = GUINT32_FROM_LE(vport->chunk_header.port);
if (vport->chunk_header.size > VD_AGENT_MAX_DATA_SIZE) {
syslog(LOG_ERR, "chunk size %u too large",
vport->chunk_header.size);
vdagent_virtio_port_destroy(vportp);
return;
}
if (vport->chunk_header.port >= VDP_END_PORT) {
syslog(LOG_ERR, "chunk port %u out of range",
vport->chunk_header.port);
vdagent_virtio_port_destroy(vportp);
return;
}
}
} else {
vport->chunk_data_pos += n;
if (vport->chunk_data_pos == vport->chunk_header.size) {
vdagent_virtio_port_do_chunk(vportp);
// coverity[check_after_deref] previous function can change *vportd
if (!*vportp)
return;
vport->chunk_header_read = 0;
vport->chunk_data_pos = 0;
}
}
}
static int vport_write(struct vdagent_virtio_port *vport, uint8_t *buf, int len)
{
if (vport->is_uds) {
return send(vport->fd, buf, len, 0);
} else {
return write(vport->fd, buf, len);
}
}
static void vdagent_virtio_port_do_write(struct vdagent_virtio_port **vportp)
{
ssize_t n;
size_t to_write;
struct vdagent_virtio_port *vport = *vportp;
struct vdagent_virtio_port_buf* wbuf = vport->write_buf;
if (!wbuf) {
syslog(LOG_ERR, "do_write called on a port without a write buf ?!");
return;
}
if (wbuf->write_pos != wbuf->size) {
syslog(LOG_ERR, "do_write: buffer is incomplete!!");
return;
}
to_write = wbuf->size - wbuf->pos;
n = vport_write(vport, wbuf->buf + wbuf->pos, to_write);
if (n < 0) {
if (errno == EINTR)
return;
syslog(LOG_ERR, "writing to vdagent virtio port: %m");
vdagent_virtio_port_destroy(vportp);
return;
}
if (n > 0)
vport->opening = 0;
wbuf->pos += n;
if (wbuf->pos == wbuf->size) {
vport->write_buf = wbuf->next;
g_free(wbuf->buf);
g_free(wbuf);
}
}
+17 -46
View File
@@ -22,81 +22,52 @@
#ifndef __VIRTIO_PORT_H
#define __VIRTIO_PORT_H
#include <stdio.h>
#include <stdint.h>
#include <sys/select.h>
#include <spice/vd_agent.h>
#include <glib-object.h>
#include "vdagent-connection.h"
struct vdagent_virtio_port;
G_BEGIN_DECLS
#define VIRTIO_TYPE_PORT virtio_port_get_type()
G_DECLARE_FINAL_TYPE(VirtioPort, virtio_port, VIRTIO, PORT, VDAgentConnection)
/* Callbacks with this type will be called when a complete message has been
received. Sometimes the callback may want to close the port, in this
case do *not* call vdagent_virtio_port_destroy from the callback. The desire
to close the port can be indicated be returning -1 from the callback,
in other cases return 0. */
typedef int (*vdagent_virtio_port_read_callback)(
struct vdagent_virtio_port *vport,
received. */
typedef void (*vdagent_virtio_port_read_callback)(
VirtioPort *vport,
int port_nr,
VDAgentMessage *message_header,
uint8_t *data);
/* Callbacks with this type will be called when the port is disconnected.
Note:
1) vdagent_virtio_port will destroy the port in question itself after
this callback has completed!
2) This callback is always called, even if the disconnect is initiated
by the vdagent_virtio_port user through returning -1 from a read
callback, or by explicitly calling vdagent_virtio_port_destroy */
typedef void (*vdagent_virtio_port_disconnect_callback)(
struct vdagent_virtio_port *conn);
/* Create a vdagent virtio port object for port portname */
struct vdagent_virtio_port *vdagent_virtio_port_create(const char *portname,
VirtioPort *vdagent_virtio_port_create(const char *portname,
vdagent_virtio_port_read_callback read_callback,
vdagent_virtio_port_disconnect_callback disconnect_callback);
/* The contents of portp will be made NULL */
void vdagent_virtio_port_destroy(struct vdagent_virtio_port **vportp);
/* Given a vdagent_virtio_port fill the fd_sets pointed to by readfds and
writefds for select() usage.
Return value: value of the highest fd + 1 */
int vdagent_virtio_port_fill_fds(struct vdagent_virtio_port *vport,
fd_set *readfds, fd_set *writefds);
/* Handle any events flagged by select for the given vdagent_virtio_port.
Note the port may be destroyed (when disconnected) by this call
in this case the disconnect calllback will get called before the
destruction and the contents of connp will be made NULL */
void vdagent_virtio_port_handle_fds(struct vdagent_virtio_port **vportp,
fd_set *readfds, fd_set *writefds);
VDAgentConnErrorCb error_cb);
/* Queue a message for delivery, either bit by bit, or all at once */
void vdagent_virtio_port_write_start(
struct vdagent_virtio_port *vport,
VirtioPort *vport,
uint32_t port_nr,
uint32_t message_type,
uint32_t message_opaque,
uint32_t data_size);
int vdagent_virtio_port_write_append(
struct vdagent_virtio_port *vport,
VirtioPort *vport,
const uint8_t *data,
uint32_t size);
void vdagent_virtio_port_write(
struct vdagent_virtio_port *vport,
VirtioPort *vport,
uint32_t port_nr,
uint32_t message_type,
uint32_t message_opaque,
const uint8_t *data,
uint32_t data_size);
void vdagent_virtio_port_flush(struct vdagent_virtio_port **vportp);
void vdagent_virtio_port_reset(struct vdagent_virtio_port *vport, int port);
void vdagent_virtio_port_reset(VirtioPort *vport, int port);
G_END_DECLS
#endif
+59
View File
@@ -0,0 +1,59 @@
/* test-session-info.c - test session info
Copyright 2020 Red Hat, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#undef NDEBUG
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "session-info.h"
int main(int argc, char *argv[])
{
int pid, uid, uid_si;
pid = (int)getpid();
struct session_info *session_info = session_info_create(1);
if (session_info == NULL) {
return 1;
}
char *session = session_info_session_for_pid(session_info, pid);
if (session == NULL) {
session_info_destroy(session_info);
return 2;
}
uid_si = session_info_uid_for_session(session_info, session);
free(session);
session_info_destroy(session_info);
uid = getuid();
printf("MAIN: uid is %d, uid_si is %d\n", uid, uid_si);
if (uid != uid_si) {
fprintf(stderr, "MAIN: uid (%d) does not match the uid "
"obtained from session info (%d)\n", uid, uid_si);
return 3;
}
return 0;
}
+143
View File
@@ -0,0 +1,143 @@
/* test-termination.c tests program terminates correctly sending SIGTERM
*
* Copyright 2020 Red Hat, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
static pid_t child_pid;
static char socket_name[1024 + 64];
static void cleanup(void)
{
if (child_pid) {
kill(child_pid, SIGKILL);
}
if (socket_name[0]) {
unlink(socket_name);
}
}
static void handle_alarm(int sig)
{
fprintf(stderr, "Alarm reached!\n");
exit(1);
}
static void check(int line, const char *cond_str, int cond_value)
{
if (!cond_value) {
alarm(0);
fprintf(stderr, "%d: Check %s failed!\n", line, cond_str);
exit(1);
}
}
#define check(cond) check(__LINE__, #cond, cond)
static pid_t get_daemon_pid(void)
{
pid_t res = 0;
FILE *f = popen("ps -efww", "r");
check(f != NULL);
char line[1024];
while (fgets(line, sizeof(line), f)) {
if (strstr(line, socket_name) != NULL) {
int pid;
check(sscanf(line, "%*s %d", &pid) == 1);
res = pid;
}
}
pclose(f);
return res;
}
int main(int argc, char **argv)
{
atexit(cleanup);
// create new filename for the socket
char cwd[1024];
check(getcwd(cwd, sizeof(cwd)) != NULL);
snprintf(socket_name, sizeof(socket_name), "%s/sock-%u", cwd, (unsigned) getpid());
// daemon should not exist now
check(get_daemon_pid() == 0);
// launch daemon with -S
int pipes[2];
check(pipe(pipes) == 0);
child_pid = fork();
check(child_pid != -1);
if (child_pid == 0) {
close(pipes[0]);
execl("src/spice-vdagentd", "spice-vdagentd", "-S", socket_name, NULL);
fprintf(stderr, "Error launching agent\n");
return 1;
}
close(pipes[1]);
pipes[1] = -1;
// test child exits with success after a bit (wait timed)
int status;
signal(SIGALRM, handle_alarm);
alarm(1);
check(waitpid(child_pid, &status, 0) == child_pid);
alarm(0);
check(WIFEXITED(status) != 0);
check(WEXITSTATUS(status) == 0);
child_pid = 0;
// test child created the socket passed
struct stat sb;
check(stat(socket_name, &sb) == 0);
check((sb.st_mode & S_IFMT) == S_IFSOCK);
// child should have created the daemon
child_pid = get_daemon_pid();
check(child_pid != 0);
// wait a bit (1 second) and test daemon is still there, not failed some initialization
sleep(1);
check(get_daemon_pid() != 0);
// send a SIGTERM, process should close in a bit
kill(child_pid, SIGTERM);
// test daemon exits after a while, we use the pipe we created above to
// check if daemon closed
alarm(1);
check(read(pipes[0], cwd, sizeof(cwd)) == 0);
alarm(0);
check(get_daemon_pid() == 0);
// test the socket disappeared, so we know the program exited successful
check(stat(socket_name, &sb) == -1);
check(errno == ENOENT);
// don't send a SIGKILL to a not existing process
child_pid = 0;
return 0;
}
+779
View File
@@ -0,0 +1,779 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 55;
objects = {
/* Begin PBXAggregateTarget section */
CE03A11A2CEA8429006884EE /* vd_agent */ = {
isa = PBXAggregateTarget;
buildConfigurationList = CE03A11B2CEA8429006884EE /* Build configuration list for PBXAggregateTarget "vd_agent" */;
buildPhases = (
);
dependencies = (
CE03A11F2CEA8442006884EE /* PBXTargetDependency */,
CE03A1212CEA8442006884EE /* PBXTargetDependency */,
);
name = vd_agent;
packageProductDependencies = (
);
productName = vd_agent;
};
/* End PBXAggregateTarget section */
/* Begin PBXBuildFile section */
CE03A0BC2CE9012D006884EE /* udscs.c in Sources */ = {isa = PBXBuildFile; fileRef = CE03A0B62CE900A0006884EE /* udscs.c */; };
CE03A0BD2CE9012D006884EE /* vdagent-connection.c in Sources */ = {isa = PBXBuildFile; fileRef = CE03A0B82CE900A0006884EE /* vdagent-connection.c */; };
CE03A0C02CE9039B006884EE /* dummy-session-info.c in Sources */ = {isa = PBXBuildFile; fileRef = CE03A0A92CE900A0006884EE /* dummy-session-info.c */; };
CE03A0C22CE90428006884EE /* virtio-port.c in Sources */ = {isa = PBXBuildFile; fileRef = CE03A0B02CE900A0006884EE /* virtio-port.c */; };
CE03A0C32CE90428006884EE /* vdagentd.c in Sources */ = {isa = PBXBuildFile; fileRef = CE03A0AE2CE900A0006884EE /* vdagentd.c */; };
CE03A0C82CE904D3006884EE /* libgio-2.0.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CE03A0C52CE904C4006884EE /* libgio-2.0.a */; };
CE03A0C92CE904D4006884EE /* libglib-2.0.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CE03A0C62CE904C4006884EE /* libglib-2.0.a */; };
CE03A0CC2CE90506006884EE /* libgobject-2.0.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CE03A0CB2CE904EA006884EE /* libgobject-2.0.a */; };
CE03A0E72CE90CFC006884EE /* Vdagent.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE03A0E62CE90CFC006884EE /* Vdagent.swift */; };
CE03A0E82CE90CFC006884EE /* vdagent.c in Sources */ = {isa = PBXBuildFile; fileRef = CE03A0E52CE90CFC006884EE /* vdagent.c */; };
CE03A0EA2CE90D38006884EE /* udscs.c in Sources */ = {isa = PBXBuildFile; fileRef = CE03A0B62CE900A0006884EE /* udscs.c */; };
CE03A0ED2CE90D55006884EE /* ArgumentParser in Frameworks */ = {isa = PBXBuildFile; productRef = CE03A0EC2CE90D55006884EE /* ArgumentParser */; };
CE03A0EE2CE97927006884EE /* vdagent-connection.c in Sources */ = {isa = PBXBuildFile; fileRef = CE03A0B82CE900A0006884EE /* vdagent-connection.c */; };
CE03A0EF2CE97931006884EE /* libgio-2.0.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CE03A0C52CE904C4006884EE /* libgio-2.0.a */; };
CE03A0F02CE97933006884EE /* libglib-2.0.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CE03A0C62CE904C4006884EE /* libglib-2.0.a */; };
CE03A0F12CE97936006884EE /* libgobject-2.0.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CE03A0CB2CE904EA006884EE /* libgobject-2.0.a */; };
CE03A1172CEA83AF006884EE /* com.redhat.spice.vdagentd.plist in CopyFiles */ = {isa = PBXBuildFile; fileRef = CE03A10D2CEA838C006884EE /* com.redhat.spice.vdagentd.plist */; };
CE03A1192CEA83C6006884EE /* com.redhat.spice.vdagent.plist in CopyFiles */ = {isa = PBXBuildFile; fileRef = CE03A10C2CEA838C006884EE /* com.redhat.spice.vdagent.plist */; };
CE03A1262CEA8EF1006884EE /* libiconv.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = CE03A1232CEA8EF1006884EE /* libiconv.tbd */; };
CE03A1272CEA8EF1006884EE /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = CE03A1242CEA8EF1006884EE /* libz.tbd */; };
CE03A1282CEA8EF1006884EE /* libpcre2-8.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = CE03A1252CEA8EF1006884EE /* libpcre2-8.tbd */; };
CE03A12A2CEA8F18006884EE /* libffi.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = CE03A1292CEA8F18006884EE /* libffi.tbd */; };
CE03A12C2CEA8F6A006884EE /* libgmodule-2.0.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CE03A12B2CEA8F60006884EE /* libgmodule-2.0.a */; };
CE03A12E2CEA8F75006884EE /* libintl.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CE03A12D2CEA8F75006884EE /* libintl.a */; };
CE03A1302CEA8FBA006884EE /* libresolv.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = CE03A12F2CEA8FBA006884EE /* libresolv.tbd */; };
CE03A1322CEA8FCE006884EE /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE03A1312CEA8FCE006884EE /* Foundation.framework */; };
CE03A1342CEA8FE4006884EE /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE03A1332CEA8FE4006884EE /* AppKit.framework */; };
CE77170B2EC0000000A1B2C3 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE77170A2EC0000000A1B2C3 /* IOKit.framework */; };
CE54BD8E2CEA90F200FE3930 /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE03A1332CEA8FE4006884EE /* AppKit.framework */; };
CE54BD8F2CEA90F400FE3930 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CE03A1312CEA8FCE006884EE /* Foundation.framework */; };
CE54BD902CEA90F600FE3930 /* libgmodule-2.0.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CE03A12B2CEA8F60006884EE /* libgmodule-2.0.a */; };
CE54BD912CEA90FD00FE3930 /* libintl.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CE03A12D2CEA8F75006884EE /* libintl.a */; };
CE54BD922CEA910000FE3930 /* libresolv.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = CE03A12F2CEA8FBA006884EE /* libresolv.tbd */; };
CE54BD932CEA910200FE3930 /* libffi.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = CE03A1292CEA8F18006884EE /* libffi.tbd */; };
CE54BD942CEA910600FE3930 /* libiconv.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = CE03A1232CEA8EF1006884EE /* libiconv.tbd */; };
CE54BD952CEA910700FE3930 /* libpcre2-8.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = CE03A1252CEA8EF1006884EE /* libpcre2-8.tbd */; };
CE54BD962CEA910E00FE3930 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = CE03A1242CEA8EF1006884EE /* libz.tbd */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
CE03A0F22CE9ED98006884EE /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = CE03A0822CE90065006884EE /* Project object */;
proxyType = 1;
remoteGlobalIDString = CE03A0892CE90065006884EE;
remoteInfo = "spice-vdagentd";
};
CE03A11E2CEA8442006884EE /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = CE03A0822CE90065006884EE /* Project object */;
proxyType = 1;
remoteGlobalIDString = CE03A0DC2CE90CE8006884EE;
remoteInfo = "spice-vdagent";
};
CE03A1202CEA8442006884EE /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = CE03A0822CE90065006884EE /* Project object */;
proxyType = 1;
remoteGlobalIDString = CE03A0892CE90065006884EE;
remoteInfo = "spice-vdagentd";
};
/* End PBXContainerItemProxy section */
/* Begin PBXCopyFilesBuildPhase section */
CE03A0882CE90065006884EE /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = /Library/LaunchDaemons;
dstSubfolderSpec = 0;
files = (
CE03A1172CEA83AF006884EE /* com.redhat.spice.vdagentd.plist in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 1;
};
CE03A1182CEA83C0006884EE /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 8;
dstPath = /Library/LaunchAgents;
dstSubfolderSpec = 0;
files = (
CE03A1192CEA83C6006884EE /* com.redhat.spice.vdagent.plist in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 1;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
CE03A08A2CE90065006884EE /* spice-vdagentd */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "spice-vdagentd"; sourceTree = BUILT_PRODUCTS_DIR; };
CE03A0A92CE900A0006884EE /* dummy-session-info.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = "dummy-session-info.c"; sourceTree = "<group>"; };
CE03A0AA2CE900A0006884EE /* session-info.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "session-info.h"; sourceTree = "<group>"; };
CE03A0AE2CE900A0006884EE /* vdagentd.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = vdagentd.c; sourceTree = "<group>"; };
CE03A0AF2CE900A0006884EE /* virtio-port.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "virtio-port.h"; sourceTree = "<group>"; };
CE03A0B02CE900A0006884EE /* virtio-port.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = "virtio-port.c"; sourceTree = "<group>"; };
CE03A0B42CE900A0006884EE /* config.h.in */ = {isa = PBXFileReference; lastKnownFileType = text; path = config.h.in; sourceTree = "<group>"; };
CE03A0B52CE900A0006884EE /* udscs.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = udscs.h; sourceTree = "<group>"; };
CE03A0B62CE900A0006884EE /* udscs.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = udscs.c; sourceTree = "<group>"; };
CE03A0B72CE900A0006884EE /* vdagent-connection.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "vdagent-connection.h"; sourceTree = "<group>"; };
CE03A0B82CE900A0006884EE /* vdagent-connection.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = "vdagent-connection.c"; sourceTree = "<group>"; };
CE03A0B92CE900A0006884EE /* vdagentd-proto.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "vdagentd-proto.h"; sourceTree = "<group>"; };
CE03A0BA2CE900A0006884EE /* vdagentd-proto-strings.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "vdagentd-proto-strings.h"; sourceTree = "<group>"; };
CE03A0BE2CE9036C006884EE /* config.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = config.h; sourceTree = "<group>"; };
CE03A0C52CE904C4006884EE /* libgio-2.0.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libgio-2.0.a"; path = "$(DERIVED_FILE_DIR)/lib/libgio-2.0.a"; sourceTree = "<absolute>"; };
CE03A0C62CE904C4006884EE /* libglib-2.0.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libglib-2.0.a"; path = "$(DERIVED_FILE_DIR)/lib/libglib-2.0.a"; sourceTree = "<absolute>"; };
CE03A0CB2CE904EA006884EE /* libgobject-2.0.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libgobject-2.0.a"; path = "$(DERIVED_FILE_DIR)/lib/libgobject-2.0.a"; sourceTree = "<absolute>"; };
CE03A0DD2CE90CE8006884EE /* spice-vdagent */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "spice-vdagent"; sourceTree = BUILT_PRODUCTS_DIR; };
CE03A0E42CE90CFC006884EE /* vdagent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = vdagent.h; sourceTree = "<group>"; };
CE03A0E52CE90CFC006884EE /* vdagent.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = vdagent.c; sourceTree = "<group>"; };
CE03A0E62CE90CFC006884EE /* Vdagent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Vdagent.swift; sourceTree = "<group>"; };
CE03A10C2CEA838C006884EE /* com.redhat.spice.vdagent.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = com.redhat.spice.vdagent.plist; sourceTree = "<group>"; };
CE03A10D2CEA838C006884EE /* com.redhat.spice.vdagentd.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = com.redhat.spice.vdagentd.plist; sourceTree = "<group>"; };
CE03A1232CEA8EF1006884EE /* libiconv.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libiconv.tbd; path = usr/lib/libiconv.tbd; sourceTree = SDKROOT; };
CE03A1242CEA8EF1006884EE /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; };
CE03A1252CEA8EF1006884EE /* libpcre2-8.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = "libpcre2-8.tbd"; path = "usr/lib/libpcre2-8.tbd"; sourceTree = SDKROOT; };
CE03A1292CEA8F18006884EE /* libffi.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libffi.tbd; path = usr/lib/libffi.tbd; sourceTree = SDKROOT; };
CE03A12B2CEA8F60006884EE /* libgmodule-2.0.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libgmodule-2.0.a"; path = "$(DERIVED_FILE_DIR)/lib/libgmodule-2.0.a"; sourceTree = "<group>"; };
CE03A12D2CEA8F75006884EE /* libintl.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libintl.a; path = "$(DERIVED_FILE_DIR)/lib/libintl.a"; sourceTree = "<group>"; };
CE03A12F2CEA8FBA006884EE /* libresolv.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libresolv.tbd; path = usr/lib/libresolv.tbd; sourceTree = SDKROOT; };
CE03A1312CEA8FCE006884EE /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
CE03A1332CEA8FE4006884EE /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
CE77170A2EC0000000A1B2C3 /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = System/Library/Frameworks/IOKit.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
CE03A0872CE90065006884EE /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
CE03A1342CEA8FE4006884EE /* AppKit.framework in Frameworks */,
CE03A1322CEA8FCE006884EE /* Foundation.framework in Frameworks */,
CE77170B2EC0000000A1B2C3 /* IOKit.framework in Frameworks */,
CE03A1302CEA8FBA006884EE /* libresolv.tbd in Frameworks */,
CE03A12E2CEA8F75006884EE /* libintl.a in Frameworks */,
CE03A12A2CEA8F18006884EE /* libffi.tbd in Frameworks */,
CE03A1262CEA8EF1006884EE /* libiconv.tbd in Frameworks */,
CE03A1272CEA8EF1006884EE /* libz.tbd in Frameworks */,
CE03A1282CEA8EF1006884EE /* libpcre2-8.tbd in Frameworks */,
CE03A0C82CE904D3006884EE /* libgio-2.0.a in Frameworks */,
CE03A0C92CE904D4006884EE /* libglib-2.0.a in Frameworks */,
CE03A0CC2CE90506006884EE /* libgobject-2.0.a in Frameworks */,
CE03A12C2CEA8F6A006884EE /* libgmodule-2.0.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
CE03A0DA2CE90CE8006884EE /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
CE03A0ED2CE90D55006884EE /* ArgumentParser in Frameworks */,
CE54BD8E2CEA90F200FE3930 /* AppKit.framework in Frameworks */,
CE54BD8F2CEA90F400FE3930 /* Foundation.framework in Frameworks */,
CE54BD912CEA90FD00FE3930 /* libintl.a in Frameworks */,
CE54BD922CEA910000FE3930 /* libresolv.tbd in Frameworks */,
CE54BD932CEA910200FE3930 /* libffi.tbd in Frameworks */,
CE54BD942CEA910600FE3930 /* libiconv.tbd in Frameworks */,
CE54BD952CEA910700FE3930 /* libpcre2-8.tbd in Frameworks */,
CE54BD962CEA910E00FE3930 /* libz.tbd in Frameworks */,
CE03A0EF2CE97931006884EE /* libgio-2.0.a in Frameworks */,
CE03A0F02CE97933006884EE /* libglib-2.0.a in Frameworks */,
CE54BD902CEA90F600FE3930 /* libgmodule-2.0.a in Frameworks */,
CE03A0F12CE97936006884EE /* libgobject-2.0.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
CE03A0812CE90065006884EE = {
isa = PBXGroup;
children = (
CE03A1162CEA838C006884EE /* data */,
CE03A0BB2CE900A0006884EE /* src */,
CE03A0C42CE904C4006884EE /* Frameworks */,
CE03A08B2CE90065006884EE /* Products */,
);
sourceTree = "<group>";
};
CE03A08B2CE90065006884EE /* Products */ = {
isa = PBXGroup;
children = (
CE03A08A2CE90065006884EE /* spice-vdagentd */,
CE03A0DD2CE90CE8006884EE /* spice-vdagent */,
);
name = Products;
sourceTree = "<group>";
};
CE03A0B32CE900A0006884EE /* vdagentd */ = {
isa = PBXGroup;
children = (
CE03A0A92CE900A0006884EE /* dummy-session-info.c */,
CE03A0AA2CE900A0006884EE /* session-info.h */,
CE03A0AE2CE900A0006884EE /* vdagentd.c */,
CE03A0AF2CE900A0006884EE /* virtio-port.h */,
CE03A0B02CE900A0006884EE /* virtio-port.c */,
);
path = vdagentd;
sourceTree = "<group>";
};
CE03A0BB2CE900A0006884EE /* src */ = {
isa = PBXGroup;
children = (
CE03A0BF2CE9036C006884EE /* darwin */,
CE03A0B32CE900A0006884EE /* vdagentd */,
CE03A0B42CE900A0006884EE /* config.h.in */,
CE03A0B52CE900A0006884EE /* udscs.h */,
CE03A0B62CE900A0006884EE /* udscs.c */,
CE03A0B72CE900A0006884EE /* vdagent-connection.h */,
CE03A0B82CE900A0006884EE /* vdagent-connection.c */,
CE03A0B92CE900A0006884EE /* vdagentd-proto.h */,
CE03A0BA2CE900A0006884EE /* vdagentd-proto-strings.h */,
);
path = src;
sourceTree = "<group>";
};
CE03A0BF2CE9036C006884EE /* darwin */ = {
isa = PBXGroup;
children = (
CE03A0E42CE90CFC006884EE /* vdagent.h */,
CE03A0E52CE90CFC006884EE /* vdagent.c */,
CE03A0E62CE90CFC006884EE /* Vdagent.swift */,
CE03A0C12CE903F0006884EE /* include */,
);
path = darwin;
sourceTree = "<group>";
};
CE03A0C12CE903F0006884EE /* include */ = {
isa = PBXGroup;
children = (
CE03A0BE2CE9036C006884EE /* config.h */,
);
path = include;
sourceTree = "<group>";
};
CE03A0C42CE904C4006884EE /* Frameworks */ = {
isa = PBXGroup;
children = (
CE03A1332CEA8FE4006884EE /* AppKit.framework */,
CE03A1312CEA8FCE006884EE /* Foundation.framework */,
CE77170A2EC0000000A1B2C3 /* IOKit.framework */,
CE03A12B2CEA8F60006884EE /* libgmodule-2.0.a */,
CE03A12D2CEA8F75006884EE /* libintl.a */,
CE03A12F2CEA8FBA006884EE /* libresolv.tbd */,
CE03A1292CEA8F18006884EE /* libffi.tbd */,
CE03A1232CEA8EF1006884EE /* libiconv.tbd */,
CE03A1252CEA8EF1006884EE /* libpcre2-8.tbd */,
CE03A1242CEA8EF1006884EE /* libz.tbd */,
CE03A0C52CE904C4006884EE /* libgio-2.0.a */,
CE03A0C62CE904C4006884EE /* libglib-2.0.a */,
CE03A0CB2CE904EA006884EE /* libgobject-2.0.a */,
);
name = Frameworks;
sourceTree = "<group>";
};
CE03A1162CEA838C006884EE /* data */ = {
isa = PBXGroup;
children = (
CE03A10C2CEA838C006884EE /* com.redhat.spice.vdagent.plist */,
CE03A10D2CEA838C006884EE /* com.redhat.spice.vdagentd.plist */,
);
path = data;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
CE03A0892CE90065006884EE /* spice-vdagentd */ = {
isa = PBXNativeTarget;
buildConfigurationList = CE03A0912CE90065006884EE /* Build configuration list for PBXNativeTarget "spice-vdagentd" */;
buildPhases = (
CE03A0F42CE9EDB0006884EE /* Fetch SPICE headers */,
CE03A1222CEA86DC006884EE /* Build universal GLib */,
CE03A0862CE90065006884EE /* Sources */,
CE03A0872CE90065006884EE /* Frameworks */,
CE03A0882CE90065006884EE /* CopyFiles */,
);
buildRules = (
);
dependencies = (
);
name = "spice-vdagentd";
packageProductDependencies = (
);
productName = vd_agent;
productReference = CE03A08A2CE90065006884EE /* spice-vdagentd */;
productType = "com.apple.product-type.tool";
};
CE03A0DC2CE90CE8006884EE /* spice-vdagent */ = {
isa = PBXNativeTarget;
buildConfigurationList = CE03A0E12CE90CE8006884EE /* Build configuration list for PBXNativeTarget "spice-vdagent" */;
buildPhases = (
CE54BD972CEA914E00FE3930 /* Build universal GLib */,
CE03A0D92CE90CE8006884EE /* Sources */,
CE03A0DA2CE90CE8006884EE /* Frameworks */,
CE03A1182CEA83C0006884EE /* CopyFiles */,
);
buildRules = (
);
dependencies = (
CE03A0F32CE9ED98006884EE /* PBXTargetDependency */,
);
name = "spice-vdagent";
packageProductDependencies = (
CE03A0EC2CE90D55006884EE /* ArgumentParser */,
);
productName = "spice-vdagent";
productReference = CE03A0DD2CE90CE8006884EE /* spice-vdagent */;
productType = "com.apple.product-type.tool";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
CE03A0822CE90065006884EE /* Project object */ = {
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1600;
LastUpgradeCheck = 1600;
TargetAttributes = {
CE03A0892CE90065006884EE = {
CreatedOnToolsVersion = 16.0;
};
CE03A0DC2CE90CE8006884EE = {
CreatedOnToolsVersion = 16.0;
LastSwiftMigration = 1600;
};
CE03A11A2CEA8429006884EE = {
CreatedOnToolsVersion = 16.0;
};
};
};
buildConfigurationList = CE03A0852CE90065006884EE /* Build configuration list for PBXProject "vd_agent" */;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = CE03A0812CE90065006884EE;
minimizedProjectReferenceProxies = 1;
packageReferences = (
CE03A0EB2CE90D55006884EE /* XCRemoteSwiftPackageReference "swift-argument-parser" */,
);
preferredProjectObjectVersion = 77;
productRefGroup = CE03A08B2CE90065006884EE /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
CE03A11A2CEA8429006884EE /* vd_agent */,
CE03A0892CE90065006884EE /* spice-vdagentd */,
CE03A0DC2CE90CE8006884EE /* spice-vdagent */,
);
};
/* End PBXProject section */
/* Begin PBXShellScriptBuildPhase section */
CE03A0F42CE9EDB0006884EE /* Fetch SPICE headers */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = "Fetch SPICE headers";
outputFileListPaths = (
);
outputPaths = (
"$(PROJECT_DIR)/src/darwin/include/spice",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "set -e\nif [ ! -d \"$SCRIPT_OUTPUT_FILE_0\" ]; then\n URL=\"https://www.spice-space.org/download/releases/spice-protocol-0.14.4.tar.xz\"\n FILE=\"$(basename $URL)\"\n NAME=\"${FILE%.tar.*}\"\n cd /tmp\n curl -L -O \"$URL\"\n tar -xf \"$FILE\"\n mv \"$NAME/spice\" \"$SCRIPT_OUTPUT_FILE_0\"\n rm -rf \"$DIR\" \"$FILE\"\nfi\n";
showEnvVarsInLog = 0;
};
CE03A1222CEA86DC006884EE /* Build universal GLib */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"$(GLIB_X86_64_PREFIX)/lib/libgio-2.0.a",
"$(GLIB_X86_64_PREFIX)/lib/libglib-2.0.a",
"$(GLIB_X86_64_PREFIX)/lib/libgobject-2.0.a",
"$(GLIB_X86_64_PREFIX)/lib/libgmodule-2.0.a",
"$(GLIB_X86_64_PREFIX)/lib/libintl.a",
"$(GLIB_ARM64_PREFIX)/lib/libgio-2.0.a",
"$(GLIB_ARM64_PREFIX)/lib/libglib-2.0.a",
"$(GLIB_ARM64_PREFIX)/lib/libgobject-2.0.a",
"$(GLIB_ARM64_PREFIX)/lib/libgmodule-2.0.a",
"$(GLIB_ARM64_PREFIX)/lib/libintl.a",
);
name = "Build universal GLib";
outputFileListPaths = (
);
outputPaths = (
"$(DERIVED_FILE_DIR)/lib/libgio-2.0.a",
"$(DERIVED_FILE_DIR)/lib/libglib-2.0.a",
"$(DERIVED_FILE_DIR)/lib/libgobject-2.0.a",
"$(DERIVED_FILE_DIR)/lib/libgmodule-2.0.a",
"$(DERIVED_FILE_DIR)/lib/libintl.a",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "set -e\n\nfor ((i=0; i<$SCRIPT_OUTPUT_FILE_COUNT; i++)); do\n output_var=\"SCRIPT_OUTPUT_FILE_$i\"\n output_path=\"${!output_var}\"\n output_dir=\"$(dirname \"$output_path\")\"\n name=\"$(basename \"$output_path\")\"\n intel_input=\"$GLIB_X86_64_PREFIX/lib/$name\"\n arm64_input=\"$GLIB_ARM64_PREFIX/lib/$name\"\n tmp_output=\"/tmp/$name.$$\"\n \n echo \"Creating $output_path\"\n lipo -output \"$tmp_output\" -create \"$intel_input\" \"$arm64_input\"\n if [ ! -d \"$output_dir\" ]; then\n mkdir -p \"$output_dir\"\n fi\n mv \"$tmp_output\" \"$output_path\"\ndone\n";
showEnvVarsInLog = 0;
};
CE54BD972CEA914E00FE3930 /* Build universal GLib */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"$(GLIB_X86_64_PREFIX)/lib/libgio-2.0.a",
"$(GLIB_X86_64_PREFIX)/lib/libglib-2.0.a",
"$(GLIB_X86_64_PREFIX)/lib/libgobject-2.0.a",
"$(GLIB_X86_64_PREFIX)/lib/libgmodule-2.0.a",
"$(GLIB_X86_64_PREFIX)/lib/libintl.a",
"$(GLIB_ARM64_PREFIX)/lib/libgio-2.0.a",
"$(GLIB_ARM64_PREFIX)/lib/libglib-2.0.a",
"$(GLIB_ARM64_PREFIX)/lib/libgobject-2.0.a",
"$(GLIB_ARM64_PREFIX)/lib/libgmodule-2.0.a",
"$(GLIB_ARM64_PREFIX)/lib/libintl.a",
);
name = "Build universal GLib";
outputFileListPaths = (
);
outputPaths = (
"$(DERIVED_FILE_DIR)/lib/libgio-2.0.a",
"$(DERIVED_FILE_DIR)/lib/libglib-2.0.a",
"$(DERIVED_FILE_DIR)/lib/libgobject-2.0.a",
"$(DERIVED_FILE_DIR)/lib/libgmodule-2.0.a",
"$(DERIVED_FILE_DIR)/lib/libintl.a",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "set -e\n\nfor ((i=0; i<$SCRIPT_OUTPUT_FILE_COUNT; i++)); do\n output_var=\"SCRIPT_OUTPUT_FILE_$i\"\n output_path=\"${!output_var}\"\n output_dir=\"$(dirname \"$output_path\")\"\n name=\"$(basename \"$output_path\")\"\n intel_input=\"$GLIB_X86_64_PREFIX/lib/$name\"\n arm64_input=\"$GLIB_ARM64_PREFIX/lib/$name\"\n tmp_output=\"/tmp/$name.$$\"\n \n echo \"Creating $output_path\"\n lipo -output \"$tmp_output\" -create \"$intel_input\" \"$arm64_input\"\n if [ ! -d \"$output_dir\" ]; then\n mkdir -p \"$output_dir\"\n fi\n mv \"$tmp_output\" \"$output_path\"\ndone\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
CE03A0862CE90065006884EE /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
CE03A0BC2CE9012D006884EE /* udscs.c in Sources */,
CE03A0C22CE90428006884EE /* virtio-port.c in Sources */,
CE03A0C32CE90428006884EE /* vdagentd.c in Sources */,
CE03A0BD2CE9012D006884EE /* vdagent-connection.c in Sources */,
CE03A0C02CE9039B006884EE /* dummy-session-info.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
CE03A0D92CE90CE8006884EE /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
CE03A0EA2CE90D38006884EE /* udscs.c in Sources */,
CE03A0E72CE90CFC006884EE /* Vdagent.swift in Sources */,
CE03A0E82CE90CFC006884EE /* vdagent.c in Sources */,
CE03A0EE2CE97927006884EE /* vdagent-connection.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXTargetDependency section */
CE03A0F32CE9ED98006884EE /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = CE03A0892CE90065006884EE /* spice-vdagentd */;
targetProxy = CE03A0F22CE9ED98006884EE /* PBXContainerItemProxy */;
};
CE03A11F2CEA8442006884EE /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = CE03A0DC2CE90CE8006884EE /* spice-vdagent */;
targetProxy = CE03A11E2CEA8442006884EE /* PBXContainerItemProxy */;
};
CE03A1212CEA8442006884EE /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = CE03A0892CE90065006884EE /* spice-vdagentd */;
targetProxy = CE03A1202CEA8442006884EE /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */
/* Begin XCBuildConfiguration section */
CE03A08F2CE90065006884EE /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu17;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
GLIB_ARM64_PREFIX = /opt/homebrew;
GLIB_X86_64_PREFIX = /usr/local;
HEADER_SEARCH_PATHS = (
"$(PROJECT_DIR)/src/darwin/include",
"$(GLIB_ARM64_PREFIX)/include/glib-2.0",
"$(GLIB_ARM64_PREFIX)/include/gio-unix-2.0",
"$(GLIB_ARM64_PREFIX)/lib/glib-2.0/include",
);
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(DERIVED_FILE_DIR)/lib",
);
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = macosx;
};
name = Debug;
};
CE03A0902CE90065006884EE /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_HARDENED_RUNTIME = YES;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
GCC_C_LANGUAGE_STANDARD = gnu17;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
GLIB_ARM64_PREFIX = /opt/homebrew;
GLIB_X86_64_PREFIX = /usr/local;
HEADER_SEARCH_PATHS = (
"$(PROJECT_DIR)/src/darwin/include",
"$(GLIB_ARM64_PREFIX)/include/glib-2.0",
"$(GLIB_ARM64_PREFIX)/include/gio-unix-2.0",
"$(GLIB_ARM64_PREFIX)/lib/glib-2.0/include",
);
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(DERIVED_FILE_DIR)/lib",
);
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = macosx;
};
name = Release;
};
CE03A0922CE90065006884EE /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
};
CE03A0932CE90065006884EE /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
};
CE03A0E22CE90CE8006884EE /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/$(DERIVED_FILE_DIR)/lib",
);
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
SWIFT_OBJC_BRIDGING_HEADER = src/darwin/vdagent.h;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
};
name = Debug;
};
CE03A0E32CE90CE8006884EE /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/$(DERIVED_FILE_DIR)/lib",
);
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OBJC_BRIDGING_HEADER = src/darwin/vdagent.h;
SWIFT_VERSION = 5.0;
};
name = Release;
};
CE03A11C2CEA8429006884EE /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
};
CE03A11D2CEA8429006884EE /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
CE03A0852CE90065006884EE /* Build configuration list for PBXProject "vd_agent" */ = {
isa = XCConfigurationList;
buildConfigurations = (
CE03A08F2CE90065006884EE /* Debug */,
CE03A0902CE90065006884EE /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
CE03A0912CE90065006884EE /* Build configuration list for PBXNativeTarget "spice-vdagentd" */ = {
isa = XCConfigurationList;
buildConfigurations = (
CE03A0922CE90065006884EE /* Debug */,
CE03A0932CE90065006884EE /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
CE03A0E12CE90CE8006884EE /* Build configuration list for PBXNativeTarget "spice-vdagent" */ = {
isa = XCConfigurationList;
buildConfigurations = (
CE03A0E22CE90CE8006884EE /* Debug */,
CE03A0E32CE90CE8006884EE /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
CE03A11B2CEA8429006884EE /* Build configuration list for PBXAggregateTarget "vd_agent" */ = {
isa = XCConfigurationList;
buildConfigurations = (
CE03A11C2CEA8429006884EE /* Debug */,
CE03A11D2CEA8429006884EE /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
/* Begin XCRemoteSwiftPackageReference section */
CE03A0EB2CE90D55006884EE /* XCRemoteSwiftPackageReference "swift-argument-parser" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/apple/swift-argument-parser.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 1.5.0;
};
};
/* End XCRemoteSwiftPackageReference section */
/* Begin XCSwiftPackageProductDependency section */
CE03A0EC2CE90D55006884EE /* ArgumentParser */ = {
isa = XCSwiftPackageProductDependency;
package = CE03A0EB2CE90D55006884EE /* XCRemoteSwiftPackageReference "swift-argument-parser" */;
productName = ArgumentParser;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = CE03A0822CE90065006884EE /* Project object */;
}
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:">
</FileRef>
</Workspace>
@@ -0,0 +1,15 @@
{
"originHash" : "59ba1edda695b389d6c9ac1809891cd779e4024f505b0ce1a9d5202b6762e38a",
"pins" : [
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser.git",
"state" : {
"revision" : "41982a3656a71c768319979febd796c6fd111d5c",
"version" : "1.5.0"
}
}
],
"version" : 3
}
@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1600"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CE03A0DC2CE90CE8006884EE"
BuildableName = "spice-vdagent"
BlueprintName = "spice-vdagent"
ReferencedContainer = "container:vd_agent.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES"
viewDebuggingEnabled = "No">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CE03A0DC2CE90CE8006884EE"
BuildableName = "spice-vdagent"
BlueprintName = "spice-vdagent"
ReferencedContainer = "container:vd_agent.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "-d"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "-x"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "-S /var/run/spice-vdagent-sock"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CE03A0DC2CE90CE8006884EE"
BuildableName = "spice-vdagent"
BlueprintName = "spice-vdagent"
ReferencedContainer = "container:vd_agent.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
@@ -0,0 +1,98 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1600"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
buildArchitectures = "Automatic">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CE03A0892CE90065006884EE"
BuildableName = "spice-vdagentd"
BlueprintName = "spice-vdagentd"
ReferencedContainer = "container:vd_agent.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
debugAsWhichUser = "root"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES"
viewDebuggingEnabled = "No">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CE03A0892CE90065006884EE"
BuildableName = "spice-vdagentd"
BlueprintName = "spice-vdagentd"
ReferencedContainer = "container:vd_agent.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "-d"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "-s /dev/tty.com.redhat.spice.0"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "-S /var/run/spice-vdagent-sock"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "-x"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CE03A0892CE90065006884EE"
BuildableName = "spice-vdagentd"
BlueprintName = "spice-vdagentd"
ReferencedContainer = "container:vd_agent.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>