mirror of
https://github.com/utmapp/vd_agent.git
synced 2026-12-01 14:02:07 -10:00
Compare commits
97
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b0b83b7f07 | ||
|
|
03ff810185 | ||
|
|
948db07d95 | ||
|
|
7a9d859399 | ||
|
|
07005a1b0e | ||
|
|
37a74cf356 | ||
|
|
15e4c3b63f | ||
|
|
5ccfc993f4 | ||
|
|
9070c8ba4d | ||
|
|
e4d0eea961 | ||
|
|
c729770965 | ||
|
|
38460ed519 | ||
|
|
684267abcb | ||
|
|
b788a2456c | ||
|
|
ee9ac60ad6 | ||
|
|
47e2539467 | ||
|
|
712c9ed7a6 | ||
|
|
a395da3eeb | ||
|
|
553cb85f10 | ||
|
|
a3c361d829 | ||
|
|
aa08162f03 | ||
|
|
bcbbea34d9 | ||
|
|
ed08813fcd | ||
|
|
a9bb1752ce | ||
|
|
0717474fec | ||
|
|
2289931e94 | ||
|
|
67090358b3 | ||
|
|
09de02fd5c | ||
|
|
1aa2c06015 | ||
|
|
8440e6010d | ||
|
|
3cd58713c9 | ||
|
|
67f3f3ed35 | ||
|
|
8348ef3c61 | ||
|
|
0105b280cb | ||
|
|
9306f18621 | ||
|
|
58d97554e5 | ||
|
|
73bf836726 | ||
|
|
21d355974f | ||
|
|
9750013f0e | ||
|
|
1d40f0e967 | ||
|
|
aa792598ea | ||
|
|
396c2b2c7d | ||
|
|
8bffaaf3e5 | ||
|
|
5094d5cfe6 | ||
|
|
b7db1c20c9 | ||
|
|
e4bfd1b632 | ||
|
|
812ca77746 | ||
|
|
5c50131797 | ||
|
|
51c415df82 | ||
|
|
91caa92238 | ||
|
|
9d35d8a86f | ||
|
|
1a8b93ca6a | ||
|
|
ce144335ff | ||
|
|
5a2471e24e | ||
|
|
0c5b8fac09 | ||
|
|
8698e1e5cc | ||
|
|
aab670b3b7 | ||
|
|
e73e330e99 | ||
|
|
9574a4299f | ||
|
|
5ab5fe3475 | ||
|
|
6c475b368d | ||
|
|
4c80090681 | ||
|
|
d92f37ae06 | ||
|
|
f59192a021 | ||
|
|
6e5e6c2ca6 | ||
|
|
8c4137de70 | ||
|
|
09733a5c81 | ||
|
|
2e2feeb93b | ||
|
|
0da3211f63 | ||
|
|
1f4a994ff1 | ||
|
|
253539275a | ||
|
|
f30becd21f | ||
|
|
7e924bcbf0 | ||
|
|
b894975bed | ||
|
|
b4479eb9b0 | ||
|
|
9f768c6037 | ||
|
|
4983eb1f42 | ||
|
|
7e37b05774 | ||
|
|
27805752fe | ||
|
|
ca4dd7e811 | ||
|
|
65f64b805b | ||
|
|
87c031a6a8 | ||
|
|
ffba3a0e2d | ||
|
|
a5932875c2 | ||
|
|
a020b8e925 | ||
|
|
ef54256abf | ||
|
|
1601f4de95 | ||
|
|
aa75e9d792 | ||
|
|
2f025381f8 | ||
|
|
98f05ec1fe | ||
|
|
9721c99396 | ||
|
|
8adf50de9a | ||
|
|
d0b5f80ada | ||
|
|
5654f4d2f9 | ||
|
|
eeb5620260 | ||
|
|
7b0435ef66 | ||
|
|
9b8c0ebb9f |
No files matched your search
@@ -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
|
||||
+21
-3
@@ -5,7 +5,10 @@ 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
|
||||
@@ -17,8 +20,10 @@ 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
|
||||
@@ -38,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
|
||||
+29
-7
@@ -1,7 +1,29 @@
|
||||
Gitlab markdown format support linking to Issues (#) and Merge requests (!) and more, see bellow:
|
||||
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
|
||||
============================
|
||||
|
||||
@@ -71,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
|
||||
============================
|
||||
@@ -95,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:
|
||||
@@ -109,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
|
||||
@@ -143,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
|
||||
===========================
|
||||
|
||||
+36
-3
@@ -41,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 \
|
||||
@@ -105,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
|
||||
@@ -124,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
|
||||
@@ -138,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
|
||||
|
||||
@@ -156,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 \
|
||||
@@ -171,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
|
||||
@@ -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,7 +29,16 @@ Features:
|
||||
* Limited support for setups with multiple Screens (multiple qxl devices each
|
||||
mapped to their own screen)
|
||||
|
||||
## Install
|
||||
### 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.
|
||||
@@ -38,6 +49,37 @@ For example, if you’re running a Debian/Ubuntu derivative in a VM, use:
|
||||
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
|
||||
@@ -53,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:
|
||||
|
||||
|
||||
+32
-6
@@ -1,5 +1,5 @@
|
||||
AC_PREREQ(2.59)
|
||||
AC_INIT([spice-vdagent], [0.20.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.22], [
|
||||
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],
|
||||
@@ -102,11 +121,15 @@ AC_ARG_ENABLE([static-uinput],
|
||||
|
||||
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.1])
|
||||
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@:>@]),
|
||||
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
Executable
+12
@@ -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
|
||||
@@ -7,3 +7,4 @@ Type=Application
|
||||
Categories=
|
||||
X-GNOME-Autostart-Phase=WindowManager
|
||||
NoDisplay=true
|
||||
X-systemd-skip=true
|
||||
@@ -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,5 +1,6 @@
|
||||
[Unit]
|
||||
Description=Agent daemon for Spice guests
|
||||
Documentation=man:spice-vdagentd(1)
|
||||
After=dbus.target
|
||||
Requires=spice-vdagentd.socket
|
||||
|
||||
|
||||
Executable
+49
@@ -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"
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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
|
||||
@@ -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(¶ms->mutex);
|
||||
params->is_done = TRUE;
|
||||
g_cond_signal(¶ms->cond);
|
||||
g_mutex_unlock(¶ms->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(¶ms.mutex);
|
||||
g_cond_init(¶ms.cond);
|
||||
g_mutex_lock(¶ms.mutex);
|
||||
g_main_context_invoke(NULL, _vdagent_write_cb, ¶ms);
|
||||
while (!params.is_done) {
|
||||
g_cond_wait(¶ms.cond, ¶ms.mutex);
|
||||
}
|
||||
g_mutex_unlock(¶ms.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);
|
||||
}
|
||||
@@ -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 */
|
||||
+22
-6
@@ -30,6 +30,12 @@
|
||||
#include "vdagentd-proto-strings.h"
|
||||
#include "vdagent-connection.h"
|
||||
|
||||
// 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 _UdscsConnection {
|
||||
VDAgentConnection parent_instance;
|
||||
int debug;
|
||||
@@ -101,16 +107,14 @@ static void udscs_connection_class_init(UdscsConnectionClass *klass)
|
||||
UdscsConnection *udscs_connect(const char *socketname,
|
||||
udscs_read_callback read_callback,
|
||||
VDAgentConnErrorCb error_cb,
|
||||
int debug)
|
||||
int debug,
|
||||
GError **err)
|
||||
{
|
||||
GIOStream *io_stream;
|
||||
UdscsConnection *conn;
|
||||
GError *err = NULL;
|
||||
|
||||
io_stream = vdagent_socket_connect(socketname, &err);
|
||||
if (err) {
|
||||
syslog(LOG_ERR, "%s: %s", __func__, err->message);
|
||||
g_error_free(err);
|
||||
io_stream = vdagent_socket_connect(socketname, err);
|
||||
if (*err) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -186,6 +190,7 @@ struct udscs_server *udscs_server_new(
|
||||
server->read_callback = read_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);
|
||||
@@ -223,6 +228,11 @@ void udscs_server_listen_to_address(struct udscs_server *server,
|
||||
g_object_unref(sock_addr);
|
||||
}
|
||||
|
||||
void udscs_server_start(struct udscs_server *server)
|
||||
{
|
||||
g_socket_service_start(server->service);
|
||||
}
|
||||
|
||||
void udscs_server_destroy_connection(struct udscs_server *server,
|
||||
UdscsConnection *conn)
|
||||
{
|
||||
@@ -248,6 +258,12 @@ static gboolean udscs_server_accept_cb(GSocketService *service,
|
||||
struct udscs_server *server = user_data;
|
||||
UdscsConnection *new_conn;
|
||||
|
||||
/* 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_object_new(UDSCS_TYPE_CONNECTION, NULL);
|
||||
new_conn->debug = server->debug;
|
||||
new_conn->read_callback = server->read_callback;
|
||||
|
||||
+6
-1
@@ -53,11 +53,14 @@ typedef void (*udscs_read_callback)(UdscsConnection *conn,
|
||||
*
|
||||
* If debug is true then the events on this connection will be traced.
|
||||
* This includes the incoming and outgoing message names.
|
||||
*
|
||||
* In case of failure, returns NULL and set @err with reason.
|
||||
*/
|
||||
UdscsConnection *udscs_connect(const char *socketname,
|
||||
udscs_read_callback read_callback,
|
||||
VDAgentConnErrorCb error_cb,
|
||||
int debug);
|
||||
int debug,
|
||||
GError **err);
|
||||
|
||||
/* Queue a message for delivery to the client connected through conn.
|
||||
*/
|
||||
@@ -98,6 +101,8 @@ 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);
|
||||
|
||||
|
||||
+10
-13
@@ -142,24 +142,25 @@ void vdagent_connection_destroy(gpointer p)
|
||||
g_object_unref(self);
|
||||
}
|
||||
|
||||
gint vdagent_connection_get_peer_pid(VDAgentConnection *self,
|
||||
GError **err)
|
||||
PidUid vdagent_connection_get_peer_pid_uid(VDAgentConnection *self,
|
||||
GError **err)
|
||||
{
|
||||
VDAgentConnectionPrivate *priv = vdagent_connection_get_instance_private(self);
|
||||
GSocket *sock;
|
||||
GCredentials *cred;
|
||||
gint pid = -1;
|
||||
PidUid pid_uid = { -1, -1 };
|
||||
|
||||
g_return_val_if_fail(G_IS_SOCKET_CONNECTION(priv->io_stream), pid);
|
||||
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 = g_credentials_get_unix_pid(cred, NULL);
|
||||
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;
|
||||
return pid_uid;
|
||||
}
|
||||
|
||||
/* Performs single write operation,
|
||||
@@ -210,11 +211,7 @@ static gboolean do_write(VDAgentConnection *self, gboolean block)
|
||||
static gboolean out_stream_ready_cb(GObject *pollable_stream,
|
||||
gpointer user_data)
|
||||
{
|
||||
if (do_write(user_data, FALSE)) {
|
||||
return TRUE;
|
||||
}
|
||||
g_object_unref(user_data);
|
||||
return FALSE;
|
||||
return do_write(user_data, FALSE);
|
||||
}
|
||||
|
||||
void vdagent_connection_write(VDAgentConnection *self,
|
||||
@@ -231,8 +228,8 @@ void vdagent_connection_write(VDAgentConnection *self,
|
||||
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, G_SOURCE_FUNC(out_stream_ready_cb),
|
||||
g_object_ref(self), NULL);
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ G_BEGIN_DECLS
|
||||
#define VDAGENT_TYPE_CONNECTION vdagent_connection_get_type()
|
||||
G_DECLARE_DERIVABLE_TYPE(VDAgentConnection, vdagent_connection, VDAGENT, CONNECTION, GObject)
|
||||
|
||||
/* Sublasses of VDAgentConnection must implement
|
||||
/* Subclasses of VDAgentConnection must implement
|
||||
* handle_header and handle_message. */
|
||||
struct _VDAgentConnectionClass {
|
||||
GObjectClass parent_class;
|
||||
@@ -92,10 +92,15 @@ void vdagent_connection_write(VDAgentConnection *self,
|
||||
/* Synchronously write all queued messages to the output stream. */
|
||||
void vdagent_connection_flush(VDAgentConnection *self);
|
||||
|
||||
/* Returns the PID of the foreign process connected to the socket
|
||||
* or -1 with @err set. */
|
||||
gint vdagent_connection_get_peer_pid(VDAgentConnection *self,
|
||||
GError **err);
|
||||
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
|
||||
|
||||
|
||||
+22
-22
@@ -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");
|
||||
|
||||
+14
-12
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
#include <config.h>
|
||||
|
||||
#ifdef WITH_GTK
|
||||
#ifdef USE_GTK_FOR_CLIPBOARD
|
||||
# include <gtk/gtk.h>
|
||||
# include <syslog.h>
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
#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)
|
||||
@@ -79,9 +79,9 @@ typedef struct {
|
||||
struct _VDAgentClipboards {
|
||||
GObject parent;
|
||||
|
||||
#ifdef USE_GTK_FOR_CLIPBOARD
|
||||
UdscsConnection *conn;
|
||||
|
||||
#ifdef WITH_GTK
|
||||
Selection selections[SELECTION_COUNT];
|
||||
#else
|
||||
struct vdagent_x11 *x11;
|
||||
@@ -95,7 +95,7 @@ struct _VDAgentClipboardsClass
|
||||
|
||||
G_DEFINE_TYPE(VDAgentClipboards, vdagent_clipboards, G_TYPE_OBJECT)
|
||||
|
||||
#ifdef WITH_GTK
|
||||
#ifdef USE_GTK_FOR_CLIPBOARD
|
||||
static const struct {
|
||||
guint type;
|
||||
const gchar *atom_name;
|
||||
@@ -281,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);
|
||||
@@ -329,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)];
|
||||
@@ -373,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);
|
||||
@@ -403,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);
|
||||
@@ -417,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;
|
||||
@@ -435,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;
|
||||
@@ -474,7 +474,7 @@ VDAgentClipboards *vdagent_clipboards_new(struct vdagent_x11 *x11)
|
||||
{
|
||||
VDAgentClipboards *self = g_object_new(VDAGENT_TYPE_CLIPBOARDS, NULL);
|
||||
|
||||
#ifndef WITH_GTK
|
||||
#ifndef USE_GTK_FOR_CLIPBOARD
|
||||
self->x11 = x11;
|
||||
#else
|
||||
guint sel_id;
|
||||
@@ -493,12 +493,14 @@ VDAgentClipboards *vdagent_clipboards_new(struct vdagent_x11 *x11)
|
||||
void
|
||||
vdagent_clipboards_set_conn(VDAgentClipboards *self, UdscsConnection *conn)
|
||||
{
|
||||
#ifdef USE_GTK_FOR_CLIPBOARD
|
||||
self->conn = conn;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void vdagent_clipboards_dispose(GObject *obj)
|
||||
{
|
||||
#ifdef WITH_GTK
|
||||
#ifdef USE_GTK_FOR_CLIPBOARD
|
||||
VDAgentClipboards *self = VDAGENT_CLIPBOARDS(obj);
|
||||
guint sel_id;
|
||||
|
||||
|
||||
+85
-70
@@ -332,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;
|
||||
@@ -388,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) {
|
||||
@@ -401,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;
|
||||
@@ -412,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) {
|
||||
@@ -493,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
|
||||
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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_ */
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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_ */
|
||||
+51
-32
@@ -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;
|
||||
UdscsConnection *conn;
|
||||
GIOChannel *x11_channel;
|
||||
gint udscs_num_retry;
|
||||
|
||||
GMainLoop *loop;
|
||||
} VDAgent;
|
||||
@@ -114,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);
|
||||
}
|
||||
@@ -144,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,
|
||||
@@ -179,7 +181,7 @@ static void daemon_read_complete(UdscsConnection *conn,
|
||||
|
||||
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);
|
||||
@@ -229,7 +231,7 @@ static void daemon_read_complete(UdscsConnection *conn,
|
||||
break;
|
||||
case VDAGENTD_AUDIO_VOLUME_SYNC: {
|
||||
VDAgentAudioVolumeSync *avs = (VDAgentAudioVolumeSync *)data;
|
||||
uint16_t *volume = g_memdup(avs->volume, sizeof(uint16_t) * avs->nchannels);
|
||||
uint16_t *volume = g_memdup2(avs->volume, sizeof(uint16_t) * avs->nchannels);
|
||||
|
||||
if (avs->is_playback) {
|
||||
vdagent_audio_playback_sync(avs->mute, avs->nchannels, volume);
|
||||
@@ -249,7 +251,7 @@ static void daemon_read_complete(UdscsConnection *conn,
|
||||
}
|
||||
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);
|
||||
@@ -335,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)
|
||||
{
|
||||
@@ -369,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);
|
||||
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);
|
||||
}
|
||||
@@ -383,32 +376,49 @@ 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_error_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;
|
||||
}
|
||||
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_new(agent->x11);
|
||||
agent->clipboards = vdagent_clipboards_new(vdagent_display_get_x11(agent->display));
|
||||
vdagent_clipboards_set_conn(agent->clipboards, agent->conn);
|
||||
|
||||
if (parent_socket != -1) {
|
||||
@@ -431,7 +441,7 @@ 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);
|
||||
@@ -440,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);
|
||||
@@ -463,7 +475,7 @@ 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;
|
||||
}
|
||||
@@ -474,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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
+26
-7
@@ -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];
|
||||
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,14 +156,18 @@ 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,
|
||||
|
||||
+85
-93
@@ -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,8 +530,9 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -533,7 +541,7 @@ int vdagent_x11_randr_handle_event(struct vdagent_x11 *x11,
|
||||
{
|
||||
int handled = TRUE;
|
||||
|
||||
switch (event->type - x11->xrandr_event_base) {
|
||||
switch (event->type - x11->randr.event_base) {
|
||||
case RRScreenChangeNotify: {
|
||||
const XRRScreenChangeNotifyEvent *sce =
|
||||
(const XRRScreenChangeNotifyEvent *) event;
|
||||
@@ -542,9 +550,11 @@ int vdagent_x11_randr_handle_event(struct vdagent_x11 *x11,
|
||||
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:
|
||||
@@ -778,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)
|
||||
@@ -1004,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;
|
||||
}
|
||||
}
|
||||
@@ -1054,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);
|
||||
@@ -1088,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;
|
||||
@@ -1104,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;
|
||||
|
||||
@@ -1119,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,
|
||||
@@ -1130,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++) {
|
||||
@@ -1139,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);
|
||||
}
|
||||
}
|
||||
@@ -1151,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;
|
||||
}
|
||||
+183
-111
@@ -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,7 +62,7 @@
|
||||
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,
|
||||
const XEvent *event, int incr);
|
||||
static void vdagent_x11_handle_selection_request(struct vdagent_x11 *x11);
|
||||
@@ -69,6 +74,7 @@ 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(UdscsConnection *vdagentd,
|
||||
int debug, int sync)
|
||||
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(UdscsConnection *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(UdscsConnection *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(UdscsConnection *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(UdscsConnection *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(UdscsConnection *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;
|
||||
@@ -436,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 */
|
||||
@@ -496,7 +484,7 @@ static int vdagent_x11_get_clipboard_selection(struct vdagent_x11 *x11,
|
||||
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) {
|
||||
@@ -562,7 +550,7 @@ static void vdagent_x11_handle_event(struct vdagent_x11 *x11, const XEvent *even
|
||||
/* 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);
|
||||
@@ -639,13 +627,27 @@ void vdagent_x11_do_read(struct vdagent_x11 *x11)
|
||||
}
|
||||
}
|
||||
|
||||
#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, const XEvent *event,
|
||||
@@ -800,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;
|
||||
@@ -969,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) {
|
||||
@@ -1030,6 +1048,11 @@ static void vdagent_x11_send_targets(struct vdagent_x11 *x11,
|
||||
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])
|
||||
@@ -1116,6 +1139,17 @@ 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);
|
||||
}
|
||||
@@ -1250,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] =
|
||||
@@ -1259,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;
|
||||
|
||||
@@ -1303,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 */
|
||||
@@ -1387,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;
|
||||
}
|
||||
+6
-3
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
@@ -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);
|
||||
@@ -392,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;
|
||||
}
|
||||
@@ -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 },
|
||||
|
||||
+267
-62
@@ -23,6 +23,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
@@ -32,6 +33,10 @@
|
||||
#include <sys/stat.h>
|
||||
#include <spice/vd_agent.h>
|
||||
#include <glib-unix.h>
|
||||
#ifdef __APPLE__
|
||||
#include <dispatch/dispatch.h>
|
||||
#include <IOKit/IOKitLib.h>
|
||||
#endif
|
||||
|
||||
#ifdef WITH_SYSTEMD_SOCKET_ACTIVATION
|
||||
#include <systemd/sd-daemon.h>
|
||||
@@ -46,6 +51,14 @@
|
||||
|
||||
#define DEFAULT_UINPUT_DEVICE "/dev/uinput"
|
||||
|
||||
// Maximum number of transfers active at any time.
|
||||
// Avoid DoS from client.
|
||||
// As each transfer could likely end up taking a file descriptor
|
||||
// it is good to have a limit less than the number of file descriptors
|
||||
// in the process (by default 1024). The daemon do not open file
|
||||
// descriptors for the transfers but the agents do.
|
||||
#define MAX_ACTIVE_TRANSFERS 128
|
||||
|
||||
struct agent_data {
|
||||
char *session;
|
||||
int width;
|
||||
@@ -54,9 +67,9 @@ struct agent_data {
|
||||
int screen_count;
|
||||
};
|
||||
|
||||
/* variables */
|
||||
static const char *pidfilename = "/run/spice-vdagentd/spice-vdagentd.pid";
|
||||
static const char pidfilename[] = "/run/spice-vdagentd/spice-vdagentd.pid";
|
||||
|
||||
/* variables */
|
||||
static gchar *portdev = NULL;
|
||||
static gchar *vdagentd_socket = NULL;
|
||||
static gchar *uinput_device = NULL;
|
||||
@@ -77,14 +90,23 @@ static int capabilities_size = 0;
|
||||
static const char *active_session = NULL;
|
||||
static unsigned int session_count = 0;
|
||||
static UdscsConnection *active_session_conn = NULL;
|
||||
static int agent_owns_clipboard[256] = { 0, };
|
||||
static bool agent_owns_clipboard[256] = { false, };
|
||||
static int retval = 0;
|
||||
static int client_connected = 0;
|
||||
static bool client_connected = false;
|
||||
static int max_clipboard = -1;
|
||||
static uint32_t clipboard_serial[256];
|
||||
|
||||
static GMainLoop *loop;
|
||||
|
||||
static void update_active_session_connection(UdscsConnection *new_conn);
|
||||
|
||||
static void agent_data_destroy(struct agent_data *agent_data)
|
||||
{
|
||||
g_free(agent_data->session);
|
||||
g_free(agent_data->screen_info);
|
||||
g_free(agent_data);
|
||||
}
|
||||
|
||||
static void vdagentd_quit(gint exit_code)
|
||||
{
|
||||
retval = exit_code;
|
||||
@@ -130,8 +152,10 @@ static void send_capabilities(VirtioPort *vport,
|
||||
size = sizeof(*caps) + VD_AGENT_CAPS_BYTES;
|
||||
caps = g_malloc0(size);
|
||||
caps->request = request;
|
||||
#ifndef __APPLE__
|
||||
VD_AGENT_SET_CAPABILITY(caps->caps, VD_AGENT_CAP_MOUSE_STATE);
|
||||
VD_AGENT_SET_CAPABILITY(caps->caps, VD_AGENT_CAP_MONITORS_CONFIG);
|
||||
#endif
|
||||
VD_AGENT_SET_CAPABILITY(caps->caps, VD_AGENT_CAP_REPLY);
|
||||
VD_AGENT_SET_CAPABILITY(caps->caps, VD_AGENT_CAP_CLIPBOARD_BY_DEMAND);
|
||||
VD_AGENT_SET_CAPABILITY(caps->caps, VD_AGENT_CAP_CLIPBOARD_SELECTION);
|
||||
@@ -152,20 +176,22 @@ static void send_capabilities(VirtioPort *vport,
|
||||
|
||||
static void do_client_disconnect(void)
|
||||
{
|
||||
g_hash_table_remove_all(active_xfers);
|
||||
if (client_connected) {
|
||||
udscs_server_write_all(server, VDAGENTD_CLIENT_DISCONNECTED, 0, 0,
|
||||
NULL, 0);
|
||||
client_connected = 0;
|
||||
client_connected = false;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef __APPLE__
|
||||
void do_client_mouse(struct vdagentd_uinput **uinputp, VDAgentMouseState *mouse)
|
||||
{
|
||||
vdagentd_uinput_do_mouse(uinputp, mouse);
|
||||
if (!*uinputp) {
|
||||
/* Try to re-open the tablet */
|
||||
if (active_session_conn) {
|
||||
struct agent_data *agent_data =
|
||||
const struct agent_data *agent_data =
|
||||
g_object_get_data(G_OBJECT(active_session_conn), "agent_data");
|
||||
*uinputp = vdagentd_uinput_create(uinput_device,
|
||||
agent_data->width,
|
||||
@@ -199,7 +225,7 @@ static void do_client_monitors(VirtioPort *vport, int port_nr,
|
||||
vdagentd_write_xorg_conf(new_monitors);
|
||||
|
||||
g_free(mon_config);
|
||||
mon_config = g_memdup(new_monitors, size);
|
||||
mon_config = g_memdup2(new_monitors, size);
|
||||
|
||||
/* Send monitor config to currently active agent */
|
||||
if (active_session_conn)
|
||||
@@ -212,6 +238,7 @@ static void do_client_monitors(VirtioPort *vport, int port_nr,
|
||||
vdagent_virtio_port_write(vport, port_nr, VD_AGENT_REPLY, 0,
|
||||
(uint8_t *)&reply, sizeof(reply));
|
||||
}
|
||||
#endif
|
||||
|
||||
static void do_client_volume_sync(VirtioPort *vport, int port_nr,
|
||||
VDAgentMessage *message_header,
|
||||
@@ -232,14 +259,14 @@ static void do_client_capabilities(VirtioPort *vport,
|
||||
{
|
||||
capabilities_size = VD_AGENT_CAPS_SIZE_FROM_MSG_SIZE(message_header->size);
|
||||
g_free(capabilities);
|
||||
capabilities = g_memdup(caps->caps, capabilities_size * sizeof(uint32_t));
|
||||
capabilities = g_memdup2(caps->caps, capabilities_size * sizeof(uint32_t));
|
||||
|
||||
if (caps->request) {
|
||||
/* Report the previous client has disconnected. */
|
||||
do_client_disconnect();
|
||||
if (debug)
|
||||
syslog(LOG_DEBUG, "New client connected");
|
||||
client_connected = 1;
|
||||
client_connected = true;
|
||||
memset(clipboard_serial, 0, sizeof(clipboard_serial));
|
||||
send_capabilities(vport, 0);
|
||||
}
|
||||
@@ -286,7 +313,7 @@ static void do_client_clipboard(VirtioPort *vport,
|
||||
}
|
||||
|
||||
msg_type = VDAGENTD_CLIPBOARD_GRAB;
|
||||
agent_owns_clipboard[selection] = 0;
|
||||
agent_owns_clipboard[selection] = false;
|
||||
break;
|
||||
case VD_AGENT_CLIPBOARD_REQUEST: {
|
||||
VDAgentClipboardRequest *req = (VDAgentClipboardRequest *)data;
|
||||
@@ -372,10 +399,34 @@ static void do_client_file_xfer(VirtioPort *vport,
|
||||
"Cancelling client file-xfer request %u",
|
||||
s->id, VD_AGENT_FILE_XFER_STATUS_SESSION_LOCKED, NULL, 0);
|
||||
return;
|
||||
} else if (g_hash_table_size(active_xfers) >= MAX_ACTIVE_TRANSFERS) {
|
||||
VDAgentFileXferStatusError error = {
|
||||
GUINT32_TO_LE(VD_AGENT_FILE_XFER_STATUS_ERROR_GLIB_IO),
|
||||
GUINT32_TO_LE(G_IO_ERROR_TOO_MANY_OPEN_FILES),
|
||||
};
|
||||
size_t detail_size = sizeof(error);
|
||||
if (!VD_AGENT_HAS_CAPABILITY(capabilities, capabilities_size,
|
||||
VD_AGENT_CAP_FILE_XFER_DETAILED_ERRORS)) {
|
||||
detail_size = 0;
|
||||
}
|
||||
send_file_xfer_status(vport,
|
||||
"Too many transfers ongoing. "
|
||||
"Cancelling client file-xfer request %u",
|
||||
s->id, VD_AGENT_FILE_XFER_STATUS_ERROR, (void*) &error, detail_size);
|
||||
return;
|
||||
} else if (g_hash_table_lookup(active_xfers, GUINT_TO_POINTER(s->id)) != NULL) {
|
||||
// id is already used -- client is confused
|
||||
send_file_xfer_status(vport,
|
||||
"File transfer ID is already used. "
|
||||
"Cancelling client file-xfer request %u",
|
||||
s->id, VD_AGENT_FILE_XFER_STATUS_ERROR, NULL, 0);
|
||||
return;
|
||||
}
|
||||
udscs_write(active_session_conn, VDAGENTD_FILE_XFER_START, 0, 0,
|
||||
data, message_header->size);
|
||||
return;
|
||||
msg_type = VDAGENTD_FILE_XFER_START;
|
||||
id = s->id;
|
||||
// associate the id with the active connection
|
||||
g_hash_table_insert(active_xfers, GUINT_TO_POINTER(id), active_session_conn);
|
||||
break;
|
||||
}
|
||||
case VD_AGENT_FILE_XFER_STATUS: {
|
||||
VDAgentFileXferStatusMessage *s = (VDAgentFileXferStatusMessage *)data;
|
||||
@@ -400,6 +451,12 @@ static void do_client_file_xfer(VirtioPort *vport,
|
||||
return;
|
||||
}
|
||||
udscs_write(conn, msg_type, 0, 0, data, message_header->size);
|
||||
|
||||
// client told that transfer is ended, agents too stop the transfer
|
||||
// and release resources
|
||||
if (message_header->type == VD_AGENT_FILE_XFER_STATUS) {
|
||||
g_hash_table_remove(active_xfers, GUINT_TO_POINTER(id));
|
||||
}
|
||||
}
|
||||
|
||||
static void forward_data_to_session_agent(uint32_t type, uint8_t *data, size_t size)
|
||||
@@ -412,7 +469,7 @@ static void forward_data_to_session_agent(uint32_t type, uint8_t *data, size_t s
|
||||
udscs_write(active_session_conn, type, 0, 0, data, size);
|
||||
}
|
||||
|
||||
static gsize vdagent_message_min_size[] =
|
||||
static const gsize vdagent_message_min_size[] =
|
||||
{
|
||||
-1, /* Does not exist */
|
||||
sizeof(VDAgentMouseState), /* VD_AGENT_MOUSE_STATE */
|
||||
@@ -561,6 +618,7 @@ static void virtio_port_read_complete(
|
||||
return;
|
||||
|
||||
switch (message_header->type) {
|
||||
#ifndef __APPLE__
|
||||
case VD_AGENT_MOUSE_STATE:
|
||||
virtio_msg_uint32_from_le(data, message_header->size, 0);
|
||||
do_client_mouse(&uinput, (VDAgentMouseState *)data);
|
||||
@@ -570,6 +628,7 @@ static void virtio_port_read_complete(
|
||||
do_client_monitors(vport, port_nr, message_header,
|
||||
(VDAgentMonitorsConfig *)data);
|
||||
break;
|
||||
#endif
|
||||
case VD_AGENT_ANNOUNCE_CAPABILITIES:
|
||||
virtio_msg_uint32_from_le(data, message_header->size, 0);
|
||||
do_client_capabilities(vport, message_header,
|
||||
@@ -598,13 +657,9 @@ static void virtio_port_read_complete(
|
||||
break;
|
||||
}
|
||||
case VD_AGENT_GRAPHICS_DEVICE_INFO: {
|
||||
if (device_info) {
|
||||
g_free(device_info);
|
||||
device_info = NULL;
|
||||
device_info_size = 0;
|
||||
}
|
||||
// store device info for re-sending when a session agent reconnects
|
||||
device_info = g_memdup(data, message_header->size);
|
||||
g_free(device_info);
|
||||
device_info = g_memdup2(data, message_header->size);
|
||||
device_info_size = message_header->size;
|
||||
forward_data_to_session_agent(VDAGENTD_GRAPHICS_DEVICE_INFO, data, message_header->size);
|
||||
break;
|
||||
@@ -624,7 +679,7 @@ static void virtio_port_read_complete(
|
||||
|
||||
static void virtio_port_error_cb(VDAgentConnection *conn, GError *err)
|
||||
{
|
||||
gboolean old_client_connected = client_connected;
|
||||
bool old_client_connected = client_connected;
|
||||
syslog(LOG_CRIT, "AIIEEE lost spice client connection, reconnecting (err: %s)",
|
||||
err ? err->message : "");
|
||||
g_clear_error(&err);
|
||||
@@ -676,7 +731,8 @@ static void virtio_write_clipboard(uint8_t selection, uint32_t msg_type,
|
||||
if (msg_type == VD_AGENT_CLIPBOARD_GRAB) {
|
||||
if (VD_AGENT_HAS_CAPABILITY(capabilities, capabilities_size,
|
||||
VD_AGENT_CAP_CLIPBOARD_GRAB_SERIAL)) {
|
||||
uint32_t serial = GUINT32_TO_LE(clipboard_serial[selection]++);
|
||||
uint32_t serial = GUINT32_TO_LE(clipboard_serial[selection]);
|
||||
clipboard_serial[selection]++;
|
||||
vdagent_virtio_port_write_append(virtio_port, (uint8_t*)&serial, sizeof(serial));
|
||||
}
|
||||
virtio_msg_uint32_to_le(data, data_size, 0);
|
||||
@@ -697,10 +753,14 @@ static void do_agent_clipboard(UdscsConnection *conn,
|
||||
|
||||
/* Check that this agent is from the currently active session */
|
||||
if (conn != active_session_conn) {
|
||||
#ifdef WITH_SESSION_SECURITY
|
||||
if (debug)
|
||||
syslog(LOG_DEBUG, "%p clipboard req from agent which is not in "
|
||||
"the active session?", conn);
|
||||
goto error;
|
||||
#else
|
||||
update_active_session_connection(conn);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!virtio_port) {
|
||||
@@ -717,7 +777,7 @@ static void do_agent_clipboard(UdscsConnection *conn,
|
||||
switch (header->type) {
|
||||
case VDAGENTD_CLIPBOARD_GRAB:
|
||||
msg_type = VD_AGENT_CLIPBOARD_GRAB;
|
||||
agent_owns_clipboard[selection] = 1;
|
||||
agent_owns_clipboard[selection] = true;
|
||||
break;
|
||||
case VDAGENTD_CLIPBOARD_REQUEST:
|
||||
msg_type = VD_AGENT_CLIPBOARD_REQUEST;
|
||||
@@ -737,7 +797,7 @@ static void do_agent_clipboard(UdscsConnection *conn,
|
||||
case VDAGENTD_CLIPBOARD_RELEASE:
|
||||
msg_type = VD_AGENT_CLIPBOARD_RELEASE;
|
||||
size = 0;
|
||||
agent_owns_clipboard[selection] = 0;
|
||||
agent_owns_clipboard[selection] = false;
|
||||
break;
|
||||
default:
|
||||
syslog(LOG_WARNING, "unexpected clipboard message type");
|
||||
@@ -772,10 +832,11 @@ error:
|
||||
closes both. */
|
||||
static void check_xorg_resolution(void)
|
||||
{
|
||||
struct agent_data *agent_data = NULL;
|
||||
const struct agent_data *agent_data = NULL;
|
||||
if (active_session_conn)
|
||||
agent_data = g_object_get_data(G_OBJECT(active_session_conn), "agent_data");
|
||||
|
||||
#ifndef __APPLE__
|
||||
if (agent_data && agent_data->screen_info) {
|
||||
if (!uinput)
|
||||
uinput = vdagentd_uinput_create(uinput_device,
|
||||
@@ -796,6 +857,9 @@ static void check_xorg_resolution(void)
|
||||
vdagentd_quit(1);
|
||||
return;
|
||||
}
|
||||
#else
|
||||
if (agent_data) {
|
||||
#endif
|
||||
|
||||
if (!virtio_port) {
|
||||
syslog(LOG_INFO, "opening vdagent virtio channel");
|
||||
@@ -811,7 +875,9 @@ static void check_xorg_resolution(void)
|
||||
}
|
||||
} else {
|
||||
#ifndef WITH_STATIC_UINPUT
|
||||
#ifndef __APPLE__
|
||||
vdagentd_uinput_destroy(&uinput);
|
||||
#endif
|
||||
#endif
|
||||
if (virtio_port) {
|
||||
if (only_once) {
|
||||
@@ -826,11 +892,68 @@ static void check_xorg_resolution(void)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
static gboolean reopen_virtio_port(gpointer user_data)
|
||||
{
|
||||
check_xorg_resolution();
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
static gboolean restart_virtio_port(gpointer user_data)
|
||||
{
|
||||
if (virtio_port) {
|
||||
syslog(LOG_INFO, "VM restored, reopening vdagent virtio channel");
|
||||
g_clear_pointer(&virtio_port, vdagent_connection_destroy);
|
||||
do_client_disconnect();
|
||||
/* the old port's cancelled read must release its file descriptor first */
|
||||
g_idle_add(reopen_virtio_port, NULL);
|
||||
}
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
/* Virtualization.framework forgets that the port is open when it restores a
|
||||
saved VM, then drops whatever the guest writes to it and never completes
|
||||
the write, which leaves the port unusable until the guest reboots. The
|
||||
virtual RTC sends a message as soon as the VM is restored, so reopen the
|
||||
port then, before anything is written, to tell the host it is open again. */
|
||||
static void rtc_interest_cb(void *refcon, io_service_t service,
|
||||
natural_t message_type, void *message_argument)
|
||||
{
|
||||
g_idle_add(restart_virtio_port, NULL);
|
||||
}
|
||||
|
||||
static IONotificationPortRef watch_vm_restore(io_object_t *notification)
|
||||
{
|
||||
io_service_t rtc;
|
||||
IONotificationPortRef port;
|
||||
kern_return_t kr;
|
||||
|
||||
rtc = IOServiceGetMatchingService(MACH_PORT_NULL,
|
||||
IOServiceMatching("AppleVirtualPlatformRTC"));
|
||||
if (!rtc) {
|
||||
/* not running in Virtualization.framework */
|
||||
return NULL;
|
||||
}
|
||||
port = IONotificationPortCreate(MACH_PORT_NULL);
|
||||
IONotificationPortSetDispatchQueue(port,
|
||||
dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0));
|
||||
kr = IOServiceAddInterestNotification(port, rtc, kIOGeneralInterest,
|
||||
rtc_interest_cb, NULL, notification);
|
||||
IOObjectRelease(rtc);
|
||||
if (kr != KERN_SUCCESS) {
|
||||
syslog(LOG_WARNING, "could not watch for VM restore: 0x%x", kr);
|
||||
IONotificationPortDestroy(port);
|
||||
return NULL;
|
||||
}
|
||||
return port;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int connection_matches_active_session(UdscsConnection *conn,
|
||||
void *priv)
|
||||
{
|
||||
UdscsConnection **conn_ret = (UdscsConnection **)priv;
|
||||
struct agent_data *agent_data = g_object_get_data(G_OBJECT(conn), "agent_data");
|
||||
const struct agent_data *agent_data = g_object_get_data(G_OBJECT(conn), "agent_data");
|
||||
|
||||
/* Check if this connection matches the currently active session */
|
||||
if (!agent_data->session || !active_session)
|
||||
@@ -851,7 +974,7 @@ static void release_clipboards(void)
|
||||
vdagent_virtio_port_write(virtio_port, VDP_CLIENT_PORT,
|
||||
VD_AGENT_CLIPBOARD_RELEASE, 0, &sel, 1);
|
||||
}
|
||||
agent_owns_clipboard[sel] = 0;
|
||||
agent_owns_clipboard[sel] = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -865,17 +988,21 @@ static void update_active_session_connection(UdscsConnection *new_conn)
|
||||
connection_matches_active_session,
|
||||
(void*)&new_conn);
|
||||
} else {
|
||||
#ifdef WITH_SESSION_SECURITY
|
||||
if (new_conn)
|
||||
session_count++;
|
||||
else
|
||||
session_count--;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef WITH_SESSION_SECURITY
|
||||
if (new_conn && session_count != 1) {
|
||||
syslog(LOG_ERR, "multiple agents in one session, "
|
||||
"disabling agent to avoid potential information leak");
|
||||
new_conn = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (new_conn == active_session_conn)
|
||||
return;
|
||||
@@ -916,28 +1043,88 @@ static gboolean remove_active_xfers(gpointer key, gpointer value, gpointer conn)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Check if this connection matches the passed session */
|
||||
static int connection_matches_session(UdscsConnection *conn, void *priv)
|
||||
{
|
||||
const char *session = priv;
|
||||
const struct agent_data *agent_data = g_object_get_data(G_OBJECT(conn), "agent_data");
|
||||
|
||||
if (!agent_data || !agent_data->session ||
|
||||
strcmp(agent_data->session, session) != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Check a given process has a given UID */
|
||||
static bool check_uid_of_pid(pid_t pid, uid_t uid)
|
||||
{
|
||||
char fn[128];
|
||||
struct stat st;
|
||||
|
||||
snprintf(fn, sizeof(fn), "/proc/%u/status", (unsigned) pid);
|
||||
if (stat(fn, &st) != 0 || st.st_uid != uid) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void agent_connect(UdscsConnection *conn)
|
||||
{
|
||||
struct agent_data *agent_data;
|
||||
agent_data = g_new0(struct agent_data, 1);
|
||||
GError *err = NULL;
|
||||
gint pid;
|
||||
|
||||
if (session_info) {
|
||||
pid = vdagent_connection_get_peer_pid(VDAGENT_CONNECTION(conn), &err);
|
||||
if (err) {
|
||||
syslog(LOG_ERR, "Could not get peer PID, disconnecting new client: %s",
|
||||
err->message);
|
||||
g_error_free(err);
|
||||
g_free(agent_data);
|
||||
PidUid pid_uid = vdagent_connection_get_peer_pid_uid(VDAGENT_CONNECTION(conn), &err);
|
||||
if (err || pid_uid.pid <= 0) {
|
||||
static const char msg[] = "Could not get peer PID, disconnecting new client";
|
||||
if (err) {
|
||||
syslog(LOG_ERR, "%s: %s", msg, err->message);
|
||||
g_error_free(err);
|
||||
} else {
|
||||
syslog(LOG_ERR, "%s", msg);
|
||||
}
|
||||
agent_data_destroy(agent_data);
|
||||
udscs_server_destroy_connection(server, conn);
|
||||
return;
|
||||
}
|
||||
|
||||
agent_data->session = session_info_session_for_pid(session_info, pid);
|
||||
agent_data->session = session_info_session_for_pid(session_info, pid_uid.pid);
|
||||
|
||||
uid_t session_uid = session_info_uid_for_session(session_info, agent_data->session);
|
||||
|
||||
/* Check that the UID of the PID did not change, this should be done after
|
||||
* computing the session to avoid race conditions.
|
||||
* This can happen as vdagent_connection_get_peer_pid_uid get information
|
||||
* from the time of creating the socket, but the process in the meantime
|
||||
* have been replaced */
|
||||
if (!check_uid_of_pid(pid_uid.pid, pid_uid.uid) ||
|
||||
/* Check that the user launching the Agent is the same as session one
|
||||
* or root user.
|
||||
* This prevents session hijacks from other users. */
|
||||
(pid_uid.uid != 0 && pid_uid.uid != session_uid)) {
|
||||
syslog(LOG_ERR, "UID mismatch: UID=%u PID=%u suid=%u", pid_uid.uid,
|
||||
pid_uid.pid, session_uid);
|
||||
agent_data_destroy(agent_data);
|
||||
udscs_server_destroy_connection(server, conn);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check there are no other connection for this session
|
||||
// Note that "conn" is not counted as "agent_data" is still not attached to it
|
||||
if (udscs_server_for_all_clients(server, connection_matches_session,
|
||||
agent_data->session) > 0) {
|
||||
syslog(LOG_ERR, "An agent is already connected for this session");
|
||||
agent_data_destroy(agent_data);
|
||||
udscs_server_destroy_connection(server, conn);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
g_object_set_data(G_OBJECT(conn), "agent_data", agent_data);
|
||||
g_object_set_data_full(G_OBJECT(conn), "agent_data", agent_data,
|
||||
(GDestroyNotify) agent_data_destroy);
|
||||
udscs_write(conn, VDAGENTD_VERSION, 0, 0,
|
||||
(uint8_t *)VERSION, strlen(VERSION) + 1);
|
||||
update_active_session_connection(conn);
|
||||
@@ -950,13 +1137,8 @@ static void agent_connect(UdscsConnection *conn)
|
||||
|
||||
static void agent_disconnect(VDAgentConnection *conn, GError *err)
|
||||
{
|
||||
struct agent_data *agent_data = g_object_get_data(G_OBJECT(conn), "agent_data");
|
||||
|
||||
g_hash_table_foreach_remove(active_xfers, remove_active_xfers, conn);
|
||||
|
||||
g_clear_pointer(&agent_data->session, g_free);
|
||||
g_free(agent_data->screen_info);
|
||||
g_free(agent_data);
|
||||
if (err) {
|
||||
syslog(LOG_ERR, "%s", err->message);
|
||||
g_error_free(err);
|
||||
@@ -966,6 +1148,7 @@ static void agent_disconnect(VDAgentConnection *conn, GError *err)
|
||||
update_active_session_connection(NULL);
|
||||
}
|
||||
|
||||
#ifndef __APPLE__
|
||||
static void do_agent_xorg_resolution(UdscsConnection *conn,
|
||||
struct udscs_message_header *header,
|
||||
guint8 *data)
|
||||
@@ -991,13 +1174,14 @@ static void do_agent_xorg_resolution(UdscsConnection *conn,
|
||||
}
|
||||
|
||||
g_free(agent_data->screen_info);
|
||||
agent_data->screen_info = g_memdup(data, header->size);
|
||||
agent_data->screen_info = g_memdup2(data, header->size);
|
||||
agent_data->width = header->arg1;
|
||||
agent_data->height = header->arg2;
|
||||
agent_data->screen_count = n;
|
||||
|
||||
check_xorg_resolution();
|
||||
}
|
||||
#endif
|
||||
|
||||
static void do_agent_file_xfer_status(UdscsConnection *conn,
|
||||
struct udscs_message_header *header,
|
||||
@@ -1007,6 +1191,15 @@ static void do_agent_file_xfer_status(UdscsConnection *conn,
|
||||
const gchar *log_msg = NULL;
|
||||
guint data_size = 0;
|
||||
|
||||
UdscsConnection *task_conn = g_hash_table_lookup(active_xfers, task_id);
|
||||
if (task_conn == NULL || task_conn != conn) {
|
||||
// Protect against misbehaving agent.
|
||||
// Ignore the message, but do not disconnect the agent, to protect against
|
||||
// a misbehaving client that tries to disconnect a good agent
|
||||
// e.g. by sending a new task and immediately cancelling it.
|
||||
return;
|
||||
}
|
||||
|
||||
/* header->arg1 = file xfer task id, header->arg2 = file xfer status */
|
||||
switch (header->arg2) {
|
||||
case VD_AGENT_FILE_XFER_STATUS_NOT_ENOUGH_SPACE:
|
||||
@@ -1021,19 +1214,20 @@ static void do_agent_file_xfer_status(UdscsConnection *conn,
|
||||
send_file_xfer_status(virtio_port, log_msg, header->arg1, header->arg2,
|
||||
data, data_size);
|
||||
|
||||
if (header->arg2 == VD_AGENT_FILE_XFER_STATUS_CAN_SEND_DATA)
|
||||
g_hash_table_insert(active_xfers, task_id, conn);
|
||||
else
|
||||
if (header->arg2 != VD_AGENT_FILE_XFER_STATUS_CAN_SEND_DATA) {
|
||||
g_hash_table_remove(active_xfers, task_id);
|
||||
}
|
||||
}
|
||||
|
||||
static void agent_read_complete(UdscsConnection *conn,
|
||||
struct udscs_message_header *header, uint8_t *data)
|
||||
{
|
||||
switch (header->type) {
|
||||
#ifndef __APPLE__
|
||||
case VDAGENTD_GUEST_XORG_RESOLUTION:
|
||||
do_agent_xorg_resolution(conn, header, data);
|
||||
break;
|
||||
#endif
|
||||
case VDAGENTD_CLIPBOARD_GRAB:
|
||||
case VDAGENTD_CLIPBOARD_REQUEST:
|
||||
case VDAGENTD_CLIPBOARD_DATA:
|
||||
@@ -1160,6 +1354,10 @@ int main(int argc, char *argv[])
|
||||
gboolean own_socket = TRUE;
|
||||
GIOChannel *si_io_channel = NULL;
|
||||
guint si_watch_id = 0;
|
||||
#ifdef __APPLE__
|
||||
IONotificationPortRef restore_notify_port;
|
||||
io_object_t restore_notification;
|
||||
#endif
|
||||
|
||||
context = g_option_context_new(NULL);
|
||||
g_option_context_add_main_entries(context, cmd_entries, NULL);
|
||||
@@ -1184,10 +1382,6 @@ int main(int argc, char *argv[])
|
||||
uinput_device = g_strdup(DEFAULT_UINPUT_DEVICE);
|
||||
}
|
||||
|
||||
g_unix_signal_add(SIGINT, signal_handler, NULL);
|
||||
g_unix_signal_add(SIGHUP, signal_handler, NULL);
|
||||
g_unix_signal_add(SIGTERM, signal_handler, NULL);
|
||||
|
||||
openlog("spice-vdagentd", do_daemonize ? 0 : LOG_PERROR, LOG_USER);
|
||||
|
||||
/* Setup communication with vdagent process(es) */
|
||||
@@ -1207,7 +1401,9 @@ int main(int argc, char *argv[])
|
||||
/* systemd socket activation not enabled, create our own */
|
||||
#endif /* WITH_SYSTEMD_SOCKET_ACTIVATION */
|
||||
{
|
||||
mode_t mode = umask(0111);
|
||||
udscs_server_listen_to_address(server, vdagentd_socket, &err);
|
||||
umask(mode);
|
||||
}
|
||||
|
||||
if (err) {
|
||||
@@ -1218,19 +1414,6 @@ int main(int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* no need to set permissions on a socket that was provided by systemd */
|
||||
if (own_socket) {
|
||||
if (chmod(vdagentd_socket, 0666)) {
|
||||
syslog(LOG_CRIT, "Fatal could not change permissions on %s: %m",
|
||||
vdagentd_socket);
|
||||
udscs_destroy_server(server);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (do_daemonize)
|
||||
daemonize();
|
||||
|
||||
#ifdef WITH_STATIC_UINPUT
|
||||
uinput = vdagentd_uinput_create(uinput_device, 1024, 768, NULL, 0,
|
||||
debug > 1, uinput_fake);
|
||||
@@ -1240,6 +1423,13 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
#endif
|
||||
|
||||
if (do_daemonize)
|
||||
daemonize();
|
||||
|
||||
g_unix_signal_add(SIGINT, signal_handler, NULL);
|
||||
g_unix_signal_add(SIGHUP, signal_handler, NULL);
|
||||
g_unix_signal_add(SIGTERM, signal_handler, NULL);
|
||||
|
||||
if (want_session_info)
|
||||
session_info = session_info_create(debug);
|
||||
if (session_info) {
|
||||
@@ -1247,20 +1437,35 @@ int main(int argc, char *argv[])
|
||||
si_watch_id = g_io_add_watch(si_io_channel, G_IO_IN, si_io_channel_cb, NULL);
|
||||
g_io_channel_unref(si_io_channel);
|
||||
} else {
|
||||
#ifdef WITH_SESSION_SECURITY
|
||||
syslog(LOG_WARNING, "no session info, max 1 session agent allowed");
|
||||
#endif
|
||||
}
|
||||
|
||||
active_xfers = g_hash_table_new(g_direct_hash, g_direct_equal);
|
||||
|
||||
#ifdef __APPLE__
|
||||
restore_notify_port = watch_vm_restore(&restore_notification);
|
||||
#endif
|
||||
|
||||
udscs_server_start(server);
|
||||
loop = g_main_loop_new(NULL, FALSE);
|
||||
g_main_loop_run(loop);
|
||||
|
||||
release_clipboards();
|
||||
|
||||
#ifndef __APPLE__
|
||||
vdagentd_uinput_destroy(&uinput);
|
||||
#endif
|
||||
if (si_watch_id > 0) {
|
||||
g_source_remove(si_watch_id);
|
||||
}
|
||||
#ifdef __APPLE__
|
||||
if (restore_notify_port) {
|
||||
IOObjectRelease(restore_notification);
|
||||
IONotificationPortDestroy(restore_notify_port);
|
||||
}
|
||||
#endif
|
||||
g_clear_pointer(&session_info, session_info_destroy);
|
||||
g_clear_pointer(&server, udscs_destroy_server);
|
||||
if (virtio_port) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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>
|
||||
Reference in new issue
Block a user