mirror of
https://github.com/utmapp/vd_agent.git
synced 2026-12-01 14:02:07 -10:00
Compare commits
420
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 | ||
|
|
bfbb63d3ae | ||
|
|
3b4b4d025d | ||
|
|
70d57b3357 | ||
|
|
e6c14d0ecc | ||
|
|
ab7901ced4 | ||
|
|
15f710dade | ||
|
|
3257a1f732 | ||
|
|
5c136cb3a3 | ||
|
|
a2fc33cbc7 | ||
|
|
c9e806722b | ||
|
|
2ad6c158ff | ||
|
|
aa26d1d95b | ||
|
|
fb69a49828 | ||
|
|
ff30f58701 | ||
|
|
79d012503f | ||
|
|
2c723788c0 | ||
|
|
e0bfa678ae | ||
|
|
b67ff71f1b | ||
|
|
f807e98bb6 | ||
|
|
56a65ad1c6 | ||
|
|
cedab5fe0e | ||
|
|
83d2dbba24 | ||
|
|
0b94306d2c | ||
|
|
66935d134e | ||
|
|
af8d1948b1 | ||
|
|
3522667bfa | ||
|
|
b6dfef73f2 | ||
|
|
6bfbd03e83 | ||
|
|
7976dc31af | ||
|
|
70c5908f8c | ||
|
|
b6fde1641a | ||
|
|
f8fa4191db | ||
|
|
0397089827 | ||
|
|
c47e073385 | ||
|
|
f5a2c1af91 | ||
|
|
beb35c375e | ||
|
|
4452b1d3bd | ||
|
|
0193a537ec | ||
|
|
a257b1c205 | ||
|
|
73c1afbf63 | ||
|
|
d4d489560b | ||
|
|
1fe876177a | ||
|
|
bfb6136411 | ||
|
|
d1bf80c924 | ||
|
|
3aff78399f | ||
|
|
783ceece02 | ||
|
|
9874e30e91 | ||
|
|
f3408fc916 | ||
|
|
f499a5126e | ||
|
|
149bba9162 | ||
|
|
74570d5f97 | ||
|
|
67f3a09c22 | ||
|
|
5ad18905c8 | ||
|
|
5374fcc5e3 | ||
|
|
254b547277 | ||
|
|
d48945fdb6 | ||
|
|
0e7e7b66e9 | ||
|
|
353592e8e1 | ||
|
|
8dc490749f | ||
|
|
56c2d29752 | ||
|
|
97aa39a872 | ||
|
|
26e2eab5d2 | ||
|
|
61bf8c4565 | ||
|
|
34f934b03f | ||
|
|
61f99bfa52 | ||
|
|
5ab83e3e3d | ||
|
|
73147aff7d | ||
|
|
aaed86b649 | ||
|
|
5be1563147 | ||
|
|
098268a33c | ||
|
|
56d50d2122 | ||
|
|
b07420eea0 | ||
|
|
41ad267d81 | ||
|
|
77ef2213aa | ||
|
|
c3046c2434 | ||
|
|
380cab695f | ||
|
|
5df766b161 | ||
|
|
a568953e79 | ||
|
|
b9c61dad55 | ||
|
|
8bef579654 | ||
|
|
0221f7f080 | ||
|
|
7ace167ec2 | ||
|
|
cb7dfbe55a | ||
|
|
ac119849a3 | ||
|
|
761887e07d | ||
|
|
a99ba0fe89 | ||
|
|
d5811d0589 | ||
|
|
2d6d0d2acd | ||
|
|
102b2e753e | ||
|
|
b245cbdd59 | ||
|
|
8df6120b7f | ||
|
|
16e3dc1035 | ||
|
|
6ee007ca33 | ||
|
|
b222ad1011 | ||
|
|
819782c48d | ||
|
|
27aa50e629 | ||
|
|
061593ed85 | ||
|
|
542ad5f828 | ||
|
|
359cceda91 | ||
|
|
0a05a7cf39 | ||
|
|
ae0fcf3566 | ||
|
|
b22d605184 | ||
|
|
b190b17902 | ||
|
|
6013078e7b | ||
|
|
7ddd30eebc | ||
|
|
9003891d5e | ||
|
|
ffdb2704b2 | ||
|
|
1f332ce3db | ||
|
|
2f54062749 | ||
|
|
a2ef594a2f | ||
|
|
694b43b5ce | ||
|
|
632fba5070 | ||
|
|
8b8f333e55 | ||
|
|
a4f5c7dcb6 | ||
|
|
d673fc7b8a | ||
|
|
c65de1b68d | ||
|
|
c74a00e4d9 | ||
|
|
b7e6f31df8 | ||
|
|
8ba174816d | ||
|
|
e5bfb1be15 | ||
|
|
3fcf2e944a | ||
|
|
d69a13803b | ||
|
|
fe3fc345e1 | ||
|
|
0ffca2b7f1 | ||
|
|
ada1c30d27 | ||
|
|
3b49c09fd4 | ||
|
|
61fc548fe1 | ||
|
|
183e2fec35 | ||
|
|
78c930e758 | ||
|
|
3760f8618c | ||
|
|
ca89a0102c | ||
|
|
9844732e22 | ||
|
|
4be96f98ba | ||
|
|
d66fbb9d12 | ||
|
|
26f5eca9bb | ||
|
|
909b00a5ce | ||
|
|
80d9d1f2f8 | ||
|
|
05706b6e8f | ||
|
|
16043df205 | ||
|
|
914574ba47 | ||
|
|
2f6324d263 | ||
|
|
69e5fd82bf | ||
|
|
99d9d35831 | ||
|
|
3903ebd593 | ||
|
|
72acb448f7 | ||
|
|
bf7cb23534 | ||
|
|
85651502e8 | ||
|
|
10cab3596d | ||
|
|
f2e0bb3c45 | ||
|
|
2dc986fcaf | ||
|
|
8f1c3c3135 | ||
|
|
c943d0b6b2 | ||
|
|
7324da13b8 | ||
|
|
05d389dc90 | ||
|
|
5dd6d2a88a | ||
|
|
08ff8d79da | ||
|
|
e76db60216 | ||
|
|
3303272d7e | ||
|
|
b7e6c56a78 | ||
|
|
8ce6ca92c6 | ||
|
|
f30a1bbaad | ||
|
|
22e32f29a6 | ||
|
|
658fbb8ea6 | ||
|
|
bfb08d5245 | ||
|
|
2192414c40 | ||
|
|
ec843a21b2 | ||
|
|
49c421a82c | ||
|
|
4c0e9c965e | ||
|
|
1700c0244f | ||
|
|
364b6bba06 | ||
|
|
0064dca2dd | ||
|
|
691893864f | ||
|
|
b5f0352e9e | ||
|
|
b1b8b71961 | ||
|
|
4c1c73cf74 | ||
|
|
9e3e121e35 | ||
|
|
15052a375b | ||
|
|
257d5fc0c1 | ||
|
|
acd48377ac | ||
|
|
62da1a3329 | ||
|
|
665926f614 | ||
|
|
eb01d32221 | ||
|
|
fff3058216 | ||
|
|
6a2effa402 | ||
|
|
c53af3260a | ||
|
|
69c88c633f | ||
|
|
02370e4445 | ||
|
|
0159111b22 | ||
|
|
8c465007b4 | ||
|
|
f97751faf0 | ||
|
|
13a4478521 | ||
|
|
d508979b6b | ||
|
|
e7f7876190 | ||
|
|
9b38dd5d6b | ||
|
|
536b63cfaf | ||
|
|
9b0eb8b124 | ||
|
|
010dc21f35 | ||
|
|
6c0160e8a3 | ||
|
|
a8bbff07b1 | ||
|
|
28618682ae | ||
|
|
21f4927531 | ||
|
|
8003f9e01f | ||
|
|
7329ad767f | ||
|
|
4835df0b64 | ||
|
|
4e9b291773 | ||
|
|
9ea18740b8 | ||
|
|
689dcd35ed | ||
|
|
7fc4525dce | ||
|
|
ec9f11064e | ||
|
|
072fb03fa4 | ||
|
|
658c4d76e2 | ||
|
|
b87fab52eb | ||
|
|
1c25f882a3 | ||
|
|
2f602c03eb | ||
|
|
251637aa23 | ||
|
|
7d858d5064 | ||
|
|
fa42110482 | ||
|
|
6e2e82e6fb | ||
|
|
9ae51f3702 | ||
|
|
a30c981870 | ||
|
|
b8c2890228 | ||
|
|
ae17559dd0 | ||
|
|
29022fdc3b | ||
|
|
c3d1aa6b35 | ||
|
|
cef12b63ef | ||
|
|
6e1e36e537 | ||
|
|
ad6ea7594a | ||
|
|
8ec5ba92c3 | ||
|
|
21175d0701 | ||
|
|
14e28e2dc6 | ||
|
|
df35b48fbe | ||
|
|
627f80372c | ||
|
|
d39230cee2 | ||
|
|
bad87034bb | ||
|
|
99a2628b0f | ||
|
|
ec872de2a1 | ||
|
|
71b8e75c6f | ||
|
|
43cde1cbed | ||
|
|
256e01c8c7 | ||
|
|
16911aa300 | ||
|
|
3502798960 | ||
|
|
e4d8c9d9cc | ||
|
|
248aef9dd6 | ||
|
|
ac8b9cff0a | ||
|
|
f55ecd9647 | ||
|
|
243ed32ac7 | ||
|
|
9c9f4e4ae6 | ||
|
|
8c60536d31 | ||
|
|
6f21924ba3 | ||
|
|
3a5e97241e | ||
|
|
a3dea8eb4b | ||
|
|
dd8b05ab01 | ||
|
|
f25f1fa472 | ||
|
|
a322d13b7e | ||
|
|
cc6f3d5a72 | ||
|
|
60ce72321b | ||
|
|
a943302487 | ||
|
|
515944aa50 | ||
|
|
15d33799ee | ||
|
|
71cf03fdcc | ||
|
|
9ac104389b | ||
|
|
92dd6caa9f | ||
|
|
d6cae7fae1 | ||
|
|
7d07bb7197 | ||
|
|
e0d8434b06 | ||
|
|
4d2fef916b | ||
|
|
c648290d68 | ||
|
|
e107565749 | ||
|
|
6c87f5aff1 | ||
|
|
36ae65709f | ||
|
|
4b0748ddcc | ||
|
|
eb7a99011c | ||
|
|
f45a4c0ae5 | ||
|
|
260cde2c88 | ||
|
|
99222bc472 | ||
|
|
fef8f6a36f | ||
|
|
a5a2a6b9c4 | ||
|
|
8684159596 | ||
|
|
4a27359e81 | ||
|
|
048bf08399 | ||
|
|
1dd73dd32b | ||
|
|
363b3b7410 | ||
|
|
060e943aaa | ||
|
|
80276ad30b | ||
|
|
765803fce0 | ||
|
|
029843152c | ||
|
|
79c2e93136 | ||
|
|
60603deb4d | ||
|
|
1cfd216171 | ||
|
|
708d8d5b98 | ||
|
|
6899fbd537 | ||
|
|
74b4506a00 | ||
|
|
3343d67d73 | ||
|
|
8c1b3c056d | ||
|
|
dddbaa7db2 | ||
|
|
3205c2c9a5 | ||
|
|
4aeb130aff | ||
|
|
2b1f1e45ce | ||
|
|
9a447b1c91 | ||
|
|
0dea1073d5 | ||
|
|
1fc816764b | ||
|
|
f269ec359e | ||
|
|
5c2de0012f | ||
|
|
adce0527f0 | ||
|
|
515b65199d | ||
|
|
dfb6589920 | ||
|
|
ae51b0a1a1 | ||
|
|
273b83f57c | ||
|
|
60aefc544c | ||
|
|
18771a6b2e | ||
|
|
407a184050 | ||
|
|
47ebbb2190 | ||
|
|
27d63542b4 | ||
|
|
e2e7571372 | ||
|
|
06e48b5e9a | ||
|
|
1e0f8b57d6 | ||
|
|
f77fad3ddf | ||
|
|
ccecfa1201 | ||
|
|
918333e9ad | ||
|
|
5b84b6cfc0 | ||
|
|
17d2d55433 | ||
|
|
1d32f9f136 | ||
|
|
3fdfcbc6eb |
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
|
||||
+14
-3
@@ -1,16 +1,27 @@
|
||||
*~
|
||||
*.o
|
||||
.deps
|
||||
.dirstamp
|
||||
data/spice-vdagent*.1
|
||||
src/config.h
|
||||
src/config.h.in
|
||||
src/spice-vdagent
|
||||
src/spice-vdagentd
|
||||
src/*.o
|
||||
src/.deps
|
||||
src/.dirstamp
|
||||
src/stamp-h1
|
||||
tests/test-*.log
|
||||
tests/test-*.trs
|
||||
tests/test-file-xfers
|
||||
tests/test-device-info
|
||||
config.log
|
||||
config.status
|
||||
aclocal.m4
|
||||
autom4te.cache
|
||||
compile
|
||||
configure
|
||||
depcomp
|
||||
install-sh
|
||||
Makefile.in
|
||||
Makefile
|
||||
missing
|
||||
test-driver
|
||||
test-suite.log
|
||||
@@ -0,0 +1,58 @@
|
||||
image: fedora:latest
|
||||
|
||||
variables:
|
||||
DEPS_COMMON: git libtool make python3 python3-six redhat-rpm-config
|
||||
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 procps-ng libdrm-devel gtk4-devel
|
||||
vulkan-headers
|
||||
DISTCHECK_CONFIGURE_FLAGS:
|
||||
--with-session-info=none
|
||||
|
||||
before_script:
|
||||
- dnf install -y $DEPS_COMMON
|
||||
- git clone https://gitlab.freedesktop.org/spice/spice-protocol.git
|
||||
- meson --buildtype=release spice-protocol build-spice-protocol --prefix=/usr --werror
|
||||
- ninja -C build-spice-protocol install
|
||||
|
||||
fedora-autotools:
|
||||
script:
|
||||
- ./autogen.sh
|
||||
- make
|
||||
- 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
|
||||
- make
|
||||
- make install
|
||||
- make uninstall
|
||||
- git clean -xfd
|
||||
|
||||
- ./autogen.sh --with-session-info=console-kit --with-init-script=redhat
|
||||
- make
|
||||
- make install
|
||||
- make uninstall
|
||||
- git clean -xfd
|
||||
|
||||
- ./autogen.sh --with-gtk=no --with-session-info=none
|
||||
- make
|
||||
- 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
|
||||
+186
@@ -0,0 +1,186 @@
|
||||
Gitlab markdown format support linking to Issues (#) and Merge requests (!) and more, see below:
|
||||
|
||||
https://gitlab.freedesktop.org/spice/linux/vd_agent/-/blob/master/CHANGELOG.md
|
||||
|
||||
News in spice-vdagent 0.22.1
|
||||
===========================
|
||||
* !42 - Fix crash on startup of session agent
|
||||
|
||||
News in spice-vdagent 0.22.0
|
||||
===========================
|
||||
* !40 - Handle side mouse buttons
|
||||
* !39 - Set retry limit to connect to vdagentd and improve logging error
|
||||
* !35 - Fix deprecation warning
|
||||
* !37 - Provide systemd spice-vdagent.service
|
||||
|
||||
News in spice-vdagent 0.21.0
|
||||
============================
|
||||
* Security fixes:
|
||||
CVE-2020-25650, CVE-2020-25651, CVE-2020-25652, CVE-2020-25653
|
||||
* Fix shutdown issue due to incompatible thread/fork uses with GLib
|
||||
* Fix mouse pointer issues under Wayland
|
||||
* Fix a crash when running without dbus (e.g: within containers)
|
||||
* !9 - Introduce optional GTK4 support for monitor management
|
||||
* !13 - Enable copying files from client using webdav
|
||||
* Bump spice-protocol dependency to v0.14.3
|
||||
|
||||
News in spice-vdagent 0.20.0
|
||||
============================
|
||||
|
||||
* Add gio-unix and gobject dependency >= 2.50
|
||||
* Bump gtk+ >= 3.22 (optional dependency)
|
||||
* Last release with gtk+ being optional
|
||||
* !4 - Race fixes between client and guest clipboard
|
||||
* !2 - Fix session lookup for new GNOME versions
|
||||
* !3 - Now using GMainLoop and GIO to handle I/O of messages
|
||||
* Several minor covscan fixes
|
||||
|
||||
News in spice-vdagent 0.19.0
|
||||
============================
|
||||
|
||||
* Add libdrm dependency
|
||||
* Fix file descriptor leak on failed connections
|
||||
* Handle new VD_AGENT_GRAPHICS_DEVICE_INFO message advertised by
|
||||
VD_AGENT_CAP_GRAPHICS_DEVICE_INFO capability
|
||||
* Session agent autostart changed to WindowManager ([rhbz#1623947])
|
||||
This fixes possible race with xdg-user-dirs
|
||||
* Fix of sending empty screen resolution messages ([rhbz#1641723])
|
||||
* Fix 'Dependency failed for Activation socket' with systemd ([rhbz#1545212])
|
||||
* Fix error messages about on selecting text on host ([rhbz#1594876])
|
||||
this was also fixed with Gtk backend
|
||||
* Update paths from /var/run → /run
|
||||
* Fix Session agent restart
|
||||
* Add test for file creation
|
||||
* Prefer GLib memory functions stdlib.h ones
|
||||
* Several code and logs improvements
|
||||
|
||||
[rhbz#1623947]: https://bugzilla.redhat.com/show_bug.cgi?id=1623947
|
||||
[rhbz#1641723]: https://bugzilla.redhat.com/show_bug.cgi?id=1641723
|
||||
[rhbz#1545212]: https://bugzilla.redhat.com/show_bug.cgi?id=1545212
|
||||
[rhbz#1594876]: https://bugzilla.redhat.com/show_bug.cgi?id=1594876
|
||||
|
||||
News in spice-vdagent 0.18.0
|
||||
============================
|
||||
|
||||
* Add GTK+ framework to handle x11 backend such as clipboard
|
||||
* Deprecate X11 backend in favor of GTK+ framework
|
||||
* Ask pkg-config to appropriate directory to install udev rules
|
||||
* Fix leak of udscs's file descriptor
|
||||
* Better quote directory path when calling xdg-open to save file transfer
|
||||
* Bump GLib to 2.34
|
||||
* Add systemd socket activation (rhbz#1340160)
|
||||
* Add support to detailed errors on file transfers
|
||||
* Add check for available free space in guest before starting a file transfer
|
||||
* Use better names for duplicated files on file transfer
|
||||
* Improve support on big endian guests (#5)
|
||||
* Use IdleHint to check if a session is locked over console-kit (rhbz#1412673)
|
||||
* Fixes double free on errors over udscs by improving memory ownership
|
||||
* Hide autostart file on Unity
|
||||
* Improve command line messages for vdagentd
|
||||
* Fix typo in --enable-static-uinput configure option
|
||||
* Code repository moved to gitlab.freedesktop.org
|
||||
|
||||
News in spice-vdagent 0.17.0
|
||||
============================
|
||||
|
||||
* Denies file-transfer in locked sessions
|
||||
* systems under systemd (rhbz#1323623)
|
||||
* systems under console-kit (rhbz#1323630)
|
||||
* Denies file-transfer in login screen
|
||||
* systems under systemd (rhbz#1328761)
|
||||
* systems under console-kit (rhbz#1323640)
|
||||
* Bump glib version to 2.28
|
||||
* 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 compatibility with different libsystemd versions (fdo#94209)
|
||||
|
||||
News in spice-vdagent 0.16.0
|
||||
============================
|
||||
|
||||
* Add audio volume synchronization support
|
||||
* Add support for maximum clipboard size
|
||||
* Add support for more clipboard targets (STRING and TIMESTAMP)
|
||||
* Improve handling of transfers of multiple files
|
||||
* Fix transfer of >2GB files on 32 bit systems
|
||||
* XSpice improvements
|
||||
* Various bug fixes related to resolution changes
|
||||
|
||||
News in spice-vdagent 0.15.0
|
||||
============================
|
||||
|
||||
* Xspice support
|
||||
* Release clipboard on client disconnect if owned by client (rhbz#1003977)
|
||||
* Turn some error messages into debugging messages (rhbz#918310)
|
||||
* Not having the virtio channel is not an error; instead silently do nothing
|
||||
|
||||
News in spice-vdagent 0.14.0
|
||||
============================
|
||||
|
||||
* 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:
|
||||
* Max one monitor per Screen / qxl device
|
||||
* All monitors / Screens must have the same resolution
|
||||
* No client -> guest resolution syncing
|
||||
* Add spice-vdagent -X cmdline option, which runtime disables console-kit /
|
||||
systemd-logind integration for setups where these are not used
|
||||
* Add manpages for spice-vdagent and spice-vdagentd
|
||||
|
||||
News in spice-vdagent 0.12.1
|
||||
============================
|
||||
|
||||
* 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 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 activation
|
||||
* Use syslog for logging, rather then logging to private log files
|
||||
|
||||
News in spice-vdagent 0.10.1
|
||||
============================
|
||||
|
||||
* Fix a race condition when opening the vdagent virtio serial port, which
|
||||
caused it to get opened / closed in rapid succession a number of times
|
||||
on vm boot
|
||||
|
||||
News in spice-vdagent 0.10.0
|
||||
============================
|
||||
|
||||
* Add limited support for multiple displays, see README
|
||||
* Add support for RHEL-5 (and other distributions with a non hotplug
|
||||
capable Xorg and/or no console-kit), see README.RHEL-5
|
||||
* Add support for using libsystemd-logind as session information source
|
||||
instead of console-kit
|
||||
|
||||
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 session vdagent re-execs itself (Marc-André Lureau)
|
||||
|
||||
News in spice-vdagent 0.8.0
|
||||
===========================
|
||||
|
||||
* Add support for copy and paste using the primary selection, to use this
|
||||
you need a spice-gtk widget based client and the latest spice-gtk code
|
||||
(Marc-André Lureau and Hans de Goede)
|
||||
* Autotoolized (Christophe Fergeau)
|
||||
* Allow building without consolekit, for systems which don't have ck, such
|
||||
as RHEL-5 (Christophe Fergeau)
|
||||
* Various small bugfixes (Hans de Goede)
|
||||
|
||||
News in spice-vdagent 0.6.3
|
||||
===========================
|
||||
|
||||
* Initial release, starting with version nr 0.6.3, to indicate that it
|
||||
more or less supports all parts of the cdagent protocol in spice-protocol
|
||||
and spice 0.6.3
|
||||
@@ -1,43 +0,0 @@
|
||||
spice-vdagent-0.12.0
|
||||
--------------------
|
||||
* Full multi-monitor and arbritary 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
|
||||
* Use syslog for logging, rather then logging to private log files
|
||||
|
||||
spice-vdagent-0.10.1
|
||||
--------------------
|
||||
* Fix a race condition when opening the vdagent virtio serial port, which
|
||||
caused it to get opened / closed in rapid succession a number of times
|
||||
on vm boot
|
||||
|
||||
spice-vdagent-0.10.0
|
||||
--------------------
|
||||
* Add limited support for multiple displays, see README
|
||||
* Add support for RHEL-5 (and other distributions with a non hotplug
|
||||
capable Xorg and/or no console-kit), see README.RHEL-5
|
||||
* Add support for using libsystemd-logind as session information source
|
||||
instead of console-kit
|
||||
|
||||
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)
|
||||
|
||||
spice-vdagent-0.8.0
|
||||
-------------------
|
||||
* Add support for copy and paste using the primary selection, to use this
|
||||
you need a spice-gtk widget based client and the latest spice-gtk code
|
||||
(Marc-André Lureau and Hans de Goede)
|
||||
* Autotoolized (Christophe Fergeau)
|
||||
* Allow building without consolekit, for systems which don't have ck, such
|
||||
as RHEL-5 (Christophe Fergeau)
|
||||
* Various small bugfixes (Hans de Goede)
|
||||
|
||||
spice-vdagent-0.6.3
|
||||
-------------------
|
||||
* Initial release, starting with version nr 0.6.3, to indicate that it
|
||||
more or less supports all parts of the cdagent protocol in spice-protocol
|
||||
and spice 0.6.3
|
||||
+161
-38
@@ -3,46 +3,155 @@ NULL =
|
||||
|
||||
bin_PROGRAMS = src/spice-vdagent
|
||||
sbin_PROGRAMS = src/spice-vdagentd
|
||||
check_PROGRAMS = tests/test-file-xfers
|
||||
TESTS = $(check_PROGRAMS)
|
||||
|
||||
src_spice_vdagent_CFLAGS = $(X_CFLAGS) $(SPICE_CFLAGS)
|
||||
src_spice_vdagent_LDADD = $(X_LIBS) $(SPICE_LIBS)
|
||||
src_spice_vdagent_SOURCES = src/vdagent.c src/vdagent-x11.c src/vdagent-x11-randr.c src/udscs.c
|
||||
common_sources = \
|
||||
src/udscs.c \
|
||||
src/udscs.h \
|
||||
src/vdagent-connection.c \
|
||||
src/vdagent-connection.h \
|
||||
src/vdagentd-proto-strings.h \
|
||||
src/vdagentd-proto.h \
|
||||
$(NULL)
|
||||
|
||||
src_spice_vdagent_CFLAGS = \
|
||||
$(DRM_CFLAGS) \
|
||||
$(X_CFLAGS) \
|
||||
$(SPICE_CFLAGS) \
|
||||
$(GIO2_CFLAGS) \
|
||||
$(GTK_CFLAGS) \
|
||||
$(ALSA_CFLAGS) \
|
||||
-I$(srcdir)/src \
|
||||
-DUDSCS_NO_SERVER \
|
||||
$(NULL)
|
||||
|
||||
src_spice_vdagent_LDADD = \
|
||||
$(DRM_LIBS) \
|
||||
$(X_LIBS) \
|
||||
$(SPICE_LIBS) \
|
||||
$(GIO2_LIBS) \
|
||||
$(GTK_LIBS) \
|
||||
$(ALSA_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
src_spice_vdagent_SOURCES = \
|
||||
$(common_sources) \
|
||||
src/vdagent/audio.c \
|
||||
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 \
|
||||
src/vdagent/x11.h \
|
||||
src/vdagent/vdagent.c \
|
||||
$(NULL)
|
||||
|
||||
tests_test_file_xfers_CFLAGS = \
|
||||
$(SPICE_CFLAGS) \
|
||||
$(GIO2_CFLAGS) \
|
||||
-I$(srcdir)/src \
|
||||
-I$(srcdir)/src/vdagent \
|
||||
-DUDSCS_NO_SERVER \
|
||||
$(NULL)
|
||||
|
||||
tests_test_file_xfers_LDADD = \
|
||||
$(SPICE_LIBS) \
|
||||
$(GIO2_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
tests_test_file_xfers_SOURCES = \
|
||||
$(common_sources) \
|
||||
src/vdagent/file-xfers.c \
|
||||
src/vdagent/file-xfers.h \
|
||||
tests/test-file-xfers.c \
|
||||
$(NULL)
|
||||
|
||||
src_spice_vdagentd_CFLAGS = \
|
||||
$(DBUS_CFLAGS) \
|
||||
$(LIBSYSTEMD_DAEMON_CFLAGS) \
|
||||
$(LIBSYSTEMD_LOGIN_CFLAGS) \
|
||||
$(PCIACCESS_CFLAGS) \
|
||||
$(SPICE_CFLAGS) \
|
||||
$(GIO2_CFLAGS) \
|
||||
$(PIE_CFLAGS) \
|
||||
-I$(srcdir)/src \
|
||||
$(NULL)
|
||||
|
||||
src_spice_vdagentd_LDADD = \
|
||||
$(DBUS_LIBS) \
|
||||
$(LIBSYSTEMD_DAEMON_LIBS) \
|
||||
$(LIBSYSTEMD_LOGIN_LIBS) \
|
||||
$(PCIACCESS_LIBS) \
|
||||
$(SPICE_LIBS) \
|
||||
$(GIO2_LIBS) \
|
||||
$(PIE_LDFLAGS) \
|
||||
$(NULL)
|
||||
|
||||
src_spice_vdagentd_SOURCES = \
|
||||
$(common_sources) \
|
||||
src/vdagentd/vdagentd.c \
|
||||
src/vdagentd/session-info.h \
|
||||
src/vdagentd/uinput.c \
|
||||
src/vdagentd/uinput.h \
|
||||
src/vdagentd/xorg-conf.c \
|
||||
src/vdagentd/xorg-conf.h \
|
||||
src/vdagentd/virtio-port.c \
|
||||
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)
|
||||
|
||||
src_spice_vdagentd_CFLAGS = $(DBUS_CFLAGS) $(LIBSYSTEMD_LOGIN_CFLAGS) $(PCIACCESS_CFLAGS) $(SPICE_CFLAGS)
|
||||
src_spice_vdagentd_LDADD = $(DBUS_LIBS) $(LIBSYSTEMD_LOGIN_LIBS) $(PCIACCESS_LIBS) $(SPICE_LIBS)
|
||||
src_spice_vdagentd_SOURCES = src/vdagentd.c \
|
||||
src/vdagentd-uinput.c \
|
||||
src/vdagentd-xorg-conf.c \
|
||||
src/vdagent-virtio-port.c \
|
||||
src/udscs.c
|
||||
if HAVE_CONSOLE_KIT
|
||||
src_spice_vdagentd_SOURCES += src/console-kit.c
|
||||
endif
|
||||
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/systemd-login.c
|
||||
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
|
||||
endif
|
||||
|
||||
noinst_HEADERS = src/session-info.h \
|
||||
src/vdagentd-proto-strings.h \
|
||||
src/vdagent-x11.h \
|
||||
src/vdagent-x11-priv.h \
|
||||
src/udscs.h \
|
||||
src/vdagentd-uinput.h \
|
||||
src/vdagentd-xorg-conf.h \
|
||||
src/vdagentd-proto.h \
|
||||
src/vdagent-virtio-port.h
|
||||
|
||||
xdgautostartdir = $(sysconfdir)/xdg/autostart
|
||||
xdgautostart_DATA = $(top_srcdir)/data/spice-vdagent.desktop
|
||||
|
||||
gdmautostartdir = $(datadir)/gdm/autostart/LoginWindow
|
||||
gdmautostartdir = $(datadir)/gdm/greeter/autostart
|
||||
gdmautostart_DATA = $(top_srcdir)/data/spice-vdagent.desktop
|
||||
|
||||
install-data-local:
|
||||
$(mkdir_p) $(DESTDIR)$(localstatedir)/run/spice-vdagentd
|
||||
|
||||
rsyslogdir = $(sysconfdir)/rsyslog.d
|
||||
rsyslog_DATA = $(top_srcdir)/data/rsyslog.d/spice-vdagentd.conf
|
||||
gdmautostart2dir = $(datadir)/gdm/autostart/LoginWindow
|
||||
gdmautostart2_DATA = $(top_srcdir)/data/spice-vdagent.desktop
|
||||
|
||||
if INIT_SCRIPT_RED_HAT
|
||||
initdir = $(sysconfdir)/rc.d/init.d
|
||||
@@ -53,27 +162,34 @@ if INIT_SCRIPT_SYSTEMD
|
||||
systemdunitdir = $(SYSTEMDSYSTEMUNITDIR)
|
||||
systemdunit_DATA = \
|
||||
$(top_srcdir)/data/spice-vdagentd.service \
|
||||
$(top_srcdir)/data/spice-vdagentd.target
|
||||
$(top_srcdir)/data/spice-vdagentd.socket
|
||||
|
||||
udevrulesdir = /lib/udev/rules.d
|
||||
userunitdir = $(SYSTEMDUSERUNITDIR)
|
||||
userunit_DATA = \
|
||||
$(top_srcdir)/data/spice-vdagent.service
|
||||
|
||||
udevrulesdir = $(udevdir)/rules.d
|
||||
udevrules_DATA = $(top_srcdir)/data/70-spice-vdagentd.rules
|
||||
|
||||
tmpfilesdir = $(prefix)/lib/tmpfiles.d
|
||||
tmpfiles_DATA = $(top_srcdir)/data/tmpfiles.d/spice-vdagentd.conf
|
||||
|
||||
modulesdir = $(sysconfdir)/modules-load.d
|
||||
modules_DATA = $(top_srcdir)/data/modules-load.d/spice-vdagentd.conf
|
||||
endif
|
||||
|
||||
manpagedir = $(mandir)/man1
|
||||
manpage_DATA = \
|
||||
data/spice-vdagent.1 \
|
||||
data/spice-vdagentd.1 \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DIST = \
|
||||
README.RHEL-5 \
|
||||
README.md \
|
||||
CHANGELOG.md \
|
||||
data/70-spice-vdagentd.rules \
|
||||
data/modules-load.d/spice-vdagentd.conf \
|
||||
data/rsyslog.d/spice-vdagentd.conf \
|
||||
data/spice-vdagent.desktop \
|
||||
data/spice-vdagent.service \
|
||||
data/spice-vdagentd \
|
||||
data/spice-vdagentd.service \
|
||||
data/spice-vdagentd.target \
|
||||
data/spice-vdagentd.socket \
|
||||
data/tmpfiles.d/spice-vdagentd.conf \
|
||||
data/xorg.conf.RHEL-5 \
|
||||
$(NULL)
|
||||
@@ -81,3 +197,10 @@ EXTRA_DIST = \
|
||||
DISTCHECK_CONFIGURE_FLAGS = \
|
||||
--with-init-script=redhat \
|
||||
$(NULL)
|
||||
|
||||
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,63 +0,0 @@
|
||||
Spice agent for 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
|
||||
through a Sys-V initscript. The per X-session gets automatically started in
|
||||
desktop environments which honor /etc/xdg/autostart, and under gdm.
|
||||
|
||||
The main daemon needs to know which X-session daemon is the currently
|
||||
active X-session (think switch user functionality) for this console kit is
|
||||
used. spice-vdagent can be compiled without console kit support for use with
|
||||
older distributions, in this case only one active X session is allowed.
|
||||
|
||||
Features:
|
||||
* Client mouse mode (no need to grab mouse by client, no mouse lag)
|
||||
this is handled by the daemon by feeding mouse events into the kernel
|
||||
via uinput. This will only work if the active X-session is running a
|
||||
spice-vdagent process so that its resolution can be determined.
|
||||
* Automatic adjustment of the X-session resolution to the client resolution
|
||||
for single monitor configurations.
|
||||
* Support of copy and paste (text and images) between the active X-session
|
||||
and the client. This supports both the primary selection and the clipboard.
|
||||
* Limited support for multiple displays using Xinerama, prerequisites:
|
||||
* A new enough Xorg-server. For Fedora atleast Fedora-17, for RHEL-6 atleast
|
||||
xorg-x11-server-1.10.4-6.el6_2.3
|
||||
* A vm configured with multiple qxl devices
|
||||
* A guest running the latest spice-vdagent
|
||||
Then connect to the vm with the multiple monitor client which you want to
|
||||
use it with using: "spicec --full-screen=auto-config" (or the user portal
|
||||
equivalent). At this point the agent will write out a:
|
||||
/var/run/spice-vdagentd/xorg.conf.spice file. With all the necessary magic
|
||||
to get Xinerama working. Move this file to /etc/X11/xorg.conf, then kill
|
||||
Xorg so that it will get restarted and you should be good to go.
|
||||
* Full support for multiple displays using Xrandr, this requires a new
|
||||
enough xorg-x11-drv-qxl driver, as well as a new enough host.
|
||||
|
||||
All vdagent communications on the guest side run over a single pipe which
|
||||
gets presented to the guest os as a virtio serial port.
|
||||
|
||||
Under windows this virtio serial port has the following name:
|
||||
\\\\.\\Global\\com.redhat.spice.0
|
||||
|
||||
Under Linux this virtio serial port has the following name:
|
||||
/dev/virtio-ports/com.redhat.spice.0
|
||||
|
||||
To enable the virtio serial port you need to pass the following params on
|
||||
the qemu cmdline:
|
||||
|
||||
For qemu < 0.14.0:
|
||||
-device spicevmc
|
||||
|
||||
For qemu >= 0.14.0:
|
||||
-device virtio-serial-pci,id=virtio-serial0,max_ports=16,bus=pci.0,addr=0x5 \
|
||||
-chardev spicevmc,name=vdagent,id=vdagent \
|
||||
-device \
|
||||
virtserialport,nr=1,bus=virtio-serial0.0,chardev=vdagent,name=com.redhat.spice.0
|
||||
|
||||
Enjoy,
|
||||
Gerd & Hans
|
||||
|
||||
--
|
||||
Gerd Hoffmann <[email protected]>
|
||||
Hans de Goede <[email protected]>
|
||||
@@ -1,34 +0,0 @@
|
||||
spice-vdagent and RHEL-5 README
|
||||
-------------------------------
|
||||
|
||||
spice-vdagent can also be used inside RHEL-5 guests, if, and only if, they
|
||||
are hosted on a host which uses virtio-serial as the agent channel. Note
|
||||
that older hosts, such as qemu shipped with RHEL-5 for example, use
|
||||
a custom pci device (the spicevmc device) for the agent channel and
|
||||
there is no Linux support for this device so spice-vdagent does not work
|
||||
inside guests hosted on such hosts! Hosts based on RHEL-6 or Fedora 15
|
||||
and newer for example, are fine.
|
||||
|
||||
spice-vdagent relies on ConsoleKit to determine the active session, since
|
||||
RHEL-5 has no ConsoleKit it cannot do this on RHEL-5, therefor only 1
|
||||
active X-session is supported with RHEL-5. If you try to start multiple
|
||||
sessions by running multiple X-servers the agent will disable itself.
|
||||
|
||||
Since the RHEL-5 X-server does not support hotplugging of input devices,
|
||||
spice-vdagentd must be started before the X-server, so that it can create
|
||||
the uinput tablet device it uses for agent mouse mode.
|
||||
|
||||
This also means that you must use a customized xorg.conf to teach the
|
||||
X-server about the uinput device. An example xorg.conf is included with
|
||||
spice-vdagent. After installing spice-vdagent, first start spice-vdagentd,
|
||||
and then copy this file to /etc/X11/xorg.conf and restart your X-server.
|
||||
|
||||
Note: the sample xorg.conf assumes that the vm has been configured to *not*
|
||||
use a usb tablet device, since there is no need for one with the agent and
|
||||
usb emulation takes a significant amount of CPU.
|
||||
|
||||
Building from source for RHEL-5
|
||||
-------------------------------
|
||||
|
||||
If you're building spice-vdagent from source on RHEL-5, you must pass
|
||||
--disable-console-kit --enable-static-uinput to ./configure!
|
||||
@@ -0,0 +1,110 @@
|
||||
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
|
||||
through a Sys-V initscript or a systemd unit. The per X-session gets
|
||||
automatically started in desktop environments which honor /etc/xdg/autostart,
|
||||
and under gdm.
|
||||
|
||||
The main daemon needs to know which X-session daemon is in the currently
|
||||
active X-session (think switch user functionality) for this console kit or
|
||||
systemd-logind (compile time option) is used. If no session info is
|
||||
available only one X-session agent is allowed.
|
||||
|
||||
Features:
|
||||
* Client mouse mode (no need to grab mouse by client, no mouse lag)
|
||||
this is handled by the daemon by feeding mouse events into the kernel
|
||||
via uinput. This will only work if the active X-session is running a
|
||||
spice-vdagent process so that its resolution can be determined.
|
||||
* Automatic adjustment of the X-session resolution to the client resolution
|
||||
* Support of copy and paste (text and images) between the active X-session
|
||||
and the client. This supports both the primary selection and the clipboard.
|
||||
* Support for transferring files from the client to the agent
|
||||
* Full support for multiple displays using Xrandr, this requires a new
|
||||
enough xorg-x11-drv-qxl driver, as well as a new enough host.
|
||||
* Limited support for multiple displays using Xinerama.
|
||||
* Limited support for setups with multiple Screens (multiple qxl devices each
|
||||
mapped to their own screen)
|
||||
|
||||
### macOS
|
||||
|
||||
Similar to Linux, the SPICE agent has a LaunchDaemon spice-vdagentd which
|
||||
handles communication with the console port and a LaunchAgent spice-vdagent
|
||||
that runs for each logged in user. Note that there is no protection against
|
||||
one logged in user from snooping another user's clipboard when this is running.
|
||||
|
||||
The macOS agent currently only supports clipboard features.
|
||||
|
||||
## Install (Linux)
|
||||
|
||||
From inside your virtual machine (e.g., GNOME Boxes), use your guest system’s
|
||||
package manager to install.
|
||||
|
||||
For example, if you’re running a Debian/Ubuntu derivative in a VM, use:
|
||||
|
||||
```shell
|
||||
sudo apt install spice-vdagent
|
||||
```
|
||||
|
||||
## Build (macOS)
|
||||
|
||||
Currently, you can only build on Apple Silicon Macs with Homebrew installed in
|
||||
both native and Rosetta. This is because we require GLib installed in both
|
||||
architectures at the default location.
|
||||
|
||||
>>>
|
||||
$ /opt/homebrew/bin/brew install glib # arm64
|
||||
$ /usr/local/bin/brew install glib # x86_64
|
||||
>>>
|
||||
|
||||
Alternatively, GLib can be built from source for each architecture (see
|
||||
`.github/workflows/build.yaml`) and the install prefixes passed to Xcode
|
||||
with `GLIB_ARM64_PREFIX=... GLIB_X86_64_PREFIX=...`.
|
||||
|
||||
Then, you can build the project with Xcode or `xcodebuild`
|
||||
|
||||
>>>
|
||||
$ xcodebuild archive -scheme vd_agent -archivePath vd_agent.xcarchive
|
||||
>>>
|
||||
|
||||
Afterwards, you can sign the output and create an installer package with a paid
|
||||
Apple Developer certificate (Developer ID Application and Developer ID
|
||||
Installer are both needed).
|
||||
|
||||
>>>
|
||||
$ ./package_macos.sh vd_agent.xcarchive spice-vdagent-x.yy.pkg
|
||||
>>>
|
||||
|
||||
You may then wish to notarize it before distributing.
|
||||
|
||||
## How it works
|
||||
|
||||
All vdagent communications on the guest side run over a single pipe which
|
||||
gets presented to the guest os as a virtio serial port.
|
||||
|
||||
Under windows this virtio serial port has the following name:
|
||||
>>>
|
||||
\\\\.\\Global\\com.redhat.spice.0
|
||||
>>>
|
||||
|
||||
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:
|
||||
|
||||
>>>
|
||||
-device virtio-serial-pci,id=virtio-serial0,max_ports=16,bus=pci.0,addr=0x5 \
|
||||
-chardev spicevmc,name=vdagent,id=vdagent \
|
||||
-device virtserialport,nr=1,bus=virtio-serial0.0,chardev=vdagent,name=com.redhat.spice.0
|
||||
>>>
|
||||
@@ -1,6 +0,0 @@
|
||||
-patch xorg driver to allow adding "random" resolutions
|
||||
-make vdagent xorg client try to add "random" resolutions
|
||||
|
||||
Maybe:
|
||||
-Add support for selections with a target of STRING, which are
|
||||
ISO Latin-1 strings, which we could support through iconv
|
||||
+3
-1
@@ -1,4 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
autoreconf -fi
|
||||
./configure $@
|
||||
if test -z "$NOCONFIGURE"; then
|
||||
exec ./configure "$@"
|
||||
fi
|
||||
+125
-18
@@ -1,5 +1,5 @@
|
||||
AC_PREREQ(2.59)
|
||||
AC_INIT([spice-vdagent], [0.12.0])
|
||||
AC_INIT([spice-vdagent], [0.22.1])
|
||||
AC_CONFIG_SRCDIR([configure.ac])
|
||||
|
||||
AM_CONFIG_HEADER([src/config.h])
|
||||
@@ -10,6 +10,7 @@ m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
|
||||
AC_PROG_CC
|
||||
AM_PROG_CC_C_O
|
||||
AC_HEADER_STDC
|
||||
AC_SYS_LARGEFILE
|
||||
AC_PROG_INSTALL
|
||||
AC_PROG_LN_S
|
||||
AC_DEFINE(_GNU_SOURCE, [1], [Enable GNU extensions])
|
||||
@@ -63,7 +64,49 @@ 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],
|
||||
[have_libsystemd_daemon="yes"],
|
||||
[have_libsystemd_daemon="no"])
|
||||
if test "$have_libsystemd_daemon" = "yes"; then
|
||||
AC_DEFINE([WITH_SYSTEMD_SOCKET_ACTIVATION], [1], [If defined, vdagentd will support socket activation with systemd] )
|
||||
fi
|
||||
fi
|
||||
|
||||
AC_ARG_WITH([gtk],
|
||||
[AS_HELP_STRING(
|
||||
[--with-gtk=@<:@auto/yes/no@:>@],
|
||||
[Use GTK+ instead of Xlib @<:@default=auto@:>@])],
|
||||
[],
|
||||
[with_gtk="auto"])
|
||||
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],
|
||||
@@ -72,18 +115,33 @@ AC_ARG_ENABLE([pciaccess],
|
||||
[enable_pciaccess="yes"])
|
||||
|
||||
AC_ARG_ENABLE([static-uinput],
|
||||
[AS_HELP_STRING([--enable-statis-uinput], [Enable use of a fixed, static uinput device for X-servers without hotplug support (default: no)])],
|
||||
[AS_HELP_STRING([--enable-static-uinput], [Enable use of a fixed, static uinput device for X-servers without hotplug support (default: no)])],
|
||||
[enable_static_uinput="$enableval"],
|
||||
[enable_static_uinput="no"])
|
||||
|
||||
PKG_CHECK_MODULES(X, [xfixes xrandr xinerama x11])
|
||||
PKG_CHECK_MODULES(SPICE, [spice-protocol >= 0.8.0])
|
||||
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.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-login >= 42],
|
||||
[libsystemd >= 209],
|
||||
[have_libsystemd_login="yes"],
|
||||
[have_libsystemd_login="no"])
|
||||
if test "$have_libsystemd_login" = "no"; then
|
||||
# for backward compatibility with older systemd versions
|
||||
PKG_CHECK_MODULES([LIBSYSTEMD_LOGIN],
|
||||
[libsystemd-login >= 42],
|
||||
[have_libsystemd_login="yes"],
|
||||
[have_libsystemd_login="no"])
|
||||
fi
|
||||
if test x"$have_libsystemd_login" = "xno" && test "$with_session_info" = "systemd"; then
|
||||
AC_MSG_ERROR([libsystemd-login support explicitly requested, but some required packages are not available])
|
||||
fi
|
||||
@@ -96,20 +154,14 @@ else
|
||||
fi
|
||||
AM_CONDITIONAL(HAVE_LIBSYSTEMD_LOGIN, test x"$have_libsystemd_login" = "xyes")
|
||||
|
||||
#udevdir
|
||||
udevdir=$($PKG_CONFIG --variable=udevdir udev)
|
||||
AC_SUBST(udevdir)
|
||||
|
||||
if test "$with_session_info" = "auto" || test "$with_session_info" = "console-kit"; then
|
||||
PKG_CHECK_MODULES([DBUS],
|
||||
[dbus-1],
|
||||
[have_console_kit="yes"],
|
||||
[have_console_kit="no"])
|
||||
if test x"$have_console_kit" = "xno" && test "$with_session_info" = "console-kit"; then
|
||||
AC_MSG_ERROR([console-kit support explicitly requested, but some required packages are not available])
|
||||
fi
|
||||
if test x"$have_console_kit" = "xyes"; then
|
||||
AC_DEFINE([HAVE_CONSOLE_KIT], [1], [If defined, vdagentd will be compiled with ConsoleKit support])
|
||||
with_session_info="console-kit"
|
||||
else
|
||||
with_session_info="none"
|
||||
fi
|
||||
AC_DEFINE([HAVE_CONSOLE_KIT], [1], [If defined, vdagentd will be compiled with ConsoleKit support])
|
||||
have_console_kit="yes"
|
||||
with_session_info="console-kit"
|
||||
else
|
||||
have_console_kit="no"
|
||||
fi
|
||||
@@ -125,8 +177,59 @@ if test x"$enable_static_uinput" = "xyes" ; then
|
||||
AC_DEFINE([WITH_STATIC_UINPUT], [1], [If defined, vdagentd will use a static uinput device] )
|
||||
fi
|
||||
|
||||
# If no CFLAGS are set, set some sane default CFLAGS
|
||||
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])
|
||||
save_CFLAGS="$CFLAGS"
|
||||
CFLAGS="$CFLAGS $F"
|
||||
AC_COMPILE_IFELSE([AC_LANG_SOURCE([ ])], [cc_flag=yes], [cc_flag=no])
|
||||
if test "x$cc_flag" != "xyes"; then
|
||||
CFLAGS="$save_CFLAGS"
|
||||
fi
|
||||
AC_MSG_RESULT([$cc_flag])
|
||||
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@:>@]),
|
||||
[],
|
||||
[enable_pie="auto"])
|
||||
|
||||
if test "x$enable_pie" != "xno"; then
|
||||
save_CFLAGS="$CFLAGS"
|
||||
save_LDFLAGS="$LDFLAGS"
|
||||
CFLAGS="$CFLAGS -fPIE"
|
||||
LDFLAGS="$LDFLAGS -pie -Wl,-z,relro -Wl,-z,now"
|
||||
AC_MSG_CHECKING([for PIE support])
|
||||
AC_LINK_IFELSE([AC_LANG_SOURCE([int main () { return 0; }])],
|
||||
[have_pie=yes],
|
||||
[have_pie=no])
|
||||
AC_MSG_RESULT([$have_pie])
|
||||
if test "x$have_pie" = "xno" && test "x$enable_pie" = "xyes"; then
|
||||
AC_MSG_ERROR([pie support explicitly requested, but your toolchain does not support it])
|
||||
fi
|
||||
if test "x$have_pie" = "xyes"; then
|
||||
PIE_CFLAGS="-fPIE"
|
||||
PIE_LDFLAGS="-pie -Wl,-z,relro -Wl,-z,now"
|
||||
AC_SUBST(PIE_CFLAGS)
|
||||
AC_SUBST(PIE_LDFLAGS)
|
||||
fi
|
||||
CFLAGS="$save_CFLAGS"
|
||||
LDFLAGS="$save_LDFLAGS"
|
||||
else
|
||||
have_pie=no
|
||||
fi
|
||||
|
||||
AC_CONFIG_FILES([
|
||||
Makefile
|
||||
data/spice-vdagent.1
|
||||
data/spice-vdagentd.1
|
||||
])
|
||||
AC_OUTPUT
|
||||
|
||||
@@ -142,9 +245,13 @@ AC_MSG_NOTICE([
|
||||
session-info: ${with_session_info}
|
||||
pciaccess: ${enable_pciaccess}
|
||||
static uinput: ${enable_static_uinput}
|
||||
vdagentd pie + relro: ${have_pie}
|
||||
|
||||
install RH initscript: ${init_redhat}
|
||||
install systemd service: ${init_systemd}
|
||||
udevdir: ${udevdir}
|
||||
|
||||
use GTK+: ${with_gtk}
|
||||
|
||||
Now type 'make' to build $PACKAGE
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
ACTION=="add", SUBSYSTEM=="virtio-ports", ENV{DEVLINKS}=="/dev/virtio-ports/com.redhat.spice.0", ENV{SYSTEMD_WANTS}="spice-vdagentd.target"
|
||||
ACTION=="add", SUBSYSTEM=="virtio-ports", ENV{DEVLINKS}=="/dev/virtio-ports/com.redhat.spice.0", ENV{SYSTEMD_WANTS}="spice-vdagentd.socket"
|
||||
@@ -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
|
||||
@@ -1,2 +0,0 @@
|
||||
# load uinput.ko for spice input
|
||||
uinput
|
||||
@@ -1,4 +0,0 @@
|
||||
# A template to for higher precision timestamps + severity logging
|
||||
$template SpiceTmpl,"%TIMESTAMP%.%TIMESTAMP:::date-subseconds% %syslogtag% %syslogseverity-text%:%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
|
||||
|
||||
:programname, startswith, "spice-vdagent" /var/log/spice-vdagent.log;SpiceTmpl
|
||||
@@ -0,0 +1,60 @@
|
||||
.TH spice-vdagent "1" "April 2013" "@PACKAGE_STRING@"
|
||||
.SH NAME
|
||||
spice-vdagent \- Spice guest agent X11 session agent
|
||||
.SH SYNOPSIS
|
||||
\fBspice-vdagent\fR [\fIOPTIONS\fR]
|
||||
.SH DESCRIPTION
|
||||
The spice guest agent for Linux consists of 2 parts, a system wide daemon
|
||||
\fBspice-vdagentd\fR and a X11 session agent \fBspice-vdagent\fR of which
|
||||
there is one per X11 session.
|
||||
.br
|
||||
\fBspice-vdagent\fR gets automatically started in desktop environments which
|
||||
honor /etc/xdg/autostart, and under gdm.
|
||||
.SH FEATURES
|
||||
The spice guest agent adds the following features to spice Linux guests:
|
||||
.P
|
||||
Client mouse mode (no need to grab mouse by client, no mouse lag)
|
||||
.P
|
||||
Automatic adjustment of the X11 session's number of virtual monitors, and their
|
||||
resolution, to the number of client windows and their resolution
|
||||
.P
|
||||
Support of copy and paste (text and images) between the active X11 session
|
||||
and the client, this supports both the primary selection and the clipboard
|
||||
.P
|
||||
Support for transferring files from the client to the agent
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
\fB-h\fP
|
||||
Print a short description of all command line options
|
||||
.TP
|
||||
\fB-d\fP
|
||||
Log debug messages
|
||||
.TP
|
||||
\fB-s\fP \fIport\fR
|
||||
Set virtio serial \fIport\fR (default: /dev/virtio-ports/com.redhat.spice.0)
|
||||
.TP
|
||||
\fB-x\fP
|
||||
Don't daemonize
|
||||
.TP
|
||||
\fB-f\fP \fIdir|xdg-desktop|xdg-download\fR
|
||||
Set directory where to save files send from the client, this can be either
|
||||
an arbitrary \fIdir\fR or one of the special values of \fIxdg-desktop\fR or
|
||||
\fIxdg-download\fR to select the default xdg Desktop resp. xdg Download
|
||||
directory. If no value is specified the default is \fIxdg-desktop\fR when
|
||||
running under a Desktop Environment which has icons on the desktop and
|
||||
\fIxdg-download\fR under other Desktop Environments
|
||||
.TP
|
||||
\fB-o\fP \fI0|1\fR
|
||||
Disable/enable opening the file save directory with xdg-open (showing the
|
||||
directory in the file manager) when a file transfer from the client
|
||||
completes. If no value is specified the default is \fI0\fR when running under
|
||||
a Desktop Environment which has icons on the desktop and \fI1\fR under other
|
||||
Desktop Environments
|
||||
.SH SEE ALSO
|
||||
\fBspice-vdagentd\fR(1)
|
||||
.SH COPYRIGHT
|
||||
Copyright 2010-2013 Red Hat, Inc. License GPLv3+: GNU GPL version 3 or later
|
||||
<http://gnu.org/licenses/gpl.html>.
|
||||
.br
|
||||
This is free software: you are free to change and redistribute it.
|
||||
There is NO WARRANTY, to the extent permitted by law.
|
||||
@@ -5,5 +5,6 @@ Exec=/usr/bin/spice-vdagent
|
||||
Terminal=false
|
||||
Type=Application
|
||||
Categories=
|
||||
X-GNOME-Autostart-Phase=Initialization
|
||||
X-GNOME-AutoRestart=true
|
||||
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
|
||||
+2
-2
@@ -27,7 +27,7 @@
|
||||
exec="/usr/sbin/spice-vdagentd"
|
||||
prog="spice-vdagentd"
|
||||
port="/dev/virtio-ports/com.redhat.spice.0"
|
||||
pid="/var/run/spice-vdagentd/spice-vdagentd.pid"
|
||||
pid="/run/spice-vdagentd/spice-vdagentd.pid"
|
||||
|
||||
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
|
||||
|
||||
@@ -38,7 +38,7 @@ start() {
|
||||
[ -c $port ] || exit 0
|
||||
modprobe uinput > /dev/null 2>&1
|
||||
# In case the previous running vdagentd crashed
|
||||
rm -f /var/run/spice-vdagentd/spice-vdagent-sock
|
||||
rm -f /run/spice-vdagentd/spice-vdagent-sock
|
||||
echo -n $"Starting $prog: "
|
||||
daemon --pidfile $pid $exec $SPICE_VDAGENTD_EXTRA_ARGS
|
||||
retval=$?
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
.TH spice-vdagentd "1" "April 2013" "@PACKAGE_STRING@"
|
||||
.SH NAME
|
||||
spice-vdagentd \- Spice guest agent daemon
|
||||
.SH SYNOPSIS
|
||||
\fBspice-vdagent\fR [\fIOPTIONS\fR]
|
||||
.SH DESCRIPTION
|
||||
The spice guest agent for Linux consists of 2 parts, a system wide daemon
|
||||
\fBspice-vdagentd\fR and a X11 session agent \fBspice-vdagent\fR of which
|
||||
there is one per X11 session.
|
||||
.br
|
||||
\fBspice-vdagentd\fR gets started through a Sys-V initscript or a systemd unit.
|
||||
.SH FEATURES
|
||||
The spice guest agent adds the following features to spice Linux guests:
|
||||
.P
|
||||
Client mouse mode (no need to grab mouse by client, no mouse lag)
|
||||
.P
|
||||
Automatic adjustment of the X11 session's number of virtual monitors, and their
|
||||
resolution, to the number of client windows and their resolution
|
||||
.P
|
||||
Support of copy and paste (text and images) between the active X11 session
|
||||
and the client, this supports both the primary selection and the clipboard
|
||||
.P
|
||||
Support for transferring files from the client to the agent
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
\fB-h\fP
|
||||
Print a short description of all command line options
|
||||
.TP
|
||||
\fB-d\fP
|
||||
Log debug messages (use twice for extra info)
|
||||
.TP
|
||||
\fB-f\fP
|
||||
Treat uinput device as fake; no ioctls.
|
||||
This is useful in combination with Xspice.
|
||||
.TP
|
||||
\fB-o\fP
|
||||
The daemon will exit after processing a single session.
|
||||
.TP
|
||||
\fB-s\fP \fIport\fR
|
||||
Set virtio serial \fIport\fR (default: /dev/virtio-ports/com.redhat.spice.0)
|
||||
.TP
|
||||
\fB-u\fP \fIdevice\fR
|
||||
Set uinput \fIdevice\fR (default: /dev/uinput)
|
||||
.TP
|
||||
\fB-x\fP
|
||||
Don't daemonize
|
||||
.TP
|
||||
\fB-X\fP
|
||||
Disable session info usage, \fBspice-vdagentd\fR needs to know which
|
||||
\fBspice-vdagent\fR is in the currently active X11 session.
|
||||
\fBspice-vdagentd\fR uses console kit or systemd-logind (compile time option)
|
||||
for this; The \fB-X\fP option disables this, if no session info is available
|
||||
only one \fBspice-vdagent\fR is allowed
|
||||
.SH FILES
|
||||
The Sys-V initscript or systemd unit parses the following files:
|
||||
.TP
|
||||
/etc/sysconfig/spice-vdagentd
|
||||
Default cmdline options can be passed to \fBspice-vdagentd\fR by setting
|
||||
them in the \fISPICE_VDAGENTD_EXTRA_ARGS\fR variable in this file
|
||||
.SH SEE ALSO
|
||||
\fBspice-vdagent\fR(1)
|
||||
.SH COPYRIGHT
|
||||
Copyright 2010-2013 Red Hat, Inc. License GPLv3+: GNU GPL version 3 or later
|
||||
<http://gnu.org/licenses/gpl.html>.
|
||||
.br
|
||||
This is free software: you are free to change and redistribute it.
|
||||
There is NO WARRANTY, to the extent permitted by law.
|
||||
@@ -1,17 +1,16 @@
|
||||
[Unit]
|
||||
Description=Agent daemon for Spice guests
|
||||
Documentation=man:spice-vdagentd(1)
|
||||
After=dbus.target
|
||||
|
||||
# TODO we should use:
|
||||
#Requires=spice-vdagentd.socket
|
||||
Requires=spice-vdagentd.socket
|
||||
|
||||
[Service]
|
||||
Type=forking
|
||||
EnvironmentFile=-/etc/sysconfig/spice-vdagentd
|
||||
ExecStartPre=/bin/rm -f /var/run/spice-vdagentd/spice-vdagent-sock
|
||||
ExecStart=/usr/sbin/spice-vdagentd $SPICE_VDAGENTD_EXTRA_ARGS
|
||||
PIDFile=/var/run/spice-vdagentd/spice-vdagentd.pid
|
||||
PIDFile=/run/spice-vdagentd/spice-vdagentd.pid
|
||||
PrivateTmp=true
|
||||
Restart=on-failure
|
||||
|
||||
[Install]
|
||||
WantedBy=spice-vdagentd.target
|
||||
Also=spice-vdagentd.socket
|
||||
@@ -0,0 +1,5 @@
|
||||
[Unit]
|
||||
Description=Activation socket for spice guest agent daemon
|
||||
|
||||
[Socket]
|
||||
ListenStream=/run/spice-vdagentd/spice-vdagent-sock
|
||||
@@ -1,2 +0,0 @@
|
||||
[Unit]
|
||||
Description=Agent daemon for Spice guests
|
||||
@@ -1,2 +1,2 @@
|
||||
# spice-vdagentd needs this and does not create it itself
|
||||
d /var/run/spice-vdagentd 0755 root root -
|
||||
d /run/spice-vdagentd 0755 root root -
|
||||
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"
|
||||
@@ -1,354 +0,0 @@
|
||||
/* console-kit.c vdagentd ConsoleKit integration code
|
||||
|
||||
Copyright 2010-2012 Red Hat, Inc.
|
||||
|
||||
Red Hat Authors:
|
||||
Hans de Goede <[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 "session-info.h"
|
||||
#include <dbus/dbus.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
|
||||
struct session_info {
|
||||
DBusConnection *connection;
|
||||
int fd;
|
||||
char *seat;
|
||||
char *active_session;
|
||||
};
|
||||
|
||||
static char *console_kit_get_first_seat(struct session_info *ck);
|
||||
static char *console_kit_check_active_session_change(struct session_info *ck);
|
||||
|
||||
struct session_info *session_info_create(int verbose)
|
||||
{
|
||||
struct session_info *ck;
|
||||
DBusError error;
|
||||
char match[1024];
|
||||
|
||||
ck = calloc(1, sizeof(*ck));
|
||||
if (!ck)
|
||||
return NULL;
|
||||
|
||||
dbus_error_init(&error);
|
||||
ck->connection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
|
||||
if (ck->connection == NULL || dbus_error_is_set(&error)) {
|
||||
if (dbus_error_is_set(&error)) {
|
||||
syslog(LOG_ERR, "Unable to connect to system bus: %s",
|
||||
error.message);
|
||||
dbus_error_free(&error);
|
||||
} else
|
||||
syslog(LOG_ERR, "Unable to connect to system bus");
|
||||
free(ck);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!dbus_connection_get_unix_fd(ck->connection, &ck->fd)) {
|
||||
syslog(LOG_ERR, "Unable to get connection fd");
|
||||
session_info_destroy(ck);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!console_kit_get_first_seat(ck)) {
|
||||
session_info_destroy(ck);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Register for active session changes */
|
||||
snprintf(match, sizeof(match),
|
||||
"type='signal',interface='org.freedesktop.ConsoleKit.Seat',"
|
||||
"path='%s',member='ActiveSessionChanged'", ck->seat);
|
||||
dbus_error_init(&error);
|
||||
dbus_bus_add_match(ck->connection, match, &error);
|
||||
if (dbus_error_is_set(&error)) {
|
||||
syslog(LOG_ERR, "Match Error (%s)", error.message);
|
||||
session_info_destroy(ck);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ck;
|
||||
}
|
||||
|
||||
void session_info_destroy(struct session_info *ck)
|
||||
{
|
||||
if (!ck)
|
||||
return;
|
||||
|
||||
dbus_connection_close(ck->connection);
|
||||
free(ck->seat);
|
||||
free(ck->active_session);
|
||||
free(ck);
|
||||
}
|
||||
|
||||
int session_info_get_fd(struct session_info *ck)
|
||||
{
|
||||
return ck->fd;
|
||||
}
|
||||
|
||||
static char *console_kit_get_first_seat(struct session_info *ck)
|
||||
{
|
||||
DBusError error;
|
||||
DBusMessage *message = NULL;
|
||||
DBusMessage *reply = NULL;
|
||||
DBusMessageIter iter, subiter;
|
||||
int type;
|
||||
char *seat = NULL;
|
||||
|
||||
message = dbus_message_new_method_call("org.freedesktop.ConsoleKit",
|
||||
"/org/freedesktop/ConsoleKit/Manager",
|
||||
"org.freedesktop.ConsoleKit.Manager",
|
||||
"GetSeats");
|
||||
if (message == NULL) {
|
||||
syslog(LOG_ERR, "Unable to create dbus message");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
dbus_error_init(&error);
|
||||
reply = dbus_connection_send_with_reply_and_block(ck->connection,
|
||||
message,
|
||||
-1,
|
||||
&error);
|
||||
if (reply == NULL || dbus_error_is_set(&error)) {
|
||||
if (dbus_error_is_set(&error)) {
|
||||
syslog(LOG_ERR, "GetSeats failed: %s", error.message);
|
||||
dbus_error_free(&error);
|
||||
} else
|
||||
syslog(LOG_ERR, "GetSeats failed");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
dbus_message_iter_init(reply, &iter);
|
||||
type = dbus_message_iter_get_arg_type(&iter);
|
||||
if (type != DBUS_TYPE_ARRAY) {
|
||||
syslog(LOG_ERR,
|
||||
"expected an array return value, got a '%c' instead", type);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
dbus_message_iter_recurse(&iter, &subiter);
|
||||
type = dbus_message_iter_get_arg_type(&subiter);
|
||||
if (type != DBUS_TYPE_OBJECT_PATH) {
|
||||
syslog(LOG_ERR,
|
||||
"expected an object path element, got a '%c' instead", type);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
dbus_message_iter_get_basic(&subiter, &seat);
|
||||
ck->seat = strdup(seat);
|
||||
|
||||
exit:
|
||||
if (reply != NULL) {
|
||||
dbus_message_unref(reply);
|
||||
}
|
||||
|
||||
if (message != NULL) {
|
||||
dbus_message_unref(message);
|
||||
}
|
||||
|
||||
return ck->seat;
|
||||
}
|
||||
|
||||
const char *session_info_get_active_session(struct session_info *ck)
|
||||
{
|
||||
DBusError error;
|
||||
DBusMessage *message = NULL;
|
||||
DBusMessage *reply = NULL;
|
||||
char *session = NULL;
|
||||
|
||||
if (!ck)
|
||||
return NULL;
|
||||
|
||||
if (ck->active_session)
|
||||
return console_kit_check_active_session_change(ck);
|
||||
|
||||
message = dbus_message_new_method_call("org.freedesktop.ConsoleKit",
|
||||
ck->seat,
|
||||
"org.freedesktop.ConsoleKit.Seat",
|
||||
"GetActiveSession");
|
||||
if (message == NULL) {
|
||||
syslog(LOG_ERR, "Unable to create dbus message");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
dbus_error_init(&error);
|
||||
reply = dbus_connection_send_with_reply_and_block(ck->connection,
|
||||
message,
|
||||
-1,
|
||||
&error);
|
||||
if (reply == NULL || dbus_error_is_set(&error)) {
|
||||
if (dbus_error_is_set(&error)) {
|
||||
syslog(LOG_ERR, "GetActiveSession failed: %s", error.message);
|
||||
dbus_error_free(&error);
|
||||
} else
|
||||
syslog(LOG_ERR, "GetActiveSession failed");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
dbus_error_init(&error);
|
||||
if (!dbus_message_get_args(reply,
|
||||
&error,
|
||||
DBUS_TYPE_OBJECT_PATH, &session,
|
||||
DBUS_TYPE_INVALID)) {
|
||||
if (dbus_error_is_set(&error)) {
|
||||
syslog(LOG_ERR, "error get ssid from reply: %s", error.message);
|
||||
dbus_error_free(&error);
|
||||
} else
|
||||
syslog(LOG_ERR, "error getting ssid from reply");
|
||||
session = NULL;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
ck->active_session = strdup(session);
|
||||
|
||||
exit:
|
||||
if (reply != NULL) {
|
||||
dbus_message_unref(reply);
|
||||
}
|
||||
|
||||
if (message != NULL) {
|
||||
dbus_message_unref(message);
|
||||
}
|
||||
|
||||
/* In case the session was changed while we were running */
|
||||
return console_kit_check_active_session_change(ck);
|
||||
}
|
||||
|
||||
char *session_info_session_for_pid(struct session_info *ck, uint32_t pid)
|
||||
{
|
||||
DBusError error;
|
||||
DBusMessage *message = NULL;
|
||||
DBusMessage *reply = NULL;
|
||||
DBusMessageIter args;
|
||||
char *ssid = NULL;
|
||||
|
||||
if (!ck)
|
||||
return NULL;
|
||||
|
||||
message = dbus_message_new_method_call("org.freedesktop.ConsoleKit",
|
||||
"/org/freedesktop/ConsoleKit/Manager",
|
||||
"org.freedesktop.ConsoleKit.Manager",
|
||||
"GetSessionForUnixProcess");
|
||||
if (message == NULL) {
|
||||
syslog(LOG_ERR, "Unable to create dbus message");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
dbus_message_iter_init_append(message, &args);
|
||||
if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_UINT32, &pid)) {
|
||||
syslog(LOG_ERR, "Unable to append dbus message args");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
dbus_error_init(&error);
|
||||
reply = dbus_connection_send_with_reply_and_block(ck->connection,
|
||||
message,
|
||||
-1,
|
||||
&error);
|
||||
if (reply == NULL || dbus_error_is_set(&error)) {
|
||||
if (dbus_error_is_set(&error)) {
|
||||
syslog(LOG_ERR, "GetSessionForUnixProcess failed: %s",
|
||||
error.message);
|
||||
dbus_error_free(&error);
|
||||
} else
|
||||
syslog(LOG_ERR, "GetSessionForUnixProces failed");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
dbus_error_init(&error);
|
||||
if (!dbus_message_get_args(reply,
|
||||
&error,
|
||||
DBUS_TYPE_OBJECT_PATH, &ssid,
|
||||
DBUS_TYPE_INVALID)) {
|
||||
if (dbus_error_is_set(&error)) {
|
||||
syslog(LOG_ERR, "error get ssid from reply: %s", error.message);
|
||||
dbus_error_free(&error);
|
||||
} else
|
||||
syslog(LOG_ERR, "error getting ssid from reply");
|
||||
ssid = NULL;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
ssid = strdup(ssid);
|
||||
|
||||
exit:
|
||||
if (reply != NULL) {
|
||||
dbus_message_unref(reply);
|
||||
}
|
||||
|
||||
if (message != NULL) {
|
||||
dbus_message_unref(message);
|
||||
}
|
||||
|
||||
return ssid;
|
||||
}
|
||||
|
||||
static char *console_kit_check_active_session_change(struct session_info *ck)
|
||||
{
|
||||
DBusMessage *message = NULL;
|
||||
DBusMessageIter iter;
|
||||
char *session;
|
||||
int type;
|
||||
|
||||
/* non blocking read of the next available message */
|
||||
dbus_connection_read_write(ck->connection, 0);
|
||||
while ((message = dbus_connection_pop_message(ck->connection))) {
|
||||
if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_SIGNAL) {
|
||||
const char *member = dbus_message_get_member (message);
|
||||
if (!strcmp(member, "NameAcquired")) {
|
||||
dbus_message_unref(message);
|
||||
continue;
|
||||
}
|
||||
if (strcmp(member, "ActiveSessionChanged")) {
|
||||
syslog(LOG_ERR, "unexpected signal member: %s", member);
|
||||
dbus_message_unref(message);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
syslog(LOG_ERR, "received non signal message!");
|
||||
dbus_message_unref(message);
|
||||
continue;
|
||||
}
|
||||
|
||||
free(ck->active_session);
|
||||
ck->active_session = NULL;
|
||||
|
||||
dbus_message_iter_init(message, &iter);
|
||||
type = dbus_message_iter_get_arg_type(&iter);
|
||||
/* Session should be an object path, but there is a bug in
|
||||
ConsoleKit where it sends a string rather then an object_path
|
||||
accept object_path too in case the bug ever gets fixed */
|
||||
if (type != DBUS_TYPE_STRING && type != DBUS_TYPE_OBJECT_PATH) {
|
||||
syslog(LOG_ERR,
|
||||
"ActiveSessionChanged message has unexpected type: '%c'",
|
||||
type);
|
||||
dbus_message_unref(message);
|
||||
continue;
|
||||
}
|
||||
|
||||
dbus_message_iter_get_basic(&iter, &session);
|
||||
ck->active_session = strdup(session);
|
||||
dbus_message_unref(message);
|
||||
|
||||
/* non blocking read of the next available message */
|
||||
dbus_connection_read_write(ck->connection, 0);
|
||||
}
|
||||
|
||||
return ck->active_session;
|
||||
}
|
||||
@@ -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 */
|
||||
@@ -1,103 +0,0 @@
|
||||
/* systemd-login.c vdagentd libsystemd-login integration code
|
||||
|
||||
Copyright 2012 Red Hat, Inc.
|
||||
|
||||
Red Hat Authors:
|
||||
Hans de Goede <[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 "session-info.h"
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include <systemd/sd-login.h>
|
||||
|
||||
struct session_info {
|
||||
int verbose;
|
||||
sd_login_monitor *mon;
|
||||
char *session;
|
||||
};
|
||||
|
||||
struct session_info *session_info_create(int verbose)
|
||||
{
|
||||
struct session_info *si;
|
||||
int r;
|
||||
|
||||
si = calloc(1, sizeof(*si));
|
||||
if (!si)
|
||||
return NULL;
|
||||
|
||||
si->verbose = verbose;
|
||||
|
||||
r = sd_login_monitor_new("session", &si->mon);
|
||||
if (r < 0) {
|
||||
syslog(LOG_ERR, "Error creating login monitor: %s", strerror(-r));
|
||||
free(si);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return si;
|
||||
}
|
||||
|
||||
void session_info_destroy(struct session_info *si)
|
||||
{
|
||||
sd_login_monitor_unref(si->mon);
|
||||
free(si->session);
|
||||
free(si);
|
||||
}
|
||||
|
||||
int session_info_get_fd(struct session_info *si)
|
||||
{
|
||||
return sd_login_monitor_get_fd(si->mon);
|
||||
}
|
||||
|
||||
const char *session_info_get_active_session(struct session_info *si)
|
||||
{
|
||||
int r;
|
||||
char *old_session = si->session;
|
||||
|
||||
si->session = NULL;
|
||||
r = sd_seat_get_active("seat0", &si->session, NULL);
|
||||
/* ENOENT happens when a seat is switching from one session to another */
|
||||
if (r < 0 && r != ENOENT)
|
||||
syslog(LOG_ERR, "Error getting active session: %s",
|
||||
strerror(-r));
|
||||
|
||||
if (si->verbose && si->session &&
|
||||
(!old_session || strcmp(old_session, si->session)))
|
||||
syslog(LOG_INFO, "Active session: %s", si->session);
|
||||
|
||||
sd_login_monitor_flush(si->mon);
|
||||
free(old_session);
|
||||
|
||||
return si->session;
|
||||
}
|
||||
|
||||
char *session_info_session_for_pid(struct session_info *si, uint32_t pid)
|
||||
{
|
||||
int r;
|
||||
char *session = NULL;
|
||||
|
||||
r = sd_pid_get_session(pid, &session);
|
||||
if (r < 0)
|
||||
syslog(LOG_ERR, "Error getting session for pid %u: %s",
|
||||
pid, strerror(-r));
|
||||
else if (si->verbose)
|
||||
syslog(LOG_INFO, "Session for pid %u: %s", pid, session);
|
||||
|
||||
return session;
|
||||
}
|
||||
+235
-482
@@ -9,555 +9,308 @@
|
||||
|
||||
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
|
||||
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
|
||||
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/>.
|
||||
*/
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <syslog.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <glib-unix.h>
|
||||
#include <gio/gunixsocketaddress.h>
|
||||
#include "udscs.h"
|
||||
#include "vdagentd-proto-strings.h"
|
||||
#include "vdagent-connection.h"
|
||||
|
||||
struct udscs_buf {
|
||||
uint8_t *buf;
|
||||
size_t pos;
|
||||
size_t size;
|
||||
|
||||
struct udscs_buf *next;
|
||||
};
|
||||
// Maximum number of connected agents.
|
||||
// Avoid DoS from agents.
|
||||
// As each connection end up taking a file descriptor is good to have a limit
|
||||
// less than the number of file descriptors in the process (by default 1024).
|
||||
#define MAX_CONNECTED_AGENTS 128
|
||||
|
||||
struct udscs_connection {
|
||||
int fd;
|
||||
const char * const *type_to_string;
|
||||
int no_types;
|
||||
struct _UdscsConnection {
|
||||
VDAgentConnection parent_instance;
|
||||
int debug;
|
||||
struct ucred peer_cred;
|
||||
void *user_data;
|
||||
|
||||
/* Read stuff, single buffer, separate header and data buffer */
|
||||
int header_read;
|
||||
struct udscs_message_header header;
|
||||
struct udscs_buf data;
|
||||
|
||||
/* Writes are stored in a linked list of buffers, with both the header
|
||||
+ data for a single message in 1 buffer. */
|
||||
struct udscs_buf *write_buf;
|
||||
|
||||
/* Callbacks */
|
||||
udscs_read_callback read_callback;
|
||||
udscs_disconnect_callback disconnect_callback;
|
||||
|
||||
struct udscs_connection *next;
|
||||
struct udscs_connection *prev;
|
||||
};
|
||||
|
||||
struct udscs_server {
|
||||
int fd;
|
||||
const char * const *type_to_string;
|
||||
int no_types;
|
||||
int debug;
|
||||
struct udscs_connection connections_head;
|
||||
udscs_connect_callback connect_callback;
|
||||
udscs_read_callback read_callback;
|
||||
udscs_disconnect_callback disconnect_callback;
|
||||
};
|
||||
G_DEFINE_TYPE(UdscsConnection, udscs_connection, VDAGENT_TYPE_CONNECTION)
|
||||
|
||||
static void udscs_do_write(struct udscs_connection **connp);
|
||||
static void udscs_do_read(struct udscs_connection **connp);
|
||||
|
||||
|
||||
struct udscs_server *udscs_create_server(const char *socketname,
|
||||
udscs_connect_callback connect_callback,
|
||||
udscs_read_callback read_callback,
|
||||
udscs_disconnect_callback disconnect_callback,
|
||||
const char * const type_to_string[], int no_types, int debug)
|
||||
static void debug_print_message_header(UdscsConnection *conn,
|
||||
struct udscs_message_header *header,
|
||||
const gchar *direction)
|
||||
{
|
||||
int c;
|
||||
struct sockaddr_un address;
|
||||
struct udscs_server *server;
|
||||
const gchar *type = "invalid message";
|
||||
|
||||
server = calloc(1, sizeof(*server));
|
||||
if (!server)
|
||||
return NULL;
|
||||
|
||||
server->type_to_string = type_to_string;
|
||||
server->no_types = no_types;
|
||||
server->debug = debug;
|
||||
|
||||
server->fd = socket(PF_UNIX, SOCK_STREAM, 0);
|
||||
if (server->fd == -1) {
|
||||
syslog(LOG_ERR, "creating unix domain socket: %m");
|
||||
free(server);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
address.sun_family = AF_UNIX;
|
||||
snprintf(address.sun_path, sizeof(address.sun_path), "%s", socketname);
|
||||
c = bind(server->fd, (struct sockaddr *)&address, sizeof(address));
|
||||
if (c != 0) {
|
||||
syslog(LOG_ERR, "bind %s: %m", socketname);
|
||||
free(server);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
c = listen(server->fd, 5);
|
||||
if (c != 0) {
|
||||
syslog(LOG_ERR, "listen: %m");
|
||||
free(server);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
server->connect_callback = connect_callback;
|
||||
server->read_callback = read_callback;
|
||||
server->disconnect_callback = disconnect_callback;
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
void udscs_destroy_server(struct udscs_server *server)
|
||||
{
|
||||
struct udscs_connection *conn, *next_conn;
|
||||
|
||||
if (!server)
|
||||
if (conn == NULL || conn->debug == FALSE)
|
||||
return;
|
||||
|
||||
conn = server->connections_head.next;
|
||||
while (conn) {
|
||||
next_conn = conn->next;
|
||||
udscs_destroy_connection(&conn);
|
||||
conn = next_conn;
|
||||
}
|
||||
close(server->fd);
|
||||
free(server);
|
||||
if (header->type < G_N_ELEMENTS(vdagentd_messages))
|
||||
type = vdagentd_messages[header->type];
|
||||
|
||||
syslog(LOG_DEBUG, "%p %s %s, arg1: %u, arg2: %u, size %u",
|
||||
conn, direction, type, header->arg1, header->arg2, header->size);
|
||||
}
|
||||
|
||||
struct udscs_connection *udscs_connect(const char *socketname,
|
||||
udscs_read_callback read_callback,
|
||||
udscs_disconnect_callback disconnect_callback,
|
||||
const char * const type_to_string[], int no_types, int debug)
|
||||
static gsize conn_handle_header(VDAgentConnection *conn,
|
||||
gpointer header_buf)
|
||||
{
|
||||
int c;
|
||||
struct sockaddr_un address;
|
||||
struct udscs_connection *conn;
|
||||
return ((struct udscs_message_header *)header_buf)->size;
|
||||
}
|
||||
|
||||
conn = calloc(1, sizeof(*conn));
|
||||
if (!conn)
|
||||
static void conn_handle_message(VDAgentConnection *conn,
|
||||
gpointer header_buf,
|
||||
gpointer data)
|
||||
{
|
||||
UdscsConnection *self = UDSCS_CONNECTION(conn);
|
||||
struct udscs_message_header *header = header_buf;
|
||||
|
||||
debug_print_message_header(self, header, "received");
|
||||
|
||||
self->read_callback(self, header, data);
|
||||
}
|
||||
|
||||
static void udscs_connection_init(UdscsConnection *self)
|
||||
{
|
||||
}
|
||||
|
||||
static void udscs_connection_finalize(GObject *obj)
|
||||
{
|
||||
UdscsConnection *self = UDSCS_CONNECTION(obj);
|
||||
|
||||
if (self->debug) {
|
||||
syslog(LOG_DEBUG, "%p disconnected", self);
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS(udscs_connection_parent_class)->finalize(obj);
|
||||
}
|
||||
|
||||
static void udscs_connection_class_init(UdscsConnectionClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
|
||||
VDAgentConnectionClass *conn_class = VDAGENT_CONNECTION_CLASS(klass);
|
||||
|
||||
gobject_class->finalize = udscs_connection_finalize;
|
||||
|
||||
conn_class->handle_header = conn_handle_header;
|
||||
conn_class->handle_message = conn_handle_message;
|
||||
}
|
||||
|
||||
UdscsConnection *udscs_connect(const char *socketname,
|
||||
udscs_read_callback read_callback,
|
||||
VDAgentConnErrorCb error_cb,
|
||||
int debug,
|
||||
GError **err)
|
||||
{
|
||||
GIOStream *io_stream;
|
||||
UdscsConnection *conn;
|
||||
|
||||
io_stream = vdagent_socket_connect(socketname, err);
|
||||
if (*err) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
conn->type_to_string = type_to_string;
|
||||
conn->no_types = no_types;
|
||||
conn = g_object_new(UDSCS_TYPE_CONNECTION, NULL);
|
||||
conn->debug = debug;
|
||||
|
||||
conn->fd = socket(PF_UNIX, SOCK_STREAM, 0);
|
||||
if (conn->fd == -1) {
|
||||
syslog(LOG_ERR, "creating unix domain socket: %m");
|
||||
free(conn);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
address.sun_family = AF_UNIX;
|
||||
snprintf(address.sun_path, sizeof(address.sun_path), "%s", socketname);
|
||||
c = connect(conn->fd, (struct sockaddr *)&address, sizeof(address));
|
||||
if (c != 0) {
|
||||
if (conn->debug) {
|
||||
syslog(LOG_DEBUG, "connect %s: %m", socketname);
|
||||
}
|
||||
free(conn);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
conn->read_callback = read_callback;
|
||||
conn->disconnect_callback = disconnect_callback;
|
||||
vdagent_connection_setup(VDAGENT_CONNECTION(conn),
|
||||
io_stream,
|
||||
FALSE,
|
||||
sizeof(struct udscs_message_header),
|
||||
error_cb);
|
||||
|
||||
if (conn->debug)
|
||||
if (conn->debug) {
|
||||
syslog(LOG_DEBUG, "%p connected to %s", conn, socketname);
|
||||
}
|
||||
|
||||
return conn;
|
||||
}
|
||||
|
||||
void udscs_destroy_connection(struct udscs_connection **connp)
|
||||
{
|
||||
struct udscs_buf *wbuf, *next_wbuf;
|
||||
struct udscs_connection *conn = *connp;
|
||||
|
||||
if (!conn)
|
||||
return;
|
||||
|
||||
if (conn->disconnect_callback)
|
||||
conn->disconnect_callback(conn);
|
||||
|
||||
wbuf = conn->write_buf;
|
||||
while (wbuf) {
|
||||
next_wbuf = wbuf->next;
|
||||
free(wbuf->buf);
|
||||
free(wbuf);
|
||||
wbuf = next_wbuf;
|
||||
}
|
||||
|
||||
free(conn->data.buf);
|
||||
|
||||
if (conn->next)
|
||||
conn->next->prev = conn->prev;
|
||||
if (conn->prev)
|
||||
conn->prev->next = conn->next;
|
||||
|
||||
close(conn->fd);
|
||||
|
||||
if (conn->debug)
|
||||
syslog(LOG_DEBUG, "%p disconnected", conn);
|
||||
|
||||
free(conn);
|
||||
*connp = NULL;
|
||||
}
|
||||
|
||||
struct ucred udscs_get_peer_cred(struct udscs_connection *conn)
|
||||
{
|
||||
return conn->peer_cred;
|
||||
}
|
||||
|
||||
int udscs_server_fill_fds(struct udscs_server *server, fd_set *readfds,
|
||||
fd_set *writefds)
|
||||
{
|
||||
struct udscs_connection *conn;
|
||||
int nfds = server->fd + 1;
|
||||
|
||||
if (!server)
|
||||
return -1;
|
||||
|
||||
FD_SET(server->fd, readfds);
|
||||
|
||||
conn = server->connections_head.next;
|
||||
while (conn) {
|
||||
int conn_nfds = udscs_client_fill_fds(conn, readfds, writefds);
|
||||
if (conn_nfds > nfds)
|
||||
nfds = conn_nfds;
|
||||
|
||||
conn = conn->next;
|
||||
}
|
||||
|
||||
return nfds;
|
||||
}
|
||||
|
||||
int udscs_client_fill_fds(struct udscs_connection *conn, fd_set *readfds,
|
||||
fd_set *writefds)
|
||||
{
|
||||
if (!conn)
|
||||
return -1;
|
||||
|
||||
FD_SET(conn->fd, readfds);
|
||||
if (conn->write_buf)
|
||||
FD_SET(conn->fd, writefds);
|
||||
|
||||
return conn->fd + 1;
|
||||
}
|
||||
|
||||
static void udscs_server_accept(struct udscs_server *server) {
|
||||
struct udscs_connection *new_conn, *conn;
|
||||
struct sockaddr_un address;
|
||||
socklen_t length = sizeof(address);
|
||||
int r, fd;
|
||||
|
||||
fd = accept(server->fd, (struct sockaddr *)&address, &length);
|
||||
if (fd == -1) {
|
||||
if (errno == EINTR)
|
||||
return;
|
||||
syslog(LOG_ERR, "accept: %m");
|
||||
return;
|
||||
}
|
||||
|
||||
new_conn = calloc(1, sizeof(*conn));
|
||||
if (!new_conn) {
|
||||
syslog(LOG_ERR, "out of memory, disconnecting new client");
|
||||
close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
new_conn->fd = fd;
|
||||
new_conn->type_to_string = server->type_to_string;
|
||||
new_conn->no_types = server->no_types;
|
||||
new_conn->debug = server->debug;
|
||||
new_conn->read_callback = server->read_callback;
|
||||
new_conn->disconnect_callback = server->disconnect_callback;
|
||||
|
||||
length = sizeof(new_conn->peer_cred);
|
||||
r = getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &new_conn->peer_cred, &length);
|
||||
if (r != 0) {
|
||||
syslog(LOG_ERR, "Could not get peercred, disconnecting new client");
|
||||
close(fd);
|
||||
free(new_conn);
|
||||
return;
|
||||
}
|
||||
|
||||
conn = &server->connections_head;
|
||||
while (conn->next)
|
||||
conn = conn->next;
|
||||
|
||||
new_conn->prev = conn;
|
||||
conn->next = new_conn;
|
||||
|
||||
if (server->debug)
|
||||
syslog(LOG_DEBUG, "new client accepted: %p, pid: %d",
|
||||
new_conn, (int)new_conn->peer_cred.pid);
|
||||
|
||||
if (server->connect_callback)
|
||||
server->connect_callback(new_conn);
|
||||
}
|
||||
|
||||
void udscs_server_handle_fds(struct udscs_server *server, fd_set *readfds,
|
||||
fd_set *writefds)
|
||||
{
|
||||
struct udscs_connection *conn, *next_conn;
|
||||
|
||||
if (!server)
|
||||
return;
|
||||
|
||||
if (FD_ISSET(server->fd, readfds))
|
||||
udscs_server_accept(server);
|
||||
|
||||
conn = server->connections_head.next;
|
||||
while (conn) {
|
||||
/* conn maybe destroyed by udscs_client_handle_fds (when disconnected),
|
||||
so get the next connection first. */
|
||||
next_conn = conn->next;
|
||||
udscs_client_handle_fds(&conn, readfds, writefds);
|
||||
conn = next_conn;
|
||||
}
|
||||
}
|
||||
|
||||
void udscs_client_handle_fds(struct udscs_connection **connp, fd_set *readfds,
|
||||
fd_set *writefds)
|
||||
{
|
||||
if (!*connp)
|
||||
return;
|
||||
|
||||
if (FD_ISSET((*connp)->fd, readfds))
|
||||
udscs_do_read(connp);
|
||||
|
||||
if (*connp && FD_ISSET((*connp)->fd, writefds))
|
||||
udscs_do_write(connp);
|
||||
}
|
||||
|
||||
int udscs_write(struct udscs_connection *conn, uint32_t type, uint32_t arg1,
|
||||
void udscs_write(UdscsConnection *conn, uint32_t type, uint32_t arg1,
|
||||
uint32_t arg2, const uint8_t *data, uint32_t size)
|
||||
{
|
||||
struct udscs_buf *wbuf, *new_wbuf;
|
||||
gpointer buf;
|
||||
guint buf_size;
|
||||
struct udscs_message_header header;
|
||||
|
||||
new_wbuf = malloc(sizeof(*new_wbuf));
|
||||
if (!new_wbuf)
|
||||
return -1;
|
||||
|
||||
new_wbuf->pos = 0;
|
||||
new_wbuf->size = sizeof(header) + size;
|
||||
new_wbuf->next = NULL;
|
||||
new_wbuf->buf = malloc(new_wbuf->size);
|
||||
if (!new_wbuf->buf) {
|
||||
free(new_wbuf);
|
||||
return -1;
|
||||
}
|
||||
buf_size = sizeof(header) + size;
|
||||
buf = g_malloc(buf_size);
|
||||
|
||||
header.type = type;
|
||||
header.arg1 = arg1;
|
||||
header.arg2 = arg2;
|
||||
header.size = size;
|
||||
|
||||
memcpy(new_wbuf->buf, &header, sizeof(header));
|
||||
memcpy(new_wbuf->buf + sizeof(header), data, size);
|
||||
memcpy(buf, &header, sizeof(header));
|
||||
memcpy(buf + sizeof(header), data, size);
|
||||
|
||||
if (conn->debug) {
|
||||
if (type < conn->no_types)
|
||||
syslog(LOG_DEBUG, "%p sent %s, arg1: %u, arg2: %u, size %u",
|
||||
conn, conn->type_to_string[type], arg1, arg2, size);
|
||||
else
|
||||
syslog(LOG_DEBUG,
|
||||
"%p sent invalid message %u, arg1: %u, arg2: %u, size %u",
|
||||
conn, type, arg1, arg2, size);
|
||||
}
|
||||
debug_print_message_header(conn, &header, "sent");
|
||||
|
||||
if (!conn->write_buf) {
|
||||
conn->write_buf = new_wbuf;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* maybe we should limit the write_buf stack depth ? */
|
||||
wbuf = conn->write_buf;
|
||||
while (wbuf->next)
|
||||
wbuf = wbuf->next;
|
||||
|
||||
wbuf->next = new_wbuf;
|
||||
|
||||
return 0;
|
||||
vdagent_connection_write(VDAGENT_CONNECTION(conn), buf, buf_size);
|
||||
}
|
||||
|
||||
int udscs_server_write_all(struct udscs_server *server,
|
||||
#ifndef UDSCS_NO_SERVER
|
||||
|
||||
/* ---------- Server-side implementation ---------- */
|
||||
|
||||
struct udscs_server {
|
||||
GSocketService *service;
|
||||
GList *connections;
|
||||
|
||||
int debug;
|
||||
udscs_connect_callback connect_callback;
|
||||
udscs_read_callback read_callback;
|
||||
VDAgentConnErrorCb error_cb;
|
||||
};
|
||||
|
||||
static gboolean udscs_server_accept_cb(GSocketService *service,
|
||||
GSocketConnection *socket_conn,
|
||||
GObject *source_object,
|
||||
gpointer user_data);
|
||||
|
||||
struct udscs_server *udscs_server_new(
|
||||
udscs_connect_callback connect_callback,
|
||||
udscs_read_callback read_callback,
|
||||
VDAgentConnErrorCb error_cb,
|
||||
int debug)
|
||||
{
|
||||
struct udscs_server *server;
|
||||
|
||||
server = g_new0(struct udscs_server, 1);
|
||||
server->debug = debug;
|
||||
server->connect_callback = connect_callback;
|
||||
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);
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
void udscs_server_listen_to_socket(struct udscs_server *server,
|
||||
gint fd,
|
||||
GError **err)
|
||||
{
|
||||
GSocket *socket;
|
||||
|
||||
socket = g_socket_new_from_fd(fd, err);
|
||||
if (socket == NULL) {
|
||||
return;
|
||||
}
|
||||
g_socket_listener_add_socket(G_SOCKET_LISTENER(server->service),
|
||||
socket, NULL, err);
|
||||
g_object_unref(socket);
|
||||
}
|
||||
|
||||
void udscs_server_listen_to_address(struct udscs_server *server,
|
||||
const gchar *addr,
|
||||
GError **err)
|
||||
{
|
||||
GSocketAddress *sock_addr;
|
||||
|
||||
sock_addr = g_unix_socket_address_new(addr);
|
||||
g_socket_listener_add_address(G_SOCKET_LISTENER(server->service),
|
||||
sock_addr,
|
||||
G_SOCKET_TYPE_STREAM,
|
||||
G_SOCKET_PROTOCOL_DEFAULT,
|
||||
NULL, NULL, err);
|
||||
g_object_unref(sock_addr);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
server->connections = g_list_remove(server->connections, conn);
|
||||
vdagent_connection_destroy(conn);
|
||||
}
|
||||
|
||||
void udscs_destroy_server(struct udscs_server *server)
|
||||
{
|
||||
if (!server)
|
||||
return;
|
||||
|
||||
g_list_free_full(server->connections, vdagent_connection_destroy);
|
||||
g_object_unref(server->service);
|
||||
g_free(server);
|
||||
}
|
||||
|
||||
static gboolean udscs_server_accept_cb(GSocketService *service,
|
||||
GSocketConnection *socket_conn,
|
||||
GObject *source_object,
|
||||
gpointer user_data)
|
||||
{
|
||||
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;
|
||||
g_object_ref(socket_conn);
|
||||
vdagent_connection_setup(VDAGENT_CONNECTION(new_conn),
|
||||
G_IO_STREAM(socket_conn),
|
||||
FALSE,
|
||||
sizeof(struct udscs_message_header),
|
||||
server->error_cb);
|
||||
|
||||
server->connections = g_list_prepend(server->connections, new_conn);
|
||||
|
||||
if (server->debug)
|
||||
syslog(LOG_DEBUG, "new client accepted: %p", new_conn);
|
||||
|
||||
if (server->connect_callback)
|
||||
server->connect_callback(new_conn);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void udscs_server_write_all(struct udscs_server *server,
|
||||
uint32_t type, uint32_t arg1, uint32_t arg2,
|
||||
const uint8_t *data, uint32_t size)
|
||||
{
|
||||
struct udscs_connection *conn;
|
||||
|
||||
conn = server->connections_head.next;
|
||||
while (conn) {
|
||||
if (udscs_write(conn, type, arg1, arg2, data, size))
|
||||
return -1;
|
||||
conn = conn->next;
|
||||
GList *l;
|
||||
for (l = server->connections; l; l = l->next) {
|
||||
udscs_write(UDSCS_CONNECTION(l->data), type, arg1, arg2, data, size);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int udscs_server_for_all_clients(struct udscs_server *server,
|
||||
udscs_for_all_clients_callback func, void *priv)
|
||||
{
|
||||
int r = 0;
|
||||
struct udscs_connection *conn, *next_conn;
|
||||
GList *l, *next;
|
||||
|
||||
if (!server)
|
||||
return 0;
|
||||
|
||||
conn = server->connections_head.next;
|
||||
while (conn) {
|
||||
/* Get next conn as func may destroy the current conn */
|
||||
next_conn = conn->next;
|
||||
r += func(&conn, priv);
|
||||
conn = next_conn;
|
||||
l = server->connections;
|
||||
while (l) {
|
||||
next = l->next;
|
||||
r += func(l->data, priv);
|
||||
l = next;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
static void udscs_read_complete(struct udscs_connection **connp)
|
||||
{
|
||||
struct udscs_connection *conn = *connp;
|
||||
|
||||
if (conn->debug) {
|
||||
if (conn->header.type < conn->no_types)
|
||||
syslog(LOG_DEBUG,
|
||||
"%p received %s, arg1: %u, arg2: %u, size %u",
|
||||
conn, conn->type_to_string[conn->header.type],
|
||||
conn->header.arg1, conn->header.arg2, conn->header.size);
|
||||
else
|
||||
syslog(LOG_DEBUG,
|
||||
"%p received invalid message %u, arg1: %u, arg2: %u, size %u",
|
||||
conn, conn->header.type, conn->header.arg1, conn->header.arg2,
|
||||
conn->header.size);
|
||||
}
|
||||
|
||||
if (conn->read_callback) {
|
||||
conn->read_callback(connp, &conn->header, conn->data.buf);
|
||||
if (!*connp) /* Was the connection disconnected by the callback ? */
|
||||
return;
|
||||
}
|
||||
|
||||
conn->header_read = 0;
|
||||
memset(&conn->data, 0, sizeof(conn->data));
|
||||
}
|
||||
|
||||
static void udscs_do_read(struct udscs_connection **connp)
|
||||
{
|
||||
ssize_t n;
|
||||
size_t to_read;
|
||||
uint8_t *dest;
|
||||
struct udscs_connection *conn = *connp;
|
||||
|
||||
if (conn->header_read < sizeof(conn->header)) {
|
||||
to_read = sizeof(conn->header) - conn->header_read;
|
||||
dest = (uint8_t *)&conn->header + conn->header_read;
|
||||
} else {
|
||||
to_read = conn->data.size - conn->data.pos;
|
||||
dest = conn->data.buf + conn->data.pos;
|
||||
}
|
||||
|
||||
n = read(conn->fd, dest, to_read);
|
||||
if (n < 0) {
|
||||
if (errno == EINTR)
|
||||
return;
|
||||
syslog(LOG_ERR, "reading unix domain socket: %m, disconnecting %p",
|
||||
conn);
|
||||
}
|
||||
if (n <= 0) {
|
||||
udscs_destroy_connection(connp);
|
||||
return;
|
||||
}
|
||||
|
||||
if (conn->header_read < sizeof(conn->header)) {
|
||||
conn->header_read += n;
|
||||
if (conn->header_read == sizeof(conn->header)) {
|
||||
if (conn->header.size == 0) {
|
||||
udscs_read_complete(connp);
|
||||
return;
|
||||
}
|
||||
conn->data.pos = 0;
|
||||
conn->data.size = conn->header.size;
|
||||
conn->data.buf = malloc(conn->data.size);
|
||||
if (!conn->data.buf) {
|
||||
syslog(LOG_ERR, "out of memory, disconnecting %p", conn);
|
||||
udscs_destroy_connection(connp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
conn->data.pos += n;
|
||||
if (conn->data.pos == conn->data.size)
|
||||
udscs_read_complete(connp);
|
||||
}
|
||||
}
|
||||
|
||||
static void udscs_do_write(struct udscs_connection **connp)
|
||||
{
|
||||
ssize_t n;
|
||||
size_t to_write;
|
||||
struct udscs_connection *conn = *connp;
|
||||
|
||||
struct udscs_buf* wbuf = conn->write_buf;
|
||||
if (!wbuf) {
|
||||
syslog(LOG_ERR,
|
||||
"%p do_write called on a connection without a write buf ?!",
|
||||
conn);
|
||||
return;
|
||||
}
|
||||
|
||||
to_write = wbuf->size - wbuf->pos;
|
||||
n = write(conn->fd, wbuf->buf + wbuf->pos, to_write);
|
||||
if (n < 0) {
|
||||
if (errno == EINTR)
|
||||
return;
|
||||
syslog(LOG_ERR, "writing to unix domain socket: %m, disconnecting %p",
|
||||
conn);
|
||||
udscs_destroy_connection(connp);
|
||||
return;
|
||||
}
|
||||
|
||||
wbuf->pos += n;
|
||||
if (wbuf->pos == wbuf->size) {
|
||||
conn->write_buf = wbuf->next;
|
||||
free(wbuf->buf);
|
||||
free(wbuf);
|
||||
}
|
||||
}
|
||||
|
||||
void udscs_set_user_data(struct udscs_connection *conn, void *data)
|
||||
{
|
||||
conn->user_data = data;
|
||||
}
|
||||
|
||||
void *udscs_get_user_data(struct udscs_connection *conn)
|
||||
{
|
||||
if (!conn)
|
||||
return NULL;
|
||||
|
||||
return conn->user_data;
|
||||
}
|
||||
#endif
|
||||
+94
-79
@@ -7,12 +7,12 @@
|
||||
|
||||
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
|
||||
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
|
||||
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
|
||||
@@ -22,103 +22,118 @@
|
||||
#ifndef __UDSCS_H
|
||||
#define __UDSCS_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/socket.h>
|
||||
#include <glib-object.h>
|
||||
#include "vdagent-connection.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define UDSCS_TYPE_CONNECTION udscs_connection_get_type()
|
||||
G_DECLARE_FINAL_TYPE(UdscsConnection, udscs_connection, UDSCS, CONNECTION, VDAgentConnection)
|
||||
|
||||
/* ---------- Generic bits and client-side API ---------- */
|
||||
|
||||
struct udscs_connection;
|
||||
struct udscs_server;
|
||||
struct udscs_message_header {
|
||||
uint32_t type;
|
||||
uint32_t arg1;
|
||||
uint32_t arg2;
|
||||
uint32_t size;
|
||||
uint32_t size;
|
||||
};
|
||||
|
||||
/* Callbacks with this type will be called when a new connection to a
|
||||
server is accepted. */
|
||||
typedef void (*udscs_connect_callback)(struct udscs_connection *conn);
|
||||
/* Callbacks with this type will be called when a complete message has been
|
||||
received. The callback may call udscs_destroy_connection, in which case
|
||||
*connp must be made NULL (which udscs_destroy_connection takes care of) */
|
||||
typedef void (*udscs_read_callback)(struct udscs_connection **connp,
|
||||
* received. The callback does not own the data buffer and should not free it.
|
||||
* The data buffer will be freed shortly after the read callback returns.
|
||||
*/
|
||||
typedef void (*udscs_read_callback)(UdscsConnection *conn,
|
||||
struct udscs_message_header *header, uint8_t *data);
|
||||
/* Callback type for udscs_server_for_all_clients. Clients can be disconnected
|
||||
from this callback just like with a read callback. */
|
||||
typedef int (*udscs_for_all_clients_callback)(struct udscs_connection **connp,
|
||||
void *priv);
|
||||
/* Callbacks with this type will be called when the connection is disconnected.
|
||||
Note:
|
||||
1) udscs will destroy the connection in question itself after
|
||||
this callback has completed!
|
||||
2) This callback is always called, even if the disconnect is initiated
|
||||
by the udscs user through returning -1 from a read callback, or
|
||||
by explictly calling udscs_destroy_connection */
|
||||
typedef void (*udscs_disconnect_callback)(struct udscs_connection *conn);
|
||||
|
||||
/* Create a unix domain socket named name and start listening on it. */
|
||||
struct udscs_server *udscs_create_server(const char *socketname,
|
||||
udscs_connect_callback connect_callback,
|
||||
/* Connect to the unix domain socket specified by socketname.
|
||||
* Only sockets bound to a pathname are supported.
|
||||
*
|
||||
* If debug is true then the events on this connection will be traced.
|
||||
* This includes the incoming and outgoing message names.
|
||||
*
|
||||
* In case of failure, returns NULL and set @err with reason.
|
||||
*/
|
||||
UdscsConnection *udscs_connect(const char *socketname,
|
||||
udscs_read_callback read_callback,
|
||||
udscs_disconnect_callback disconnect_callback,
|
||||
const char * const type_to_string[], int no_types, int debug);
|
||||
|
||||
void udscs_destroy_server(struct udscs_server *server);
|
||||
|
||||
/* Connect to a unix domain socket named name. */
|
||||
struct udscs_connection *udscs_connect(const char *socketname,
|
||||
udscs_read_callback read_callback,
|
||||
udscs_disconnect_callback disconnect_callback,
|
||||
const char * const type_to_string[], int no_types, int debug);
|
||||
|
||||
/* The contents of connp will be made NULL */
|
||||
void udscs_destroy_connection(struct udscs_connection **connp);
|
||||
|
||||
|
||||
/* Given an udscs server or client fill the fd_sets pointed to by readfds and
|
||||
writefds for select() usage.
|
||||
|
||||
Return value: value of the highest fd + 1 */
|
||||
int udscs_server_fill_fds(struct udscs_server *server, fd_set *readfds,
|
||||
fd_set *writefds);
|
||||
|
||||
int udscs_client_fill_fds(struct udscs_connection *conn, fd_set *readfds,
|
||||
fd_set *writefds);
|
||||
|
||||
/* Handle any events flagged by select for the given udscs server or client. */
|
||||
void udscs_server_handle_fds(struct udscs_server *server, fd_set *readfds,
|
||||
fd_set *writefds);
|
||||
|
||||
/* Note the connection may be destroyed (when disconnected) by this call
|
||||
in this case the disconnect calllback will get called before the
|
||||
destruction and the contents of connp will be made NULL */
|
||||
void udscs_client_handle_fds(struct udscs_connection **connp, fd_set *readfds,
|
||||
fd_set *writefds);
|
||||
|
||||
VDAgentConnErrorCb error_cb,
|
||||
int debug,
|
||||
GError **err);
|
||||
|
||||
/* Queue a message for delivery to the client connected through conn.
|
||||
|
||||
Returns 0 on success -1 on error (only happens when malloc fails) */
|
||||
int udscs_write(struct udscs_connection *conn, uint32_t type, uint32_t arg1,
|
||||
*/
|
||||
void udscs_write(UdscsConnection *conn, uint32_t type, uint32_t arg1,
|
||||
uint32_t arg2, const uint8_t *data, uint32_t size);
|
||||
|
||||
#ifndef UDSCS_NO_SERVER
|
||||
|
||||
/* ---------- Server-side API ---------- */
|
||||
|
||||
struct udscs_server;
|
||||
|
||||
/* Callbacks with this type will be called when a new connection to a
|
||||
* server is accepted.
|
||||
*/
|
||||
typedef void (*udscs_connect_callback)(UdscsConnection *conn);
|
||||
|
||||
/* Initialize a new udscs_server struct.
|
||||
*
|
||||
* If debug is true then the events on this socket and related individual
|
||||
* connections will be traced.
|
||||
* This includes the incoming and outgoing message names.
|
||||
*/
|
||||
struct udscs_server *udscs_server_new(
|
||||
udscs_connect_callback connect_callback,
|
||||
udscs_read_callback read_callback,
|
||||
VDAgentConnErrorCb error_cb,
|
||||
int debug);
|
||||
|
||||
/* Start listening on a pre-configured socket specified by the given @fd.
|
||||
* This can be used with systemd socket activation, etc. */
|
||||
void udscs_server_listen_to_socket(struct udscs_server *server,
|
||||
gint fd,
|
||||
GError **err);
|
||||
|
||||
/* Create a new socket, bind it to @address and start listening on it. */
|
||||
void udscs_server_listen_to_address(struct udscs_server *server,
|
||||
const gchar *addr,
|
||||
GError **err);
|
||||
|
||||
void udscs_server_start(struct udscs_server *server);
|
||||
|
||||
void udscs_server_destroy_connection(struct udscs_server *server,
|
||||
UdscsConnection *conn);
|
||||
|
||||
/* Close all the server's connections and releases the corresponding
|
||||
* resources.
|
||||
* Does nothing if server is NULL.
|
||||
*/
|
||||
void udscs_destroy_server(struct udscs_server *server);
|
||||
|
||||
/* Like udscs_write, but then send the message to all clients connected to
|
||||
the server */
|
||||
int udscs_server_write_all(struct udscs_server *server,
|
||||
uint32_t type, uint32_t arg1, uint32_t arg2,
|
||||
const uint8_t *data, uint32_t size);
|
||||
* the server.
|
||||
*/
|
||||
void udscs_server_write_all(struct udscs_server *server,
|
||||
uint32_t type, uint32_t arg1, uint32_t arg2,
|
||||
const uint8_t *data, uint32_t size);
|
||||
|
||||
/* Callback type for udscs_server_for_all_clients. Clients can be disconnected
|
||||
* from this callback just like with a read callback.
|
||||
*/
|
||||
typedef int (*udscs_for_all_clients_callback)(UdscsConnection *conn,
|
||||
void *priv);
|
||||
|
||||
/* Call func for all clients connected to the server, passing through
|
||||
priv to all func calls. Returns the total of the return values from all
|
||||
calls to func */
|
||||
* priv to all func calls. Returns the total of the return values from all
|
||||
* calls to func or 0 if server is NULL.
|
||||
*/
|
||||
int udscs_server_for_all_clients(struct udscs_server *server,
|
||||
udscs_for_all_clients_callback func, void *priv);
|
||||
udscs_for_all_clients_callback func, void *priv);
|
||||
|
||||
#endif
|
||||
|
||||
struct ucred udscs_get_peer_cred(struct udscs_connection *conn);
|
||||
|
||||
/* For server use, to associate per connection data with a connection */
|
||||
void udscs_set_user_data(struct udscs_connection *conn, void *data);
|
||||
void *udscs_get_user_data(struct udscs_connection *conn);
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,319 @@
|
||||
/* vdagent-connection.c
|
||||
|
||||
Copyright 2019 Red Hat, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <syslog.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <gio/gunixinputstream.h>
|
||||
#include <gio/gunixoutputstream.h>
|
||||
#include <gio/gunixsocketaddress.h>
|
||||
|
||||
#include "vdagent-connection.h"
|
||||
|
||||
typedef struct {
|
||||
GIOStream *io_stream;
|
||||
gboolean opening;
|
||||
VDAgentConnErrorCb error_cb;
|
||||
GCancellable *cancellable;
|
||||
|
||||
GQueue *write_queue;
|
||||
gsize bytes_written;
|
||||
|
||||
gsize header_size;
|
||||
gpointer header_buf;
|
||||
gpointer data_buf;
|
||||
} VDAgentConnectionPrivate;
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE(VDAgentConnection, vdagent_connection, G_TYPE_OBJECT)
|
||||
|
||||
static void read_next_message(VDAgentConnection *self);
|
||||
|
||||
GIOStream *vdagent_file_open(const gchar *path, GError **err)
|
||||
{
|
||||
gint fd, errsv;
|
||||
|
||||
fd = g_open(path, O_RDWR);
|
||||
if (fd == -1) {
|
||||
errsv = errno;
|
||||
g_set_error_literal(err, G_FILE_ERROR,
|
||||
g_file_error_from_errno(errsv),
|
||||
g_strerror(errsv));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return g_simple_io_stream_new(g_unix_input_stream_new(fd, TRUE),
|
||||
g_unix_output_stream_new(fd, TRUE));
|
||||
}
|
||||
|
||||
GIOStream *vdagent_socket_connect(const gchar *path, GError **err)
|
||||
{
|
||||
GSocketConnection *conn;
|
||||
GSocketAddress *addr;
|
||||
GSocketClient *client;
|
||||
|
||||
addr = g_unix_socket_address_new(path);
|
||||
client = g_object_new(G_TYPE_SOCKET_CLIENT,
|
||||
"family", G_SOCKET_FAMILY_UNIX,
|
||||
"type", G_SOCKET_TYPE_STREAM,
|
||||
NULL);
|
||||
conn = g_socket_client_connect(client, G_SOCKET_CONNECTABLE(addr), NULL, err);
|
||||
g_object_unref(client);
|
||||
g_object_unref(addr);
|
||||
return G_IO_STREAM(conn);
|
||||
}
|
||||
|
||||
static void vdagent_connection_init(VDAgentConnection *self)
|
||||
{
|
||||
VDAgentConnectionPrivate *priv = vdagent_connection_get_instance_private(self);
|
||||
priv->cancellable = g_cancellable_new();
|
||||
priv->write_queue = g_queue_new();
|
||||
}
|
||||
|
||||
static void vdagent_connection_dispose(GObject *obj)
|
||||
{
|
||||
VDAgentConnection *self = VDAGENT_CONNECTION(obj);
|
||||
VDAgentConnectionPrivate *priv = vdagent_connection_get_instance_private(self);
|
||||
|
||||
g_clear_object(&priv->cancellable);
|
||||
g_clear_object(&priv->io_stream);
|
||||
|
||||
G_OBJECT_CLASS(vdagent_connection_parent_class)->dispose(obj);
|
||||
}
|
||||
|
||||
static void vdagent_connection_finalize(GObject *obj)
|
||||
{
|
||||
VDAgentConnection *self = VDAGENT_CONNECTION(obj);
|
||||
VDAgentConnectionPrivate *priv = vdagent_connection_get_instance_private(self);
|
||||
|
||||
g_queue_free_full(priv->write_queue, (GDestroyNotify)g_bytes_unref);
|
||||
g_free(priv->header_buf);
|
||||
g_free(priv->data_buf);
|
||||
|
||||
G_OBJECT_CLASS(vdagent_connection_parent_class)->finalize(obj);
|
||||
}
|
||||
|
||||
static void vdagent_connection_class_init(VDAgentConnectionClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
|
||||
gobject_class->dispose = vdagent_connection_dispose;
|
||||
gobject_class->finalize = vdagent_connection_finalize;
|
||||
}
|
||||
|
||||
void vdagent_connection_setup(VDAgentConnection *self,
|
||||
GIOStream *io_stream,
|
||||
gboolean wait_on_opening,
|
||||
gsize header_size,
|
||||
VDAgentConnErrorCb error_cb)
|
||||
{
|
||||
VDAgentConnectionPrivate *priv = vdagent_connection_get_instance_private(self);
|
||||
priv->io_stream = io_stream;
|
||||
priv->opening = wait_on_opening;
|
||||
priv->header_size = header_size;
|
||||
priv->header_buf = g_malloc(header_size);
|
||||
priv->error_cb = error_cb;
|
||||
|
||||
read_next_message(self);
|
||||
}
|
||||
|
||||
void vdagent_connection_destroy(gpointer p)
|
||||
{
|
||||
g_return_if_fail(VDAGENT_IS_CONNECTION(p));
|
||||
|
||||
VDAgentConnection *self = VDAGENT_CONNECTION(p);
|
||||
VDAgentConnectionPrivate *priv = vdagent_connection_get_instance_private(self);
|
||||
g_cancellable_cancel(priv->cancellable);
|
||||
g_io_stream_close(priv->io_stream, NULL, NULL);
|
||||
g_object_unref(self);
|
||||
}
|
||||
|
||||
PidUid vdagent_connection_get_peer_pid_uid(VDAgentConnection *self,
|
||||
GError **err)
|
||||
{
|
||||
VDAgentConnectionPrivate *priv = vdagent_connection_get_instance_private(self);
|
||||
GSocket *sock;
|
||||
GCredentials *cred;
|
||||
PidUid pid_uid = { -1, -1 };
|
||||
|
||||
g_return_val_if_fail(G_IS_SOCKET_CONNECTION(priv->io_stream), pid_uid);
|
||||
|
||||
sock = g_socket_connection_get_socket(G_SOCKET_CONNECTION(priv->io_stream));
|
||||
cred = g_socket_get_credentials(sock, err);
|
||||
if (cred) {
|
||||
pid_uid.pid = g_credentials_get_unix_pid(cred, err);
|
||||
pid_uid.uid = g_credentials_get_unix_user(cred, err);
|
||||
g_object_unref(cred);
|
||||
}
|
||||
|
||||
return pid_uid;
|
||||
}
|
||||
|
||||
/* Performs single write operation,
|
||||
* returns TRUE if there's still data to be written, otherwise FALSE. */
|
||||
static gboolean do_write(VDAgentConnection *self, gboolean block)
|
||||
{
|
||||
VDAgentConnectionPrivate *priv = vdagent_connection_get_instance_private(self);
|
||||
GOutputStream *out;
|
||||
GBytes *msg;
|
||||
gssize res;
|
||||
GError *err = NULL;
|
||||
|
||||
msg = g_queue_peek_head(priv->write_queue);
|
||||
out = g_io_stream_get_output_stream(priv->io_stream);
|
||||
|
||||
if (!msg) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
res = g_pollable_stream_write(out,
|
||||
g_bytes_get_data(msg, NULL) + priv->bytes_written,
|
||||
g_bytes_get_size(msg) - priv->bytes_written,
|
||||
block, priv->cancellable, &err);
|
||||
|
||||
if (err) {
|
||||
if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK)) {
|
||||
g_error_free(err);
|
||||
return TRUE;
|
||||
} else if (g_error_matches(err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
|
||||
g_error_free(err);
|
||||
return FALSE;
|
||||
} else {
|
||||
priv->error_cb(self, err);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
priv->bytes_written += res;
|
||||
|
||||
if (priv->bytes_written == g_bytes_get_size(msg)) {
|
||||
g_bytes_unref(g_queue_pop_head(priv->write_queue));
|
||||
priv->bytes_written = 0;
|
||||
}
|
||||
|
||||
return !g_queue_is_empty(priv->write_queue);
|
||||
}
|
||||
|
||||
static gboolean out_stream_ready_cb(GObject *pollable_stream,
|
||||
gpointer user_data)
|
||||
{
|
||||
return do_write(user_data, FALSE);
|
||||
}
|
||||
|
||||
void vdagent_connection_write(VDAgentConnection *self,
|
||||
gpointer data,
|
||||
gsize size)
|
||||
{
|
||||
VDAgentConnectionPrivate *priv = vdagent_connection_get_instance_private(self);
|
||||
GPollableOutputStream *out;
|
||||
GSource *source;
|
||||
|
||||
g_queue_push_tail(priv->write_queue, g_bytes_new_take(data, size));
|
||||
|
||||
if (g_queue_get_length(priv->write_queue) == 1) {
|
||||
out = G_POLLABLE_OUTPUT_STREAM(g_io_stream_get_output_stream(priv->io_stream));
|
||||
|
||||
source = g_pollable_output_stream_create_source(out, priv->cancellable);
|
||||
g_source_set_callback(source, (GSourceFunc) out_stream_ready_cb,
|
||||
g_object_ref(self), g_object_unref);
|
||||
g_source_attach(source, NULL);
|
||||
g_source_unref(source);
|
||||
}
|
||||
}
|
||||
|
||||
void vdagent_connection_flush(VDAgentConnection *self)
|
||||
{
|
||||
while (do_write(self, TRUE));
|
||||
}
|
||||
|
||||
static void message_read_cb(GObject *source_object,
|
||||
GAsyncResult *res,
|
||||
gpointer user_data)
|
||||
{
|
||||
VDAgentConnection *self = user_data;
|
||||
VDAgentConnectionPrivate *priv = vdagent_connection_get_instance_private(self);
|
||||
GInputStream *in = G_INPUT_STREAM(source_object);
|
||||
GError *err = NULL;
|
||||
gsize bytes_read, data_size;
|
||||
|
||||
g_input_stream_read_all_finish(in, res, &bytes_read, &err);
|
||||
if (err) {
|
||||
if (g_error_matches(err, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
|
||||
g_error_free(err);
|
||||
} else {
|
||||
priv->error_cb(self, err);
|
||||
}
|
||||
goto unref;
|
||||
}
|
||||
|
||||
if (bytes_read == 0) {
|
||||
/* see virtio-port.c for the rationale behind this */
|
||||
if (priv->opening) {
|
||||
g_usleep(10000);
|
||||
read_next_message(self);
|
||||
} else {
|
||||
priv->error_cb(self, NULL);
|
||||
}
|
||||
goto unref;
|
||||
}
|
||||
priv->opening = FALSE;
|
||||
|
||||
if (!priv->data_buf) {
|
||||
/* we've read the message header, now let's read its body */
|
||||
data_size = VDAGENT_CONNECTION_GET_CLASS(self)->handle_header(
|
||||
self, priv->header_buf);
|
||||
|
||||
if (g_cancellable_is_cancelled(priv->cancellable)) {
|
||||
goto unref;
|
||||
}
|
||||
|
||||
if (data_size > 0) {
|
||||
priv->data_buf = g_malloc(data_size);
|
||||
g_input_stream_read_all_async(in,
|
||||
priv->data_buf, data_size,
|
||||
G_PRIORITY_DEFAULT, priv->cancellable,
|
||||
message_read_cb, g_object_ref(self));
|
||||
goto unref;
|
||||
}
|
||||
}
|
||||
|
||||
VDAGENT_CONNECTION_GET_CLASS(self)->handle_message(
|
||||
self, priv->header_buf, priv->data_buf);
|
||||
|
||||
g_clear_pointer(&priv->data_buf, g_free);
|
||||
read_next_message(self);
|
||||
|
||||
unref:
|
||||
g_object_unref(self);
|
||||
}
|
||||
|
||||
static void read_next_message(VDAgentConnection *self)
|
||||
{
|
||||
VDAgentConnectionPrivate *priv = vdagent_connection_get_instance_private(self);
|
||||
GInputStream *in;
|
||||
|
||||
if (g_cancellable_is_cancelled(priv->cancellable)) {
|
||||
return;
|
||||
}
|
||||
|
||||
in = g_io_stream_get_input_stream(priv->io_stream);
|
||||
|
||||
g_input_stream_read_all_async(in,
|
||||
priv->header_buf, priv->header_size,
|
||||
G_PRIORITY_DEFAULT, priv->cancellable,
|
||||
message_read_cb, g_object_ref(self));
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/* vdagent-connection.h
|
||||
|
||||
Copyright 2019 Red Hat, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __VDAGENT_CONNECTION_H
|
||||
#define __VDAGENT_CONNECTION_H
|
||||
|
||||
#include <glib.h>
|
||||
#include <gio/gio.h>
|
||||
#include <glib-object.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define VDAGENT_TYPE_CONNECTION vdagent_connection_get_type()
|
||||
G_DECLARE_DERIVABLE_TYPE(VDAgentConnection, vdagent_connection, VDAGENT, CONNECTION, GObject)
|
||||
|
||||
/* Subclasses of VDAgentConnection must implement
|
||||
* handle_header and handle_message. */
|
||||
struct _VDAgentConnectionClass {
|
||||
GObjectClass parent_class;
|
||||
|
||||
/* Called when a message header has been read.
|
||||
*
|
||||
* Handler must parse the @header_buf and
|
||||
* return the size of message's body.
|
||||
*
|
||||
* @header_buf must not be freed. */
|
||||
gsize (*handle_header) (VDAgentConnection *self,
|
||||
gpointer header_buf);
|
||||
|
||||
/* Called when a full message has been read.
|
||||
*
|
||||
* @header, @data must not be freed. */
|
||||
void (*handle_message) (VDAgentConnection *self,
|
||||
gpointer header_buf,
|
||||
gpointer data_buf);
|
||||
};
|
||||
|
||||
/* Invoked when an error occurs during read or write.
|
||||
*
|
||||
* If @err is NULL, the connection was closed by the remote side,
|
||||
* otherwise the handler must free @err using g_error_free().
|
||||
*
|
||||
* VDAgentConnection will not continue with the given I/O-op that failed. */
|
||||
typedef void (*VDAgentConnErrorCb)(VDAgentConnection *self, GError *err);
|
||||
|
||||
/* Open a file in @path for read and write.
|
||||
* Returns a new GIOStream to the given file or NULL when @err is set. */
|
||||
GIOStream *vdagent_file_open(const gchar *path, GError **err);
|
||||
|
||||
/* Create a socket and initiate a new connection to the socket in @path.
|
||||
* Returns a new GIOStream or NULL when @err is set. */
|
||||
GIOStream *vdagent_socket_connect(const gchar *path, GError **err);
|
||||
|
||||
/* Set up @self to use @io_stream and start reading from it.
|
||||
*
|
||||
* If @wait_on_opening is set to TRUE, EOF won't be treated as an error
|
||||
* until the first message is successfully read or written to the @io_stream. */
|
||||
void vdagent_connection_setup(VDAgentConnection *self,
|
||||
GIOStream *io_stream,
|
||||
gboolean wait_on_opening,
|
||||
gsize header_size,
|
||||
VDAgentConnErrorCb error_cb);
|
||||
|
||||
|
||||
/* Cancel running I/O-operations, close the underlying FD and
|
||||
* unref the VDAgentConnection object. */
|
||||
void vdagent_connection_destroy(gpointer p);
|
||||
|
||||
/* Append a message to the write queue.
|
||||
*
|
||||
* VDAgentConnection takes ownership of @data
|
||||
* and frees it once the message is flushed. */
|
||||
void vdagent_connection_write(VDAgentConnection *self,
|
||||
gpointer data,
|
||||
gsize size);
|
||||
|
||||
/* Synchronously write all queued messages to the output stream. */
|
||||
void vdagent_connection_flush(VDAgentConnection *self);
|
||||
|
||||
typedef struct PidUid {
|
||||
pid_t pid;
|
||||
uid_t uid;
|
||||
} PidUid;
|
||||
|
||||
/* Returns the PID and UID of the foreign process connected to the socket
|
||||
* or fill @err set. */
|
||||
PidUid vdagent_connection_get_peer_pid_uid(VDAgentConnection *self,
|
||||
GError **err);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
||||
@@ -1,436 +0,0 @@
|
||||
/* vdagent-virtio-port.c virtio port communication code
|
||||
|
||||
Copyright 2010 Red Hat, Inc.
|
||||
|
||||
Red Hat Authors:
|
||||
Hans de Goede <[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 <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/select.h>
|
||||
#include "vdagent-virtio-port.h"
|
||||
|
||||
#define VDP_LAST_PORT VDP_SERVER_PORT
|
||||
|
||||
struct vdagent_virtio_port_buf {
|
||||
uint8_t *buf;
|
||||
size_t pos;
|
||||
size_t size;
|
||||
size_t write_pos;
|
||||
|
||||
struct vdagent_virtio_port_buf *next;
|
||||
};
|
||||
|
||||
/* Data to keep track of the assembling of vdagent messages per chunk port,
|
||||
for de-multiplexing the messages */
|
||||
struct vdagent_virtio_port_chunk_port_data {
|
||||
int message_header_read;
|
||||
int message_data_pos;
|
||||
VDAgentMessage message_header;
|
||||
uint8_t *message_data;
|
||||
};
|
||||
|
||||
struct vdagent_virtio_port {
|
||||
int fd;
|
||||
int opening;
|
||||
|
||||
/* Chunk read stuff, single buffer, separate header and data buffer */
|
||||
int chunk_header_read;
|
||||
int chunk_data_pos;
|
||||
VDIChunkHeader chunk_header;
|
||||
uint8_t chunk_data[VD_AGENT_MAX_DATA_SIZE];
|
||||
|
||||
/* Per chunk port data */
|
||||
struct vdagent_virtio_port_chunk_port_data port_data[VDP_LAST_PORT + 1];
|
||||
|
||||
/* Writes are stored in a linked list of buffers, with both the header
|
||||
+ data for a single message in 1 buffer. */
|
||||
struct vdagent_virtio_port_buf *write_buf;
|
||||
|
||||
/* Callbacks */
|
||||
vdagent_virtio_port_read_callback read_callback;
|
||||
vdagent_virtio_port_disconnect_callback disconnect_callback;
|
||||
};
|
||||
|
||||
static void vdagent_virtio_port_do_write(struct vdagent_virtio_port **vportp);
|
||||
static void vdagent_virtio_port_do_read(struct vdagent_virtio_port **vportp);
|
||||
|
||||
struct vdagent_virtio_port *vdagent_virtio_port_create(const char *portname,
|
||||
vdagent_virtio_port_read_callback read_callback,
|
||||
vdagent_virtio_port_disconnect_callback disconnect_callback)
|
||||
{
|
||||
struct vdagent_virtio_port *vport;
|
||||
|
||||
vport = calloc(1, sizeof(*vport));
|
||||
if (!vport)
|
||||
return 0;
|
||||
|
||||
vport->fd = open(portname, O_RDWR);
|
||||
if (vport->fd == -1) {
|
||||
syslog(LOG_ERR, "open %s: %m", portname);
|
||||
free(vport);
|
||||
return NULL;
|
||||
}
|
||||
vport->opening = 1;
|
||||
|
||||
vport->read_callback = read_callback;
|
||||
vport->disconnect_callback = disconnect_callback;
|
||||
|
||||
return vport;
|
||||
}
|
||||
|
||||
void vdagent_virtio_port_destroy(struct vdagent_virtio_port **vportp)
|
||||
{
|
||||
struct vdagent_virtio_port_buf *wbuf, *next_wbuf;
|
||||
struct vdagent_virtio_port *vport = *vportp;
|
||||
int i;
|
||||
|
||||
if (!vport)
|
||||
return;
|
||||
|
||||
if (vport->disconnect_callback)
|
||||
vport->disconnect_callback(vport);
|
||||
|
||||
wbuf = vport->write_buf;
|
||||
while (wbuf) {
|
||||
next_wbuf = wbuf->next;
|
||||
free(wbuf->buf);
|
||||
free(wbuf);
|
||||
wbuf = next_wbuf;
|
||||
}
|
||||
|
||||
for (i = 0; i <= VDP_LAST_PORT; i++) {
|
||||
free(vport->port_data[i].message_data);
|
||||
}
|
||||
|
||||
close(vport->fd);
|
||||
free(vport);
|
||||
*vportp = NULL;
|
||||
}
|
||||
|
||||
int vdagent_virtio_port_fill_fds(struct vdagent_virtio_port *vport,
|
||||
fd_set *readfds, fd_set *writefds)
|
||||
{
|
||||
if (!vport)
|
||||
return -1;
|
||||
|
||||
FD_SET(vport->fd, readfds);
|
||||
if (vport->write_buf)
|
||||
FD_SET(vport->fd, writefds);
|
||||
|
||||
return vport->fd + 1;
|
||||
}
|
||||
|
||||
void vdagent_virtio_port_handle_fds(struct vdagent_virtio_port **vportp,
|
||||
fd_set *readfds, fd_set *writefds)
|
||||
{
|
||||
if (!*vportp)
|
||||
return;
|
||||
|
||||
if (FD_ISSET((*vportp)->fd, readfds))
|
||||
vdagent_virtio_port_do_read(vportp);
|
||||
|
||||
if (*vportp && FD_ISSET((*vportp)->fd, writefds))
|
||||
vdagent_virtio_port_do_write(vportp);
|
||||
}
|
||||
|
||||
static struct vdagent_virtio_port_buf* vdagent_virtio_port_get_last_wbuf(
|
||||
struct vdagent_virtio_port *vport)
|
||||
{
|
||||
struct vdagent_virtio_port_buf *wbuf;
|
||||
|
||||
wbuf = vport->write_buf;
|
||||
if (!wbuf)
|
||||
return NULL;
|
||||
|
||||
while (wbuf->next)
|
||||
wbuf = wbuf->next;
|
||||
|
||||
return wbuf;
|
||||
}
|
||||
|
||||
int vdagent_virtio_port_write_start(
|
||||
struct vdagent_virtio_port *vport,
|
||||
uint32_t port_nr,
|
||||
uint32_t message_type,
|
||||
uint32_t message_opaque,
|
||||
uint32_t data_size)
|
||||
{
|
||||
struct vdagent_virtio_port_buf *wbuf, *new_wbuf;
|
||||
VDIChunkHeader chunk_header;
|
||||
VDAgentMessage message_header;
|
||||
|
||||
new_wbuf = malloc(sizeof(*new_wbuf));
|
||||
if (!new_wbuf)
|
||||
return -1;
|
||||
|
||||
new_wbuf->pos = 0;
|
||||
new_wbuf->write_pos = 0;
|
||||
new_wbuf->size = sizeof(chunk_header) + sizeof(message_header) + data_size;
|
||||
new_wbuf->next = NULL;
|
||||
new_wbuf->buf = malloc(new_wbuf->size);
|
||||
if (!new_wbuf->buf) {
|
||||
free(new_wbuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
chunk_header.port = port_nr;
|
||||
chunk_header.size = sizeof(message_header) + data_size;
|
||||
memcpy(new_wbuf->buf + new_wbuf->write_pos, &chunk_header,
|
||||
sizeof(chunk_header));
|
||||
new_wbuf->write_pos += sizeof(chunk_header);
|
||||
|
||||
message_header.protocol = VD_AGENT_PROTOCOL;
|
||||
message_header.type = message_type;
|
||||
message_header.opaque = message_opaque;
|
||||
message_header.size = data_size;
|
||||
memcpy(new_wbuf->buf + new_wbuf->write_pos, &message_header,
|
||||
sizeof(message_header));
|
||||
new_wbuf->write_pos += sizeof(message_header);
|
||||
|
||||
if (!vport->write_buf) {
|
||||
vport->write_buf = new_wbuf;
|
||||
return 0;
|
||||
}
|
||||
|
||||
wbuf = vdagent_virtio_port_get_last_wbuf(vport);
|
||||
wbuf->next = new_wbuf;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vdagent_virtio_port_write_append(struct vdagent_virtio_port *vport,
|
||||
const uint8_t *data, uint32_t size)
|
||||
{
|
||||
struct vdagent_virtio_port_buf *wbuf;
|
||||
|
||||
wbuf = vdagent_virtio_port_get_last_wbuf(vport);
|
||||
if (!wbuf) {
|
||||
syslog(LOG_ERR, "can't append without a buffer");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (wbuf->size - wbuf->write_pos < size) {
|
||||
syslog(LOG_ERR, "can't append to full buffer");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(wbuf->buf + wbuf->write_pos, data, size);
|
||||
wbuf->write_pos += size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int vdagent_virtio_port_write(
|
||||
struct vdagent_virtio_port *vport,
|
||||
uint32_t port_nr,
|
||||
uint32_t message_type,
|
||||
uint32_t message_opaque,
|
||||
const uint8_t *data,
|
||||
uint32_t data_size)
|
||||
{
|
||||
if (vdagent_virtio_port_write_start(vport, port_nr, message_type,
|
||||
message_opaque, data_size)) {
|
||||
return -1;
|
||||
}
|
||||
vdagent_virtio_port_write_append(vport, data, data_size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void vdagent_virtio_port_flush(struct vdagent_virtio_port **vportp)
|
||||
{
|
||||
while (*vportp && (*vportp)->write_buf)
|
||||
vdagent_virtio_port_do_write(vportp);
|
||||
}
|
||||
|
||||
static void vdagent_virtio_port_do_chunk(struct vdagent_virtio_port **vportp)
|
||||
{
|
||||
int avail, read, pos = 0;
|
||||
struct vdagent_virtio_port *vport = *vportp;
|
||||
struct vdagent_virtio_port_chunk_port_data *port =
|
||||
&vport->port_data[vport->chunk_header.port];
|
||||
|
||||
if (port->message_header_read < sizeof(port->message_header)) {
|
||||
read = sizeof(port->message_header) - port->message_header_read;
|
||||
if (read > vport->chunk_header.size) {
|
||||
read = vport->chunk_header.size;
|
||||
}
|
||||
memcpy((uint8_t *)&port->message_header + port->message_header_read,
|
||||
vport->chunk_data, read);
|
||||
port->message_header_read += read;
|
||||
if (port->message_header_read == sizeof(port->message_header) &&
|
||||
port->message_header.size) {
|
||||
port->message_data = malloc(port->message_header.size);
|
||||
if (!port->message_data) {
|
||||
syslog(LOG_ERR, "out of memory, disconnecting virtio");
|
||||
vdagent_virtio_port_destroy(vportp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
pos = read;
|
||||
}
|
||||
|
||||
if (port->message_header_read == sizeof(port->message_header)) {
|
||||
read = port->message_header.size - port->message_data_pos;
|
||||
avail = vport->chunk_header.size - pos;
|
||||
|
||||
if (avail > read) {
|
||||
syslog(LOG_ERR, "chunk larger then message, lost sync?");
|
||||
vdagent_virtio_port_destroy(vportp);
|
||||
return;
|
||||
}
|
||||
|
||||
if (avail < read)
|
||||
read = avail;
|
||||
|
||||
if (read) {
|
||||
memcpy(port->message_data + port->message_data_pos,
|
||||
vport->chunk_data + pos, read);
|
||||
port->message_data_pos += read;
|
||||
}
|
||||
|
||||
if (port->message_data_pos == port->message_header.size) {
|
||||
if (vport->read_callback) {
|
||||
int r = vport->read_callback(vport, vport->chunk_header.port,
|
||||
&port->message_header, port->message_data);
|
||||
if (r == -1) {
|
||||
vdagent_virtio_port_destroy(vportp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
port->message_header_read = 0;
|
||||
port->message_data_pos = 0;
|
||||
free(port->message_data);
|
||||
port->message_data = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void vdagent_virtio_port_do_read(struct vdagent_virtio_port **vportp)
|
||||
{
|
||||
ssize_t n;
|
||||
size_t to_read;
|
||||
uint8_t *dest;
|
||||
struct vdagent_virtio_port *vport = *vportp;
|
||||
|
||||
if (vport->chunk_header_read < sizeof(vport->chunk_header)) {
|
||||
to_read = sizeof(vport->chunk_header) - vport->chunk_header_read;
|
||||
dest = (uint8_t *)&vport->chunk_header + vport->chunk_header_read;
|
||||
} else {
|
||||
to_read = vport->chunk_header.size - vport->chunk_data_pos;
|
||||
dest = vport->chunk_data + vport->chunk_data_pos;
|
||||
}
|
||||
|
||||
n = read(vport->fd, dest, to_read);
|
||||
if (n < 0) {
|
||||
if (errno == EINTR)
|
||||
return;
|
||||
syslog(LOG_ERR, "reading from vdagent virtio port: %m");
|
||||
}
|
||||
if (n == 0 && vport->opening) {
|
||||
/* When we open the virtio serial port, the following happens:
|
||||
1) The linux kernel virtio_console driver sends a
|
||||
VIRTIO_CONSOLE_PORT_OPEN message to qemu
|
||||
2) qemu's spicevmc chardev driver calls qemu_spice_add_interface to
|
||||
register the agent chardev with the spice-server
|
||||
3) spice-server then calls the spicevmc chardev driver's state
|
||||
callback to let it know it is ready to receive data
|
||||
4) The state callback sends a CHR_EVENT_OPENED to the virtio-console
|
||||
chardev backend
|
||||
5) The virtio-console chardev backend sends VIRTIO_CONSOLE_PORT_OPEN
|
||||
to the linux kernel virtio_console driver
|
||||
|
||||
Until steps 1 - 5 have completed the linux kernel virtio_console
|
||||
driver sees the virtio serial port as being in a disconnected state
|
||||
and read will return 0 ! So if we blindly assume that a read 0 means
|
||||
that the channel is closed we will hit a race here.
|
||||
|
||||
Therefore we ignore read returning 0 until we've successfully read
|
||||
or written some data. If we hit this race we also sleep a bit here
|
||||
to avoid busy waiting until the above steps complete */
|
||||
usleep(10000);
|
||||
return;
|
||||
}
|
||||
if (n <= 0) {
|
||||
vdagent_virtio_port_destroy(vportp);
|
||||
return;
|
||||
}
|
||||
vport->opening = 0;
|
||||
|
||||
if (vport->chunk_header_read < sizeof(vport->chunk_header)) {
|
||||
vport->chunk_header_read += n;
|
||||
if (vport->chunk_header_read == sizeof(vport->chunk_header)) {
|
||||
if (vport->chunk_header.size > VD_AGENT_MAX_DATA_SIZE) {
|
||||
syslog(LOG_ERR, "chunk size too large");
|
||||
vdagent_virtio_port_destroy(vportp);
|
||||
return;
|
||||
}
|
||||
if (vport->chunk_header.port > VDP_LAST_PORT) {
|
||||
syslog(LOG_ERR, "chunk port out of range");
|
||||
vdagent_virtio_port_destroy(vportp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
vport->chunk_data_pos += n;
|
||||
if (vport->chunk_data_pos == vport->chunk_header.size) {
|
||||
vdagent_virtio_port_do_chunk(vportp);
|
||||
vport->chunk_header_read = 0;
|
||||
vport->chunk_data_pos = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void vdagent_virtio_port_do_write(struct vdagent_virtio_port **vportp)
|
||||
{
|
||||
ssize_t n;
|
||||
size_t to_write;
|
||||
struct vdagent_virtio_port *vport = *vportp;
|
||||
|
||||
struct vdagent_virtio_port_buf* wbuf = vport->write_buf;
|
||||
if (!wbuf) {
|
||||
syslog(LOG_ERR, "do_write called on a port without a write buf ?!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (wbuf->write_pos != wbuf->size) {
|
||||
syslog(LOG_ERR, "do_write: buffer is incomplete!!");
|
||||
return;
|
||||
}
|
||||
|
||||
to_write = wbuf->size - wbuf->pos;
|
||||
n = write(vport->fd, wbuf->buf + wbuf->pos, to_write);
|
||||
if (n < 0) {
|
||||
if (errno == EINTR)
|
||||
return;
|
||||
syslog(LOG_ERR, "writing to vdagent virtio port: %m");
|
||||
vdagent_virtio_port_destroy(vportp);
|
||||
return;
|
||||
}
|
||||
if (n > 0)
|
||||
vport->opening = 0;
|
||||
|
||||
wbuf->pos += n;
|
||||
if (wbuf->pos == wbuf->size) {
|
||||
vport->write_buf = wbuf->next;
|
||||
free(wbuf->buf);
|
||||
free(wbuf);
|
||||
}
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
/* vdagent-virtio-port.h virtio port communication header
|
||||
|
||||
Copyright 2010 Red Hat, Inc.
|
||||
|
||||
Red Hat Authors:
|
||||
Hans de Goede <[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 __VIRTIO_PORT_H
|
||||
#define __VIRTIO_PORT_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/select.h>
|
||||
#include <spice/vd_agent.h>
|
||||
|
||||
struct vdagent_virtio_port;
|
||||
|
||||
/* Callbacks with this type will be called when a complete message has been
|
||||
received. Sometimes the callback may want to close the port, in this
|
||||
case do *not* call vdagent_virtio_port_destroy from the callback. The desire
|
||||
to close the port can be indicated be returning -1 from the callback,
|
||||
in other cases return 0. */
|
||||
typedef int (*vdagent_virtio_port_read_callback)(
|
||||
struct vdagent_virtio_port *vport,
|
||||
int port_nr,
|
||||
VDAgentMessage *message_header,
|
||||
uint8_t *data);
|
||||
|
||||
/* Callbacks with this type will be called when the port is disconnected.
|
||||
Note:
|
||||
1) vdagent_virtio_port will destroy the port in question itself after
|
||||
this callback has completed!
|
||||
2) This callback is always called, even if the disconnect is initiated
|
||||
by the vdagent_virtio_port user through returning -1 from a read
|
||||
callback, or by explictly calling vdagent_virtio_port_destroy */
|
||||
typedef void (*vdagent_virtio_port_disconnect_callback)(
|
||||
struct vdagent_virtio_port *conn);
|
||||
|
||||
|
||||
/* Create a vdagent virtio port object for port portname */
|
||||
struct vdagent_virtio_port *vdagent_virtio_port_create(const char *portname,
|
||||
vdagent_virtio_port_read_callback read_callback,
|
||||
vdagent_virtio_port_disconnect_callback disconnect_callback);
|
||||
|
||||
/* The contents of portp will be made NULL */
|
||||
void vdagent_virtio_port_destroy(struct vdagent_virtio_port **vportp);
|
||||
|
||||
|
||||
/* Given a vdagent_virtio_port fill the fd_sets pointed to by readfds and
|
||||
writefds for select() usage.
|
||||
|
||||
Return value: value of the highest fd + 1 */
|
||||
int vdagent_virtio_port_fill_fds(struct vdagent_virtio_port *vport,
|
||||
fd_set *readfds, fd_set *writefds);
|
||||
|
||||
/* Handle any events flagged by select for the given vdagent_virtio_port.
|
||||
Note the port may be destroyed (when disconnected) by this call
|
||||
in this case the disconnect calllback will get called before the
|
||||
destruction and the contents of connp will be made NULL */
|
||||
void vdagent_virtio_port_handle_fds(struct vdagent_virtio_port **vportp,
|
||||
fd_set *readfds, fd_set *writefds);
|
||||
|
||||
|
||||
/* Queue a message for delivery, either bit by bit, or all at once
|
||||
|
||||
Returns 0 on success -1 on error (only happens when malloc fails) */
|
||||
int vdagent_virtio_port_write_start(
|
||||
struct vdagent_virtio_port *vport,
|
||||
uint32_t port_nr,
|
||||
uint32_t message_type,
|
||||
uint32_t message_opaque,
|
||||
uint32_t data_size);
|
||||
|
||||
int vdagent_virtio_port_write_append(
|
||||
struct vdagent_virtio_port *vport,
|
||||
const uint8_t *data,
|
||||
uint32_t size);
|
||||
|
||||
int vdagent_virtio_port_write(
|
||||
struct vdagent_virtio_port *vport,
|
||||
uint32_t port_nr,
|
||||
uint32_t message_type,
|
||||
uint32_t message_opaque,
|
||||
const uint8_t *data,
|
||||
uint32_t data_size);
|
||||
|
||||
void vdagent_virtio_port_flush(struct vdagent_virtio_port **vportp);
|
||||
|
||||
#endif
|
||||
@@ -1,728 +0,0 @@
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <X11/extensions/Xinerama.h>
|
||||
|
||||
#include "vdagentd-proto.h"
|
||||
#include "vdagent-x11.h"
|
||||
#include "vdagent-x11-priv.h"
|
||||
|
||||
static int caught_error;
|
||||
static int (*old_error_handler)(Display *, XErrorEvent *);
|
||||
|
||||
static int error_handler(Display *display, XErrorEvent *error)
|
||||
{
|
||||
caught_error = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void arm_error_handler(struct vdagent_x11 *x11)
|
||||
{
|
||||
caught_error = 0;
|
||||
XSync(x11->display, False);
|
||||
old_error_handler = XSetErrorHandler(error_handler);
|
||||
}
|
||||
|
||||
static void check_error_handler(struct vdagent_x11 *x11)
|
||||
{
|
||||
XSync(x11->display, False);
|
||||
XSetErrorHandler(old_error_handler);
|
||||
if (caught_error) {
|
||||
x11->set_crtc_config_not_functional = 1;
|
||||
}
|
||||
}
|
||||
|
||||
static XRRModeInfo *mode_from_id(struct vdagent_x11 *x11, int id)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0 ; i < x11->randr.res->nmode ; ++i) {
|
||||
if (id == x11->randr.res->modes[i].id) {
|
||||
return &x11->randr.res->modes[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static XRRCrtcInfo *crtc_from_id(struct vdagent_x11 *x11, int id)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0 ; i < x11->randr.res->ncrtc ; ++i) {
|
||||
if (id == x11->randr.res->crtcs[i]) {
|
||||
return x11->randr.crtcs[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void free_randr_resources(struct vdagent_x11 *x11)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!x11->randr.res) {
|
||||
return;
|
||||
}
|
||||
if (x11->randr.outputs != NULL) {
|
||||
for (i = 0 ; i < x11->randr.res->noutput; ++i) {
|
||||
XRRFreeOutputInfo(x11->randr.outputs[i]);
|
||||
}
|
||||
free(x11->randr.outputs);
|
||||
}
|
||||
if (x11->randr.crtcs != NULL) {
|
||||
for (i = 0 ; i < x11->randr.res->ncrtc; ++i) {
|
||||
XRRFreeCrtcInfo(x11->randr.crtcs[i]);
|
||||
}
|
||||
free(x11->randr.crtcs);
|
||||
}
|
||||
XRRFreeScreenResources(x11->randr.res);
|
||||
x11->randr.res = NULL;
|
||||
x11->randr.outputs = NULL;
|
||||
x11->randr.crtcs = NULL;
|
||||
}
|
||||
|
||||
static void update_randr_res(struct vdagent_x11 *x11)
|
||||
{
|
||||
int i;
|
||||
|
||||
free_randr_resources(x11);
|
||||
/* Note: we don't need XRRGetScreenResourcesCurrent since we cache the changes */
|
||||
x11->randr.res = XRRGetScreenResources(x11->display, x11->root_window);
|
||||
x11->randr.outputs = malloc(x11->randr.res->noutput * sizeof(*x11->randr.outputs));
|
||||
x11->randr.crtcs = malloc(x11->randr.res->ncrtc * sizeof(*x11->randr.crtcs));
|
||||
for (i = 0 ; i < x11->randr.res->noutput; ++i) {
|
||||
x11->randr.outputs[i] = XRRGetOutputInfo(x11->display, x11->randr.res,
|
||||
x11->randr.res->outputs[i]);
|
||||
}
|
||||
for (i = 0 ; i < x11->randr.res->ncrtc; ++i) {
|
||||
x11->randr.crtcs[i] = XRRGetCrtcInfo(x11->display, x11->randr.res,
|
||||
x11->randr.res->crtcs[i]);
|
||||
}
|
||||
/* XXX is this dynamic? should it be cached? */
|
||||
if (XRRGetScreenSizeRange(x11->display, x11->root_window,
|
||||
&x11->randr.min_width,
|
||||
&x11->randr.min_height,
|
||||
&x11->randr.max_width,
|
||||
&x11->randr.max_height) != 1) {
|
||||
syslog(LOG_ERR, "update_randr_res: RRGetScreenSizeRange failed");
|
||||
}
|
||||
}
|
||||
|
||||
void vdagent_x11_randr_init(struct vdagent_x11 *x11)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (XRRQueryExtension(x11->display, &i, &i)) {
|
||||
x11->has_xrandr = 1;
|
||||
update_randr_res(x11);
|
||||
XRRQueryVersion(x11->display, &x11->xrandr_major, &x11->xrandr_minor);
|
||||
} else {
|
||||
x11->randr.res = NULL;
|
||||
}
|
||||
|
||||
if (XineramaQueryExtension(x11->display, &i, &i))
|
||||
x11->has_xinerama = 1;
|
||||
|
||||
switch (x11->has_xrandr << 4 | x11->has_xinerama) {
|
||||
case 0x00:
|
||||
syslog(LOG_ERR, "Neither Xrandr nor Xinerama found, assuming single monitor setup");
|
||||
break;
|
||||
case 0x01:
|
||||
if (x11->debug)
|
||||
syslog(LOG_DEBUG, "Found Xinerama extension without Xrandr, assuming Xinerama multi monitor setup");
|
||||
break;
|
||||
case 0x10:
|
||||
syslog(LOG_ERR, "Found Xrandr but no Xinerama, weird!");
|
||||
break;
|
||||
case 0x11:
|
||||
/* Standard xrandr setup, nothing to see here */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static XRRModeInfo *
|
||||
find_mode_by_name (struct vdagent_x11 *x11, char *name)
|
||||
{
|
||||
int m;
|
||||
XRRModeInfo *ret = NULL;
|
||||
|
||||
for (m = 0; m < x11->randr.res->nmode; m++) {
|
||||
XRRModeInfo *mode = &x11->randr.res->modes[m];
|
||||
if (!strcmp (name, mode->name)) {
|
||||
ret = mode;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static XRRModeInfo *
|
||||
find_mode_by_size (struct vdagent_x11 *x11, int width, int height)
|
||||
{
|
||||
int m;
|
||||
XRRModeInfo *ret = NULL;
|
||||
|
||||
for (m = 0; m < x11->randr.res->nmode; m++) {
|
||||
XRRModeInfo *mode = &x11->randr.res->modes[m];
|
||||
if (mode->width == width && mode->height == height) {
|
||||
ret = mode;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void delete_mode(struct vdagent_x11 *x11, int output_index, const char *name)
|
||||
{
|
||||
int m;
|
||||
XRRModeInfo *mode;
|
||||
XRROutputInfo *output_info;
|
||||
XRRCrtcInfo *crtc_info;
|
||||
RRCrtc crtc;
|
||||
int current_mode = -1;
|
||||
|
||||
output_info = x11->randr.outputs[output_index];
|
||||
if (output_info->ncrtc != 1) {
|
||||
syslog(LOG_ERR, "output has %d crtcs, expected exactly 1, "
|
||||
"failed to delete mode", output_info->ncrtc);
|
||||
return;
|
||||
}
|
||||
crtc_info = crtc_from_id(x11, output_info->crtcs[0]);
|
||||
current_mode = crtc_info->mode;
|
||||
crtc = output_info->crtc;
|
||||
for (m = 0 ; m < x11->randr.res->nmode; ++m) {
|
||||
mode = &x11->randr.res->modes[m];
|
||||
if (strcmp(mode->name, name) == 0)
|
||||
break;
|
||||
}
|
||||
if (m < x11->randr.res->nmode) {
|
||||
if (crtc && mode->id == current_mode) {
|
||||
syslog(LOG_DEBUG,
|
||||
"delete_mode of in use mode, setting crtc to NULL mode");
|
||||
XRRSetCrtcConfig(x11->display, x11->randr.res, crtc,
|
||||
CurrentTime, 0, 0, None, RR_Rotate_0, NULL, 0);
|
||||
}
|
||||
XRRDeleteOutputMode (x11->display, x11->randr.res->outputs[output_index],
|
||||
mode->id);
|
||||
XRRDestroyMode (x11->display, mode->id);
|
||||
}
|
||||
}
|
||||
|
||||
void set_reduced_cvt_mode(XRRModeInfo *mode, int width, int height)
|
||||
{
|
||||
/* Code taken from hw/xfree86/modes/xf86cvt.c
|
||||
* See that file for lineage. Originated in public domain code
|
||||
* Would be nice if xorg exported this in a library */
|
||||
|
||||
/* 1) top/bottom margin size (% of height) - default: 1.8 */
|
||||
#define CVT_MARGIN_PERCENTAGE 1.8
|
||||
|
||||
/* 2) character cell horizontal granularity (pixels) - default 8 */
|
||||
#define CVT_H_GRANULARITY 8
|
||||
|
||||
/* 4) Minimum vertical porch (lines) - default 3 */
|
||||
#define CVT_MIN_V_PORCH 3
|
||||
|
||||
/* 4) Minimum number of vertical back porch lines - default 6 */
|
||||
#define CVT_MIN_V_BPORCH 6
|
||||
|
||||
/* Pixel Clock step (kHz) */
|
||||
#define CVT_CLOCK_STEP 250
|
||||
|
||||
/* Minimum vertical blanking interval time (µs) - default 460 */
|
||||
#define CVT_RB_MIN_VBLANK 460.0
|
||||
|
||||
/* Fixed number of clocks for horizontal sync */
|
||||
#define CVT_RB_H_SYNC 32.0
|
||||
|
||||
/* Fixed number of clocks for horizontal blanking */
|
||||
#define CVT_RB_H_BLANK 160.0
|
||||
|
||||
/* Fixed number of lines for vertical front porch - default 3 */
|
||||
#define CVT_RB_VFPORCH 3
|
||||
|
||||
int VBILines;
|
||||
float VFieldRate = 60.0;
|
||||
int VSync;
|
||||
float HPeriod;
|
||||
|
||||
/* 2. Horizontal pixels */
|
||||
width = width - (width % CVT_H_GRANULARITY);
|
||||
|
||||
mode->width = width;
|
||||
mode->height = height;
|
||||
VSync = 10;
|
||||
|
||||
/* 8. Estimate Horizontal period. */
|
||||
HPeriod = ((float) (1000000.0 / VFieldRate - CVT_RB_MIN_VBLANK)) / height;
|
||||
|
||||
/* 9. Find number of lines in vertical blanking */
|
||||
VBILines = ((float) CVT_RB_MIN_VBLANK) / HPeriod + 1;
|
||||
|
||||
/* 10. Check if vertical blanking is sufficient */
|
||||
if (VBILines < (CVT_RB_VFPORCH + VSync + CVT_MIN_V_BPORCH))
|
||||
VBILines = CVT_RB_VFPORCH + VSync + CVT_MIN_V_BPORCH;
|
||||
|
||||
/* 11. Find total number of lines in vertical field */
|
||||
mode->vTotal = height + VBILines;
|
||||
|
||||
/* 12. Find total number of pixels in a line */
|
||||
mode->hTotal = mode->width + CVT_RB_H_BLANK;
|
||||
|
||||
/* Fill in HSync values */
|
||||
mode->hSyncEnd = mode->width + CVT_RB_H_BLANK / 2;
|
||||
mode->hSyncStart = mode->hSyncEnd - CVT_RB_H_SYNC;
|
||||
|
||||
/* Fill in VSync values */
|
||||
mode->vSyncStart = mode->height + CVT_RB_VFPORCH;
|
||||
mode->vSyncEnd = mode->vSyncStart + VSync;
|
||||
|
||||
/* 15/13. Find pixel clock frequency (kHz for xf86) */
|
||||
mode->dotClock = mode->hTotal * 1000.0 / HPeriod;
|
||||
mode->dotClock -= mode->dotClock % CVT_CLOCK_STEP;
|
||||
|
||||
}
|
||||
|
||||
static XRRModeInfo *create_new_mode(struct vdagent_x11 *x11, int output_index,
|
||||
int width, int height)
|
||||
{
|
||||
char modename[20];
|
||||
XRRModeInfo mode;
|
||||
|
||||
/* we may be using this mode from an old invocation - check first */
|
||||
snprintf(modename, sizeof(modename), "vdagent-%d", output_index);
|
||||
arm_error_handler(x11);
|
||||
delete_mode(x11, output_index, modename);
|
||||
check_error_handler(x11);
|
||||
if (x11->set_crtc_config_not_functional) {
|
||||
return NULL;
|
||||
}
|
||||
mode.hSkew = 0;
|
||||
mode.name = modename;
|
||||
mode.nameLength = strlen(mode.name);
|
||||
set_reduced_cvt_mode(&mode, width, height);
|
||||
mode.modeFlags = 0;
|
||||
mode.id = 0;
|
||||
|
||||
XRRCreateMode (x11->display, x11->root_window, &mode);
|
||||
/* silly to update everytime for more then one monitor */
|
||||
update_randr_res(x11);
|
||||
return find_mode_by_name(x11, modename);
|
||||
}
|
||||
|
||||
static int xrandr_add_and_set(struct vdagent_x11 *x11, int output, int x, int y,
|
||||
int width, int height)
|
||||
{
|
||||
XRRModeInfo *mode;
|
||||
int xid;
|
||||
Status s;
|
||||
RROutput outputs[1];
|
||||
|
||||
if (!x11->randr.res || output >= x11->randr.res->noutput || output < 0) {
|
||||
syslog(LOG_ERR, "%s: program error: missing RANDR or bad output",
|
||||
__FUNCTION__);
|
||||
return 0;
|
||||
}
|
||||
if (x11->set_crtc_config_not_functional) {
|
||||
/* succeed without doing anything. set_best_mode will
|
||||
* find something close. */
|
||||
return 1;
|
||||
}
|
||||
xid = x11->randr.res->outputs[output];
|
||||
mode = find_mode_by_size(x11, width, height);
|
||||
if (!mode) {
|
||||
mode = create_new_mode(x11, output, width, height);
|
||||
}
|
||||
if (!mode) {
|
||||
syslog(LOG_ERR, "failed to add a new mode");
|
||||
return 0;
|
||||
}
|
||||
XRRAddOutputMode(x11->display, xid, mode->id); // Call this anyway?
|
||||
outputs[0] = xid;
|
||||
s = XRRSetCrtcConfig(x11->display, x11->randr.res, x11->randr.res->crtcs[output],
|
||||
CurrentTime, x, y, mode->id, RR_Rotate_0, outputs,
|
||||
1);
|
||||
if (s != RRSetConfigSuccess) {
|
||||
syslog(LOG_ERR, "failed to XRRSetCrtcConfig");
|
||||
// TODO - return crtc config to default
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void xrandr_disable_output(struct vdagent_x11 *x11, int output)
|
||||
{
|
||||
Status s;
|
||||
|
||||
if (!x11->randr.res || output >= x11->randr.res->noutput || output < 0) {
|
||||
syslog(LOG_ERR, "%s: program error: missing RANDR or bad output",
|
||||
__FUNCTION__);
|
||||
return;
|
||||
}
|
||||
|
||||
s = XRRSetCrtcConfig(x11->display, x11->randr.res,
|
||||
x11->randr.res->crtcs[output],
|
||||
CurrentTime, 0, 0, None, RR_Rotate_0,
|
||||
NULL, 0);
|
||||
|
||||
if (s != RRSetConfigSuccess)
|
||||
syslog(LOG_ERR, "failed to disable monitor");
|
||||
}
|
||||
|
||||
static int set_screen_to_best_size(struct vdagent_x11 *x11, int width, int height,
|
||||
int *out_width, int *out_height){
|
||||
int i, num_sizes = 0;
|
||||
int best = -1;
|
||||
unsigned int closest_diff = -1;
|
||||
XRRScreenSize *sizes;
|
||||
XRRScreenConfiguration *config;
|
||||
Rotation rotation;
|
||||
|
||||
sizes = XRRSizes(x11->display, x11->screen, &num_sizes);
|
||||
if (!sizes || !num_sizes) {
|
||||
syslog(LOG_ERR, "XRRSizes failed");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Find the closest size which will fit within the monitor */
|
||||
for (i = 0; i < num_sizes; i++) {
|
||||
if (sizes[i].width > width ||
|
||||
sizes[i].height > height)
|
||||
continue; /* Too large for the monitor */
|
||||
|
||||
unsigned int wdiff = width - sizes[i].width;
|
||||
unsigned int hdiff = height - sizes[i].height;
|
||||
unsigned int diff = wdiff * wdiff + hdiff * hdiff;
|
||||
if (diff < closest_diff) {
|
||||
closest_diff = diff;
|
||||
best = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (best == -1) {
|
||||
syslog(LOG_ERR, "no suitable resolution found for monitor");
|
||||
return 0;
|
||||
}
|
||||
|
||||
config = XRRGetScreenInfo(x11->display, x11->root_window);
|
||||
if(!config) {
|
||||
syslog(LOG_ERR, "get screen info failed");
|
||||
return 0;
|
||||
}
|
||||
XRRConfigCurrentConfiguration(config, &rotation);
|
||||
XRRSetScreenConfig(x11->display, config, x11->root_window, best,
|
||||
rotation, CurrentTime);
|
||||
XRRFreeScreenConfigInfo(config);
|
||||
|
||||
*out_width = sizes[best].width;
|
||||
*out_height = sizes[best].height;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void vdagent_x11_randr_handle_root_size_change(struct vdagent_x11 *x11,
|
||||
int width, int height)
|
||||
{
|
||||
if (width == x11->width && height == x11->height) {
|
||||
return;
|
||||
}
|
||||
|
||||
x11->width = width;
|
||||
x11->height = height;
|
||||
if (!x11->dont_send_guest_xorg_res) {
|
||||
vdagent_x11_send_daemon_guest_xorg_res(x11);
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t min_int(uint32_t x, uint32_t y)
|
||||
{
|
||||
return x > y ? y : x;
|
||||
}
|
||||
|
||||
static uint32_t max_int(uint32_t x, uint32_t y)
|
||||
{
|
||||
return x > y ? x : y;
|
||||
}
|
||||
|
||||
int constrain_to_range(uint32_t low, uint32_t *val, uint32_t high)
|
||||
{
|
||||
if (low <= *val && *val <= high) {
|
||||
return 0;
|
||||
}
|
||||
if (low > *val) {
|
||||
*val = low;
|
||||
}
|
||||
if (*val > high) {
|
||||
*val = high;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void constrain_to_screen(struct vdagent_x11 *x11, uint32_t *w, uint32_t *h)
|
||||
{
|
||||
uint32_t lx, ly, hx, hy;
|
||||
uint32_t orig_h = *h;
|
||||
uint32_t orig_w = *w;
|
||||
|
||||
lx = x11->randr.min_width;
|
||||
hx = x11->randr.max_width;
|
||||
ly = x11->randr.min_height;
|
||||
hy = x11->randr.max_height;
|
||||
if (constrain_to_range(lx, w, hx)) {
|
||||
syslog(LOG_ERR, "width not in driver range: ! %d < %d < %d",
|
||||
lx, orig_w, hx);
|
||||
}
|
||||
if (constrain_to_range(ly, h, hy)) {
|
||||
syslog(LOG_ERR, "height not in driver range: ! %d < %d < %d",
|
||||
ly, orig_h, hy);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The agent config doesn't contain a primary size, just the monitors, but
|
||||
* we need to total size as well, to make sure we have enough memory and
|
||||
* because X needs it.
|
||||
*
|
||||
* At the same pass constrain any provided size to what the server accepts.
|
||||
*
|
||||
* Exit axioms:
|
||||
* x >= 0, y >= 0 for all x, y in mon_config
|
||||
* max_width >= width >= min_width,
|
||||
* max_height >= height >= min_height for all monitors in mon_config
|
||||
*/
|
||||
static void zero_base_monitors(struct vdagent_x11 *x11,
|
||||
VDAgentMonitorsConfig *mon_config,
|
||||
uint32_t *width, uint32_t *height)
|
||||
{
|
||||
int i = 0;
|
||||
uint32_t min_x, min_y, max_x, max_y;
|
||||
uint32_t *mon_height, *mon_width;
|
||||
|
||||
mon_width = &mon_config->monitors[i].width;
|
||||
mon_height = &mon_config->monitors[i].height;
|
||||
constrain_to_screen(x11, mon_width, mon_height);
|
||||
min_x = mon_config->monitors[0].x;
|
||||
min_y = mon_config->monitors[0].y;
|
||||
max_x = mon_config->monitors[0].width + min_x;
|
||||
max_y = mon_config->monitors[0].height + min_y;
|
||||
for (++i ; i < mon_config->num_of_monitors; ++i) {
|
||||
mon_width = &mon_config->monitors[i].width;
|
||||
mon_height = &mon_config->monitors[i].height;
|
||||
constrain_to_screen(x11, mon_width, mon_height);
|
||||
min_x = min_int(mon_config->monitors[i].x, min_x);
|
||||
min_y = min_int(mon_config->monitors[i].y, min_y);
|
||||
max_x = max_int(mon_config->monitors[i].x + *mon_width, max_x);
|
||||
max_y = max_int(mon_config->monitors[i].y + *mon_height, max_y);
|
||||
}
|
||||
if (min_x != 0 || min_y != 0) {
|
||||
syslog(LOG_ERR, "%s: agent config %d,%d rooted, adjusting to 0,0.",
|
||||
__FUNCTION__, min_x, min_y);
|
||||
for (i = 0 ; i < mon_config->num_of_monitors; ++i) {
|
||||
mon_config->monitors[i].x -= min_x;
|
||||
mon_config->monitors[i].y -= min_y;
|
||||
}
|
||||
}
|
||||
max_x -= min_x;
|
||||
max_y -= min_y;
|
||||
*width = max_x;
|
||||
*height = max_y;
|
||||
}
|
||||
|
||||
int same_monitor_configs(struct vdagent_x11 *x11, VDAgentMonitorsConfig *mon)
|
||||
{
|
||||
int i;
|
||||
XRRModeInfo *mode;
|
||||
XRRCrtcInfo *crtc;
|
||||
VDAgentMonConfig *client_mode;
|
||||
XRRScreenResources *res = x11->randr.res;
|
||||
|
||||
if (res->noutput > res->ncrtc) {
|
||||
syslog(LOG_ERR, "error: unexpected noutput > ncrtc in driver");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (mon->num_of_monitors > res->noutput) {
|
||||
syslog(LOG_ERR,
|
||||
"error: unexpected client request: #mon %d > driver output %d",
|
||||
mon->num_of_monitors, res->noutput);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0 ; i < mon->num_of_monitors; ++i) {
|
||||
if (x11->randr.outputs[i]->ncrtc == 0) {
|
||||
return 0;
|
||||
}
|
||||
if (x11->randr.outputs[i]->ncrtc != 1) {
|
||||
syslog(LOG_ERR, "error: unexpected driver config, ncrtc %d != 1",
|
||||
x11->randr.outputs[i]->ncrtc);
|
||||
return 0;
|
||||
}
|
||||
crtc = crtc_from_id(x11, x11->randr.outputs[i]->crtcs[0]);
|
||||
if (!crtc) {
|
||||
syslog(LOG_ERR, "error: inconsistent or stale data from X");
|
||||
return 0;
|
||||
}
|
||||
client_mode = &mon->monitors[i];
|
||||
mode = mode_from_id(x11, crtc->mode);
|
||||
if (!mode) {
|
||||
return 0;
|
||||
}
|
||||
/* NOTE: we don't compare depth. */
|
||||
/* NOTE 2: width set by X is a multiple of 8, so ignore lower 3 bits */
|
||||
if ((mode->width & ~7) != (client_mode->width & ~7) ||
|
||||
mode->height != client_mode->height ||
|
||||
(crtc->x & ~7) != (client_mode->x & ~7) ||
|
||||
crtc->y != client_mode->y) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void dump_monitors_config(struct vdagent_x11 *x11,
|
||||
VDAgentMonitorsConfig *mon_config,
|
||||
const char *prefix)
|
||||
{
|
||||
int i;
|
||||
VDAgentMonConfig *m;
|
||||
|
||||
syslog(LOG_DEBUG, "%s: %d, %x", prefix, mon_config->num_of_monitors,
|
||||
mon_config->flags);
|
||||
for (i = 0 ; i < mon_config->num_of_monitors; ++i) {
|
||||
m = &mon_config->monitors[i];
|
||||
syslog(LOG_DEBUG, "received monitor %d config %dx%d+%d+%d", i,
|
||||
m->width, m->height, m->x, m->y);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 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_x11_set_monitor_config(struct vdagent_x11 *x11,
|
||||
VDAgentMonitorsConfig *mon_config)
|
||||
{
|
||||
int i;
|
||||
int width, height;
|
||||
int x, y;
|
||||
uint32_t primary_w, primary_h;
|
||||
|
||||
if (!x11->has_xrandr)
|
||||
goto exit;
|
||||
|
||||
if (mon_config->num_of_monitors < 1) {
|
||||
syslog(LOG_ERR, "client sent invalid monitor config number %d",
|
||||
mon_config->num_of_monitors);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (same_monitor_configs(x11, mon_config)) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (x11->debug) {
|
||||
dump_monitors_config(x11, mon_config, "from guest");
|
||||
}
|
||||
|
||||
zero_base_monitors(x11, mon_config, &primary_w, &primary_h);
|
||||
|
||||
constrain_to_screen(x11, &primary_w, &primary_h);
|
||||
|
||||
if (x11->debug) {
|
||||
dump_monitors_config(x11, mon_config, "after zeroing");
|
||||
}
|
||||
|
||||
for (i = mon_config->num_of_monitors; i < x11->randr.res->noutput; i++)
|
||||
xrandr_disable_output(x11, i);
|
||||
|
||||
for (i = 0; i < mon_config->num_of_monitors; ++i) {
|
||||
/* Try to create the requested resolution */
|
||||
width = mon_config->monitors[i].width;
|
||||
height = mon_config->monitors[i].height;
|
||||
x = mon_config->monitors[i].x;
|
||||
y = mon_config->monitors[i].y;
|
||||
if (!xrandr_add_and_set(x11, i, x, y, width, height) &&
|
||||
mon_config->num_of_monitors == 1) {
|
||||
set_screen_to_best_size(x11, width, height, &width, &height);
|
||||
}
|
||||
}
|
||||
|
||||
if (primary_w != x11->width || primary_h != x11->height) {
|
||||
arm_error_handler(x11);
|
||||
XRRSetScreenSize(x11->display, x11->root_window, primary_w, primary_h,
|
||||
DisplayWidthMM(x11->display, x11->screen),
|
||||
DisplayHeightMM(x11->display, x11->screen));
|
||||
check_error_handler(x11);
|
||||
}
|
||||
|
||||
update_randr_res(x11);
|
||||
x11->width = primary_w;
|
||||
x11->height = primary_h;
|
||||
|
||||
/* Flush output buffers and consume any pending events (ConfigureNotify) */
|
||||
x11->dont_send_guest_xorg_res = 1;
|
||||
vdagent_x11_do_read(x11);
|
||||
x11->dont_send_guest_xorg_res = 0;
|
||||
|
||||
exit:
|
||||
vdagent_x11_send_daemon_guest_xorg_res(x11);
|
||||
|
||||
/* Flush output buffers and consume any pending events */
|
||||
vdagent_x11_do_read(x11);
|
||||
}
|
||||
|
||||
void vdagent_x11_send_daemon_guest_xorg_res(struct vdagent_x11 *x11)
|
||||
{
|
||||
struct vdagentd_guest_xorg_resolution *res = NULL;
|
||||
XineramaScreenInfo *screen_info = NULL;
|
||||
int i, screen_count = 0;
|
||||
|
||||
if (x11->has_xinerama) {
|
||||
/* Xinerama reports the same information RANDR reports, so stay
|
||||
* with Xinerama for support of Xinerama only setups */
|
||||
screen_info = XineramaQueryScreens(x11->display, &screen_count);
|
||||
}
|
||||
|
||||
if (screen_count == 0)
|
||||
screen_count = 1;
|
||||
|
||||
res = malloc(screen_count * sizeof(*res));
|
||||
if (!res) {
|
||||
syslog(LOG_ERR, "out of memory while trying to send resolutions, not sending resolutions.");
|
||||
if (screen_info)
|
||||
XFree(screen_info);
|
||||
return;
|
||||
}
|
||||
|
||||
if (screen_info) {
|
||||
for (i = 0; i < screen_count; i++) {
|
||||
if (screen_info[i].screen_number >= screen_count) {
|
||||
syslog(LOG_ERR, "Invalid screen number in xinerama screen info (%d >= %d)",
|
||||
screen_info[i].screen_number, screen_count);
|
||||
XFree(screen_info);
|
||||
free(res);
|
||||
return;
|
||||
}
|
||||
res[screen_info[i].screen_number].width = screen_info[i].width;
|
||||
res[screen_info[i].screen_number].height = screen_info[i].height;
|
||||
res[screen_info[i].screen_number].x = screen_info[i].x_org;
|
||||
res[screen_info[i].screen_number].y = screen_info[i].y_org;
|
||||
}
|
||||
XFree(screen_info);
|
||||
} else {
|
||||
res[0].width = x11->width;
|
||||
res[0].height = x11->height;
|
||||
res[0].x = 0;
|
||||
res[0].y = 0;
|
||||
}
|
||||
|
||||
udscs_write(x11->vdagentd, VDAGENTD_GUEST_XORG_RESOLUTION, x11->width,
|
||||
x11->height, (uint8_t *)res, screen_count * sizeof(*res));
|
||||
free(res);
|
||||
}
|
||||
-248
@@ -1,248 +0,0 @@
|
||||
/* vdagent.c xorg-client to vdagentd (daemon).
|
||||
|
||||
Copyright 2010 Red Hat, Inc.
|
||||
|
||||
Red Hat Authors:
|
||||
Hans de Goede <[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/>.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/stat.h>
|
||||
#include <spice/vd_agent.h>
|
||||
|
||||
#include "udscs.h"
|
||||
#include "vdagentd-proto.h"
|
||||
#include "vdagentd-proto-strings.h"
|
||||
#include "vdagent-x11.h"
|
||||
|
||||
static const char *portdev = "/dev/virtio-ports/com.redhat.spice.0";
|
||||
static int debug = 0;
|
||||
static struct vdagent_x11 *x11 = NULL;
|
||||
static struct udscs_connection *client = NULL;
|
||||
static int quit = 0;
|
||||
static int version_mismatch = 0;
|
||||
|
||||
void daemon_read_complete(struct udscs_connection **connp,
|
||||
struct udscs_message_header *header, uint8_t *data)
|
||||
{
|
||||
switch (header->type) {
|
||||
case VDAGENTD_MONITORS_CONFIG:
|
||||
vdagent_x11_set_monitor_config(x11, (VDAgentMonitorsConfig *)data);
|
||||
free(data);
|
||||
break;
|
||||
case VDAGENTD_CLIPBOARD_REQUEST:
|
||||
vdagent_x11_clipboard_request(x11, header->arg1, header->arg2);
|
||||
free(data);
|
||||
break;
|
||||
case VDAGENTD_CLIPBOARD_GRAB:
|
||||
vdagent_x11_clipboard_grab(x11, header->arg1, (uint32_t *)data,
|
||||
header->size / sizeof(uint32_t));
|
||||
free(data);
|
||||
break;
|
||||
case VDAGENTD_CLIPBOARD_DATA:
|
||||
vdagent_x11_clipboard_data(x11, header->arg1, header->arg2,
|
||||
data, header->size);
|
||||
/* vdagent_x11_clipboard_data takes ownership of the data (or frees
|
||||
it immediately) */
|
||||
break;
|
||||
case VDAGENTD_CLIPBOARD_RELEASE:
|
||||
vdagent_x11_clipboard_release(x11, header->arg1);
|
||||
free(data);
|
||||
break;
|
||||
case VDAGENTD_VERSION:
|
||||
if (strcmp((char *)data, VERSION) != 0) {
|
||||
syslog(LOG_INFO, "vdagentd version mismatch: got %s expected %s",
|
||||
data, VERSION);
|
||||
udscs_destroy_connection(connp);
|
||||
version_mismatch = 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
syslog(LOG_ERR, "Unknown message from vdagentd type: %d, ignoring",
|
||||
header->type);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
|
||||
int client_setup(int reconnect)
|
||||
{
|
||||
while (!quit) {
|
||||
client = udscs_connect(VDAGENTD_SOCKET, daemon_read_complete, NULL,
|
||||
vdagentd_messages, VDAGENTD_NO_MESSAGES,
|
||||
debug);
|
||||
if (client || !reconnect || quit) {
|
||||
break;
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
return client == NULL;
|
||||
}
|
||||
|
||||
static void usage(FILE *fp)
|
||||
{
|
||||
fprintf(fp,
|
||||
"vdagent -- spice agent xorg client\n"
|
||||
"options:\n"
|
||||
" -h print this text\n"
|
||||
" -d log debug messages\n"
|
||||
" -s <port> set virtio serial port [%s]\n"
|
||||
" -x don't daemonize\n",
|
||||
portdev);
|
||||
}
|
||||
|
||||
static void quit_handler(int sig)
|
||||
{
|
||||
quit = 1;
|
||||
}
|
||||
|
||||
void daemonize(void)
|
||||
{
|
||||
int x, retval = 0;
|
||||
|
||||
/* detach from terminal */
|
||||
switch (fork()) {
|
||||
case 0:
|
||||
close(0); close(1); close(2);
|
||||
setsid();
|
||||
x = open("/dev/null", O_RDWR); x = dup(x); x = dup(x);
|
||||
break;
|
||||
case -1:
|
||||
syslog(LOG_ERR, "fork: %s", strerror(errno));
|
||||
retval = 1;
|
||||
default:
|
||||
exit(retval);
|
||||
}
|
||||
}
|
||||
|
||||
static int file_test(const char *path)
|
||||
{
|
||||
struct stat buffer;
|
||||
|
||||
return stat(path, &buffer);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
fd_set readfds, writefds;
|
||||
int c, n, nfds, x11_fd;
|
||||
int do_daemonize = 1;
|
||||
int x11_sync = 0;
|
||||
struct sigaction act;
|
||||
|
||||
for (;;) {
|
||||
if (-1 == (c = getopt(argc, argv, "-dxhys:")))
|
||||
break;
|
||||
switch (c) {
|
||||
case 'd':
|
||||
debug++;
|
||||
break;
|
||||
case 's':
|
||||
portdev = optarg;
|
||||
break;
|
||||
case 'x':
|
||||
do_daemonize = 0;
|
||||
break;
|
||||
case 'y':
|
||||
x11_sync = 1;
|
||||
break;
|
||||
case 'h':
|
||||
usage(stdout);
|
||||
return 0;
|
||||
default:
|
||||
usage(stderr);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
memset(&act, 0, sizeof(act));
|
||||
act.sa_flags = SA_RESTART;
|
||||
act.sa_handler = quit_handler;
|
||||
sigaction(SIGINT, &act, NULL);
|
||||
sigaction(SIGHUP, &act, NULL);
|
||||
sigaction(SIGTERM, &act, NULL);
|
||||
sigaction(SIGQUIT, &act, NULL);
|
||||
|
||||
openlog("spice-vdagent", do_daemonize ? LOG_PID : (LOG_PID | LOG_PERROR),
|
||||
LOG_USER);
|
||||
|
||||
if (file_test(portdev) != 0) {
|
||||
syslog(LOG_ERR, "Missing virtio device '%s': %s",
|
||||
portdev, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (do_daemonize)
|
||||
daemonize();
|
||||
|
||||
reconnect:
|
||||
if (version_mismatch) {
|
||||
syslog(LOG_INFO, "Version mismatch, restarting");
|
||||
sleep(1);
|
||||
execvp(argv[0], argv);
|
||||
}
|
||||
|
||||
if (client_setup(do_daemonize)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
x11 = vdagent_x11_create(client, debug, x11_sync);
|
||||
if (!x11) {
|
||||
udscs_destroy_connection(&client);
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (client && !quit) {
|
||||
FD_ZERO(&readfds);
|
||||
FD_ZERO(&writefds);
|
||||
|
||||
nfds = udscs_client_fill_fds(client, &readfds, &writefds);
|
||||
x11_fd = vdagent_x11_get_fd(x11);
|
||||
FD_SET(x11_fd, &readfds);
|
||||
if (x11_fd >= nfds)
|
||||
nfds = x11_fd + 1;
|
||||
|
||||
n = select(nfds, &readfds, &writefds, NULL, NULL);
|
||||
if (n == -1) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
syslog(LOG_ERR, "Fatal error select: %s", strerror(errno));
|
||||
break;
|
||||
}
|
||||
|
||||
if (FD_ISSET(x11_fd, &readfds))
|
||||
vdagent_x11_do_read(x11);
|
||||
udscs_client_handle_fds(&client, &readfds, &writefds);
|
||||
}
|
||||
|
||||
vdagent_x11_destroy(x11);
|
||||
udscs_destroy_connection(&client);
|
||||
if (!quit)
|
||||
goto reconnect;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
/* vdagent-audio.c vdagentd audio handling code
|
||||
|
||||
Copyright 2015 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 <glib.h>
|
||||
#include <syslog.h>
|
||||
#include <stdbool.h>
|
||||
#include <alsa/asoundlib.h>
|
||||
#include <alsa/mixer.h>
|
||||
#include <alsa/error.h>
|
||||
#include "audio.h"
|
||||
|
||||
#define ALSA_MUTE 0
|
||||
#define ALSA_UNMUTE 1
|
||||
|
||||
static snd_mixer_elem_t *
|
||||
get_alsa_default_mixer_by_name(snd_mixer_t **handle, const char *name)
|
||||
{
|
||||
snd_mixer_selem_id_t *sid;
|
||||
int err = 0;
|
||||
|
||||
if ((err = snd_mixer_open(handle, 0)) < 0)
|
||||
goto fail;
|
||||
|
||||
if ((err = snd_mixer_attach(*handle, "default")) < 0)
|
||||
goto fail;
|
||||
|
||||
if ((err = snd_mixer_selem_register(*handle, NULL, NULL)) < 0)
|
||||
goto fail;
|
||||
|
||||
if ((err = snd_mixer_load(*handle)) < 0)
|
||||
goto fail;
|
||||
|
||||
snd_mixer_selem_id_alloca(&sid);
|
||||
snd_mixer_selem_id_set_index(sid, 0);
|
||||
snd_mixer_selem_id_set_name(sid, name);
|
||||
return snd_mixer_find_selem(*handle, sid);
|
||||
|
||||
fail:
|
||||
syslog(LOG_WARNING, "%s fail: %s", __func__, snd_strerror(err));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
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 vol;
|
||||
bool ret = true;
|
||||
int alsa_mute;
|
||||
|
||||
e = get_alsa_default_mixer_by_name (&handle, "Capture");
|
||||
if (e == NULL) {
|
||||
syslog(LOG_WARNING, "vdagent-audio: can't get default alsa mixer");
|
||||
ret = false;
|
||||
goto end;
|
||||
}
|
||||
|
||||
alsa_mute = (mute) ? ALSA_MUTE : ALSA_UNMUTE;
|
||||
snd_mixer_selem_set_capture_switch_all(e, alsa_mute);
|
||||
|
||||
snd_mixer_selem_set_capture_volume_range(e, 0, UINT16_MAX);
|
||||
switch (nchannels) {
|
||||
case 1: /* MONO */
|
||||
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, 100.0 * vol / UINT16_MAX);
|
||||
break;
|
||||
case 2: /* LEFT-RIGHT */
|
||||
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, 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, 100.0 * vol / UINT16_MAX);
|
||||
break;
|
||||
default:
|
||||
syslog(LOG_WARNING, "vdagent-audio: number of channels not supported");
|
||||
ret = false;
|
||||
}
|
||||
end:
|
||||
if (handle != NULL)
|
||||
snd_mixer_close(handle);
|
||||
return ret;
|
||||
}
|
||||
|
||||
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 vol;
|
||||
bool ret = true;
|
||||
int alsa_mute;
|
||||
|
||||
e = get_alsa_default_mixer_by_name (&handle, "Master");
|
||||
if (e == NULL) {
|
||||
syslog(LOG_WARNING, "vdagent-audio: can't get default alsa mixer");
|
||||
ret = false;
|
||||
goto end;
|
||||
}
|
||||
|
||||
alsa_mute = (mute) ? ALSA_MUTE : ALSA_UNMUTE;
|
||||
snd_mixer_selem_set_playback_switch_all(e, alsa_mute);
|
||||
|
||||
snd_mixer_selem_set_playback_volume_range(e, 0, UINT16_MAX);
|
||||
switch (nchannels) {
|
||||
case 1: /* MONO */
|
||||
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, 100.0 * vol / UINT16_MAX);
|
||||
break;
|
||||
case 2: /* LEFT-RIGHT */
|
||||
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, 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, 100.0 * vol / UINT16_MAX);
|
||||
break;
|
||||
default:
|
||||
syslog(LOG_WARNING, "vdagent-audio: number of channels not supported");
|
||||
ret = false;
|
||||
}
|
||||
end:
|
||||
if (handle != NULL)
|
||||
snd_mixer_close(handle);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void vdagent_audio_playback_sync(uint8_t mute, uint8_t nchannels, uint16_t *volume)
|
||||
{
|
||||
syslog(LOG_DEBUG, "%s mute=%s nchannels=%u",
|
||||
__func__, (mute) ? "yes" : "no", nchannels);
|
||||
if (set_alsa_playback (mute, nchannels, volume) == false)
|
||||
syslog(LOG_WARNING, "Fail to sync playback volume");
|
||||
}
|
||||
|
||||
void vdagent_audio_record_sync(uint8_t mute, uint8_t nchannels, uint16_t *volume)
|
||||
{
|
||||
syslog(LOG_DEBUG, "%s mute=%s nchannels=%u",
|
||||
__func__, (mute) ? "yes" : "no", nchannels);
|
||||
if (set_alsa_capture (mute, nchannels, volume) == false)
|
||||
syslog(LOG_WARNING, "Fail to sync record volume");
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/* audio.h vdagentd audio handling header
|
||||
|
||||
Copyright 2015, 2016 Red Hat, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef __VDAGENT_AUDIO_H
|
||||
#define __VDAGENT_AUDIO_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
void vdagent_audio_playback_sync(uint8_t mute, uint8_t nchannels, uint16_t *volume);
|
||||
void vdagent_audio_record_sync(uint8_t mute, uint8_t nchannels, uint16_t *volume);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,522 @@
|
||||
/* clipboard.c - vdagent clipboard handling code
|
||||
|
||||
Copyright 2017 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>
|
||||
|
||||
#ifdef USE_GTK_FOR_CLIPBOARD
|
||||
# include <gtk/gtk.h>
|
||||
# include <syslog.h>
|
||||
|
||||
# include "vdagentd-proto.h"
|
||||
# include "spice/vd_agent.h"
|
||||
#endif
|
||||
|
||||
#include "clipboard.h"
|
||||
|
||||
#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)
|
||||
|
||||
static const GdkAtom sel_atom[] = {
|
||||
[VD_AGENT_CLIPBOARD_SELECTION_CLIPBOARD] = GDK_SELECTION_CLIPBOARD,
|
||||
[VD_AGENT_CLIPBOARD_SELECTION_PRIMARY] = GDK_SELECTION_PRIMARY,
|
||||
};
|
||||
|
||||
G_STATIC_ASSERT(G_N_ELEMENTS(sel_atom) == SELECTION_COUNT);
|
||||
|
||||
static gint sel_id_from_clip(GtkClipboard *clipboard)
|
||||
{
|
||||
GdkAtom sel = gtk_clipboard_get_selection(clipboard);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS(sel_atom); i++) {
|
||||
if (sel == sel_atom[i]) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
g_return_val_if_reached(0);
|
||||
}
|
||||
|
||||
enum {
|
||||
OWNER_NONE,
|
||||
OWNER_GUEST,
|
||||
OWNER_CLIENT
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
GMainLoop *loop;
|
||||
GtkSelectionData *sel_data;
|
||||
} AppRequest;
|
||||
|
||||
typedef struct {
|
||||
GtkClipboard *clipboard;
|
||||
guint owner;
|
||||
|
||||
GList *requests_from_apps; /* VDAgent --> Client */
|
||||
GList *requests_from_client; /* Client --> VDAgent */
|
||||
gpointer *last_targets_req;
|
||||
|
||||
GdkAtom targets[TYPE_COUNT];
|
||||
} Selection;
|
||||
#endif
|
||||
|
||||
struct _VDAgentClipboards {
|
||||
GObject parent;
|
||||
|
||||
#ifdef USE_GTK_FOR_CLIPBOARD
|
||||
UdscsConnection *conn;
|
||||
|
||||
Selection selections[SELECTION_COUNT];
|
||||
#else
|
||||
struct vdagent_x11 *x11;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct _VDAgentClipboardsClass
|
||||
{
|
||||
GObjectClass parent;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(VDAgentClipboards, vdagent_clipboards, G_TYPE_OBJECT)
|
||||
|
||||
#ifdef USE_GTK_FOR_CLIPBOARD
|
||||
static const struct {
|
||||
guint type;
|
||||
const gchar *atom_name;
|
||||
} atom2agent[] = {
|
||||
{VD_AGENT_CLIPBOARD_UTF8_TEXT, "UTF8_STRING"},
|
||||
{VD_AGENT_CLIPBOARD_UTF8_TEXT, "text/plain;charset=utf-8"},
|
||||
{VD_AGENT_CLIPBOARD_UTF8_TEXT, "STRING"},
|
||||
{VD_AGENT_CLIPBOARD_UTF8_TEXT, "TEXT"},
|
||||
{VD_AGENT_CLIPBOARD_UTF8_TEXT, "text/plain"},
|
||||
{VD_AGENT_CLIPBOARD_IMAGE_PNG, "image/png"},
|
||||
{VD_AGENT_CLIPBOARD_IMAGE_BMP, "image/bmp"},
|
||||
{VD_AGENT_CLIPBOARD_IMAGE_BMP, "image/x-bmp"},
|
||||
{VD_AGENT_CLIPBOARD_IMAGE_BMP, "image/x-MS-bmp"},
|
||||
{VD_AGENT_CLIPBOARD_IMAGE_BMP, "image/x-win-bitmap"},
|
||||
{VD_AGENT_CLIPBOARD_IMAGE_TIFF,"image/tiff"},
|
||||
{VD_AGENT_CLIPBOARD_IMAGE_JPG, "image/jpeg"},
|
||||
};
|
||||
|
||||
static guint get_type_from_atom(GdkAtom atom)
|
||||
{
|
||||
gchar *name = gdk_atom_name(atom);
|
||||
int i;
|
||||
for (i = 0; i < G_N_ELEMENTS(atom2agent); i++) {
|
||||
if (!g_ascii_strcasecmp(name, atom2agent[i].atom_name)) {
|
||||
g_free(name);
|
||||
return atom2agent[i].type;
|
||||
}
|
||||
}
|
||||
g_free(name);
|
||||
return VD_AGENT_CLIPBOARD_NONE;
|
||||
}
|
||||
|
||||
/* gtk_clipboard_request_(, callback, user_data) cannot be cancelled.
|
||||
Instead, gpointer *ref = request_ref_new() is passed to the callback.
|
||||
Callback can check using request_ref_is_cancelled(ref)
|
||||
whether request_ref_cancel(ref) was called.
|
||||
This mechanism enables cancellation of the request
|
||||
as well as passing VDAgentClipboards reference to the desired callback.
|
||||
*/
|
||||
static gpointer *request_ref_new(gpointer data)
|
||||
{
|
||||
gpointer *ref = g_new(gpointer, 1);
|
||||
*ref = data;
|
||||
return ref;
|
||||
}
|
||||
|
||||
static gpointer request_ref_free(gpointer *ref)
|
||||
{
|
||||
gpointer data = *ref;
|
||||
g_free(ref);
|
||||
return data;
|
||||
}
|
||||
|
||||
static void request_ref_cancel(gpointer *ref)
|
||||
{
|
||||
g_return_if_fail(ref != NULL);
|
||||
*ref = NULL;
|
||||
}
|
||||
|
||||
static gboolean request_ref_is_cancelled(gpointer *ref)
|
||||
{
|
||||
g_return_val_if_fail(ref != NULL, TRUE);
|
||||
return *ref == NULL;
|
||||
}
|
||||
|
||||
static void clipboard_new_owner(VDAgentClipboards *c, guint sel_id, guint new_owner)
|
||||
{
|
||||
Selection *sel = &c->selections[sel_id];
|
||||
GList *l;
|
||||
/* let the other apps know no data is coming */
|
||||
for (l = sel->requests_from_apps; l != NULL; l= l->next) {
|
||||
AppRequest *req = l->data;
|
||||
g_main_loop_quit(req->loop);
|
||||
}
|
||||
g_clear_pointer(&sel->requests_from_apps, g_list_free);
|
||||
|
||||
/* respond to pending client's data requests */
|
||||
for (l = sel->requests_from_client; l != NULL; l = l->next) {
|
||||
request_ref_cancel(l->data);
|
||||
if (c->conn)
|
||||
udscs_write(c->conn, VDAGENTD_CLIPBOARD_DATA,
|
||||
sel_id, VD_AGENT_CLIPBOARD_NONE, NULL, 0);
|
||||
}
|
||||
g_clear_pointer(&sel->requests_from_client, g_list_free);
|
||||
|
||||
sel->owner = new_owner;
|
||||
}
|
||||
|
||||
static void clipboard_targets_received_cb(GtkClipboard *clipboard,
|
||||
GdkAtom *atoms,
|
||||
gint n_atoms,
|
||||
gpointer user_data)
|
||||
{
|
||||
if (request_ref_is_cancelled(user_data))
|
||||
return;
|
||||
|
||||
VDAgentClipboards *c = request_ref_free(user_data);
|
||||
Selection *sel;
|
||||
guint32 types[G_N_ELEMENTS(atom2agent)];
|
||||
guint sel_id, type, n_types, a;
|
||||
|
||||
sel_id = sel_id_from_clip(clipboard);
|
||||
sel = &c->selections[sel_id];
|
||||
sel->last_targets_req = NULL;
|
||||
|
||||
if (atoms == NULL)
|
||||
return;
|
||||
|
||||
for (type = 0; type < TYPE_COUNT; type++)
|
||||
sel->targets[type] = GDK_NONE;
|
||||
|
||||
n_types = 0;
|
||||
for (a = 0; a < n_atoms; a++) {
|
||||
type = get_type_from_atom(atoms[a]);
|
||||
if (type == VD_AGENT_CLIPBOARD_NONE || sel->targets[type] != GDK_NONE)
|
||||
continue;
|
||||
|
||||
sel->targets[type] = atoms[a];
|
||||
types[n_types] = type;
|
||||
n_types++;
|
||||
}
|
||||
|
||||
if (n_types == 0) {
|
||||
syslog(LOG_WARNING, "%s: sel_id=%u: no target supported", __func__, sel_id);
|
||||
return;
|
||||
}
|
||||
|
||||
clipboard_new_owner(c, sel_id, OWNER_GUEST);
|
||||
|
||||
udscs_write(c->conn, VDAGENTD_CLIPBOARD_GRAB, sel_id, 0,
|
||||
(guint8 *)types, n_types * sizeof(guint32));
|
||||
}
|
||||
|
||||
static void clipboard_owner_change_cb(GtkClipboard *clipboard,
|
||||
GdkEventOwnerChange *event,
|
||||
gpointer user_data)
|
||||
{
|
||||
VDAgentClipboards *c = user_data;
|
||||
guint sel_id = sel_id_from_clip(clipboard);
|
||||
Selection *sel = &c->selections[sel_id];
|
||||
|
||||
/* if the event was caused by gtk_clipboard_set_with_data(), ignore it */
|
||||
if (gtk_clipboard_get_owner(clipboard) == G_OBJECT(c)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event->reason != GDK_OWNER_CHANGE_NEW_OWNER) {
|
||||
if (sel->owner == OWNER_GUEST) {
|
||||
clipboard_new_owner(c, sel_id, OWNER_NONE);
|
||||
udscs_write(c->conn, VDAGENTD_CLIPBOARD_RELEASE, sel_id, 0, NULL, 0);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* if there's a pending request for clipboard targets, cancel it */
|
||||
if (sel->last_targets_req)
|
||||
request_ref_cancel(sel->last_targets_req);
|
||||
|
||||
sel->last_targets_req = request_ref_new(c);
|
||||
gtk_clipboard_request_targets(clipboard, clipboard_targets_received_cb,
|
||||
sel->last_targets_req);
|
||||
}
|
||||
|
||||
static void clipboard_contents_received_cb(GtkClipboard *clipboard,
|
||||
GtkSelectionData *sel_data,
|
||||
gpointer user_data)
|
||||
{
|
||||
if (request_ref_is_cancelled(user_data))
|
||||
return;
|
||||
|
||||
VDAgentClipboards *c = request_ref_free(user_data);
|
||||
guint sel_id, type, target;
|
||||
|
||||
sel_id = sel_id_from_clip(clipboard);
|
||||
c->selections[sel_id].requests_from_client =
|
||||
g_list_remove(c->selections[sel_id].requests_from_client, user_data);
|
||||
|
||||
type = get_type_from_atom(gtk_selection_data_get_data_type(sel_data));
|
||||
target = get_type_from_atom(gtk_selection_data_get_target(sel_data));
|
||||
|
||||
if (type == target) {
|
||||
udscs_write(c->conn, VDAGENTD_CLIPBOARD_DATA, sel_id, type,
|
||||
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, received %u, "
|
||||
"skipping", __func__, sel_id, target, type);
|
||||
udscs_write(c->conn, VDAGENTD_CLIPBOARD_DATA, sel_id,
|
||||
VD_AGENT_CLIPBOARD_NONE, NULL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static void clipboard_get_cb(GtkClipboard *clipboard,
|
||||
GtkSelectionData *sel_data,
|
||||
guint info,
|
||||
gpointer user_data)
|
||||
{
|
||||
AppRequest req;
|
||||
VDAgentClipboards *c = user_data;
|
||||
guint sel_id, type;
|
||||
|
||||
sel_id = sel_id_from_clip(clipboard);
|
||||
g_return_if_fail(c->selections[sel_id].owner == OWNER_CLIENT);
|
||||
|
||||
type = get_type_from_atom(gtk_selection_data_get_target(sel_data));
|
||||
g_return_if_fail(type != VD_AGENT_CLIPBOARD_NONE);
|
||||
|
||||
req.sel_data = sel_data;
|
||||
req.loop = g_main_loop_new(NULL, FALSE);
|
||||
c->selections[sel_id].requests_from_apps =
|
||||
g_list_prepend(c->selections[sel_id].requests_from_apps, &req);
|
||||
|
||||
udscs_write(c->conn, VDAGENTD_CLIPBOARD_REQUEST, sel_id, type, NULL, 0);
|
||||
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
gdk_threads_leave();
|
||||
g_main_loop_run(req.loop);
|
||||
gdk_threads_enter();
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
|
||||
g_main_loop_unref(req.loop);
|
||||
}
|
||||
|
||||
static void clipboard_clear_cb(GtkClipboard *clipboard, gpointer user_data)
|
||||
{
|
||||
VDAgentClipboards *c = user_data;
|
||||
clipboard_new_owner(c, sel_id_from_clip(clipboard), OWNER_NONE);
|
||||
}
|
||||
#endif
|
||||
|
||||
void vdagent_clipboard_grab(VDAgentClipboards *c, guint sel_id,
|
||||
guint32 *types, guint n_types)
|
||||
{
|
||||
#ifndef USE_GTK_FOR_CLIPBOARD
|
||||
vdagent_x11_clipboard_grab(c->x11, sel_id, types, n_types);
|
||||
#else
|
||||
GtkTargetEntry targets[G_N_ELEMENTS(atom2agent)];
|
||||
Selection *sel;
|
||||
guint n_targets, i, t;
|
||||
|
||||
g_return_if_fail(sel_id < SELECTION_COUNT);
|
||||
|
||||
n_targets = 0;
|
||||
for (i = 0; i < G_N_ELEMENTS(atom2agent); i++)
|
||||
for (t = 0; t < n_types; t++)
|
||||
if (atom2agent[i].type == types[t]) {
|
||||
targets[n_targets].target = (gchar *)atom2agent[i].atom_name;
|
||||
n_targets++;
|
||||
break;
|
||||
}
|
||||
|
||||
if (n_targets == 0) {
|
||||
syslog(LOG_WARNING, "%s: sel_id=%u: no type supported", __func__, sel_id);
|
||||
return;
|
||||
}
|
||||
|
||||
sel = &c->selections[sel_id];
|
||||
|
||||
if (sel->last_targets_req) {
|
||||
g_clear_pointer(&sel->last_targets_req, request_ref_cancel);
|
||||
}
|
||||
|
||||
if (gtk_clipboard_set_with_owner(sel->clipboard,
|
||||
targets, n_targets,
|
||||
clipboard_get_cb, clipboard_clear_cb,
|
||||
G_OBJECT(c)))
|
||||
clipboard_new_owner(c, sel_id, OWNER_CLIENT);
|
||||
else {
|
||||
syslog(LOG_ERR, "%s: sel_id=%u: clipboard grab failed", __func__, sel_id);
|
||||
clipboard_new_owner(c, sel_id, OWNER_NONE);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void vdagent_clipboard_data(VDAgentClipboards *c, guint sel_id,
|
||||
guint type, guchar *data, guint size)
|
||||
{
|
||||
#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);
|
||||
Selection *sel = &c->selections[sel_id];
|
||||
AppRequest *req;
|
||||
GList *l;
|
||||
|
||||
for (l = sel->requests_from_apps; l != NULL; l = l->next) {
|
||||
req = l->data;
|
||||
if (get_type_from_atom(gtk_selection_data_get_target(req->sel_data)) == type)
|
||||
break;
|
||||
}
|
||||
if (l == NULL) {
|
||||
syslog(LOG_WARNING, "%s: sel_id=%u: no corresponding request found for "
|
||||
"type=%u, skipping", __func__, sel_id, type);
|
||||
return;
|
||||
}
|
||||
sel->requests_from_apps = g_list_delete_link(sel->requests_from_apps, l);
|
||||
|
||||
gtk_selection_data_set(req->sel_data,
|
||||
gtk_selection_data_get_target(req->sel_data),
|
||||
8, data, size);
|
||||
|
||||
g_main_loop_quit(req->loop);
|
||||
#endif
|
||||
}
|
||||
|
||||
void vdagent_clipboard_release(VDAgentClipboards *c, guint sel_id)
|
||||
{
|
||||
#ifndef USE_GTK_FOR_CLIPBOARD
|
||||
vdagent_x11_clipboard_release(c->x11, sel_id);
|
||||
#else
|
||||
g_return_if_fail(sel_id < SELECTION_COUNT);
|
||||
if (c->selections[sel_id].owner != OWNER_CLIENT)
|
||||
return;
|
||||
|
||||
clipboard_new_owner(c, sel_id, OWNER_NONE);
|
||||
gtk_clipboard_clear(c->selections[sel_id].clipboard);
|
||||
#endif
|
||||
}
|
||||
|
||||
void vdagent_clipboards_release_all(VDAgentClipboards *c)
|
||||
{
|
||||
#ifndef USE_GTK_FOR_CLIPBOARD
|
||||
vdagent_x11_client_disconnected(c->x11);
|
||||
#else
|
||||
guint sel_id, owner;
|
||||
|
||||
for (sel_id = 0; sel_id < SELECTION_COUNT; sel_id++) {
|
||||
owner = c->selections[sel_id].owner;
|
||||
clipboard_new_owner(c, sel_id, OWNER_NONE);
|
||||
if (owner == OWNER_CLIENT)
|
||||
gtk_clipboard_clear(c->selections[sel_id].clipboard);
|
||||
else if (owner == OWNER_GUEST && c->conn)
|
||||
udscs_write(c->conn, VDAGENTD_CLIPBOARD_RELEASE, sel_id, 0, NULL, 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void vdagent_clipboard_request(VDAgentClipboards *c, guint sel_id, guint type)
|
||||
{
|
||||
#ifndef USE_GTK_FOR_CLIPBOARD
|
||||
vdagent_x11_clipboard_request(c->x11, sel_id, type);
|
||||
#else
|
||||
Selection *sel;
|
||||
|
||||
if (sel_id >= SELECTION_COUNT)
|
||||
goto err;
|
||||
sel = &c->selections[sel_id];
|
||||
if (sel->owner != OWNER_GUEST) {
|
||||
syslog(LOG_WARNING, "%s: sel_id=%d: received request "
|
||||
"while not owning clipboard", __func__, sel_id);
|
||||
goto err;
|
||||
}
|
||||
if (type >= TYPE_COUNT || sel->targets[type] == GDK_NONE) {
|
||||
syslog(LOG_WARNING, "%s: sel_id=%d: unadvertised data type requested",
|
||||
__func__, sel_id);
|
||||
goto err;
|
||||
}
|
||||
|
||||
gpointer *ref = request_ref_new(c);
|
||||
sel->requests_from_client = g_list_prepend(sel->requests_from_client, ref);
|
||||
gtk_clipboard_request_contents(sel->clipboard, sel->targets[type],
|
||||
clipboard_contents_received_cb, ref);
|
||||
return;
|
||||
err:
|
||||
udscs_write(c->conn, VDAGENTD_CLIPBOARD_DATA, sel_id,
|
||||
VD_AGENT_CLIPBOARD_NONE, NULL, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
vdagent_clipboards_init(VDAgentClipboards *self)
|
||||
{
|
||||
}
|
||||
|
||||
VDAgentClipboards *vdagent_clipboards_new(struct vdagent_x11 *x11)
|
||||
{
|
||||
VDAgentClipboards *self = g_object_new(VDAGENT_TYPE_CLIPBOARDS, NULL);
|
||||
|
||||
#ifndef USE_GTK_FOR_CLIPBOARD
|
||||
self->x11 = x11;
|
||||
#else
|
||||
guint sel_id;
|
||||
|
||||
for (sel_id = 0; sel_id < SELECTION_COUNT; sel_id++) {
|
||||
GtkClipboard *clipboard = gtk_clipboard_get(sel_atom[sel_id]);
|
||||
self->selections[sel_id].clipboard = clipboard;
|
||||
g_signal_connect(G_OBJECT(clipboard), "owner-change",
|
||||
G_CALLBACK(clipboard_owner_change_cb), self);
|
||||
}
|
||||
#endif
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
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 USE_GTK_FOR_CLIPBOARD
|
||||
VDAgentClipboards *self = VDAGENT_CLIPBOARDS(obj);
|
||||
guint sel_id;
|
||||
|
||||
for (sel_id = 0; sel_id < SELECTION_COUNT; sel_id++)
|
||||
g_signal_handlers_disconnect_by_func(self->selections[sel_id].clipboard,
|
||||
G_CALLBACK(clipboard_owner_change_cb), self);
|
||||
|
||||
if (self->conn)
|
||||
vdagent_clipboards_release_all(self);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
vdagent_clipboards_class_init(VDAgentClipboardsClass *klass)
|
||||
{
|
||||
GObjectClass *oclass = G_OBJECT_CLASS(klass);
|
||||
|
||||
oclass->dispose = vdagent_clipboards_dispose;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/* clipboard.h - vdagent clipboard handling header
|
||||
|
||||
Copyright 2017 Red Hat, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __VDAGENT_CLIPBOARD_H
|
||||
#define __VDAGENT_CLIPBOARD_H
|
||||
|
||||
#include <glib-object.h>
|
||||
|
||||
#include "x11.h"
|
||||
#include "udscs.h"
|
||||
|
||||
#define VDAGENT_TYPE_CLIPBOARDS vdagent_clipboards_get_type()
|
||||
G_DECLARE_FINAL_TYPE(VDAgentClipboards, vdagent_clipboards, VDAGENT, CLIPBOARDS, GObject)
|
||||
|
||||
VDAgentClipboards *vdagent_clipboards_new(struct vdagent_x11 *x11);
|
||||
|
||||
void vdagent_clipboards_set_conn(VDAgentClipboards *self, UdscsConnection *conn);
|
||||
|
||||
void vdagent_clipboard_request(VDAgentClipboards *c, guint sel_id, guint type);
|
||||
|
||||
void vdagent_clipboard_release(VDAgentClipboards *c, guint sel_id);
|
||||
|
||||
void vdagent_clipboards_release_all(VDAgentClipboards *c);
|
||||
|
||||
void vdagent_clipboard_data(VDAgentClipboards *c, guint sel_id,
|
||||
guint type, guchar *data, guint size);
|
||||
|
||||
void vdagent_clipboard_grab(VDAgentClipboards *c, guint sel_id,
|
||||
guint32 *types, guint n_types);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,533 @@
|
||||
/* device-info.c utility function for looking up the xrandr output id for a
|
||||
* given device address and display id
|
||||
*
|
||||
* Copyright 2018 Red Hat, Inc.
|
||||
*
|
||||
* Red Hat Authors:
|
||||
* Jonathon Jongsma <[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 <assert.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <syslog.h>
|
||||
#include <xf86drm.h>
|
||||
#include <xf86drmMode.h>
|
||||
#include <unistd.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include "device-info.h"
|
||||
|
||||
#define PCI_VENDOR_ID_REDHAT 0x1b36
|
||||
#define PCI_VENDOR_ID_REDHAT_QUMRANET 0x1af4 // virtio-gpu
|
||||
#define PCI_VENDOR_ID_INTEL 0x8086
|
||||
#define PCI_VENDOR_ID_NVIDIA 0x10de
|
||||
|
||||
#define PCI_DEVICE_ID_QXL 0x0100
|
||||
#define PCI_DEVICE_ID_VIRTIO_GPU 0x1050
|
||||
|
||||
typedef struct PciDevice {
|
||||
int domain;
|
||||
uint8_t bus;
|
||||
uint8_t slot;
|
||||
uint8_t function;
|
||||
} PciDevice;
|
||||
|
||||
typedef struct PciAddress {
|
||||
int domain;
|
||||
GList *devices; /* PciDevice */
|
||||
} PciAddress;
|
||||
|
||||
static PciAddress* pci_address_new()
|
||||
{
|
||||
return g_new0(PciAddress, 1);
|
||||
}
|
||||
|
||||
static void pci_address_free(PciAddress *addr)
|
||||
{
|
||||
g_list_free_full(addr->devices, g_free);
|
||||
g_free(addr);
|
||||
}
|
||||
|
||||
|
||||
static int read_next_hex_number(const char *input, char delim, char **endptr)
|
||||
{
|
||||
assert(input != NULL);
|
||||
assert(endptr != NULL);
|
||||
|
||||
const char *pos = strchr(input, delim);
|
||||
int n;
|
||||
if (!pos) {
|
||||
*endptr = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *endpos;
|
||||
n = strtol(input, &endpos, 16);
|
||||
|
||||
// check if we read all characters until the delimiter
|
||||
if (endpos != pos) {
|
||||
endpos = NULL;
|
||||
}
|
||||
|
||||
*endptr = endpos;
|
||||
return n;
|
||||
}
|
||||
|
||||
// the device should be specified in BDF notation (e.g. 0000:00:02.0)
|
||||
// see https://wiki.xen.org/wiki/Bus:Device.Function_(BDF)_Notation
|
||||
static bool parse_pci_device(const char *bdf, const char *end, PciDevice *device)
|
||||
{
|
||||
if (!end) {
|
||||
end = strchr(bdf, 0);
|
||||
}
|
||||
|
||||
int endpos = -1;
|
||||
int domain, bus, slot, function;
|
||||
sscanf(bdf, "%x:%x:%x.%x%n", &domain, &bus, &slot, &function, &endpos);
|
||||
if (!device || endpos < 0 || bdf + endpos != end) {
|
||||
return false;
|
||||
}
|
||||
if (domain < 0 || bus < 0 || slot < 0 || function < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
device->domain = domain;
|
||||
device->bus = bus;
|
||||
device->slot = slot;
|
||||
device->function = function;
|
||||
return true;
|
||||
}
|
||||
|
||||
// We need to extract the pci address of the device from the sysfs entry for the device like so:
|
||||
// $ readlink /sys/class/drm/card0
|
||||
// This should give you a path such as this for cards on the root bus:
|
||||
// /sys/devices/pci0000:00/0000:00:02.0/drm/card0
|
||||
// or something like this if there is a pci bridge:
|
||||
// /sys/devices/pci0000:00/0000:00:03.0/0000:01:01.0/0000:02:03.0/virtio2/drm/card0
|
||||
static PciAddress* parse_pci_address_from_sysfs_path(const char* addr)
|
||||
{
|
||||
char *pos = strstr(addr, "/pci");
|
||||
if (!pos) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// advance to the numbers in pci0000:00
|
||||
pos += 4;
|
||||
int domain = read_next_hex_number(pos, ':', &pos);
|
||||
if (!pos) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// not used right now.
|
||||
G_GNUC_UNUSED uint8_t bus = read_next_hex_number(pos + 1, '/', &pos);
|
||||
if (!pos) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PciAddress *address = pci_address_new();
|
||||
address->domain = domain;
|
||||
// now read all of the devices
|
||||
while (pos) {
|
||||
PciDevice *dev = g_new0(PciDevice, 1);
|
||||
char *next = strchr(pos + 1, '/');
|
||||
if (!parse_pci_device(pos + 1, next, dev)) {
|
||||
g_free(dev);
|
||||
break;
|
||||
}
|
||||
address->devices = g_list_append(address->devices, dev);
|
||||
pos = next;
|
||||
}
|
||||
return address;
|
||||
}
|
||||
|
||||
// format should be something like pci/$domain/$slot.$fn/$slot.$fn
|
||||
static PciAddress* parse_pci_address_from_spice(char *input)
|
||||
{
|
||||
static const char prefix[] = "pci/";
|
||||
if (strncmp(input, prefix, strlen(prefix)) != 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *pos = input + strlen(prefix);
|
||||
int domain = read_next_hex_number(pos, '/', &pos);
|
||||
if (!pos) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PciAddress *address = pci_address_new();
|
||||
address->domain = domain;
|
||||
// now read all of the devices
|
||||
for (int n = 0; ; n++) {
|
||||
PciDevice *dev = g_new0(PciDevice, 1);
|
||||
char *next = strchr(pos + 1, '/');
|
||||
|
||||
dev->slot = read_next_hex_number(pos + 1, '.', &pos);
|
||||
if (!pos) {
|
||||
g_free(dev);
|
||||
break;
|
||||
}
|
||||
|
||||
dev->function = strtol(pos + 1, &pos, 16);
|
||||
if (!pos || (next != NULL && next != pos)) {
|
||||
g_free(dev);
|
||||
break;
|
||||
}
|
||||
|
||||
address->devices = g_list_append(address->devices, dev);
|
||||
pos = next;
|
||||
if (!pos) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return address;
|
||||
}
|
||||
|
||||
static bool compare_addresses(PciAddress *a, PciAddress *b)
|
||||
{
|
||||
// only check domain, slot, and function
|
||||
if (a->domain != b->domain) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const GList *la, *lb;
|
||||
for (la = a->devices, lb = b->devices;
|
||||
la != NULL && lb != NULL;
|
||||
la = la->next, lb = lb->next) {
|
||||
PciDevice *deva = la->data;
|
||||
PciDevice *devb = lb->data;
|
||||
|
||||
if (deva->slot != devb->slot
|
||||
|| deva->function != devb->function) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/* True only if both have the same length */
|
||||
return (la == NULL && lb == NULL);
|
||||
}
|
||||
|
||||
// Connector type names from xorg modesetting driver
|
||||
static const char * const modesetting_output_names[] = {
|
||||
[DRM_MODE_CONNECTOR_Unknown] = "None" ,
|
||||
[DRM_MODE_CONNECTOR_VGA] = "VGA" ,
|
||||
[DRM_MODE_CONNECTOR_DVII] = "DVI-I" ,
|
||||
[DRM_MODE_CONNECTOR_DVID] = "DVI-D" ,
|
||||
[DRM_MODE_CONNECTOR_DVIA] = "DVI-A" ,
|
||||
[DRM_MODE_CONNECTOR_Composite] = "Composite" ,
|
||||
[DRM_MODE_CONNECTOR_SVIDEO] = "SVIDEO" ,
|
||||
[DRM_MODE_CONNECTOR_LVDS] = "LVDS" ,
|
||||
[DRM_MODE_CONNECTOR_Component] = "Component" ,
|
||||
[DRM_MODE_CONNECTOR_9PinDIN] = "DIN" ,
|
||||
[DRM_MODE_CONNECTOR_DisplayPort] = "DP" ,
|
||||
[DRM_MODE_CONNECTOR_HDMIA] = "HDMI" ,
|
||||
[DRM_MODE_CONNECTOR_HDMIB] = "HDMI-B" ,
|
||||
[DRM_MODE_CONNECTOR_TV] = "TV" ,
|
||||
[DRM_MODE_CONNECTOR_eDP] = "eDP" ,
|
||||
[DRM_MODE_CONNECTOR_VIRTUAL] = "Virtual" ,
|
||||
[DRM_MODE_CONNECTOR_DSI] = "DSI" ,
|
||||
[DRM_MODE_CONNECTOR_DPI] = "DPI" ,
|
||||
};
|
||||
// Connector type names from qxl driver
|
||||
static const char * const qxl_output_names[] = {
|
||||
[DRM_MODE_CONNECTOR_Unknown] = "None" ,
|
||||
[DRM_MODE_CONNECTOR_VGA] = "VGA" ,
|
||||
[DRM_MODE_CONNECTOR_DVII] = "DVI" ,
|
||||
[DRM_MODE_CONNECTOR_DVID] = "DVI" ,
|
||||
[DRM_MODE_CONNECTOR_DVIA] = "DVI" ,
|
||||
[DRM_MODE_CONNECTOR_Composite] = "Composite" ,
|
||||
[DRM_MODE_CONNECTOR_SVIDEO] = "S-video" ,
|
||||
[DRM_MODE_CONNECTOR_LVDS] = "LVDS" ,
|
||||
[DRM_MODE_CONNECTOR_Component] = "CTV" ,
|
||||
[DRM_MODE_CONNECTOR_9PinDIN] = "DIN" ,
|
||||
[DRM_MODE_CONNECTOR_DisplayPort] = "DisplayPort" ,
|
||||
[DRM_MODE_CONNECTOR_HDMIA] = "HDMI" ,
|
||||
[DRM_MODE_CONNECTOR_HDMIB] = "HDMI" ,
|
||||
[DRM_MODE_CONNECTOR_TV] = "TV" ,
|
||||
[DRM_MODE_CONNECTOR_eDP] = "eDP" ,
|
||||
[DRM_MODE_CONNECTOR_VIRTUAL] = "Virtual" ,
|
||||
};
|
||||
|
||||
|
||||
static void drm_conn_name_full(drmModeConnector *conn,
|
||||
const char * const *names,
|
||||
int nnames, char *dest,
|
||||
size_t dlen, bool decrement_id)
|
||||
{
|
||||
const char *type;
|
||||
|
||||
if (conn->connector_type < nnames &&
|
||||
names[conn->connector_type]) {
|
||||
type = names[conn->connector_type];
|
||||
} else {
|
||||
type = "unknown";
|
||||
}
|
||||
|
||||
uint8_t id = conn->connector_type_id;
|
||||
if (decrement_id) {
|
||||
id--;
|
||||
}
|
||||
snprintf(dest, dlen, "%s-%d", type, id);
|
||||
}
|
||||
|
||||
static void drm_conn_name_qxl(drmModeConnector *conn, char *dest, size_t dlen, bool decrement_id)
|
||||
{
|
||||
return drm_conn_name_full(conn, qxl_output_names,
|
||||
sizeof(qxl_output_names)/sizeof(qxl_output_names[0]),
|
||||
dest, dlen, decrement_id);
|
||||
}
|
||||
|
||||
// NOTE: there are some cases (for example, in a Lenovo T460p laptop with
|
||||
// intel graphics when attached to a docking station) where the modesetting
|
||||
// driver uses a name such as DP-3-1 instead of DP-4. These outputs are not
|
||||
// likely to exist in virtual machines, so they shouldn't matter much
|
||||
static void drm_conn_name_modesetting(drmModeConnector *conn, char *dest, size_t dlen)
|
||||
{
|
||||
return drm_conn_name_full(conn, modesetting_output_names,
|
||||
sizeof(modesetting_output_names)/sizeof(modesetting_output_names[0]),
|
||||
dest, dlen, false);
|
||||
}
|
||||
|
||||
static bool read_hex_value_from_file(const char *path, int* value)
|
||||
{
|
||||
if (value == NULL || path == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
FILE *f = fopen(path, "r");
|
||||
if (f == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int endpos = -1;
|
||||
bool result = (fscanf(f, "%x\n%n", value, &endpos) > 0 && endpos >= 0);
|
||||
|
||||
fclose(f);
|
||||
return result;
|
||||
}
|
||||
|
||||
// returns a path to a drm device found at the given PCI Address. Returned
|
||||
// string must be freed by caller.
|
||||
static char* find_device_at_pci_address(PciAddress *pci_addr, int *vendor_id, int *device_id)
|
||||
{
|
||||
g_return_val_if_fail(pci_addr != NULL, NULL);
|
||||
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 subsystem
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
char dev_path[64];
|
||||
struct stat buf;
|
||||
|
||||
// device node for the card is needed to access libdrm functionality
|
||||
snprintf(dev_path, sizeof(dev_path), DRM_DEV_NAME, DRM_DIR_NAME, i);
|
||||
if (stat(dev_path, &buf) != 0) {
|
||||
// no card exists, exit loop
|
||||
syslog(LOG_DEBUG, "card%i not found while listing DRM devices.", i);
|
||||
break;
|
||||
}
|
||||
|
||||
// the sysfs directory for the card will allow us to determine the
|
||||
// pci address for the device
|
||||
char sys_path[64];
|
||||
snprintf(sys_path, sizeof(sys_path), "/sys/class/drm/card%d", i);
|
||||
|
||||
// the file /sys/class/drm/card0 is a symlink to a file that
|
||||
// specifies the device's address. It usually points to something
|
||||
// like /sys/devices/pci0000:00/0000:00:02.0/drm/card0
|
||||
char device_link[PATH_MAX];
|
||||
if (realpath(sys_path, device_link) == NULL) {
|
||||
syslog(LOG_WARNING, "Failed to get the real path of %s", sys_path);
|
||||
break;
|
||||
}
|
||||
syslog(LOG_DEBUG, "Device %s is at %s", dev_path, device_link);
|
||||
|
||||
PciAddress *drm_pci_addr = parse_pci_address_from_sysfs_path(device_link);
|
||||
if (!drm_pci_addr) {
|
||||
syslog(LOG_WARNING, "Can't determine pci address from '%s'", device_link);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!compare_addresses(pci_addr, drm_pci_addr)) {
|
||||
pci_address_free(drm_pci_addr);
|
||||
continue;
|
||||
}
|
||||
pci_address_free(drm_pci_addr);
|
||||
char id_path[150];
|
||||
snprintf(id_path, sizeof(id_path), "%s/device/vendor", sys_path);
|
||||
if (!read_hex_value_from_file(id_path, vendor_id)) {
|
||||
syslog(LOG_WARNING, "Unable to read vendor ID of card: %s", strerror(errno));
|
||||
}
|
||||
snprintf(id_path, sizeof(id_path), "%s/device/device", sys_path);
|
||||
if (!read_hex_value_from_file(id_path, device_id)) {
|
||||
syslog(LOG_WARNING, "Unable to read device ID of card: %s", strerror(errno));
|
||||
}
|
||||
|
||||
syslog(LOG_DEBUG, "Found card '%s' with Vendor ID %#x, Device ID %#x",
|
||||
device_link, *device_id, *vendor_id);
|
||||
return g_strdup(dev_path);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
syslog(LOG_WARNING,
|
||||
"Couldn't parse PCI address '%s'. "
|
||||
"Address should be the form 'pci/$domain/$slot.$fn/$slot.fn...",
|
||||
device_info->device_address);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int vendor_id = 0;
|
||||
int device_id = 0;
|
||||
char *dev_path = find_device_at_pci_address(user_pci_addr, &vendor_id, &device_id);
|
||||
pci_address_free(user_pci_addr);
|
||||
|
||||
int drm_fd = open(dev_path, O_RDWR);
|
||||
if (drm_fd < 0) {
|
||||
syslog(LOG_WARNING, "Unable to open file %s", dev_path);
|
||||
g_free(dev_path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
drmModeResPtr res = drmModeGetResources(drm_fd);
|
||||
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
|
||||
}
|
||||
|
||||
// no need for dev_path anymore
|
||||
g_free(dev_path);
|
||||
|
||||
// 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) {
|
||||
int oid = xres->outputs[i];
|
||||
XRROutputInfo *oinfo = XRRGetOutputInfo(xdisplay, xres, oid);
|
||||
if (!oinfo) {
|
||||
syslog(LOG_WARNING, "Unable to lookup XRandr output info for output %i", oid);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strcmp(oinfo->name, expected_name) == 0) {
|
||||
*output_id = oid;
|
||||
syslog(LOG_DEBUG, "Found matching X Output: name=%s id=%i",
|
||||
oinfo->name, (int)oid);
|
||||
XRRFreeOutputInfo(oinfo);
|
||||
return true;
|
||||
}
|
||||
XRRFreeOutputInfo(oinfo);
|
||||
}
|
||||
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
|
||||
// xrandr output order to determine the proper display.
|
||||
if (device_info->device_display_id >= xres->noutput) {
|
||||
syslog(LOG_WARNING, "The device display id %i does not exist",
|
||||
device_info->device_display_id);
|
||||
return false;
|
||||
}
|
||||
*output_id = xres->outputs[device_info->device_display_id];
|
||||
return true;
|
||||
}
|
||||
|
||||
syslog(LOG_WARNING, "Couldn't find an XRandr output for the specified device");
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/* device-info.c utility function for looking up the xrandr output id for a
|
||||
* given device address and display id
|
||||
*
|
||||
* Copyright 2018 Red Hat, Inc.
|
||||
*
|
||||
* Red Hat Authors:
|
||||
* Jonathon Jongsma <[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 <spice/vd_agent.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
struct vdagent_x11;
|
||||
bool lookup_xrandr_output_for_device_info(VDAgentDeviceDisplayInfo *device_info,
|
||||
Display *xdisplay,
|
||||
XRRScreenResources *xres,
|
||||
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,382 @@
|
||||
/* vdagent file xfers code
|
||||
|
||||
Copyright 2013 - 2016 Red Hat, Inc.
|
||||
|
||||
Red Hat Authors:
|
||||
Hans de Goede <[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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <sys/types.h>
|
||||
#include <spice/vd_agent.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include "vdagentd-proto.h"
|
||||
#include "file-xfers.h"
|
||||
|
||||
struct vdagent_file_xfers {
|
||||
GHashTable *xfers;
|
||||
UdscsConnection *vdagentd;
|
||||
char *save_dir;
|
||||
int open_save_dir;
|
||||
int debug;
|
||||
};
|
||||
|
||||
typedef struct AgentFileXferTask {
|
||||
uint32_t id;
|
||||
int file_fd;
|
||||
uint64_t read_bytes;
|
||||
char *file_name;
|
||||
uint64_t file_size;
|
||||
int file_xfer_nr;
|
||||
int file_xfer_total;
|
||||
int debug;
|
||||
} AgentFileXferTask;
|
||||
|
||||
static void vdagent_file_xfer_task_free(gpointer data)
|
||||
{
|
||||
AgentFileXferTask *task = data;
|
||||
|
||||
g_return_if_fail(task != NULL);
|
||||
|
||||
if (task->file_fd > 0) {
|
||||
syslog(LOG_ERR, "file-xfer: Removing task %u and file %s due to error",
|
||||
task->id, task->file_name);
|
||||
close(task->file_fd);
|
||||
unlink(task->file_name);
|
||||
} else if (task->debug)
|
||||
syslog(LOG_DEBUG, "file-xfer: Removing task %u %s",
|
||||
task->id, task->file_name);
|
||||
|
||||
g_free(task->file_name);
|
||||
g_free(task);
|
||||
}
|
||||
|
||||
struct vdagent_file_xfers *vdagent_file_xfers_create(
|
||||
UdscsConnection *vdagentd, const char *save_dir,
|
||||
int open_save_dir, int debug)
|
||||
{
|
||||
struct vdagent_file_xfers *xfers;
|
||||
|
||||
xfers = g_malloc(sizeof(*xfers));
|
||||
xfers->xfers = g_hash_table_new_full(g_direct_hash, g_direct_equal,
|
||||
NULL, vdagent_file_xfer_task_free);
|
||||
xfers->vdagentd = vdagentd;
|
||||
xfers->save_dir = g_strdup(save_dir);
|
||||
xfers->open_save_dir = open_save_dir;
|
||||
xfers->debug = debug;
|
||||
|
||||
return xfers;
|
||||
}
|
||||
|
||||
void vdagent_file_xfers_destroy(struct vdagent_file_xfers *xfers)
|
||||
{
|
||||
g_return_if_fail(xfers != NULL);
|
||||
|
||||
g_hash_table_destroy(xfers->xfers);
|
||||
g_free(xfers->save_dir);
|
||||
g_free(xfers);
|
||||
}
|
||||
|
||||
static AgentFileXferTask *vdagent_file_xfers_get_task(
|
||||
struct vdagent_file_xfers *xfers, uint32_t id)
|
||||
{
|
||||
AgentFileXferTask *task;
|
||||
|
||||
g_return_val_if_fail(xfers != NULL, NULL);
|
||||
|
||||
task = g_hash_table_lookup(xfers->xfers, GUINT_TO_POINTER(id));
|
||||
if (task == NULL)
|
||||
syslog(LOG_ERR, "file-xfer: error cannot find task %u", id);
|
||||
|
||||
return task;
|
||||
}
|
||||
|
||||
/* Parse start message then create a new file xfer task */
|
||||
static AgentFileXferTask *vdagent_parse_start_msg(
|
||||
VDAgentFileXferStartMessage *msg)
|
||||
{
|
||||
GKeyFile *keyfile = NULL;
|
||||
AgentFileXferTask *task = NULL;
|
||||
GError *error = NULL;
|
||||
|
||||
keyfile = g_key_file_new();
|
||||
if (g_key_file_load_from_data(keyfile,
|
||||
(const gchar *)msg->data,
|
||||
-1,
|
||||
G_KEY_FILE_NONE, &error) == FALSE) {
|
||||
syslog(LOG_ERR, "file-xfer: failed to load keyfile: %s",
|
||||
error->message);
|
||||
goto error;
|
||||
}
|
||||
task = g_new0(AgentFileXferTask, 1);
|
||||
task->file_fd = -1;
|
||||
task->id = msg->id;
|
||||
task->file_name = g_key_file_get_string(
|
||||
keyfile, "vdagent-file-xfer", "name", &error);
|
||||
if (error) {
|
||||
syslog(LOG_ERR, "file-xfer: failed to parse filename: %s",
|
||||
error->message);
|
||||
goto error;
|
||||
}
|
||||
task->file_size = g_key_file_get_uint64(
|
||||
keyfile, "vdagent-file-xfer", "size", &error);
|
||||
if (error) {
|
||||
syslog(LOG_ERR, "file-xfer: failed to parse filesize: %s",
|
||||
error->message);
|
||||
goto error;
|
||||
}
|
||||
/* These are set for xfers which are part of a multi-file xfer */
|
||||
task->file_xfer_nr = g_key_file_get_integer(
|
||||
keyfile, "vdagent-file-xfer", "file-xfer-nr", NULL);
|
||||
task->file_xfer_total = g_key_file_get_integer(
|
||||
keyfile, "vdagent-file-xfer", "file-xfer-total", NULL);
|
||||
|
||||
g_key_file_free(keyfile);
|
||||
return task;
|
||||
|
||||
error:
|
||||
g_clear_error(&error);
|
||||
if (task)
|
||||
vdagent_file_xfer_task_free(task);
|
||||
if (keyfile)
|
||||
g_key_file_free(keyfile);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static uint64_t get_free_space_available(const char *path)
|
||||
{
|
||||
struct statvfs stat;
|
||||
if (statvfs(path, &stat) != 0) {
|
||||
syslog(LOG_WARNING, "file-xfer: failed to get free space, statvfs error: %s",
|
||||
strerror(errno));
|
||||
return G_MAXUINT64;
|
||||
}
|
||||
return stat.f_bsize * stat.f_bavail;
|
||||
}
|
||||
|
||||
int
|
||||
vdagent_file_xfers_create_file(const char *save_dir, char **file_name_p)
|
||||
{
|
||||
char *file_path = NULL;
|
||||
char *dir = NULL;
|
||||
char *path = NULL;
|
||||
int file_fd = -1;
|
||||
int i;
|
||||
|
||||
file_path = g_build_filename(save_dir, *file_name_p, NULL);
|
||||
dir = g_path_get_dirname(file_path);
|
||||
if (g_mkdir_with_parents(dir, S_IRWXU) == -1) {
|
||||
syslog(LOG_ERR, "file-xfer: Failed to create dir %s", dir);
|
||||
goto error;
|
||||
}
|
||||
|
||||
path = g_strdup(file_path);
|
||||
for (i = 0; i < 64; i++) {
|
||||
file_fd = open(path, O_CREAT | O_WRONLY | O_EXCL, 0644);
|
||||
if (file_fd >= 0) {
|
||||
break;
|
||||
}
|
||||
if (errno != EEXIST) {
|
||||
syslog(LOG_ERR, "file-xfer: failed to create file %s: %s",
|
||||
path, strerror(errno));
|
||||
goto error;
|
||||
}
|
||||
g_free(path);
|
||||
char *extension = strrchr(file_path, '/');
|
||||
extension = strrchr(extension != NULL ? extension + 1 : file_path, '.');
|
||||
int basename_len = extension != NULL ? extension - file_path : strlen(file_path);
|
||||
path = g_strdup_printf("%.*s (%i)%s", basename_len, file_path,
|
||||
i + 1, extension ? extension : "");
|
||||
}
|
||||
if (file_fd < 0) {
|
||||
syslog(LOG_ERR, "file-xfer: more than 63 copies of %s exist?", file_path);
|
||||
goto error;
|
||||
}
|
||||
g_free(*file_name_p);
|
||||
*file_name_p = path;
|
||||
path = NULL;
|
||||
|
||||
error:
|
||||
g_free(path);
|
||||
g_free(file_path);
|
||||
g_free(dir);
|
||||
return file_fd;
|
||||
}
|
||||
|
||||
void vdagent_file_xfers_start(struct vdagent_file_xfers *xfers,
|
||||
VDAgentFileXferStartMessage *msg)
|
||||
{
|
||||
AgentFileXferTask *task;
|
||||
uint64_t free_space;
|
||||
|
||||
g_return_if_fail(xfers != NULL);
|
||||
|
||||
if (g_hash_table_lookup(xfers->xfers, GUINT_TO_POINTER(msg->id))) {
|
||||
syslog(LOG_ERR, "file-xfer: error id %u already exists, ignoring!",
|
||||
msg->id);
|
||||
return;
|
||||
}
|
||||
|
||||
task = vdagent_parse_start_msg(msg);
|
||||
if (task == NULL) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
task->debug = xfers->debug;
|
||||
|
||||
free_space = get_free_space_available(xfers->save_dir);
|
||||
if (task->file_size > free_space) {
|
||||
gchar *free_space_str, *file_size_str;
|
||||
free_space_str = g_format_size(free_space);
|
||||
file_size_str = g_format_size(task->file_size);
|
||||
syslog(LOG_ERR, "file-xfer: not enough free space (%s to copy, %s free)",
|
||||
file_size_str, free_space_str);
|
||||
g_free(free_space_str);
|
||||
g_free(file_size_str);
|
||||
|
||||
udscs_write(xfers->vdagentd,
|
||||
VDAGENTD_FILE_XFER_STATUS,
|
||||
msg->id,
|
||||
VD_AGENT_FILE_XFER_STATUS_NOT_ENOUGH_SPACE,
|
||||
(uint8_t *)&free_space,
|
||||
sizeof(free_space));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
task->file_fd = vdagent_file_xfers_create_file(xfers->save_dir, &task->file_name);
|
||||
if (task->file_fd < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (ftruncate(task->file_fd, task->file_size) < 0) {
|
||||
syslog(LOG_ERR, "file-xfer: err reserving %"PRIu64" bytes for %s: %s",
|
||||
task->file_size, task->file_name, strerror(errno));
|
||||
goto error;
|
||||
}
|
||||
|
||||
g_hash_table_insert(xfers->xfers, GUINT_TO_POINTER(msg->id), task);
|
||||
|
||||
if (xfers->debug)
|
||||
syslog(LOG_DEBUG, "file-xfer: Adding task %u %s %"PRIu64" bytes",
|
||||
task->id, task->file_name, task->file_size);
|
||||
|
||||
udscs_write(xfers->vdagentd, VDAGENTD_FILE_XFER_STATUS,
|
||||
msg->id, VD_AGENT_FILE_XFER_STATUS_CAN_SEND_DATA, NULL, 0);
|
||||
return ;
|
||||
|
||||
error:
|
||||
udscs_write(xfers->vdagentd, VDAGENTD_FILE_XFER_STATUS,
|
||||
msg->id, VD_AGENT_FILE_XFER_STATUS_ERROR, NULL, 0);
|
||||
cleanup:
|
||||
if (task)
|
||||
vdagent_file_xfer_task_free(task);
|
||||
}
|
||||
|
||||
void vdagent_file_xfers_status(struct vdagent_file_xfers *xfers,
|
||||
VDAgentFileXferStatusMessage *msg)
|
||||
{
|
||||
AgentFileXferTask *task;
|
||||
|
||||
g_return_if_fail(xfers != NULL);
|
||||
|
||||
task = vdagent_file_xfers_get_task(xfers, msg->id);
|
||||
if (!task)
|
||||
return;
|
||||
|
||||
switch (msg->result) {
|
||||
case VD_AGENT_FILE_XFER_STATUS_CAN_SEND_DATA:
|
||||
syslog(LOG_ERR, "file-xfer: task %u %s received unexpected 0 response",
|
||||
task->id, task->file_name);
|
||||
break;
|
||||
default:
|
||||
/* Cancel or Error, remove this task */
|
||||
g_hash_table_remove(xfers->xfers, GUINT_TO_POINTER(msg->id));
|
||||
}
|
||||
}
|
||||
|
||||
void vdagent_file_xfers_data(struct vdagent_file_xfers *xfers,
|
||||
VDAgentFileXferDataMessage *msg)
|
||||
{
|
||||
AgentFileXferTask *task;
|
||||
int len, status = -1;
|
||||
|
||||
g_return_if_fail(xfers != NULL);
|
||||
|
||||
task = vdagent_file_xfers_get_task(xfers, msg->id);
|
||||
if (!task)
|
||||
return;
|
||||
|
||||
len = write(task->file_fd, msg->data, msg->size);
|
||||
if (len == msg->size) {
|
||||
task->read_bytes += msg->size;
|
||||
if (task->read_bytes >= task->file_size) {
|
||||
if (task->read_bytes == task->file_size) {
|
||||
if (xfers->debug)
|
||||
syslog(LOG_DEBUG, "file-xfer: task %u %s has completed",
|
||||
task->id, task->file_name);
|
||||
close(task->file_fd);
|
||||
task->file_fd = -1;
|
||||
if (xfers->open_save_dir &&
|
||||
task->file_xfer_nr == task->file_xfer_total &&
|
||||
g_hash_table_size(xfers->xfers) == 1) {
|
||||
GError *error = NULL;
|
||||
gchar *argv[] = { "xdg-open", xfers->save_dir, NULL };
|
||||
if (!g_spawn_async(NULL, argv, NULL,
|
||||
G_SPAWN_SEARCH_PATH,
|
||||
NULL, NULL, NULL, &error)) {
|
||||
syslog(LOG_WARNING,
|
||||
"file-xfer: failed to open save directory: %s",
|
||||
error->message);
|
||||
g_error_free(error);
|
||||
}
|
||||
}
|
||||
status = VD_AGENT_FILE_XFER_STATUS_SUCCESS;
|
||||
} else {
|
||||
syslog(LOG_ERR, "file-xfer: error received too much data");
|
||||
status = VD_AGENT_FILE_XFER_STATUS_ERROR;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
syslog(LOG_ERR, "file-xfer: error writing %s: %s", task->file_name,
|
||||
strerror(errno));
|
||||
status = VD_AGENT_FILE_XFER_STATUS_ERROR;
|
||||
}
|
||||
|
||||
if (status != -1) {
|
||||
udscs_write(xfers->vdagentd, VDAGENTD_FILE_XFER_STATUS,
|
||||
msg->id, status, NULL, 0);
|
||||
g_hash_table_remove(xfers->xfers, GUINT_TO_POINTER(msg->id));
|
||||
}
|
||||
}
|
||||
|
||||
void vdagent_file_xfers_error_disabled(UdscsConnection *vdagentd, uint32_t msg_id)
|
||||
{
|
||||
g_return_if_fail(vdagentd != NULL);
|
||||
|
||||
udscs_write(vdagentd, VDAGENTD_FILE_XFER_STATUS,
|
||||
msg_id, VD_AGENT_FILE_XFER_STATUS_DISABLED, NULL, 0);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/* vdagent file xfers header
|
||||
|
||||
Copyright 2013 Red Hat, Inc.
|
||||
|
||||
Red Hat Authors:
|
||||
Hans de Goede <[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 __VDAGENT_FILE_XFERS_H
|
||||
#define __VDAGENT_FILE_XFERS_H
|
||||
|
||||
#include "udscs.h"
|
||||
|
||||
struct vdagent_file_xfers;
|
||||
|
||||
struct vdagent_file_xfers *vdagent_file_xfers_create(
|
||||
UdscsConnection *vdagentd, const char *save_dir,
|
||||
int open_save_dir, int debug);
|
||||
void vdagent_file_xfers_destroy(struct vdagent_file_xfers *xfer);
|
||||
|
||||
void vdagent_file_xfers_start(struct vdagent_file_xfers *xfers,
|
||||
VDAgentFileXferStartMessage *msg);
|
||||
void vdagent_file_xfers_status(struct vdagent_file_xfers *xfers,
|
||||
VDAgentFileXferStatusMessage *msg);
|
||||
void vdagent_file_xfers_data(struct vdagent_file_xfers *xfers,
|
||||
VDAgentFileXferDataMessage *msg);
|
||||
void vdagent_file_xfers_error_disabled(UdscsConnection *vdagentd,
|
||||
uint32_t msg_id);
|
||||
int vdagent_file_xfers_create_file(const char *save_dir, char **file_name_p);
|
||||
|
||||
#endif
|
||||
@@ -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_ */
|
||||
@@ -0,0 +1,528 @@
|
||||
/* vdagent.c xorg-client to vdagentd (daemon).
|
||||
|
||||
Copyright 2010-2013 Red Hat, Inc.
|
||||
|
||||
Red Hat Authors:
|
||||
Hans de Goede <[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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <spice/vd_agent.h>
|
||||
#include <poll.h>
|
||||
#include <glib-unix.h>
|
||||
#ifdef WITH_GTK
|
||||
# include <gtk/gtk.h>
|
||||
#endif
|
||||
|
||||
#include "udscs.h"
|
||||
#include "vdagentd-proto.h"
|
||||
#include "audio.h"
|
||||
#include "file-xfers.h"
|
||||
#include "clipboard.h"
|
||||
#include "display.h"
|
||||
|
||||
#define MAX_RETRY_CONNECT_SYSTEM_AGENT 60
|
||||
|
||||
typedef struct VDAgent {
|
||||
VDAgentClipboards *clipboards;
|
||||
VDAgentDisplay *display;
|
||||
struct vdagent_file_xfers *xfers;
|
||||
UdscsConnection *conn;
|
||||
gint udscs_num_retry;
|
||||
|
||||
GMainLoop *loop;
|
||||
} VDAgent;
|
||||
|
||||
static int quit = 0;
|
||||
static int parent_socket = -1;
|
||||
static int version_mismatch = 0;
|
||||
|
||||
/* Command line options */
|
||||
static gboolean debug = FALSE;
|
||||
static gboolean x11_sync = FALSE;
|
||||
static gboolean do_daemonize = TRUE;
|
||||
static gint fx_open_dir = -1;
|
||||
static gchar *fx_dir = NULL;
|
||||
static gchar *portdev = NULL;
|
||||
static gchar *vdagentd_socket = NULL;
|
||||
|
||||
static GOptionEntry entries[] = {
|
||||
{ "debug", 'd',
|
||||
G_OPTION_FLAG_NONE,
|
||||
G_OPTION_ARG_NONE, &debug,
|
||||
"Enable debug", NULL },
|
||||
{ "virtio-serial-port-path", 's',
|
||||
G_OPTION_FLAG_NONE,
|
||||
G_OPTION_ARG_STRING, &portdev,
|
||||
"Set virtio-serial path (" DEFAULT_VIRTIO_PORT_PATH ")", NULL },
|
||||
{ "vdagentd-socket", 'S',
|
||||
G_OPTION_FLAG_NONE,
|
||||
G_OPTION_ARG_STRING, &vdagentd_socket,
|
||||
"Set spice-vdagentd socket (" VDAGENTD_SOCKET ")", NULL },
|
||||
{ "foreground", 'x',
|
||||
G_OPTION_FLAG_REVERSE,
|
||||
G_OPTION_ARG_NONE, &do_daemonize,
|
||||
"Do not daemonize the agent", NULL },
|
||||
{ "file-xfer-save-dir", 'f',
|
||||
G_OPTION_FLAG_NONE,
|
||||
G_OPTION_ARG_STRING, &fx_dir,
|
||||
"Set directory to file transfers files", "<dir|xdg-desktop|xdg-download>"},
|
||||
{ "file-xfer-open-dir", 'o',
|
||||
G_OPTION_FLAG_NONE,
|
||||
G_OPTION_ARG_INT, &fx_open_dir,
|
||||
"Open directory after completing file transfer", "<0|1>" },
|
||||
{ "x11-abort-on-error", 'y',
|
||||
G_OPTION_FLAG_HIDDEN,
|
||||
G_OPTION_ARG_NONE, &x11_sync,
|
||||
"Aborts on errors from X11", NULL },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
/**
|
||||
* xfer_get_download_directory
|
||||
*
|
||||
* Return path where transferred files should be stored.
|
||||
* Returned path should not be freed or modified.
|
||||
**/
|
||||
static const gchar *xfer_get_download_directory(VDAgent *agent)
|
||||
{
|
||||
if (fx_dir != NULL) {
|
||||
if (!strcmp(fx_dir, "xdg-desktop"))
|
||||
return g_get_user_special_dir(G_USER_DIRECTORY_DESKTOP);
|
||||
if (!strcmp(fx_dir, "xdg-download"))
|
||||
return g_get_user_special_dir(G_USER_DIRECTORY_DOWNLOAD);
|
||||
|
||||
return fx_dir;
|
||||
}
|
||||
|
||||
return g_get_user_special_dir(vdagent_display_has_icons_on_desktop(agent->display) ?
|
||||
G_USER_DIRECTORY_DESKTOP :
|
||||
G_USER_DIRECTORY_DOWNLOAD);
|
||||
}
|
||||
|
||||
/**
|
||||
* vdagent_init_file_xfer
|
||||
*
|
||||
* Initialize handler for file xfer,
|
||||
* return TRUE on success (agent->xfers is not NULL).
|
||||
**/
|
||||
static gboolean vdagent_init_file_xfer(VDAgent *agent)
|
||||
{
|
||||
const gchar *xfer_dir;
|
||||
gboolean open_dir;
|
||||
|
||||
if (agent->xfers != NULL) {
|
||||
syslog(LOG_DEBUG, "File-xfer already initialized");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
xfer_dir = xfer_get_download_directory(agent);
|
||||
if (xfer_dir == NULL) {
|
||||
syslog(LOG_WARNING,
|
||||
"warning could not get file xfer save dir, "
|
||||
"file transfers will be disabled");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
open_dir = fx_open_dir == -1 ?
|
||||
!vdagent_display_has_icons_on_desktop(agent->display) :
|
||||
fx_open_dir;
|
||||
|
||||
agent->xfers = vdagent_file_xfers_create(agent->conn, xfer_dir,
|
||||
open_dir, debug);
|
||||
return (agent->xfers != NULL);
|
||||
}
|
||||
|
||||
static gboolean vdagent_finalize_file_xfer(VDAgent *agent)
|
||||
{
|
||||
if (agent->xfers == NULL)
|
||||
return FALSE;
|
||||
|
||||
g_clear_pointer(&agent->xfers, vdagent_file_xfers_destroy);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void vdagent_quit_loop(VDAgent *agent)
|
||||
{
|
||||
/* other GMainLoop(s) might be running, quit them before agent->loop */
|
||||
if (agent->clipboards) {
|
||||
vdagent_clipboards_set_conn(agent->clipboards, agent->conn);
|
||||
g_clear_object(&agent->clipboards);
|
||||
}
|
||||
if (agent->loop)
|
||||
g_main_loop_quit(agent->loop);
|
||||
}
|
||||
|
||||
static void daemon_read_complete(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_MONITORS_CONFIG:
|
||||
vdagent_display_set_monitor_config(agent->display, (VDAgentMonitorsConfig *)data, 0);
|
||||
break;
|
||||
case VDAGENTD_CLIPBOARD_REQUEST:
|
||||
vdagent_clipboard_request(agent->clipboards, header->arg1, header->arg2);
|
||||
break;
|
||||
case VDAGENTD_CLIPBOARD_GRAB:
|
||||
vdagent_clipboard_grab(agent->clipboards, header->arg1,
|
||||
(guint32 *)data, header->size / sizeof(guint32));
|
||||
break;
|
||||
case VDAGENTD_CLIPBOARD_DATA:
|
||||
vdagent_clipboard_data(agent->clipboards, header->arg1, header->arg2,
|
||||
data, header->size);
|
||||
break;
|
||||
case VDAGENTD_CLIPBOARD_RELEASE:
|
||||
vdagent_clipboard_release(agent->clipboards, 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_FILE_XFER_START:
|
||||
if (agent->xfers != NULL) {
|
||||
vdagent_file_xfers_start(agent->xfers,
|
||||
(VDAgentFileXferStartMessage *)data);
|
||||
} else {
|
||||
vdagent_file_xfers_error_disabled(conn,
|
||||
((VDAgentFileXferStartMessage *)data)->id);
|
||||
}
|
||||
break;
|
||||
case VDAGENTD_FILE_XFER_STATUS:
|
||||
if (agent->xfers != NULL) {
|
||||
vdagent_file_xfers_status(agent->xfers,
|
||||
(VDAgentFileXferStatusMessage *)data);
|
||||
} else {
|
||||
vdagent_file_xfers_error_disabled(conn,
|
||||
((VDAgentFileXferStatusMessage *)data)->id);
|
||||
}
|
||||
break;
|
||||
case VDAGENTD_FILE_XFER_DISABLE:
|
||||
if (debug)
|
||||
syslog(LOG_DEBUG, "Disabling file-xfers");
|
||||
|
||||
vdagent_finalize_file_xfer(agent);
|
||||
break;
|
||||
case VDAGENTD_AUDIO_VOLUME_SYNC: {
|
||||
VDAgentAudioVolumeSync *avs = (VDAgentAudioVolumeSync *)data;
|
||||
uint16_t *volume = g_memdup2(avs->volume, sizeof(uint16_t) * avs->nchannels);
|
||||
|
||||
if (avs->is_playback) {
|
||||
vdagent_audio_playback_sync(avs->mute, avs->nchannels, volume);
|
||||
} else {
|
||||
vdagent_audio_record_sync(avs->mute, avs->nchannels, volume);
|
||||
}
|
||||
g_free(volume);
|
||||
break;
|
||||
}
|
||||
case VDAGENTD_FILE_XFER_DATA:
|
||||
if (agent->xfers != NULL) {
|
||||
vdagent_file_xfers_data(agent->xfers,
|
||||
(VDAgentFileXferDataMessage *)data);
|
||||
} else {
|
||||
vdagent_file_xfers_error_disabled(conn,
|
||||
((VDAgentFileXferDataMessage *)data)->id);
|
||||
}
|
||||
break;
|
||||
case VDAGENTD_GRAPHICS_DEVICE_INFO:
|
||||
vdagent_display_handle_graphics_device_info(agent->display, data, header->size);
|
||||
break;
|
||||
case VDAGENTD_CLIENT_DISCONNECTED:
|
||||
vdagent_clipboards_release_all(agent->clipboards);
|
||||
if (vdagent_finalize_file_xfer(agent)) {
|
||||
vdagent_init_file_xfer(agent);
|
||||
}
|
||||
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(&agent->conn, vdagent_connection_destroy);
|
||||
vdagent_quit_loop(agent);
|
||||
}
|
||||
|
||||
/* When we daemonize, it is useful to have the main process
|
||||
wait to make sure the X connection worked. We wait up
|
||||
to 10 seconds to get an 'all clear' from the child
|
||||
before we exit. If we don't, we're able to exit with a
|
||||
status that indicates an error occurred */
|
||||
static void wait_and_exit(int s)
|
||||
{
|
||||
char buf[4];
|
||||
struct pollfd p;
|
||||
p.fd = s;
|
||||
p.events = POLLIN;
|
||||
|
||||
if (poll(&p, 1, 10000) > 0)
|
||||
if (read(s, buf, sizeof(buf)) > 0)
|
||||
exit(0);
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static int daemonize(void)
|
||||
{
|
||||
int fd[2];
|
||||
|
||||
if (socketpair(PF_LOCAL, SOCK_STREAM, 0, fd)) {
|
||||
syslog(LOG_ERR, "socketpair : %s", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* detach from terminal */
|
||||
switch (fork()) {
|
||||
case 0:
|
||||
close(STDIN_FILENO);
|
||||
close(STDOUT_FILENO);
|
||||
close(STDERR_FILENO);
|
||||
setsid();
|
||||
// coverity[leaked_handle] just opening standard file descriptors
|
||||
if (open("/dev/null", O_RDWR) != STDIN_FILENO) {
|
||||
exit(1);
|
||||
}
|
||||
// coverity[leaked_handle] just opening standard file descriptors
|
||||
if (dup(STDIN_FILENO) != STDOUT_FILENO) {
|
||||
exit(1);
|
||||
}
|
||||
// coverity[leaked_handle] just opening standard file descriptors
|
||||
if (dup(STDOUT_FILENO) != STDERR_FILENO) {
|
||||
exit(1);
|
||||
}
|
||||
close(fd[0]);
|
||||
return fd[1];
|
||||
case -1:
|
||||
syslog(LOG_ERR, "fork: %s", strerror(errno));
|
||||
exit(1);
|
||||
default:
|
||||
close(fd[1]);
|
||||
wait_and_exit(fd[0]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
gboolean vdagent_signal_handler(gpointer user_data)
|
||||
{
|
||||
VDAgent *agent = user_data;
|
||||
quit = TRUE;
|
||||
vdagent_quit_loop(agent);
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
static VDAgent *vdagent_new(void)
|
||||
{
|
||||
VDAgent *agent = g_new0(VDAgent, 1);
|
||||
|
||||
agent->loop = g_main_loop_new(NULL, FALSE);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static void vdagent_destroy(VDAgent *agent)
|
||||
{
|
||||
vdagent_finalize_file_xfer(agent);
|
||||
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->loop, g_main_loop_unref);
|
||||
g_free(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);
|
||||
|
||||
agent->display = vdagent_display_create(agent->conn, debug, x11_sync);
|
||||
if (agent->display == NULL)
|
||||
goto err_init;
|
||||
|
||||
|
||||
if (!vdagent_init_file_xfer(agent))
|
||||
syslog(LOG_WARNING, "File transfer is disabled");
|
||||
|
||||
agent->clipboards = vdagent_clipboards_new(vdagent_display_get_x11(agent->display));
|
||||
vdagent_clipboards_set_conn(agent->clipboards, agent->conn);
|
||||
|
||||
if (parent_socket != -1) {
|
||||
if (write(parent_socket, "OK", 2) != 2)
|
||||
syslog(LOG_WARNING, "Parent already gone.");
|
||||
close(parent_socket);
|
||||
parent_socket = -1;
|
||||
}
|
||||
|
||||
return G_SOURCE_REMOVE;
|
||||
|
||||
err_init:
|
||||
vdagent_quit_loop(agent);
|
||||
quit = TRUE;
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
GOptionContext *context;
|
||||
GError *error = NULL;
|
||||
VDAgent *agent;
|
||||
char **orig_argv = g_memdup2(argv, sizeof(char*) * (argc+1));
|
||||
orig_argv[argc] = NULL; /* To avoid clang analyzer false-positive */
|
||||
|
||||
context = g_option_context_new(NULL);
|
||||
g_option_context_add_main_entries(context, entries, NULL);
|
||||
g_option_context_set_summary(context,
|
||||
"\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);
|
||||
|
||||
if (error != NULL) {
|
||||
g_printerr("Invalid arguments, %s\n", error->message);
|
||||
g_clear_error(&error);
|
||||
g_free(orig_argv);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Set default path value if none was set */
|
||||
if (portdev == NULL)
|
||||
portdev = g_strdup(DEFAULT_VIRTIO_PORT_PATH);
|
||||
|
||||
if (vdagentd_socket == NULL)
|
||||
vdagentd_socket = g_strdup(VDAGENTD_SOCKET);
|
||||
|
||||
openlog("spice-vdagent", do_daemonize ? LOG_PID : (LOG_PID | LOG_PERROR),
|
||||
LOG_USER);
|
||||
|
||||
if (!g_file_test(portdev, G_FILE_TEST_EXISTS)) {
|
||||
syslog(LOG_DEBUG, "vdagent virtio channel %s does not exist, exiting", portdev);
|
||||
g_free(orig_argv);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (do_daemonize)
|
||||
parent_socket = daemonize();
|
||||
|
||||
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) {
|
||||
syslog(LOG_INFO, "Version mismatch, restarting");
|
||||
sleep(1);
|
||||
execvp(orig_argv[0], orig_argv);
|
||||
}
|
||||
|
||||
agent = vdagent_new();
|
||||
|
||||
g_timeout_add(0, vdagent_init_async_cb, agent);
|
||||
|
||||
g_main_loop_run(agent->loop);
|
||||
|
||||
vdagent_destroy(agent);
|
||||
agent = NULL;
|
||||
|
||||
/* allow the VDAgentConnection to finalize properly */
|
||||
g_main_context_iteration(NULL, FALSE);
|
||||
|
||||
if (!quit && do_daemonize)
|
||||
goto reconnect;
|
||||
|
||||
g_free(fx_dir);
|
||||
g_free(portdev);
|
||||
g_free(vdagentd_socket);
|
||||
g_free(orig_argv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -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);
|
||||
@@ -7,6 +7,11 @@
|
||||
#include <spice/vd_agent.h>
|
||||
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
#include "display.h"
|
||||
|
||||
#ifndef USE_GTK_FOR_CLIPBOARD
|
||||
|
||||
#include "webdav-cb.h"
|
||||
|
||||
/* Macros to print a message to the logfile prefixed by the selection */
|
||||
#define SELPRINTF(format, ...) \
|
||||
@@ -33,7 +38,7 @@ struct vdagent_x11_selection_request {
|
||||
struct vdagent_x11_selection_request *next;
|
||||
};
|
||||
|
||||
/* A conversion request is X11 speak for asking an other app to give its
|
||||
/* A conversion request is X11 speak for asking another app to give its
|
||||
clipboard data to us, we do these on behalf of the spice client to copy
|
||||
data from the guest to the client. Like selection requests we process
|
||||
these one at a time. */
|
||||
@@ -55,40 +60,57 @@ struct clipboard_format_info {
|
||||
};
|
||||
|
||||
static const struct clipboard_format_tmpl clipboard_format_templates[] = {
|
||||
{ VD_AGENT_CLIPBOARD_UTF8_TEXT, { "UTF8_STRING",
|
||||
"text/plain;charset=UTF-8", "text/plain;charset=utf-8", NULL }, },
|
||||
{ VD_AGENT_CLIPBOARD_UTF8_TEXT, { "UTF8_STRING", "text/plain;charset=UTF-8",
|
||||
"text/plain;charset=utf-8", "STRING", NULL }, },
|
||||
{ VD_AGENT_CLIPBOARD_IMAGE_PNG, { "image/png", NULL }, },
|
||||
{ VD_AGENT_CLIPBOARD_IMAGE_BMP, { "image/bmp", "image/x-bmp",
|
||||
"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
|
||||
/* Same as qxl_dev.h client_monitors_config.heads count */
|
||||
#define MONITOR_SIZE_COUNT 64
|
||||
|
||||
struct monitor_size {
|
||||
int width;
|
||||
int height;
|
||||
};
|
||||
|
||||
struct vdagent_x11 {
|
||||
struct clipboard_format_info clipboard_formats[clipboard_format_count];
|
||||
Display *display;
|
||||
#ifndef USE_GTK_FOR_CLIPBOARD
|
||||
struct clipboard_format_info clipboard_formats[clipboard_format_count];
|
||||
Atom clipboard_atom;
|
||||
Atom clipboard_primary_atom;
|
||||
Atom targets_atom;
|
||||
Atom incr_atom;
|
||||
Atom multiple_atom;
|
||||
Window root_window;
|
||||
Atom timestamp_atom;
|
||||
struct atom_name_cache_item atom_name_cache[ATOM_NAME_CACHE_SIZE];
|
||||
int atom_name_cache_next;
|
||||
Window selection_window;
|
||||
struct udscs_connection *vdagentd;
|
||||
int debug;
|
||||
int fd;
|
||||
int screen;
|
||||
int width;
|
||||
int height;
|
||||
int has_xfixes;
|
||||
int xfixes_event_base;
|
||||
int max_prop_size;
|
||||
int expected_targets_notifies[256];
|
||||
int ignore_targets_notifies[256];
|
||||
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;
|
||||
@@ -101,16 +123,28 @@ 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 screen_count;
|
||||
int width[MAX_SCREENS];
|
||||
int height[MAX_SCREENS];
|
||||
/* resolution change state */
|
||||
struct {
|
||||
XRRScreenResources *res;
|
||||
XRROutputInfo **outputs;
|
||||
XRRCrtcInfo **crtcs;
|
||||
int event_base;
|
||||
int min_width;
|
||||
int max_width;
|
||||
int min_height;
|
||||
int max_height;
|
||||
int num_monitors;
|
||||
struct monitor_size monitor_sizes[MONITOR_SIZE_COUNT];
|
||||
VDAgentMonitorsConfig *failed_conf;
|
||||
} randr;
|
||||
|
||||
/* NB: we cache this assuming the driver isn't changed under our feet */
|
||||
@@ -121,11 +155,25 @@ struct vdagent_x11 {
|
||||
int xrandr_minor;
|
||||
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);
|
||||
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 width, int height);
|
||||
int screen, int width, int height);
|
||||
int vdagent_x11_randr_handle_event(struct vdagent_x11 *x11,
|
||||
const XEvent *event);
|
||||
void vdagent_x11_set_error_handler(struct vdagent_x11 *x11,
|
||||
int (*handler)(Display *, XErrorEvent *));
|
||||
int vdagent_x11_restore_error_handler(struct vdagent_x11 *x11);
|
||||
|
||||
#endif // VDAGENT_X11_PRIV
|
||||
File diff suppressed because it is too large.
Load diff
@@ -23,37 +23,58 @@
|
||||
X11 socket. If events have arrived and have already been read by libX11 from
|
||||
the socket triggered by other libX11 calls from this file, the select for
|
||||
read in the main loop, won't see these and our event loop won't get called!
|
||||
|
||||
|
||||
Thus we must make sure that all queued events have been consumed, whenever
|
||||
we return to the main loop. IOW all (externally callable) functions in this
|
||||
file must end with calling XPending and consuming all queued events.
|
||||
|
||||
|
||||
Calling XPending when-ever we return to the mainloop also ensures any
|
||||
pending writes are flushed. */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <glib.h>
|
||||
#ifdef WITH_GTK
|
||||
#include <gdk/gdk.h>
|
||||
#include <gtk/gtk.h> // for GTK_CHECK_VERSION
|
||||
#ifdef GDK_WINDOWING_X11
|
||||
#if GTK_CHECK_VERSION(3, 98, 0)
|
||||
#include <gdk/x11/gdkx.h>
|
||||
#else
|
||||
#include <gdk/gdkx.h>
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/extensions/Xfixes.h>
|
||||
#include "vdagentd-proto.h"
|
||||
#include "vdagent-x11.h"
|
||||
#include "vdagent-x11-priv.h"
|
||||
#include "x11.h"
|
||||
#include "x11-priv.h"
|
||||
|
||||
/* Stupid X11 API, there goes our encapsulate all data in a struct design */
|
||||
int (*vdagent_x11_prev_error_handler)(Display *, XErrorEvent *);
|
||||
int vdagent_x11_caught_error;
|
||||
|
||||
#ifndef USE_GTK_FOR_CLIPBOARD
|
||||
static void vdagent_x11_handle_selection_notify(struct vdagent_x11 *x11,
|
||||
XEvent *event, int incr);
|
||||
const XEvent *event, int incr);
|
||||
static void vdagent_x11_handle_selection_request(struct vdagent_x11 *x11);
|
||||
static void vdagent_x11_handle_targets_notify(struct vdagent_x11 *x11,
|
||||
XEvent *event);
|
||||
const XEvent *event);
|
||||
static void vdagent_x11_handle_property_delete_notify(struct vdagent_x11 *x11,
|
||||
XEvent *del_event);
|
||||
const XEvent *del_event);
|
||||
static void vdagent_x11_send_selection_notify(struct vdagent_x11 *x11,
|
||||
Atom prop, struct vdagent_x11_selection_request *request);
|
||||
static void vdagent_x11_set_clipboard_owner(struct vdagent_x11 *x11,
|
||||
uint8_t selection, int new_owner);
|
||||
static void uris_ready_cb(GObject *source, GAsyncResult *res, gpointer user_data);
|
||||
|
||||
static const char *vdagent_x11_sel_to_str(uint8_t selection) {
|
||||
switch (selection) {
|
||||
@@ -67,48 +88,161 @@ static const char *vdagent_x11_sel_to_str(uint8_t selection) {
|
||||
return "unknown";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static int debug_error_handler(Display *display, XErrorEvent *error)
|
||||
static int vdagent_x11_debug_error_handler(
|
||||
Display *display, XErrorEvent *error)
|
||||
{
|
||||
abort();
|
||||
}
|
||||
|
||||
struct vdagent_x11 *vdagent_x11_create(struct udscs_connection *vdagentd,
|
||||
int debug, int sync)
|
||||
/* 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(
|
||||
Display *display, XErrorEvent *error)
|
||||
{
|
||||
if (error->error_code == BadWindow)
|
||||
return 0;
|
||||
|
||||
return vdagent_x11_prev_error_handler(display, error);
|
||||
}
|
||||
|
||||
void vdagent_x11_set_error_handler(struct vdagent_x11 *x11,
|
||||
int (*handler)(Display *, XErrorEvent *))
|
||||
{
|
||||
XSync(x11->display, False);
|
||||
vdagent_x11_caught_error = 0;
|
||||
vdagent_x11_prev_error_handler = XSetErrorHandler(handler);
|
||||
}
|
||||
|
||||
int vdagent_x11_restore_error_handler(struct vdagent_x11 *x11)
|
||||
{
|
||||
int error;
|
||||
|
||||
XSync(x11->display, False);
|
||||
XSetErrorHandler(vdagent_x11_prev_error_handler);
|
||||
error = vdagent_x11_caught_error;
|
||||
vdagent_x11_caught_error = 0;
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
gchar *vdagent_x11_get_wm_name(struct vdagent_x11 *x11)
|
||||
{
|
||||
Atom type_ret;
|
||||
int format_ret;
|
||||
unsigned long len, remain;
|
||||
unsigned char *data = NULL;
|
||||
Window sup_window = None;
|
||||
gchar *net_wm_name = NULL;
|
||||
|
||||
/* XGetWindowProperty can throw a BadWindow error. One way we can trigger
|
||||
this is when the display-manager (ie gdm) has set, and not cleared the
|
||||
_NET_SUPPORTING_WM_CHECK property, and the window manager running in
|
||||
the user session has not yet updated it to point to its window, so its
|
||||
pointing to a nonexistent window. */
|
||||
vdagent_x11_set_error_handler(x11, vdagent_x11_ignore_bad_window_handler);
|
||||
|
||||
/* Get the window manager SUPPORTING_WM_CHECK window */
|
||||
if (XGetWindowProperty(x11->display, x11->root_window[0],
|
||||
XInternAtom(x11->display, "_NET_SUPPORTING_WM_CHECK", False), 0,
|
||||
LONG_MAX, False, XA_WINDOW, &type_ret, &format_ret, &len,
|
||||
&remain, &data) == Success) {
|
||||
if (type_ret == XA_WINDOW)
|
||||
sup_window = *((Window *)data);
|
||||
XFree(data);
|
||||
}
|
||||
if (sup_window == None &&
|
||||
XGetWindowProperty(x11->display, x11->root_window[0],
|
||||
XInternAtom(x11->display, "_WIN_SUPPORTING_WM_CHECK", False), 0,
|
||||
LONG_MAX, False, XA_CARDINAL, &type_ret, &format_ret, &len,
|
||||
&remain, &data) == Success) {
|
||||
if (type_ret == XA_CARDINAL)
|
||||
sup_window = *((Window *)data);
|
||||
XFree(data);
|
||||
}
|
||||
/* So that we can get the net_wm_name */
|
||||
if (sup_window != None) {
|
||||
Atom utf8 = XInternAtom(x11->display, "UTF8_STRING", False);
|
||||
if (XGetWindowProperty(x11->display, sup_window,
|
||||
XInternAtom(x11->display, "_NET_WM_NAME", False), 0,
|
||||
LONG_MAX, False, utf8, &type_ret, &format_ret, &len,
|
||||
&remain, &data) == Success) {
|
||||
if (type_ret == utf8) {
|
||||
net_wm_name = g_strndup((char *)data, (format_ret / 8) * len);
|
||||
}
|
||||
XFree(data);
|
||||
}
|
||||
if (net_wm_name == NULL &&
|
||||
XGetWindowProperty(x11->display, sup_window,
|
||||
XInternAtom(x11->display, "_NET_WM_NAME", False), 0,
|
||||
LONG_MAX, False, XA_STRING, &type_ret, &format_ret, &len,
|
||||
&remain, &data) == Success) {
|
||||
if (type_ret == XA_STRING) {
|
||||
net_wm_name = g_strndup((char *)data, (format_ret / 8) * len);
|
||||
}
|
||||
XFree(data);
|
||||
}
|
||||
}
|
||||
|
||||
vdagent_x11_restore_error_handler(x11);
|
||||
|
||||
if (net_wm_name == NULL)
|
||||
return g_strdup("unknown");
|
||||
return net_wm_name;
|
||||
}
|
||||
|
||||
struct vdagent_x11 *vdagent_x11_create(UdscsConnection *vdagentd,
|
||||
int debug, int sync)
|
||||
{
|
||||
struct vdagent_x11 *x11;
|
||||
XWindowAttributes attrib;
|
||||
#ifdef USE_GTK_FOR_CLIPBOARD
|
||||
int i;
|
||||
#else
|
||||
int i, j, major, minor;
|
||||
#endif
|
||||
|
||||
x11 = calloc(1, sizeof(*x11));
|
||||
if (!x11) {
|
||||
syslog(LOG_ERR, "out of memory allocating vdagent_x11 struct");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
x11 = g_new0(struct vdagent_x11, 1);
|
||||
x11->vdagentd = vdagentd;
|
||||
x11->debug = debug;
|
||||
|
||||
x11->guest_output_map = g_hash_table_new_full(&g_direct_hash,
|
||||
&g_direct_equal,
|
||||
NULL,
|
||||
NULL);
|
||||
|
||||
|
||||
x11->display = XOpenDisplay(NULL);
|
||||
if (!x11->display) {
|
||||
syslog(LOG_ERR, "could not connect to X-server");
|
||||
free(x11);
|
||||
g_free(x11);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
x11->screen_count = ScreenCount(x11->display);
|
||||
if (x11->screen_count > MAX_SCREENS) {
|
||||
syslog(LOG_ERR, "Error too much screens: %d > %d",
|
||||
x11->screen_count, MAX_SCREENS);
|
||||
XCloseDisplay(x11->display);
|
||||
g_free(x11);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (sync) {
|
||||
XSetErrorHandler(debug_error_handler);
|
||||
XSetErrorHandler(vdagent_x11_debug_error_handler);
|
||||
XSynchronize(x11->display, True);
|
||||
}
|
||||
|
||||
x11->screen = DefaultScreen(x11->display);
|
||||
x11->root_window = RootWindow(x11->display, x11->screen);
|
||||
x11->fd = ConnectionNumber(x11->display);
|
||||
for (i = 0; i < x11->screen_count; i++)
|
||||
x11->root_window[i] = RootWindow(x11->display, i);
|
||||
#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);
|
||||
x11->incr_atom = XInternAtom(x11->display, "INCR", False);
|
||||
x11->multiple_atom = XInternAtom(x11->display, "MULTIPLE", False);
|
||||
x11->timestamp_atom = XInternAtom(x11->display, "TIMESTAMP", False);
|
||||
for(i = 0; i < clipboard_format_count; i++) {
|
||||
x11->clipboard_formats[i].type = clipboard_format_templates[i].type;
|
||||
for(j = 0; clipboard_format_templates[i].atom_names[j]; j++) {
|
||||
@@ -121,22 +255,23 @@ struct vdagent_x11 *vdagent_x11_create(struct udscs_connection *vdagentd,
|
||||
}
|
||||
|
||||
/* We should not store properties (for selections) on the root window */
|
||||
x11->selection_window = XCreateSimpleWindow(x11->display, x11->root_window,
|
||||
x11->selection_window = XCreateSimpleWindow(x11->display, x11->root_window[0],
|
||||
0, 0, 1, 1, 0, 0, 0);
|
||||
if (x11->debug)
|
||||
syslog(LOG_DEBUG, "Selection window: %u", (int)x11->selection_window);
|
||||
#endif
|
||||
|
||||
vdagent_x11_randr_init(x11);
|
||||
|
||||
#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,
|
||||
XFixesSelectSelectionInput(x11->display, x11->root_window[0],
|
||||
x11->clipboard_atom,
|
||||
XFixesSetSelectionOwnerNotifyMask|
|
||||
XFixesSelectionWindowDestroyNotifyMask|
|
||||
XFixesSelectionClientCloseNotifyMask);
|
||||
XFixesSelectSelectionInput(x11->display, x11->root_window,
|
||||
XFixesSelectSelectionInput(x11->display, x11->root_window[0],
|
||||
x11->clipboard_primary_atom,
|
||||
XFixesSetSelectionOwnerNotifyMask|
|
||||
XFixesSelectionWindowDestroyNotifyMask|
|
||||
@@ -154,41 +289,57 @@ struct vdagent_x11 *vdagent_x11_create(struct udscs_connection *vdagentd,
|
||||
if (x11->max_prop_size > 262144)
|
||||
x11->max_prop_size = 262144;
|
||||
|
||||
/* Catch resolution changes */
|
||||
XSelectInput(x11->display, x11->root_window, StructureNotifyMask);
|
||||
clipboard_webdav_init();
|
||||
#endif
|
||||
|
||||
/* Get the current resolution */
|
||||
XGetWindowAttributes(x11->display, x11->root_window, &attrib);
|
||||
x11->width = attrib.width;
|
||||
x11->height = attrib.height;
|
||||
vdagent_x11_send_daemon_guest_xorg_res(x11);
|
||||
for (i = 0; i < x11->screen_count; i++) {
|
||||
/* Catch resolution changes */
|
||||
XSelectInput(x11->display, x11->root_window[i], StructureNotifyMask);
|
||||
|
||||
/* Flush output buffers and consume any pending events */
|
||||
vdagent_x11_do_read(x11);
|
||||
/* Get the current resolution */
|
||||
XGetWindowAttributes(x11->display, x11->root_window[i], &attrib);
|
||||
x11->width[i] = attrib.width;
|
||||
x11->height[i] = attrib.height;
|
||||
}
|
||||
|
||||
return x11;
|
||||
}
|
||||
|
||||
void vdagent_x11_destroy(struct vdagent_x11 *x11)
|
||||
void vdagent_x11_destroy(struct vdagent_x11 *x11, int vdagentd_disconnected)
|
||||
{
|
||||
uint8_t sel;
|
||||
|
||||
if (!x11)
|
||||
return;
|
||||
|
||||
#ifndef USE_GTK_FOR_CLIPBOARD
|
||||
if (vdagentd_disconnected)
|
||||
x11->vdagentd = NULL;
|
||||
|
||||
uint8_t sel;
|
||||
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);
|
||||
free(x11);
|
||||
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 USE_GTK_FOR_CLIPBOARD
|
||||
static void vdagent_x11_next_selection_request(struct vdagent_x11 *x11)
|
||||
{
|
||||
struct vdagent_x11_selection_request *selection_request;
|
||||
@@ -226,7 +377,7 @@ static void vdagent_x11_set_clipboard_owner(struct vdagent_x11 *x11,
|
||||
once = 0;
|
||||
}
|
||||
vdagent_x11_send_selection_notify(x11, None, curr_sel);
|
||||
if (curr_sel == x11->selection_req) {
|
||||
if (prev_sel == NULL) {
|
||||
x11->selection_req = next_sel;
|
||||
free(x11->selection_req_data);
|
||||
x11->selection_req_data = NULL;
|
||||
@@ -254,9 +405,10 @@ static void vdagent_x11_set_clipboard_owner(struct vdagent_x11 *x11,
|
||||
"ownership change, clearing");
|
||||
once = 0;
|
||||
}
|
||||
udscs_write(x11->vdagentd, VDAGENTD_CLIPBOARD_DATA, selection,
|
||||
VD_AGENT_CLIPBOARD_NONE, NULL, 0);
|
||||
if (curr_conv == x11->conversion_req) {
|
||||
if (x11->vdagentd)
|
||||
udscs_write(x11->vdagentd, VDAGENTD_CLIPBOARD_DATA, selection,
|
||||
VD_AGENT_CLIPBOARD_NONE, NULL, 0);
|
||||
if (prev_conv == NULL) {
|
||||
x11->conversion_req = next_conv;
|
||||
x11->clipboard_data_size = 0;
|
||||
x11->expect_property_notify = 0;
|
||||
@@ -269,10 +421,13 @@ 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 */
|
||||
if (x11->clipboard_owner[selection] == owner_guest) {
|
||||
if (x11->clipboard_owner[selection] == owner_guest && x11->vdagentd) {
|
||||
udscs_write(x11->vdagentd, VDAGENTD_CLIPBOARD_RELEASE, selection,
|
||||
0, NULL, 0);
|
||||
}
|
||||
@@ -296,12 +451,13 @@ static int vdagent_x11_get_clipboard_atom(struct vdagent_x11 *x11, uint8_t selec
|
||||
}
|
||||
|
||||
static int vdagent_x11_get_clipboard_selection(struct vdagent_x11 *x11,
|
||||
XEvent *event, uint8_t *selection)
|
||||
const XEvent *event, uint8_t *selection)
|
||||
{
|
||||
Atom atom;
|
||||
|
||||
if (event->type == x11->xfixes_event_base) {
|
||||
XFixesSelectionNotifyEvent *xfev = (XFixesSelectionNotifyEvent *)event;
|
||||
const XFixesSelectionNotifyEvent *xfev =
|
||||
(const XFixesSelectionNotifyEvent *)event;
|
||||
atom = xfev->selection;
|
||||
} else if (event->type == SelectionNotify) {
|
||||
atom = event->xselection.selection;
|
||||
@@ -323,23 +479,25 @@ static int vdagent_x11_get_clipboard_selection(struct vdagent_x11 *x11,
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void vdagent_x11_handle_event(struct vdagent_x11 *x11, XEvent event)
|
||||
static void vdagent_x11_handle_event(struct vdagent_x11 *x11, const XEvent *event)
|
||||
{
|
||||
int handled = 0;
|
||||
int i, handled = 0;
|
||||
#ifndef USE_GTK_FOR_CLIPBOARD
|
||||
uint8_t selection;
|
||||
|
||||
if (event.type == x11->xfixes_event_base) {
|
||||
if (event->type == x11->xfixes_event_base) {
|
||||
union {
|
||||
XEvent ev;
|
||||
XFixesSelectionNotifyEvent xfev;
|
||||
} ev;
|
||||
|
||||
if (vdagent_x11_get_clipboard_selection(x11, &event, &selection)) {
|
||||
if (vdagent_x11_get_clipboard_selection(x11, event, &selection)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ev.ev = event;
|
||||
ev.ev = *event;
|
||||
switch (ev.xfev.subtype) {
|
||||
case XFixesSetSelectionOwnerNotify:
|
||||
break;
|
||||
@@ -350,7 +508,7 @@ static void vdagent_x11_handle_event(struct vdagent_x11 *x11, XEvent event)
|
||||
break;
|
||||
default:
|
||||
VSELPRINTF("unexpected xfix event subtype %d window %d",
|
||||
(int)ev.xfev.subtype, (int)event.xany.window);
|
||||
(int)ev.xfev.subtype, (int)event->xany.window);
|
||||
return;
|
||||
}
|
||||
VSELPRINTF("New selection owner: %u", (unsigned int)ev.xfev.owner);
|
||||
@@ -359,11 +517,10 @@ static void vdagent_x11_handle_event(struct vdagent_x11 *x11, XEvent event)
|
||||
if (ev.xfev.owner == x11->selection_window)
|
||||
return;
|
||||
|
||||
/* If the clipboard owner is changed we no longer own it */
|
||||
vdagent_x11_set_clipboard_owner(x11, selection, owner_none);
|
||||
|
||||
if (ev.xfev.owner == None)
|
||||
if (ev.xfev.owner == None) {
|
||||
vdagent_x11_set_clipboard_owner(x11, selection, owner_none);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Request the supported targets from the new owner */
|
||||
XConvertSelection(x11->display, ev.xfev.selection, x11->targets_atom,
|
||||
@@ -372,37 +529,44 @@ static void vdagent_x11_handle_event(struct vdagent_x11 *x11, XEvent event)
|
||||
x11->expected_targets_notifies[selection]++;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
switch (event.type) {
|
||||
if (vdagent_x11_randr_handle_event(x11, event))
|
||||
return;
|
||||
|
||||
switch (event->type) {
|
||||
case ConfigureNotify:
|
||||
// TODO: handle CrtcConfigureNotify, OutputConfigureNotify can be ignored.
|
||||
if (event.xconfigure.window != x11->root_window)
|
||||
for (i = 0; i < x11->screen_count; i++)
|
||||
if (event->xconfigure.window == x11->root_window[i])
|
||||
break;
|
||||
if (i == x11->screen_count)
|
||||
break;
|
||||
|
||||
handled = 1;
|
||||
vdagent_x11_randr_handle_root_size_change(x11,
|
||||
event.xconfigure.width, event.xconfigure.height);
|
||||
vdagent_x11_randr_handle_root_size_change(x11, i,
|
||||
event->xconfigure.width, event->xconfigure.height);
|
||||
break;
|
||||
case MappingNotify:
|
||||
/* These are uninteresting */
|
||||
handled = 1;
|
||||
break;
|
||||
#ifndef USE_GTK_FOR_CLIPBOARD
|
||||
case SelectionNotify:
|
||||
if (event.xselection.target == x11->targets_atom)
|
||||
vdagent_x11_handle_targets_notify(x11, &event);
|
||||
if (event->xselection.target == x11->targets_atom)
|
||||
vdagent_x11_handle_targets_notify(x11, event);
|
||||
else
|
||||
vdagent_x11_handle_selection_notify(x11, &event, 0);
|
||||
vdagent_x11_handle_selection_notify(x11, event, 0);
|
||||
|
||||
handled = 1;
|
||||
break;
|
||||
case PropertyNotify:
|
||||
if (x11->expect_property_notify &&
|
||||
event.xproperty.state == PropertyNewValue) {
|
||||
vdagent_x11_handle_selection_notify(x11, &event, 1);
|
||||
event->xproperty.state == PropertyNewValue) {
|
||||
vdagent_x11_handle_selection_notify(x11, event, 1);
|
||||
}
|
||||
if (x11->selection_req_data &&
|
||||
event.xproperty.state == PropertyDelete) {
|
||||
vdagent_x11_handle_property_delete_notify(x11, &event);
|
||||
if (x11->selection_req_data &&
|
||||
event->xproperty.state == PropertyDelete) {
|
||||
vdagent_x11_handle_property_delete_notify(x11, event);
|
||||
}
|
||||
/* Always mark as handled, since we cannot unselect input for property
|
||||
notifications once we are done with handling the incr transfer. */
|
||||
@@ -416,7 +580,7 @@ static void vdagent_x11_handle_event(struct vdagent_x11 *x11, XEvent event)
|
||||
case SelectionRequest: {
|
||||
struct vdagent_x11_selection_request *req, *new_req;
|
||||
|
||||
if (vdagent_x11_get_clipboard_selection(x11, &event, &selection)) {
|
||||
if (vdagent_x11_get_clipboard_selection(x11, event, &selection)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -428,7 +592,7 @@ static void vdagent_x11_handle_event(struct vdagent_x11 *x11, XEvent event)
|
||||
|
||||
handled = 1;
|
||||
|
||||
new_req->event = event;
|
||||
new_req->event = *event;
|
||||
new_req->selection = selection;
|
||||
new_req->next = NULL;
|
||||
|
||||
@@ -446,10 +610,11 @@ static void vdagent_x11_handle_event(struct vdagent_x11 *x11, XEvent event)
|
||||
req->next = new_req;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (!handled && x11->debug)
|
||||
syslog(LOG_DEBUG, "unhandled x11 event, type %d, window %d",
|
||||
(int)event.type, (int)event.xany.window);
|
||||
(int)event->type, (int)event->xany.window);
|
||||
}
|
||||
|
||||
void vdagent_x11_do_read(struct vdagent_x11 *x11)
|
||||
@@ -458,19 +623,34 @@ void vdagent_x11_do_read(struct vdagent_x11 *x11)
|
||||
|
||||
while (XPending(x11->display)) {
|
||||
XNextEvent(x11->display, &event);
|
||||
vdagent_x11_handle_event(x11, event);
|
||||
vdagent_x11_handle_event(x11, &event);
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef USE_GTK_FOR_CLIPBOARD
|
||||
static const char *vdagent_x11_get_atom_name(struct vdagent_x11 *x11, Atom a)
|
||||
{
|
||||
if (a == None)
|
||||
return "None";
|
||||
|
||||
return XGetAtomName(x11->display, a);
|
||||
for (int i = 0; i < ATOM_NAME_CACHE_SIZE; i++) {
|
||||
if (x11->atom_name_cache[i].atom == a) {
|
||||
return x11->atom_name_cache[i].name;
|
||||
}
|
||||
}
|
||||
|
||||
struct atom_name_cache_item *cch;
|
||||
cch = &x11->atom_name_cache[x11->atom_name_cache_next];
|
||||
if (cch->name) {
|
||||
XFree(cch->name);
|
||||
}
|
||||
cch->atom = a;
|
||||
cch->name = XGetAtomName(x11->display, a);
|
||||
x11->atom_name_cache_next = (x11->atom_name_cache_next + 1) % ATOM_NAME_CACHE_SIZE;
|
||||
return cch->name;
|
||||
}
|
||||
|
||||
static int vdagent_x11_get_selection(struct vdagent_x11 *x11, XEvent *event,
|
||||
static int vdagent_x11_get_selection(struct vdagent_x11 *x11, const XEvent *event,
|
||||
uint8_t selection, Atom type, Atom prop, int format,
|
||||
unsigned char **data_ret, int incr)
|
||||
{
|
||||
@@ -552,6 +732,7 @@ static int vdagent_x11_get_selection(struct vdagent_x11 *x11, XEvent *event,
|
||||
len *= sizeof(short);
|
||||
break;
|
||||
case 32:
|
||||
// on X11, a format of 32 is always a long
|
||||
len *= sizeof(long);
|
||||
break;
|
||||
}
|
||||
@@ -621,15 +802,26 @@ static uint32_t vdagent_x11_target_to_type(struct vdagent_x11 *x11,
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < clipboard_format_count; i++) {
|
||||
for (j = 0; j < x11->clipboard_formats[i].atom_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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SELPRINTF("unexpected selection type %s",
|
||||
vdagent_x11_get_atom_name(x11, target));
|
||||
VSELPRINTF("unexpected selection type %s",
|
||||
vdagent_x11_get_atom_name(x11, target));
|
||||
return VD_AGENT_CLIPBOARD_NONE;
|
||||
}
|
||||
|
||||
@@ -661,7 +853,7 @@ static void vdagent_x11_handle_conversion_request(struct vdagent_x11 *x11)
|
||||
}
|
||||
|
||||
static void vdagent_x11_handle_selection_notify(struct vdagent_x11 *x11,
|
||||
XEvent *event, int incr)
|
||||
const XEvent *event, int incr)
|
||||
{
|
||||
int len = 0;
|
||||
unsigned char *data = NULL;
|
||||
@@ -700,6 +892,9 @@ static void vdagent_x11_handle_selection_notify(struct vdagent_x11 *x11,
|
||||
selection = x11->conversion_req->selection;
|
||||
type = vdagent_x11_target_to_type(x11, selection,
|
||||
x11->conversion_req->target);
|
||||
if (type == VD_AGENT_CLIPBOARD_NONE)
|
||||
SELPRINTF("internal error conversion_req has bad target %s",
|
||||
vdagent_x11_get_atom_name(x11, x11->conversion_req->target));
|
||||
if (len == 0) { /* No errors so far */
|
||||
len = vdagent_x11_get_selection(x11, event, selection,
|
||||
x11->conversion_req->target,
|
||||
@@ -743,7 +938,7 @@ static void vdagent_x11_print_targets(struct vdagent_x11 *x11,
|
||||
}
|
||||
|
||||
static void vdagent_x11_handle_targets_notify(struct vdagent_x11 *x11,
|
||||
XEvent *event)
|
||||
const XEvent *event)
|
||||
{
|
||||
int i, len;
|
||||
Atom atom, *atoms = NULL;
|
||||
@@ -761,6 +956,12 @@ static void vdagent_x11_handle_targets_notify(struct vdagent_x11 *x11,
|
||||
|
||||
x11->expected_targets_notifies[selection]--;
|
||||
|
||||
if (x11->ignore_targets_notifies[selection] > 0) {
|
||||
x11->ignore_targets_notifies[selection]--;
|
||||
VSELPRINTF("ignoring selection notify TARGETS");
|
||||
return;
|
||||
}
|
||||
|
||||
/* If we have more targets_notifies pending, ignore this one, we
|
||||
are only interested in the targets list of the current owner
|
||||
(which is the last one we've requested a targets list from) */
|
||||
@@ -781,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) {
|
||||
@@ -824,7 +1030,10 @@ static void vdagent_x11_send_selection_notify(struct vdagent_x11 *x11,
|
||||
res.xselection.selection = event->xselectionrequest.selection;
|
||||
res.xselection.target = event->xselectionrequest.target;
|
||||
res.xselection.time = event->xselectionrequest.time;
|
||||
|
||||
vdagent_x11_set_error_handler(x11, vdagent_x11_ignore_bad_window_handler);
|
||||
XSendEvent(x11->display, event->xselectionrequest.requestor, 0, 0, &res);
|
||||
vdagent_x11_restore_error_handler(x11);
|
||||
|
||||
if (!request) {
|
||||
vdagent_x11_next_selection_request(x11);
|
||||
@@ -833,12 +1042,17 @@ static void vdagent_x11_send_selection_notify(struct vdagent_x11 *x11,
|
||||
}
|
||||
|
||||
static void vdagent_x11_send_targets(struct vdagent_x11 *x11,
|
||||
uint8_t selection, XEvent *event)
|
||||
uint8_t selection, const XEvent *event)
|
||||
{
|
||||
Atom prop, targets[256] = { x11->targets_atom, };
|
||||
int i, j, k, target_count = 1;
|
||||
|
||||
for (i = 0; i < x11->clipboard_type_count[selection]; i++) {
|
||||
if (x11->clipboard_agent_types[selection][i] == VD_AGENT_CLIPBOARD_UTF8_TEXT &&
|
||||
x11->clipboard_has_files[selection]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (j = 0; j < clipboard_format_count; j++) {
|
||||
if (x11->clipboard_formats[j].type !=
|
||||
x11->clipboard_agent_types[selection][i])
|
||||
@@ -860,11 +1074,16 @@ exit_loop:
|
||||
if (prop == None)
|
||||
prop = event->xselectionrequest.target;
|
||||
|
||||
vdagent_x11_set_error_handler(x11, vdagent_x11_ignore_bad_window_handler);
|
||||
XChangeProperty(x11->display, event->xselectionrequest.requestor, prop,
|
||||
XA_ATOM, 32, PropModeReplace, (unsigned char *)&targets,
|
||||
target_count);
|
||||
vdagent_x11_print_targets(x11, selection, "sent", targets, target_count);
|
||||
vdagent_x11_send_selection_notify(x11, prop, NULL);
|
||||
if (vdagent_x11_restore_error_handler(x11) == 0) {
|
||||
vdagent_x11_print_targets(x11, selection, "sent",
|
||||
targets, target_count);
|
||||
vdagent_x11_send_selection_notify(x11, prop, NULL);
|
||||
} else
|
||||
SELPRINTF("send_targets: Failed to sent, requestor window gone");
|
||||
}
|
||||
|
||||
static void vdagent_x11_handle_selection_request(struct vdagent_x11 *x11)
|
||||
@@ -893,6 +1112,20 @@ static void vdagent_x11_handle_selection_request(struct vdagent_x11 *x11)
|
||||
return;
|
||||
}
|
||||
|
||||
if (event->xselectionrequest.target == x11->timestamp_atom) {
|
||||
/* TODO: use more accurate selection time */
|
||||
guint32 timestamp = event->xselectionrequest.time;
|
||||
|
||||
XChangeProperty(x11->display, event->xselectionrequest.requestor,
|
||||
event->xselectionrequest.property,
|
||||
event->xselectionrequest.target, 32, PropModeReplace,
|
||||
(guint8*)×tamp, 1);
|
||||
vdagent_x11_send_selection_notify(x11,
|
||||
event->xselectionrequest.property, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (event->xselectionrequest.target == x11->targets_atom) {
|
||||
vdagent_x11_send_targets(x11, selection, event);
|
||||
return;
|
||||
@@ -901,16 +1134,28 @@ static void vdagent_x11_handle_selection_request(struct vdagent_x11 *x11)
|
||||
type = vdagent_x11_target_to_type(x11, selection,
|
||||
event->xselectionrequest.target);
|
||||
if (type == VD_AGENT_CLIPBOARD_NONE) {
|
||||
VSELPRINTF("guest app requested a non-advertised target");
|
||||
vdagent_x11_send_selection_notify(x11, None, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == VD_AGENT_CLIPBOARD_FILE_LIST && x11->file_list_data[selection]) {
|
||||
VSELPRINTF("setting file list from cache");
|
||||
|
||||
clipboard_data_translate_to_uris_async(
|
||||
vdagent_x11_get_atom_name(x11, event->xselectionrequest.target),
|
||||
x11->file_list_data[selection],
|
||||
NULL, uris_ready_cb, x11
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
udscs_write(x11->vdagentd, VDAGENTD_CLIPBOARD_REQUEST, selection, type,
|
||||
NULL, 0);
|
||||
}
|
||||
|
||||
static void vdagent_x11_handle_property_delete_notify(struct vdagent_x11 *x11,
|
||||
XEvent *del_event)
|
||||
const XEvent *del_event)
|
||||
{
|
||||
XEvent *sel_event;
|
||||
int len;
|
||||
@@ -937,14 +1182,20 @@ static void vdagent_x11_handle_property_delete_notify(struct vdagent_x11 *x11,
|
||||
} else {
|
||||
VSELPRINTF("Ending incr send of clipboard data");
|
||||
}
|
||||
vdagent_x11_set_error_handler(x11, vdagent_x11_ignore_bad_window_handler);
|
||||
XChangeProperty(x11->display, sel_event->xselectionrequest.requestor,
|
||||
x11->selection_req_atom,
|
||||
sel_event->xselectionrequest.target, 8, PropModeReplace,
|
||||
x11->selection_req_data + x11->selection_req_data_pos,
|
||||
len);
|
||||
if (vdagent_x11_restore_error_handler(x11)) {
|
||||
SELPRINTF("incr sent failed, requestor window gone");
|
||||
len = 0;
|
||||
}
|
||||
|
||||
x11->selection_req_data_pos += len;
|
||||
|
||||
/* Note we must explictly send a 0 sized XChangeProperty to signal the
|
||||
/* Note we must explicitly send a 0 sized XChangeProperty to signal the
|
||||
incr transfer is done. Hence we do not check if we've send all data
|
||||
but instead check we've send the final 0 sized XChangeProperty. */
|
||||
if (len == 0) {
|
||||
@@ -1033,6 +1284,104 @@ 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] =
|
||||
x11->expected_targets_notifies[selection];
|
||||
|
||||
/* Flush output buffers and consume any pending events */
|
||||
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);
|
||||
}
|
||||
@@ -1040,7 +1389,6 @@ void vdagent_x11_clipboard_grab(struct vdagent_x11 *x11, uint8_t selection,
|
||||
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;
|
||||
|
||||
@@ -1049,7 +1397,6 @@ void vdagent_x11_clipboard_data(struct vdagent_x11 *x11, uint8_t selection,
|
||||
SELPRINTF("received clipboard data while still sending"
|
||||
" data from previous request, ignoring");
|
||||
}
|
||||
free(data);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1058,12 +1405,11 @@ void vdagent_x11_clipboard_data(struct vdagent_x11 *x11, uint8_t selection,
|
||||
SELPRINTF("received clipboard data without an "
|
||||
"outstanding selection request, ignoring");
|
||||
}
|
||||
free(data);
|
||||
return;
|
||||
}
|
||||
|
||||
event = &x11->selection_req->event;
|
||||
type_from_event = vdagent_x11_target_to_type(x11,
|
||||
type_from_event = vdagent_x11_target_to_type(x11,
|
||||
x11->selection_req->selection,
|
||||
event->xselectionrequest.target);
|
||||
if (type_from_event != type ||
|
||||
@@ -1077,36 +1423,23 @@ void vdagent_x11_clipboard_data(struct vdagent_x11 *x11, uint8_t selection,
|
||||
type_from_event, type);
|
||||
}
|
||||
vdagent_x11_send_selection_notify(x11, None, NULL);
|
||||
free(data);
|
||||
|
||||
/* Flush output buffers and consume any pending events */
|
||||
vdagent_x11_do_read(x11);
|
||||
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");
|
||||
x11->selection_req_data = data;
|
||||
x11->selection_req_data_pos = 0;
|
||||
x11->selection_req_data_size = size;
|
||||
x11->selection_req_atom = prop;
|
||||
XSelectInput(x11->display, event->xselectionrequest.requestor,
|
||||
PropertyChangeMask);
|
||||
XChangeProperty(x11->display, event->xselectionrequest.requestor, prop,
|
||||
x11->incr_atom, 32, PropModeReplace,
|
||||
(unsigned char*)&len, 1);
|
||||
vdagent_x11_send_selection_notify(x11, prop, x11->selection_req);
|
||||
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 {
|
||||
XChangeProperty(x11->display, event->xselectionrequest.requestor, prop,
|
||||
event->xselectionrequest.target, 8, PropModeReplace,
|
||||
data, size);
|
||||
vdagent_x11_send_selection_notify(x11, prop, NULL);
|
||||
free(data);
|
||||
clipboard_data_send_to_requestor(x11, selection, data, size, False);
|
||||
}
|
||||
|
||||
/* Flush output buffers and consume any pending events */
|
||||
@@ -1123,7 +1456,7 @@ void vdagent_x11_clipboard_release(struct vdagent_x11 *x11, uint8_t selection)
|
||||
}
|
||||
|
||||
if (x11->clipboard_owner[selection] != owner_client) {
|
||||
SELPRINTF("received release while not owning client clipboard");
|
||||
VSELPRINTF("received release while not owning client clipboard");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1134,7 +1467,7 @@ void vdagent_x11_clipboard_release(struct vdagent_x11 *x11, uint8_t selection)
|
||||
XSync(x11->display, False);
|
||||
while (XCheckTypedEvent(x11->display, x11->xfixes_event_base,
|
||||
&event))
|
||||
vdagent_x11_handle_event(x11, event);
|
||||
vdagent_x11_handle_event(x11, &event);
|
||||
|
||||
/* Note no need to do a set_clipboard_owner(owner_none) here, as that is
|
||||
already done by processing the XFixesSetSelectionOwnerNotify event. */
|
||||
@@ -1142,3 +1475,14 @@ void vdagent_x11_clipboard_release(struct vdagent_x11 *x11, uint8_t selection)
|
||||
/* Flush output buffers and consume any pending events */
|
||||
vdagent_x11_do_read(x11);
|
||||
}
|
||||
|
||||
void vdagent_x11_client_disconnected(struct vdagent_x11 *x11)
|
||||
{
|
||||
int sel;
|
||||
|
||||
for (sel = 0; sel < VD_AGENT_CLIPBOARD_SELECTION_SECONDARY; sel++) {
|
||||
if (x11->clipboard_owner[sel] == owner_client)
|
||||
vdagent_x11_clipboard_release(x11, sel);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,26 +1,26 @@
|
||||
/* vdagent-x11.h vdagent x11 code header file
|
||||
/* x11.h vdagent x11 code header file
|
||||
|
||||
Copyright 2010 Red Hat, Inc.
|
||||
Copyright 2010 - 2016 Red Hat, Inc.
|
||||
|
||||
Red Hat Authors:
|
||||
Hans de Goede <[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
|
||||
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
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __VDAGENT_H
|
||||
#define __VDAGENT_H
|
||||
#ifndef __VDAGENT_X11_H
|
||||
#define __VDAGENT_X11_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <spice/vd_agent.h>
|
||||
@@ -28,15 +28,17 @@
|
||||
|
||||
struct vdagent_x11;
|
||||
|
||||
struct vdagent_x11 *vdagent_x11_create(struct udscs_connection *vdagentd,
|
||||
struct vdagent_x11 *vdagent_x11_create(UdscsConnection *vdagentd,
|
||||
int debug, int sync);
|
||||
void vdagent_x11_destroy(struct vdagent_x11 *x11);
|
||||
void vdagent_x11_destroy(struct vdagent_x11 *x11, int vdagentd_disconnected);
|
||||
|
||||
int vdagent_x11_get_fd(struct vdagent_x11 *x11);
|
||||
void vdagent_x11_do_read(struct vdagent_x11 *x11);
|
||||
|
||||
void vdagent_x11_set_monitor_config(struct vdagent_x11 *x11,
|
||||
VDAgentMonitorsConfig *mon_config);
|
||||
VDAgentMonitorsConfig *mon_config, int fallback);
|
||||
|
||||
#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,
|
||||
@@ -45,4 +47,13 @@ void vdagent_x11_clipboard_data(struct vdagent_x11 *x11, uint8_t selection,
|
||||
uint32_t type, uint8_t *data, uint32_t size);
|
||||
void vdagent_x11_clipboard_release(struct vdagent_x11 *x11, uint8_t selection);
|
||||
|
||||
void vdagent_x11_client_disconnected(struct vdagent_x11 *x11);
|
||||
#endif
|
||||
|
||||
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
|
||||
@@ -1,18 +1,18 @@
|
||||
/* vdagentd-proto-strings.h header file
|
||||
|
||||
Copyright 2010 Red Hat, Inc.
|
||||
Copyright 2010-2013 Red Hat, Inc.
|
||||
|
||||
Red Hat Authors:
|
||||
Hans de Goede <[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
|
||||
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
|
||||
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
|
||||
@@ -30,6 +30,13 @@ static const char * const vdagentd_messages[] = {
|
||||
"clipboard data",
|
||||
"clipboard release",
|
||||
"version",
|
||||
};
|
||||
"audio volume sync",
|
||||
"file xfer start",
|
||||
"file xfer status",
|
||||
"file xfer data",
|
||||
"file xfer disable",
|
||||
"client disconnected",
|
||||
"graphics device info",
|
||||
};
|
||||
|
||||
#endif
|
||||
+15
-5
@@ -1,19 +1,19 @@
|
||||
/* vdagentd-proto.h header file for the protocol over the unix domain socket
|
||||
between the vdagent process / xorg-client and the vdagentd (daemon).
|
||||
|
||||
Copyright 2010 Red Hat, Inc.
|
||||
Copyright 2010-2013 Red Hat, Inc.
|
||||
|
||||
Red Hat Authors:
|
||||
Hans de Goede <[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
|
||||
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
|
||||
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
|
||||
@@ -23,7 +23,9 @@
|
||||
#ifndef __VDAGENTD_PROTO_H
|
||||
#define __VDAGENTD_PROTO_H
|
||||
|
||||
#define VDAGENTD_SOCKET "/var/run/spice-vdagentd/spice-vdagent-sock"
|
||||
#define VDAGENTD_SOCKET "/run/spice-vdagentd/spice-vdagent-sock"
|
||||
|
||||
#define DEFAULT_VIRTIO_PORT_PATH "/dev/virtio-ports/com.redhat.spice.0"
|
||||
|
||||
enum {
|
||||
VDAGENTD_GUEST_XORG_RESOLUTION, /* client -> daemon, arg1: overall width,
|
||||
@@ -36,6 +38,13 @@ enum {
|
||||
VDAGENTD_CLIPBOARD_DATA, /* arg1: sel, arg 2: type, data: data */
|
||||
VDAGENTD_CLIPBOARD_RELEASE, /* arg1: selection */
|
||||
VDAGENTD_VERSION, /* daemon -> client, data: version string */
|
||||
VDAGENTD_AUDIO_VOLUME_SYNC,
|
||||
VDAGENTD_FILE_XFER_START,
|
||||
VDAGENTD_FILE_XFER_STATUS,
|
||||
VDAGENTD_FILE_XFER_DATA,
|
||||
VDAGENTD_FILE_XFER_DISABLE,
|
||||
VDAGENTD_CLIENT_DISCONNECTED, /* daemon -> client */
|
||||
VDAGENTD_GRAPHICS_DEVICE_INFO, /* daemon -> client */
|
||||
VDAGENTD_NO_MESSAGES /* Must always be last */
|
||||
};
|
||||
|
||||
@@ -44,6 +53,7 @@ struct vdagentd_guest_xorg_resolution {
|
||||
int height;
|
||||
int x;
|
||||
int y;
|
||||
int display_id;
|
||||
};
|
||||
|
||||
#endif
|
||||
-826
@@ -1,826 +0,0 @@
|
||||
/* vdagentd.c vdagentd (daemon) code
|
||||
|
||||
Copyright 2010-2012 Red Hat, Inc.
|
||||
|
||||
Red Hat Authors:
|
||||
Hans de Goede <[email protected]>
|
||||
Gerd Hoffmann <[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/>.
|
||||
*/
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <syslog.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/stat.h>
|
||||
#include <spice/vd_agent.h>
|
||||
|
||||
#include "udscs.h"
|
||||
#include "vdagentd-proto.h"
|
||||
#include "vdagentd-proto-strings.h"
|
||||
#include "vdagentd-uinput.h"
|
||||
#include "vdagentd-xorg-conf.h"
|
||||
#include "vdagent-virtio-port.h"
|
||||
#include "session-info.h"
|
||||
|
||||
struct agent_data {
|
||||
char *session;
|
||||
int width;
|
||||
int height;
|
||||
struct vdagentd_guest_xorg_resolution *screen_info;
|
||||
int screen_count;
|
||||
};
|
||||
|
||||
/* variables */
|
||||
static const char *pidfilename = "/var/run/spice-vdagentd/spice-vdagentd.pid";
|
||||
static const char *portdev = "/dev/virtio-ports/com.redhat.spice.0";
|
||||
static const char *uinput_device = "/dev/uinput";
|
||||
static int debug = 0;
|
||||
static struct udscs_server *server = NULL;
|
||||
static struct vdagent_virtio_port *virtio_port = NULL;
|
||||
#ifdef HAVE_SESSION_INFO
|
||||
static struct session_info *session_info = NULL;
|
||||
#endif
|
||||
static struct vdagentd_uinput *uinput = NULL;
|
||||
static VDAgentMonitorsConfig *mon_config = NULL;
|
||||
static uint32_t *capabilities = NULL;
|
||||
static int capabilities_size = 0;
|
||||
#ifdef HAVE_SESSION_INFO
|
||||
static const char *active_session = NULL;
|
||||
#else
|
||||
static unsigned int session_count = 0;
|
||||
#endif
|
||||
static struct udscs_connection *active_session_conn = NULL;
|
||||
static int agent_owns_clipboard[256] = { 0, };
|
||||
static int quit = 0;
|
||||
static int retval = 0;
|
||||
|
||||
/* utility functions */
|
||||
/* vdagentd <-> spice-client communication handling */
|
||||
static void send_capabilities(struct vdagent_virtio_port *vport,
|
||||
uint32_t request)
|
||||
{
|
||||
VDAgentAnnounceCapabilities *caps;
|
||||
uint32_t size;
|
||||
|
||||
size = sizeof(*caps) + VD_AGENT_CAPS_BYTES;
|
||||
caps = calloc(1, size);
|
||||
if (!caps) {
|
||||
syslog(LOG_ERR, "out of memory allocating capabilities array (write)");
|
||||
return;
|
||||
}
|
||||
|
||||
caps->request = request;
|
||||
VD_AGENT_SET_CAPABILITY(caps->caps, VD_AGENT_CAP_MOUSE_STATE);
|
||||
VD_AGENT_SET_CAPABILITY(caps->caps, VD_AGENT_CAP_MONITORS_CONFIG);
|
||||
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);
|
||||
|
||||
vdagent_virtio_port_write(vport, VDP_CLIENT_PORT,
|
||||
VD_AGENT_ANNOUNCE_CAPABILITIES, 0,
|
||||
(uint8_t *)caps, size);
|
||||
free(caps);
|
||||
}
|
||||
|
||||
static void do_client_monitors(struct vdagent_virtio_port *vport, int port_nr,
|
||||
VDAgentMessage *message_header, VDAgentMonitorsConfig *new_monitors)
|
||||
{
|
||||
VDAgentReply reply;
|
||||
uint32_t size;
|
||||
|
||||
/* Store monitor config to send to agents when they connect */
|
||||
size = sizeof(VDAgentMonitorsConfig) +
|
||||
new_monitors->num_of_monitors * sizeof(VDAgentMonConfig);
|
||||
if (message_header->size != size) {
|
||||
syslog(LOG_ERR, "invalid message size for VDAgentMonitorsConfig");
|
||||
return;
|
||||
}
|
||||
|
||||
vdagentd_write_xorg_conf(new_monitors);
|
||||
|
||||
if (!mon_config ||
|
||||
mon_config->num_of_monitors != new_monitors->num_of_monitors) {
|
||||
free(mon_config);
|
||||
mon_config = malloc(size);
|
||||
if (!mon_config) {
|
||||
syslog(LOG_ERR, "out of memory allocating monitors config");
|
||||
return;
|
||||
}
|
||||
}
|
||||
memcpy(mon_config, new_monitors, size);
|
||||
|
||||
/* Send monitor config to currently connected agents */
|
||||
udscs_server_write_all(server, VDAGENTD_MONITORS_CONFIG, 0, 0,
|
||||
(uint8_t *)mon_config, size);
|
||||
|
||||
/* Acknowledge reception of monitors config to spice server / client */
|
||||
reply.type = VD_AGENT_MONITORS_CONFIG;
|
||||
reply.error = VD_AGENT_SUCCESS;
|
||||
vdagent_virtio_port_write(vport, port_nr, VD_AGENT_REPLY, 0,
|
||||
(uint8_t *)&reply, sizeof(reply));
|
||||
}
|
||||
|
||||
static void do_client_capabilities(struct vdagent_virtio_port *vport,
|
||||
VDAgentMessage *message_header,
|
||||
VDAgentAnnounceCapabilities *caps)
|
||||
{
|
||||
int new_size = VD_AGENT_CAPS_SIZE_FROM_MSG_SIZE(message_header->size);
|
||||
|
||||
if (capabilities_size != new_size) {
|
||||
capabilities_size = new_size;
|
||||
free(capabilities);
|
||||
capabilities = malloc(capabilities_size * sizeof(uint32_t));
|
||||
if (!capabilities) {
|
||||
syslog(LOG_ERR, "oom allocating capabilities array (read)");
|
||||
capabilities_size = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
memcpy(capabilities, caps->caps, capabilities_size * sizeof(uint32_t));
|
||||
if (caps->request)
|
||||
send_capabilities(vport, 0);
|
||||
}
|
||||
|
||||
static void do_client_clipboard(struct vdagent_virtio_port *vport,
|
||||
VDAgentMessage *message_header, uint8_t *data)
|
||||
{
|
||||
uint32_t msg_type = 0, data_type = 0, size = message_header->size;
|
||||
uint8_t selection = VD_AGENT_CLIPBOARD_SELECTION_CLIPBOARD;
|
||||
|
||||
if (!active_session_conn) {
|
||||
syslog(LOG_WARNING,
|
||||
"Could not find an agent connnection belonging to the "
|
||||
"active session, ignoring client clipboard request");
|
||||
return;
|
||||
}
|
||||
|
||||
if (VD_AGENT_HAS_CAPABILITY(capabilities, capabilities_size,
|
||||
VD_AGENT_CAP_CLIPBOARD_SELECTION)) {
|
||||
selection = data[0];
|
||||
data += 4;
|
||||
size -= 4;
|
||||
}
|
||||
|
||||
switch (message_header->type) {
|
||||
case VD_AGENT_CLIPBOARD_GRAB:
|
||||
msg_type = VDAGENTD_CLIPBOARD_GRAB;
|
||||
agent_owns_clipboard[selection] = 0;
|
||||
break;
|
||||
case VD_AGENT_CLIPBOARD_REQUEST: {
|
||||
VDAgentClipboardRequest *req = (VDAgentClipboardRequest *)data;
|
||||
msg_type = VDAGENTD_CLIPBOARD_REQUEST;
|
||||
data_type = req->type;
|
||||
data = NULL;
|
||||
size = 0;
|
||||
break;
|
||||
}
|
||||
case VD_AGENT_CLIPBOARD: {
|
||||
VDAgentClipboard *clipboard = (VDAgentClipboard *)data;
|
||||
msg_type = VDAGENTD_CLIPBOARD_DATA;
|
||||
data_type = clipboard->type;
|
||||
size = size - sizeof(VDAgentClipboard);
|
||||
data = clipboard->data;
|
||||
break;
|
||||
}
|
||||
case VD_AGENT_CLIPBOARD_RELEASE:
|
||||
msg_type = VDAGENTD_CLIPBOARD_RELEASE;
|
||||
data = NULL;
|
||||
size = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
udscs_write(active_session_conn, msg_type, selection, data_type,
|
||||
data, size);
|
||||
}
|
||||
|
||||
int virtio_port_read_complete(
|
||||
struct vdagent_virtio_port *vport,
|
||||
int port_nr,
|
||||
VDAgentMessage *message_header,
|
||||
uint8_t *data)
|
||||
{
|
||||
uint32_t min_size = 0;
|
||||
|
||||
if (message_header->protocol != VD_AGENT_PROTOCOL) {
|
||||
syslog(LOG_ERR, "message with wrong protocol version ignoring");
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (message_header->type) {
|
||||
case VD_AGENT_MOUSE_STATE:
|
||||
if (message_header->size != sizeof(VDAgentMouseState))
|
||||
goto size_error;
|
||||
vdagentd_uinput_do_mouse(&uinput, (VDAgentMouseState *)data);
|
||||
if (!uinput) {
|
||||
/* Try to re-open the tablet */
|
||||
struct agent_data *agent_data =
|
||||
udscs_get_user_data(active_session_conn);
|
||||
if (agent_data)
|
||||
uinput = vdagentd_uinput_create(uinput_device,
|
||||
agent_data->width,
|
||||
agent_data->height,
|
||||
agent_data->screen_info,
|
||||
agent_data->screen_count,
|
||||
debug > 1);
|
||||
if (!uinput) {
|
||||
syslog(LOG_CRIT, "Fatal uinput error");
|
||||
retval = 1;
|
||||
quit = 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case VD_AGENT_MONITORS_CONFIG:
|
||||
if (message_header->size < sizeof(VDAgentMonitorsConfig))
|
||||
goto size_error;
|
||||
do_client_monitors(vport, port_nr, message_header,
|
||||
(VDAgentMonitorsConfig *)data);
|
||||
break;
|
||||
case VD_AGENT_ANNOUNCE_CAPABILITIES:
|
||||
if (message_header->size < sizeof(VDAgentAnnounceCapabilities))
|
||||
goto size_error;
|
||||
do_client_capabilities(vport, message_header,
|
||||
(VDAgentAnnounceCapabilities *)data);
|
||||
break;
|
||||
case VD_AGENT_CLIPBOARD_GRAB:
|
||||
case VD_AGENT_CLIPBOARD_REQUEST:
|
||||
case VD_AGENT_CLIPBOARD:
|
||||
case VD_AGENT_CLIPBOARD_RELEASE:
|
||||
switch (message_header->type) {
|
||||
case VD_AGENT_CLIPBOARD_GRAB:
|
||||
min_size = sizeof(VDAgentClipboardGrab); break;
|
||||
case VD_AGENT_CLIPBOARD_REQUEST:
|
||||
min_size = sizeof(VDAgentClipboardRequest); break;
|
||||
case VD_AGENT_CLIPBOARD:
|
||||
min_size = sizeof(VDAgentClipboard); break;
|
||||
}
|
||||
if (VD_AGENT_HAS_CAPABILITY(capabilities, capabilities_size,
|
||||
VD_AGENT_CAP_CLIPBOARD_SELECTION)) {
|
||||
min_size += 4;
|
||||
}
|
||||
if (message_header->size < min_size) {
|
||||
goto size_error;
|
||||
}
|
||||
do_client_clipboard(vport, message_header, data);
|
||||
break;
|
||||
default:
|
||||
syslog(LOG_WARNING, "unknown message type %d, ignoring",
|
||||
message_header->type);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
size_error:
|
||||
syslog(LOG_ERR, "read: invalid message size: %u for message type: %u",
|
||||
message_header->size, message_header->type);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vdagentd <-> vdagent communication handling */
|
||||
int do_agent_clipboard(struct udscs_connection *conn,
|
||||
struct udscs_message_header *header, const uint8_t *data)
|
||||
{
|
||||
uint8_t selection = header->arg1;
|
||||
uint32_t msg_type = 0, data_type = -1, size = header->size;
|
||||
|
||||
if (!VD_AGENT_HAS_CAPABILITY(capabilities, capabilities_size,
|
||||
VD_AGENT_CAP_CLIPBOARD_BY_DEMAND))
|
||||
goto error;
|
||||
|
||||
/* Check that this agent is from the currently active session */
|
||||
if (conn != active_session_conn) {
|
||||
if (debug)
|
||||
syslog(LOG_DEBUG, "%p clipboard req from agent which is not in "
|
||||
"the active session?", conn);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!virtio_port) {
|
||||
syslog(LOG_ERR, "Clipboard req from agent but no client connection");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!VD_AGENT_HAS_CAPABILITY(capabilities, capabilities_size,
|
||||
VD_AGENT_CAP_CLIPBOARD_SELECTION) &&
|
||||
selection != VD_AGENT_CLIPBOARD_SELECTION_CLIPBOARD) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
switch (header->type) {
|
||||
case VDAGENTD_CLIPBOARD_GRAB:
|
||||
msg_type = VD_AGENT_CLIPBOARD_GRAB;
|
||||
agent_owns_clipboard[selection] = 1;
|
||||
break;
|
||||
case VDAGENTD_CLIPBOARD_REQUEST:
|
||||
msg_type = VD_AGENT_CLIPBOARD_REQUEST;
|
||||
data_type = header->arg2;
|
||||
size = 0;
|
||||
break;
|
||||
case VDAGENTD_CLIPBOARD_DATA:
|
||||
msg_type = VD_AGENT_CLIPBOARD;
|
||||
data_type = header->arg2;
|
||||
break;
|
||||
case VDAGENTD_CLIPBOARD_RELEASE:
|
||||
msg_type = VD_AGENT_CLIPBOARD_RELEASE;
|
||||
size = 0;
|
||||
agent_owns_clipboard[selection] = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (size != header->size) {
|
||||
syslog(LOG_ERR,
|
||||
"unexpected extra data in clipboard msg, disconnecting agent");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (VD_AGENT_HAS_CAPABILITY(capabilities, capabilities_size,
|
||||
VD_AGENT_CAP_CLIPBOARD_SELECTION)) {
|
||||
size += 4;
|
||||
}
|
||||
if (data_type != -1) {
|
||||
size += 4;
|
||||
}
|
||||
|
||||
vdagent_virtio_port_write_start(virtio_port, VDP_CLIENT_PORT, msg_type,
|
||||
0, size);
|
||||
|
||||
if (VD_AGENT_HAS_CAPABILITY(capabilities, capabilities_size,
|
||||
VD_AGENT_CAP_CLIPBOARD_SELECTION)) {
|
||||
uint8_t sel[4] = { selection, 0, 0, 0 };
|
||||
vdagent_virtio_port_write_append(virtio_port, sel, 4);
|
||||
}
|
||||
if (data_type != -1) {
|
||||
vdagent_virtio_port_write_append(virtio_port, (uint8_t*)&data_type, 4);
|
||||
}
|
||||
|
||||
vdagent_virtio_port_write_append(virtio_port, data, header->size);
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
if (header->type == VDAGENTD_CLIPBOARD_REQUEST) {
|
||||
/* Let the agent know no answer is coming */
|
||||
udscs_write(conn, VDAGENTD_CLIPBOARD_DATA,
|
||||
selection, VD_AGENT_CLIPBOARD_NONE, NULL, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* When we open the vdagent virtio channel, the server automatically goes into
|
||||
client mouse mode, so we can only have the channel open when we know the
|
||||
active session resolution. This function checks that we have an agent in the
|
||||
active session, and that it has told us its resolution. If these conditions
|
||||
are met it sets the uinput tablet device's resolution and opens the virtio
|
||||
channel (if it is not already open). If these conditions are not met, it
|
||||
closes both. */
|
||||
static void check_xorg_resolution(void)
|
||||
{
|
||||
struct agent_data *agent_data = udscs_get_user_data(active_session_conn);
|
||||
|
||||
if (agent_data && agent_data->screen_info) {
|
||||
if (!uinput)
|
||||
uinput = vdagentd_uinput_create(uinput_device,
|
||||
agent_data->width,
|
||||
agent_data->height,
|
||||
agent_data->screen_info,
|
||||
agent_data->screen_count,
|
||||
debug > 1);
|
||||
else
|
||||
vdagentd_uinput_update_size(&uinput,
|
||||
agent_data->width,
|
||||
agent_data->height,
|
||||
agent_data->screen_info,
|
||||
agent_data->screen_count);
|
||||
if (!uinput) {
|
||||
syslog(LOG_CRIT, "Fatal uinput error");
|
||||
retval = 1;
|
||||
quit = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!virtio_port) {
|
||||
syslog(LOG_INFO, "opening vdagent virtio channel");
|
||||
virtio_port = vdagent_virtio_port_create(portdev,
|
||||
virtio_port_read_complete,
|
||||
NULL);
|
||||
if (!virtio_port) {
|
||||
syslog(LOG_CRIT, "Fatal error opening vdagent virtio channel");
|
||||
retval = 1;
|
||||
quit = 1;
|
||||
return;
|
||||
}
|
||||
send_capabilities(virtio_port, 1);
|
||||
}
|
||||
} else {
|
||||
#ifndef WITH_STATIC_UINPUT
|
||||
vdagentd_uinput_destroy(&uinput);
|
||||
#endif
|
||||
if (virtio_port) {
|
||||
vdagent_virtio_port_flush(&virtio_port);
|
||||
vdagent_virtio_port_destroy(&virtio_port);
|
||||
syslog(LOG_INFO, "closed vdagent virtio channel");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_SESSION_INFO
|
||||
static int connection_matches_active_session(struct udscs_connection **connp,
|
||||
void *priv)
|
||||
{
|
||||
struct udscs_connection **conn_ret = (struct udscs_connection **)priv;
|
||||
struct agent_data *agent_data = udscs_get_user_data(*connp);
|
||||
|
||||
/* Check if this connection matches the currently active session */
|
||||
if (!agent_data->session || !active_session)
|
||||
return 0;
|
||||
if (strcmp(agent_data->session, active_session))
|
||||
return 0;
|
||||
|
||||
*conn_ret = *connp;
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
void release_clipboards(void)
|
||||
{
|
||||
uint8_t sel;
|
||||
|
||||
for (sel = 0; sel < VD_AGENT_CLIPBOARD_SELECTION_SECONDARY; ++sel) {
|
||||
if (agent_owns_clipboard[sel] && virtio_port) {
|
||||
vdagent_virtio_port_write(virtio_port, VDP_CLIENT_PORT,
|
||||
VD_AGENT_CLIPBOARD_RELEASE, 0, &sel, 1);
|
||||
}
|
||||
agent_owns_clipboard[sel] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void update_active_session_connection(void)
|
||||
{
|
||||
struct udscs_connection *new_conn = NULL;
|
||||
int n;
|
||||
|
||||
#ifdef HAVE_SESSION_INFO
|
||||
if (!active_session)
|
||||
active_session = session_info_get_active_session(session_info);
|
||||
|
||||
n = udscs_server_for_all_clients(server, connection_matches_active_session,
|
||||
(void*)&new_conn);
|
||||
if (n != 1)
|
||||
new_conn = NULL;
|
||||
|
||||
if (new_conn == active_session_conn)
|
||||
return;
|
||||
|
||||
active_session_conn = new_conn;
|
||||
if (debug)
|
||||
syslog(LOG_DEBUG, "%p is now the active session", new_conn);
|
||||
#endif
|
||||
|
||||
release_clipboards();
|
||||
|
||||
check_xorg_resolution();
|
||||
}
|
||||
|
||||
void agent_connect(struct udscs_connection *conn)
|
||||
{
|
||||
uint32_t pid;
|
||||
struct agent_data *agent_data;
|
||||
|
||||
agent_data = calloc(1, sizeof(*agent_data));
|
||||
if (!agent_data) {
|
||||
syslog(LOG_ERR, "Out of memory allocating agent data, disconnecting");
|
||||
udscs_destroy_connection(&conn);
|
||||
return;
|
||||
}
|
||||
#ifdef HAVE_SESSION_INFO
|
||||
pid = udscs_get_peer_cred(conn).pid;
|
||||
agent_data->session = session_info_session_for_pid(session_info, pid);
|
||||
#else
|
||||
session_count++;
|
||||
if (session_count == 1) {
|
||||
active_session_conn = conn;
|
||||
} else {
|
||||
/* disable communication with agents when we've got multiple
|
||||
* connections to the vdagentd and no consolekit since we can't
|
||||
* know to which one we should send data
|
||||
*/
|
||||
syslog(LOG_ERR, "Trying to use multiple vdagent without ConsoleKit, "
|
||||
"disabling vdagent to avoid potential information leak");
|
||||
active_session_conn = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
udscs_set_user_data(conn, (void *)agent_data);
|
||||
update_active_session_connection();
|
||||
|
||||
udscs_write(conn, VDAGENTD_VERSION, 0, 0,
|
||||
(uint8_t *)VERSION, strlen(VERSION) + 1);
|
||||
|
||||
if (mon_config)
|
||||
udscs_write(conn, VDAGENTD_MONITORS_CONFIG, 0, 0,
|
||||
(uint8_t *)mon_config, sizeof(VDAgentMonitorsConfig) +
|
||||
mon_config->num_of_monitors * sizeof(VDAgentMonConfig));
|
||||
}
|
||||
|
||||
void agent_disconnect(struct udscs_connection *conn)
|
||||
{
|
||||
struct agent_data *agent_data = udscs_get_user_data(conn);
|
||||
|
||||
#ifndef HAVE_SESSION_INFO
|
||||
if (conn == active_session_conn)
|
||||
active_session_conn = NULL;
|
||||
#endif
|
||||
|
||||
free(agent_data->session);
|
||||
agent_data->session = NULL;
|
||||
update_active_session_connection();
|
||||
|
||||
free(agent_data);
|
||||
#ifndef HAVE_SESSION_INFO
|
||||
session_count--;
|
||||
#endif
|
||||
}
|
||||
|
||||
void agent_read_complete(struct udscs_connection **connp,
|
||||
struct udscs_message_header *header, uint8_t *data)
|
||||
{
|
||||
struct agent_data *agent_data = udscs_get_user_data(*connp);
|
||||
|
||||
switch (header->type) {
|
||||
case VDAGENTD_GUEST_XORG_RESOLUTION: {
|
||||
struct vdagentd_guest_xorg_resolution *res;
|
||||
int n = header->size / sizeof(*res);
|
||||
|
||||
/* Detect older version session agent, but don't disconnect, as
|
||||
that stops it from getting the VDAGENTD_VERSION message, and then
|
||||
it will never re-exec the new version... */
|
||||
if (header->arg1 == 0 && header->arg2 == 0) {
|
||||
syslog(LOG_INFO, "got old session agent xorg resolution message, "
|
||||
"ignoring");
|
||||
free(data);
|
||||
return;
|
||||
}
|
||||
|
||||
if (header->size != n * sizeof(*res)) {
|
||||
syslog(LOG_ERR, "guest xorg resolution message has wrong size, "
|
||||
"disconnecting agent");
|
||||
udscs_destroy_connection(connp);
|
||||
free(data);
|
||||
return;
|
||||
}
|
||||
|
||||
free(agent_data->screen_info);
|
||||
res = malloc(n * sizeof(*res));
|
||||
if (!res) {
|
||||
syslog(LOG_ERR, "out of memory allocating screen info");
|
||||
n = 0;
|
||||
}
|
||||
memcpy(res, data, n * sizeof(*res));
|
||||
agent_data->width = header->arg1;
|
||||
agent_data->height = header->arg2;
|
||||
agent_data->screen_info = res;
|
||||
agent_data->screen_count = n;
|
||||
|
||||
check_xorg_resolution();
|
||||
break;
|
||||
}
|
||||
case VDAGENTD_CLIPBOARD_GRAB:
|
||||
case VDAGENTD_CLIPBOARD_REQUEST:
|
||||
case VDAGENTD_CLIPBOARD_DATA:
|
||||
case VDAGENTD_CLIPBOARD_RELEASE:
|
||||
if (do_agent_clipboard(*connp, header, data)) {
|
||||
udscs_destroy_connection(connp);
|
||||
free(data);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
syslog(LOG_ERR, "unknown message from vdagent: %u, ignoring",
|
||||
header->type);
|
||||
}
|
||||
free(data);
|
||||
}
|
||||
|
||||
/* main */
|
||||
|
||||
static void usage(FILE *fp)
|
||||
{
|
||||
fprintf(fp,
|
||||
"vdagentd\n"
|
||||
"options:\n"
|
||||
" -h print this text\n"
|
||||
" -d log debug messages (use twice for extra info)\n"
|
||||
" -s <port> set virtio serial port [%s]\n"
|
||||
" -u <dev> set uinput device [%s]\n"
|
||||
" -x don't daemonize\n",
|
||||
portdev, uinput_device);
|
||||
}
|
||||
|
||||
void daemonize(void)
|
||||
{
|
||||
int x;
|
||||
FILE *pidfile;
|
||||
|
||||
/* detach from terminal */
|
||||
switch (fork()) {
|
||||
case 0:
|
||||
close(0); close(1); close(2);
|
||||
setsid();
|
||||
x = open("/dev/null", O_RDWR); x = dup(x); x = dup(x);
|
||||
pidfile = fopen(pidfilename, "w");
|
||||
if (pidfile) {
|
||||
fprintf(pidfile, "%d\n", (int)getpid());
|
||||
fclose(pidfile);
|
||||
}
|
||||
break;
|
||||
case -1:
|
||||
syslog(LOG_ERR, "fork: %m");
|
||||
retval = 1;
|
||||
default:
|
||||
udscs_destroy_server(server);
|
||||
exit(retval);
|
||||
}
|
||||
}
|
||||
|
||||
void main_loop(void)
|
||||
{
|
||||
fd_set readfds, writefds;
|
||||
int n, nfds, ck_fd = 0;
|
||||
|
||||
while (!quit) {
|
||||
FD_ZERO(&readfds);
|
||||
FD_ZERO(&writefds);
|
||||
|
||||
nfds = udscs_server_fill_fds(server, &readfds, &writefds);
|
||||
n = vdagent_virtio_port_fill_fds(virtio_port, &readfds, &writefds);
|
||||
if (n >= nfds)
|
||||
nfds = n + 1;
|
||||
|
||||
#ifdef HAVE_SESSION_INFO
|
||||
ck_fd = session_info_get_fd(session_info);
|
||||
FD_SET(ck_fd, &readfds);
|
||||
if (ck_fd >= nfds)
|
||||
nfds = ck_fd + 1;
|
||||
#endif
|
||||
|
||||
n = select(nfds, &readfds, &writefds, NULL, NULL);
|
||||
if (n == -1) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
syslog(LOG_CRIT, "Fatal error select: %m");
|
||||
retval = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
udscs_server_handle_fds(server, &readfds, &writefds);
|
||||
|
||||
if (virtio_port) {
|
||||
vdagent_virtio_port_handle_fds(&virtio_port, &readfds, &writefds);
|
||||
if (!virtio_port) {
|
||||
syslog(LOG_CRIT,
|
||||
"AIIEEE lost spice client connection, reconnecting");
|
||||
virtio_port = vdagent_virtio_port_create(portdev,
|
||||
virtio_port_read_complete,
|
||||
NULL);
|
||||
}
|
||||
if (!virtio_port) {
|
||||
syslog(LOG_CRIT, "Fatal error opening vdagent virtio channel");
|
||||
retval = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_SESSION_INFO
|
||||
if (FD_ISSET(ck_fd, &readfds)) {
|
||||
active_session = session_info_get_active_session(session_info);
|
||||
update_active_session_connection();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static void quit_handler(int sig)
|
||||
{
|
||||
quit = 1;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int c;
|
||||
int do_daemonize = 1;
|
||||
struct sigaction act;
|
||||
|
||||
for (;;) {
|
||||
if (-1 == (c = getopt(argc, argv, "-dhxs:u:")))
|
||||
break;
|
||||
switch (c) {
|
||||
case 'd':
|
||||
debug++;
|
||||
break;
|
||||
case 's':
|
||||
portdev = optarg;
|
||||
break;
|
||||
case 'u':
|
||||
uinput_device = optarg;
|
||||
break;
|
||||
case 'x':
|
||||
do_daemonize = 0;
|
||||
break;
|
||||
case 'h':
|
||||
usage(stdout);
|
||||
return 0;
|
||||
default:
|
||||
usage(stderr);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
memset(&act, 0, sizeof(act));
|
||||
act.sa_flags = SA_RESTART;
|
||||
act.sa_handler = quit_handler;
|
||||
sigaction(SIGINT, &act, NULL);
|
||||
sigaction(SIGHUP, &act, NULL);
|
||||
sigaction(SIGTERM, &act, NULL);
|
||||
sigaction(SIGQUIT, &act, NULL);
|
||||
|
||||
openlog("spice-vdagentd", do_daemonize ? 0 : LOG_PERROR, LOG_USER);
|
||||
|
||||
/* Setup communication with vdagent process(es) */
|
||||
server = udscs_create_server(VDAGENTD_SOCKET, agent_connect,
|
||||
agent_read_complete, agent_disconnect,
|
||||
vdagentd_messages, VDAGENTD_NO_MESSAGES,
|
||||
debug);
|
||||
if (!server) {
|
||||
syslog(LOG_CRIT, "Fatal could not create server socket %s",
|
||||
VDAGENTD_SOCKET);
|
||||
return 1;
|
||||
}
|
||||
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);
|
||||
if (!uinput) {
|
||||
udscs_destroy_server(server);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SESSION_INFO
|
||||
session_info = session_info_create(debug);
|
||||
if (!session_info) {
|
||||
syslog(LOG_CRIT, "Fatal could not get session information");
|
||||
vdagentd_uinput_destroy(&uinput);
|
||||
udscs_destroy_server(server);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
main_loop();
|
||||
|
||||
release_clipboards();
|
||||
|
||||
vdagentd_uinput_destroy(&uinput);
|
||||
vdagent_virtio_port_flush(&virtio_port);
|
||||
vdagent_virtio_port_destroy(&virtio_port);
|
||||
#ifdef HAVE_SESSION_INFO
|
||||
session_info_destroy(session_info);
|
||||
#endif
|
||||
udscs_destroy_server(server);
|
||||
if (unlink(VDAGENTD_SOCKET) != 0)
|
||||
syslog(LOG_ERR, "unlink %s: %s", VDAGENTD_SOCKET, strerror(errno));
|
||||
syslog(LOG_INFO, "vdagentd quiting, returning status %d", retval);
|
||||
|
||||
if (do_daemonize)
|
||||
unlink(pidfilename);
|
||||
|
||||
return retval;
|
||||
}
|
||||
@@ -0,0 +1,637 @@
|
||||
/* console-kit.c vdagentd ConsoleKit integration code
|
||||
|
||||
Copyright 2010-2012 Red Hat, Inc.
|
||||
|
||||
Red Hat Authors:
|
||||
Hans de Goede <[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 "session-info.h"
|
||||
#include <dbus/dbus.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include <glib.h>
|
||||
|
||||
struct session_info {
|
||||
DBusConnection *connection;
|
||||
int fd;
|
||||
char *seat;
|
||||
char *active_session;
|
||||
int verbose;
|
||||
gchar *match_seat_signals;
|
||||
gchar *match_session_signals;
|
||||
gboolean session_is_locked;
|
||||
gboolean session_idle_hint;
|
||||
};
|
||||
|
||||
#define INTERFACE_CONSOLE_KIT "org.freedesktop.ConsoleKit"
|
||||
#define OBJ_PATH_CONSOLE_KIT "/org/freedesktop/ConsoleKit"
|
||||
|
||||
#define INTERFACE_CONSOLE_KIT_MANAGER INTERFACE_CONSOLE_KIT ".Manager"
|
||||
#define OBJ_PATH_CONSOLE_KIT_MANAGER OBJ_PATH_CONSOLE_KIT "/Manager"
|
||||
|
||||
#define INTERFACE_CONSOLE_KIT_SEAT INTERFACE_CONSOLE_KIT ".Seat"
|
||||
|
||||
#define INTERFACE_CONSOLE_KIT_SESSION INTERFACE_CONSOLE_KIT ".Session"
|
||||
#define OBJ_PATH_CONSOLE_KIT_SESSION OBJ_PATH_CONSOLE_KIT "/Session"
|
||||
|
||||
#define SEAT_SIGNAL_ACTIVE_SESSION_CHANGED "ActiveSessionChanged"
|
||||
|
||||
#define SESSION_SIGNAL_LOCK "Lock"
|
||||
#define SESSION_SIGNAL_UNLOCK "Unlock"
|
||||
#define SESSION_SIGNAL_IDLE_HINT_CHANGED "IdleHintChanged"
|
||||
|
||||
static char *console_kit_get_first_seat(struct session_info *info);
|
||||
static char *console_kit_check_active_session_change(struct session_info *info);
|
||||
|
||||
static void si_dbus_match_remove(struct session_info *info)
|
||||
{
|
||||
DBusError error;
|
||||
if (info->match_seat_signals != NULL) {
|
||||
dbus_error_init(&error);
|
||||
dbus_bus_remove_match(info->connection,
|
||||
info->match_seat_signals,
|
||||
&error);
|
||||
if (info->verbose)
|
||||
syslog(LOG_DEBUG, "(console-kit) seat match removed: %s",
|
||||
info->match_seat_signals);
|
||||
g_clear_pointer(&info->match_seat_signals, g_free);
|
||||
}
|
||||
|
||||
if (info->match_session_signals != NULL) {
|
||||
dbus_error_init(&error);
|
||||
dbus_bus_remove_match(info->connection,
|
||||
info->match_session_signals,
|
||||
&error);
|
||||
|
||||
if (info->verbose)
|
||||
syslog(LOG_DEBUG, "(console-kit) session match removed: %s",
|
||||
info->match_session_signals);
|
||||
g_clear_pointer(&info->match_session_signals, g_free);
|
||||
}
|
||||
}
|
||||
|
||||
static void si_dbus_match_rule_update(struct session_info *info)
|
||||
{
|
||||
DBusError error;
|
||||
|
||||
if (info->connection == NULL)
|
||||
return;
|
||||
|
||||
si_dbus_match_remove(info);
|
||||
|
||||
/* Seat signals */
|
||||
if (info->seat != NULL) {
|
||||
info->match_seat_signals =
|
||||
g_strdup_printf ("type='signal',interface='%s',path='%s',"
|
||||
"member='ActiveSessionChanged'",
|
||||
INTERFACE_CONSOLE_KIT_SEAT,
|
||||
info->seat);
|
||||
if (info->verbose)
|
||||
syslog(LOG_DEBUG, "(console-kit) seat match: %s",
|
||||
info->match_seat_signals);
|
||||
|
||||
dbus_error_init(&error);
|
||||
dbus_bus_add_match(info->connection,
|
||||
info->match_seat_signals,
|
||||
&error);
|
||||
if (dbus_error_is_set(&error)) {
|
||||
syslog(LOG_WARNING, "Unable to add dbus rule match: %s",
|
||||
error.message);
|
||||
dbus_error_free(&error);
|
||||
g_clear_pointer(&info->match_seat_signals, g_free);
|
||||
}
|
||||
}
|
||||
|
||||
/* Session signals */
|
||||
if (info->active_session != NULL) {
|
||||
info->match_session_signals =
|
||||
g_strdup_printf ("type='signal',interface='%s',path='%s'",
|
||||
INTERFACE_CONSOLE_KIT_SESSION,
|
||||
info->active_session);
|
||||
if (info->verbose)
|
||||
syslog(LOG_DEBUG, "(console-kit) session match: %s",
|
||||
info->match_session_signals);
|
||||
|
||||
dbus_error_init(&error);
|
||||
dbus_bus_add_match(info->connection,
|
||||
info->match_session_signals,
|
||||
&error);
|
||||
if (dbus_error_is_set(&error)) {
|
||||
syslog(LOG_WARNING, "Unable to add dbus rule match: %s",
|
||||
error.message);
|
||||
dbus_error_free(&error);
|
||||
g_clear_pointer(&info->match_session_signals, g_free);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
si_dbus_read_signals(struct session_info *info)
|
||||
{
|
||||
DBusMessage *message = NULL;
|
||||
|
||||
dbus_connection_read_write(info->connection, 0);
|
||||
message = dbus_connection_pop_message(info->connection);
|
||||
while (message != NULL) {
|
||||
const char *member;
|
||||
|
||||
member = dbus_message_get_member (message);
|
||||
if (g_strcmp0(member, SEAT_SIGNAL_ACTIVE_SESSION_CHANGED) == 0) {
|
||||
DBusMessageIter iter;
|
||||
gint type;
|
||||
gchar *session;
|
||||
|
||||
g_clear_pointer(&info->active_session, g_free);
|
||||
|
||||
dbus_message_iter_init(message, &iter);
|
||||
type = dbus_message_iter_get_arg_type(&iter);
|
||||
/* Session should be an object path, but there is a bug in
|
||||
ConsoleKit where it sends a string rather than an object_path
|
||||
accept object_path too in case the bug ever gets fixed */
|
||||
if (type == DBUS_TYPE_STRING || type == DBUS_TYPE_OBJECT_PATH) {
|
||||
dbus_message_iter_get_basic(&iter, &session);
|
||||
if (session != NULL && session[0] != '\0') {
|
||||
info->active_session = g_strdup(session);
|
||||
si_dbus_match_rule_update(info);
|
||||
} else {
|
||||
syslog(LOG_WARNING, "(console-kit) received invalid session. "
|
||||
"No active-session at the moment");
|
||||
}
|
||||
} else {
|
||||
syslog(LOG_ERR,
|
||||
"ActiveSessionChanged message has unexpected type: '%c'",
|
||||
type);
|
||||
}
|
||||
} else if (g_strcmp0(member, SESSION_SIGNAL_LOCK) == 0) {
|
||||
info->session_is_locked = TRUE;
|
||||
} else if (g_strcmp0(member, SESSION_SIGNAL_UNLOCK) == 0) {
|
||||
info->session_is_locked = FALSE;
|
||||
} else if (g_strcmp0(member, SESSION_SIGNAL_IDLE_HINT_CHANGED) == 0) {
|
||||
DBusMessageIter iter;
|
||||
gint type;
|
||||
dbus_bool_t idle_hint;
|
||||
|
||||
dbus_message_iter_init(message, &iter);
|
||||
type = dbus_message_iter_get_arg_type(&iter);
|
||||
if (type == DBUS_TYPE_BOOLEAN) {
|
||||
dbus_message_iter_get_basic(&iter, &idle_hint);
|
||||
info->session_idle_hint = (idle_hint);
|
||||
} else {
|
||||
syslog(LOG_ERR,
|
||||
"(console-kit) IdleHintChanged has unexpected type: '%c'",
|
||||
type);
|
||||
}
|
||||
} else {
|
||||
if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_SIGNAL) {
|
||||
syslog(LOG_WARNING, "(console-kit) received non signal message");
|
||||
} else if (info->verbose) {
|
||||
syslog(LOG_DEBUG, "(console-kit) Signal not handled: %s", member);
|
||||
}
|
||||
}
|
||||
|
||||
dbus_message_unref(message);
|
||||
dbus_connection_read_write(info->connection, 0);
|
||||
message = dbus_connection_pop_message(info->connection);
|
||||
}
|
||||
}
|
||||
|
||||
struct session_info *session_info_create(int verbose)
|
||||
{
|
||||
struct session_info *info;
|
||||
DBusError error;
|
||||
|
||||
info = g_new0(struct session_info, 1);
|
||||
info->verbose = verbose;
|
||||
info->session_is_locked = FALSE;
|
||||
info->session_idle_hint = FALSE;
|
||||
|
||||
dbus_error_init(&error);
|
||||
info->connection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
|
||||
if (info->connection == NULL || dbus_error_is_set(&error)) {
|
||||
if (dbus_error_is_set(&error)) {
|
||||
syslog(LOG_ERR, "Unable to connect to system bus: %s",
|
||||
error.message);
|
||||
dbus_error_free(&error);
|
||||
} else
|
||||
syslog(LOG_ERR, "Unable to connect to system bus");
|
||||
g_free(info);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!dbus_connection_get_unix_fd(info->connection, &info->fd)) {
|
||||
syslog(LOG_ERR, "Unable to get connection fd");
|
||||
session_info_destroy(info);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!console_kit_get_first_seat(info)) {
|
||||
session_info_destroy(info);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
si_dbus_match_rule_update(info);
|
||||
return info;
|
||||
}
|
||||
|
||||
void session_info_destroy(struct session_info *info)
|
||||
{
|
||||
if (!info)
|
||||
return;
|
||||
|
||||
si_dbus_match_remove(info);
|
||||
dbus_connection_close(info->connection);
|
||||
g_free(info->seat);
|
||||
g_free(info->active_session);
|
||||
g_free(info);
|
||||
}
|
||||
|
||||
int session_info_get_fd(struct session_info *info)
|
||||
{
|
||||
return info->fd;
|
||||
}
|
||||
|
||||
static char *console_kit_get_first_seat(struct session_info *info)
|
||||
{
|
||||
DBusError error;
|
||||
DBusMessage *message = NULL;
|
||||
DBusMessage *reply = NULL;
|
||||
DBusMessageIter iter, subiter;
|
||||
int type;
|
||||
char *seat = NULL;
|
||||
|
||||
|
||||
message = dbus_message_new_method_call(INTERFACE_CONSOLE_KIT,
|
||||
OBJ_PATH_CONSOLE_KIT_MANAGER,
|
||||
INTERFACE_CONSOLE_KIT_MANAGER,
|
||||
"GetSeats");
|
||||
if (message == NULL) {
|
||||
syslog(LOG_ERR, "Unable to create dbus message");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
dbus_error_init(&error);
|
||||
reply = dbus_connection_send_with_reply_and_block(info->connection,
|
||||
message,
|
||||
-1,
|
||||
&error);
|
||||
if (reply == NULL || dbus_error_is_set(&error)) {
|
||||
if (dbus_error_is_set(&error)) {
|
||||
syslog(LOG_ERR, "GetSeats failed: %s", error.message);
|
||||
dbus_error_free(&error);
|
||||
} else
|
||||
syslog(LOG_ERR, "GetSeats failed");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
dbus_message_iter_init(reply, &iter);
|
||||
type = dbus_message_iter_get_arg_type(&iter);
|
||||
if (type != DBUS_TYPE_ARRAY) {
|
||||
syslog(LOG_ERR,
|
||||
"expected an array return value, got a '%c' instead", type);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
dbus_message_iter_recurse(&iter, &subiter);
|
||||
type = dbus_message_iter_get_arg_type(&subiter);
|
||||
if (type != DBUS_TYPE_OBJECT_PATH) {
|
||||
syslog(LOG_ERR,
|
||||
"expected an object path element, got a '%c' instead", type);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
dbus_message_iter_get_basic(&subiter, &seat);
|
||||
info->seat = g_strdup(seat);
|
||||
|
||||
exit:
|
||||
if (reply != NULL) {
|
||||
dbus_message_unref(reply);
|
||||
}
|
||||
|
||||
if (message != NULL) {
|
||||
dbus_message_unref(message);
|
||||
}
|
||||
|
||||
syslog(LOG_INFO, "(console-kit) seat: %s", info->seat);
|
||||
return info->seat;
|
||||
}
|
||||
|
||||
const char *session_info_get_active_session(struct session_info *info)
|
||||
{
|
||||
DBusError error;
|
||||
DBusMessage *message = NULL;
|
||||
DBusMessage *reply = NULL;
|
||||
char *session = NULL;
|
||||
|
||||
if (!info)
|
||||
return NULL;
|
||||
|
||||
if (info->active_session)
|
||||
return console_kit_check_active_session_change(info);
|
||||
|
||||
message = dbus_message_new_method_call(INTERFACE_CONSOLE_KIT,
|
||||
info->seat,
|
||||
INTERFACE_CONSOLE_KIT_SEAT,
|
||||
"GetActiveSession");
|
||||
if (message == NULL) {
|
||||
syslog(LOG_ERR, "Unable to create dbus message");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
dbus_error_init(&error);
|
||||
reply = dbus_connection_send_with_reply_and_block(info->connection,
|
||||
message,
|
||||
-1,
|
||||
&error);
|
||||
if (reply == NULL || dbus_error_is_set(&error)) {
|
||||
if (dbus_error_is_set(&error)) {
|
||||
syslog(LOG_ERR, "GetActiveSession failed: %s", error.message);
|
||||
dbus_error_free(&error);
|
||||
} else
|
||||
syslog(LOG_ERR, "GetActiveSession failed");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
dbus_error_init(&error);
|
||||
if (!dbus_message_get_args(reply,
|
||||
&error,
|
||||
DBUS_TYPE_OBJECT_PATH, &session,
|
||||
DBUS_TYPE_INVALID)) {
|
||||
if (dbus_error_is_set(&error)) {
|
||||
syslog(LOG_ERR, "error get ssid from reply: %s", error.message);
|
||||
dbus_error_free(&error);
|
||||
} else
|
||||
syslog(LOG_ERR, "error getting ssid from reply");
|
||||
session = NULL;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
info->active_session = g_strdup(session);
|
||||
si_dbus_match_rule_update(info);
|
||||
|
||||
exit:
|
||||
if (reply != NULL) {
|
||||
dbus_message_unref(reply);
|
||||
}
|
||||
|
||||
if (message != NULL) {
|
||||
dbus_message_unref(message);
|
||||
}
|
||||
|
||||
/* In case the session was changed while we were running */
|
||||
return console_kit_check_active_session_change(info);
|
||||
}
|
||||
|
||||
char *session_info_session_for_pid(struct session_info *info, uint32_t pid)
|
||||
{
|
||||
DBusError error;
|
||||
DBusMessage *message = NULL;
|
||||
DBusMessage *reply = NULL;
|
||||
DBusMessageIter args;
|
||||
char *ssid = NULL;
|
||||
|
||||
if (!info)
|
||||
return NULL;
|
||||
|
||||
message = dbus_message_new_method_call(INTERFACE_CONSOLE_KIT,
|
||||
OBJ_PATH_CONSOLE_KIT_MANAGER,
|
||||
INTERFACE_CONSOLE_KIT_MANAGER,
|
||||
"GetSessionForUnixProcess");
|
||||
if (message == NULL) {
|
||||
syslog(LOG_ERR, "Unable to create dbus message");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
dbus_message_iter_init_append(message, &args);
|
||||
if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_UINT32, &pid)) {
|
||||
syslog(LOG_ERR, "Unable to append dbus message args");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
dbus_error_init(&error);
|
||||
reply = dbus_connection_send_with_reply_and_block(info->connection,
|
||||
message,
|
||||
-1,
|
||||
&error);
|
||||
if (reply == NULL || dbus_error_is_set(&error)) {
|
||||
if (dbus_error_is_set(&error)) {
|
||||
syslog(LOG_ERR, "GetSessionForUnixProcess failed: %s",
|
||||
error.message);
|
||||
dbus_error_free(&error);
|
||||
} else
|
||||
syslog(LOG_ERR, "GetSessionForUnixProcess failed");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
dbus_error_init(&error);
|
||||
if (!dbus_message_get_args(reply,
|
||||
&error,
|
||||
DBUS_TYPE_OBJECT_PATH, &ssid,
|
||||
DBUS_TYPE_INVALID)) {
|
||||
if (dbus_error_is_set(&error)) {
|
||||
syslog(LOG_ERR, "error get ssid from reply: %s", error.message);
|
||||
dbus_error_free(&error);
|
||||
} else
|
||||
syslog(LOG_ERR, "error getting ssid from reply");
|
||||
ssid = NULL;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
ssid = strdup(ssid);
|
||||
|
||||
exit:
|
||||
if (reply != NULL) {
|
||||
dbus_message_unref(reply);
|
||||
}
|
||||
|
||||
if (message != NULL) {
|
||||
dbus_message_unref(message);
|
||||
}
|
||||
|
||||
return ssid;
|
||||
}
|
||||
|
||||
static char *console_kit_check_active_session_change(struct session_info *info)
|
||||
{
|
||||
si_dbus_read_signals(info);
|
||||
if (info->verbose)
|
||||
syslog(LOG_DEBUG, "(console-kit) active-session: '%s'",
|
||||
(info->active_session ? info->active_session : "None"));
|
||||
|
||||
return info->active_session;
|
||||
}
|
||||
|
||||
gboolean session_info_session_is_locked(struct session_info *info)
|
||||
{
|
||||
gboolean locked;
|
||||
|
||||
g_return_val_if_fail (info != NULL, FALSE);
|
||||
|
||||
/* Not every system does emit Lock and Unlock signals (for instance, such
|
||||
* is the case for RHEL6) but most of the systems seems to emit the
|
||||
* IdleHintChanged. So use the IdleHint value.
|
||||
* systemd-login uses locked-hint which is not implemented in ConsoleKit,
|
||||
* see https://github.com/ConsoleKit2/ConsoleKit2/issues/89 */
|
||||
si_dbus_read_signals(info);
|
||||
locked = info->session_idle_hint;
|
||||
if (info->verbose) {
|
||||
syslog(LOG_DEBUG, "(console-kit) session is locked: %s",
|
||||
locked ? "yes" : "no");
|
||||
}
|
||||
return locked;
|
||||
}
|
||||
|
||||
/* This function should only be called after session_info_get_active_session
|
||||
* in order to verify if active session belongs to user (non greeter) */
|
||||
gboolean session_info_is_user(struct session_info *info)
|
||||
{
|
||||
DBusError error;
|
||||
DBusMessage *message = NULL;
|
||||
DBusMessage *reply = NULL;
|
||||
gchar *session_type = NULL;
|
||||
gboolean ret = TRUE;
|
||||
|
||||
g_return_val_if_fail (info != NULL, TRUE);
|
||||
g_return_val_if_fail (info->connection != NULL, TRUE);
|
||||
g_return_val_if_fail (info->active_session != NULL, TRUE);
|
||||
|
||||
message = dbus_message_new_method_call(INTERFACE_CONSOLE_KIT,
|
||||
info->active_session,
|
||||
INTERFACE_CONSOLE_KIT_SESSION,
|
||||
"GetSessionType");
|
||||
if (message == NULL) {
|
||||
syslog(LOG_ERR,
|
||||
"(console-kit) Unable to create dbus message for GetSessionType");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
dbus_error_init(&error);
|
||||
reply = dbus_connection_send_with_reply_and_block(info->connection,
|
||||
message,
|
||||
-1,
|
||||
&error);
|
||||
if (reply == NULL || dbus_error_is_set(&error)) {
|
||||
if (dbus_error_is_set(&error)) {
|
||||
syslog(LOG_ERR, "GetSessionType failed: %s", error.message);
|
||||
dbus_error_free(&error);
|
||||
} else
|
||||
syslog(LOG_ERR, "GetSessionType failed");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
dbus_error_init(&error);
|
||||
if (!dbus_message_get_args(reply,
|
||||
&error,
|
||||
DBUS_TYPE_STRING, &session_type,
|
||||
DBUS_TYPE_INVALID)) {
|
||||
if (dbus_error_is_set(&error)) {
|
||||
syslog(LOG_ERR,
|
||||
"(console-kit) fail to get session-type from reply: %s",
|
||||
error.message);
|
||||
dbus_error_free(&error);
|
||||
} else {
|
||||
syslog(LOG_ERR, "(console-kit) fail to get session-type from reply");
|
||||
}
|
||||
session_type = NULL;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* Empty session_type means user */
|
||||
if (info->verbose)
|
||||
syslog(LOG_DEBUG, "(console-kit) session-type is '%s'", session_type);
|
||||
|
||||
ret = (g_strcmp0 (session_type, "LoginWindow") != 0);
|
||||
|
||||
exit:
|
||||
if (reply != NULL) {
|
||||
dbus_message_unref(reply);
|
||||
}
|
||||
if (message != NULL) {
|
||||
dbus_message_unref(message);
|
||||
}
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/* dummy-session-info.c spice vdagentd dummy session info handler
|
||||
|
||||
Copyright 2013 Red Hat, Inc.
|
||||
|
||||
Red Hat Authors:
|
||||
Hans de Goede <[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 "session-info.h"
|
||||
|
||||
struct session_info *session_info_create(int verbose)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void session_info_destroy(struct session_info *si)
|
||||
{
|
||||
}
|
||||
|
||||
int session_info_get_fd(struct session_info *si)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *session_info_get_active_session(struct session_info *si)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *session_info_session_for_pid(struct session_info *si, uint32_t pid)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gboolean session_info_is_user(struct session_info *si)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -7,12 +7,12 @@
|
||||
|
||||
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
|
||||
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
|
||||
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
|
||||
@@ -24,10 +24,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined HAVE_CONSOLE_KIT || defined HAVE_LIBSYSTEMD_LOGIN
|
||||
#define HAVE_SESSION_INFO
|
||||
#endif
|
||||
#include <glib.h>
|
||||
|
||||
struct session_info;
|
||||
|
||||
@@ -40,4 +37,10 @@ const char *session_info_get_active_session(struct session_info *ck);
|
||||
/* Note result must be free()-ed by caller */
|
||||
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
|
||||
@@ -0,0 +1,405 @@
|
||||
/* systemd-login.c vdagentd libsystemd-login integration code
|
||||
|
||||
Copyright 2012 Red Hat, Inc.
|
||||
|
||||
Red Hat Authors:
|
||||
Hans de Goede <[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 "session-info.h"
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include <systemd/sd-login.h>
|
||||
#include <dbus/dbus.h>
|
||||
|
||||
struct session_info {
|
||||
int verbose;
|
||||
sd_login_monitor *mon;
|
||||
char *session;
|
||||
struct {
|
||||
DBusConnection *system_connection;
|
||||
char *match_session_signals;
|
||||
} dbus;
|
||||
gboolean session_is_locked;
|
||||
gboolean session_locked_hint;
|
||||
};
|
||||
|
||||
#define LOGIND_INTERFACE "org.freedesktop.login1"
|
||||
|
||||
#define LOGIND_SESSION_INTERFACE "org.freedesktop.login1.Session"
|
||||
#define LOGIND_SESSION_OBJ_TEMPLATE "/org/freedesktop/login1/session/_3%s"
|
||||
|
||||
#define DBUS_PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
|
||||
|
||||
#define SESSION_SIGNAL_LOCK "Lock"
|
||||
#define SESSION_SIGNAL_UNLOCK "Unlock"
|
||||
|
||||
#define SESSION_PROP_LOCKED_HINT "LockedHint"
|
||||
|
||||
/* dbus related */
|
||||
static DBusConnection *si_dbus_get_system_bus(void)
|
||||
{
|
||||
DBusConnection *connection;
|
||||
DBusError error;
|
||||
|
||||
dbus_error_init(&error);
|
||||
connection = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error);
|
||||
if (connection == NULL || dbus_error_is_set(&error)) {
|
||||
if (dbus_error_is_set(&error)) {
|
||||
syslog(LOG_WARNING, "Unable to connect to system bus: %s",
|
||||
error.message);
|
||||
dbus_error_free(&error);
|
||||
} else {
|
||||
syslog(LOG_WARNING, "Unable to connect to system bus");
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
||||
static void si_dbus_match_remove(struct session_info *si)
|
||||
{
|
||||
DBusError error;
|
||||
if (si->dbus.match_session_signals == NULL)
|
||||
return;
|
||||
|
||||
dbus_error_init(&error);
|
||||
dbus_bus_remove_match(si->dbus.system_connection,
|
||||
si->dbus.match_session_signals,
|
||||
&error);
|
||||
|
||||
g_clear_pointer(&si->dbus.match_session_signals, g_free);
|
||||
}
|
||||
|
||||
static void si_dbus_match_rule_update(struct session_info *si)
|
||||
{
|
||||
DBusError error;
|
||||
|
||||
if (si->dbus.system_connection == NULL ||
|
||||
si->session == NULL)
|
||||
return;
|
||||
|
||||
si_dbus_match_remove(si);
|
||||
|
||||
si->dbus.match_session_signals =
|
||||
g_strdup_printf ("type='signal',interface='%s',path='"
|
||||
LOGIND_SESSION_OBJ_TEMPLATE"'",
|
||||
LOGIND_SESSION_INTERFACE,
|
||||
si->session);
|
||||
if (si->verbose)
|
||||
syslog(LOG_DEBUG, "logind match: %s", si->dbus.match_session_signals);
|
||||
|
||||
dbus_error_init(&error);
|
||||
dbus_bus_add_match(si->dbus.system_connection,
|
||||
si->dbus.match_session_signals,
|
||||
&error);
|
||||
if (dbus_error_is_set(&error)) {
|
||||
syslog(LOG_WARNING, "Unable to add dbus rule match: %s",
|
||||
error.message);
|
||||
dbus_error_free(&error);
|
||||
g_clear_pointer(&si->dbus.match_session_signals, g_free);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
si_dbus_read_properties(struct session_info *si)
|
||||
{
|
||||
dbus_bool_t locked_hint, ret;
|
||||
DBusMessageIter iter, iter_variant;
|
||||
gint type;
|
||||
DBusError error;
|
||||
DBusMessage *message = NULL;
|
||||
DBusMessage *reply = NULL;
|
||||
gchar *session_object;
|
||||
const gchar *interface, *property;
|
||||
|
||||
if (si->session == NULL)
|
||||
return;
|
||||
|
||||
session_object = g_strdup_printf(LOGIND_SESSION_OBJ_TEMPLATE, si->session);
|
||||
message = dbus_message_new_method_call(LOGIND_INTERFACE,
|
||||
session_object,
|
||||
DBUS_PROPERTIES_INTERFACE,
|
||||
"Get");
|
||||
g_free (session_object);
|
||||
if (message == NULL) {
|
||||
syslog(LOG_ERR, "Unable to create dbus message");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
interface = LOGIND_SESSION_INTERFACE;
|
||||
property = SESSION_PROP_LOCKED_HINT;
|
||||
ret = dbus_message_append_args(message,
|
||||
DBUS_TYPE_STRING, &interface,
|
||||
DBUS_TYPE_STRING, &property,
|
||||
DBUS_TYPE_INVALID);
|
||||
if (!ret) {
|
||||
syslog(LOG_ERR, "Unable to request locked-hint");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
dbus_error_init(&error);
|
||||
reply = dbus_connection_send_with_reply_and_block(si->dbus.system_connection,
|
||||
message,
|
||||
-1,
|
||||
&error);
|
||||
if (reply == NULL) {
|
||||
if (dbus_error_is_set(&error)) {
|
||||
syslog(LOG_ERR, "Properties.Get failed (locked-hint) due %s", error.message);
|
||||
dbus_error_free(&error);
|
||||
} else {
|
||||
syslog(LOG_ERR, "Properties.Get failed (locked-hint)");
|
||||
}
|
||||
goto exit;
|
||||
}
|
||||
|
||||
dbus_message_iter_init(reply, &iter);
|
||||
type = dbus_message_iter_get_arg_type(&iter);
|
||||
if (type != DBUS_TYPE_VARIANT) {
|
||||
syslog(LOG_ERR, "expected a variant, got a '%c' instead", type);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
dbus_message_iter_recurse(&iter, &iter_variant);
|
||||
type = dbus_message_iter_get_arg_type(&iter_variant);
|
||||
if (type != DBUS_TYPE_BOOLEAN) {
|
||||
syslog(LOG_ERR, "expected a boolean, got a '%c' instead", type);
|
||||
goto exit;
|
||||
}
|
||||
dbus_message_iter_get_basic(&iter_variant, &locked_hint);
|
||||
|
||||
si->session_locked_hint = (locked_hint) ? TRUE : FALSE;
|
||||
exit:
|
||||
if (reply != NULL) {
|
||||
dbus_message_unref(reply);
|
||||
}
|
||||
|
||||
if (message != NULL) {
|
||||
dbus_message_unref(message);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
si_dbus_read_signals(struct session_info *si)
|
||||
{
|
||||
DBusMessage *message = NULL;
|
||||
|
||||
dbus_connection_read_write(si->dbus.system_connection, 0);
|
||||
message = dbus_connection_pop_message(si->dbus.system_connection);
|
||||
while (message != NULL) {
|
||||
const char *member;
|
||||
|
||||
member = dbus_message_get_member (message);
|
||||
if (g_strcmp0(member, SESSION_SIGNAL_LOCK) == 0) {
|
||||
si->session_is_locked = TRUE;
|
||||
} else if (g_strcmp0(member, SESSION_SIGNAL_UNLOCK) == 0) {
|
||||
si->session_is_locked = FALSE;
|
||||
} else {
|
||||
if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_SIGNAL) {
|
||||
syslog(LOG_WARNING, "(systemd-login) received non signal message");
|
||||
} else if (si->verbose) {
|
||||
syslog(LOG_DEBUG, "(systemd-login) Signal not handled: %s", member);
|
||||
}
|
||||
}
|
||||
|
||||
dbus_message_unref(message);
|
||||
dbus_connection_read_write(si->dbus.system_connection, 0);
|
||||
message = dbus_connection_pop_message(si->dbus.system_connection);
|
||||
}
|
||||
}
|
||||
|
||||
struct session_info *session_info_create(int verbose)
|
||||
{
|
||||
struct session_info *si;
|
||||
int r;
|
||||
|
||||
si = g_new0(struct session_info, 1);
|
||||
si->verbose = verbose;
|
||||
si->session_is_locked = FALSE;
|
||||
|
||||
r = sd_login_monitor_new("session", &si->mon);
|
||||
if (r < 0) {
|
||||
syslog(LOG_ERR, "Error creating login monitor: %s", strerror(-r));
|
||||
g_free(si);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
si->dbus.system_connection = si_dbus_get_system_bus();
|
||||
return si;
|
||||
}
|
||||
|
||||
void session_info_destroy(struct session_info *si)
|
||||
{
|
||||
if (!si)
|
||||
return;
|
||||
|
||||
si_dbus_match_remove(si);
|
||||
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);
|
||||
}
|
||||
|
||||
int session_info_get_fd(struct session_info *si)
|
||||
{
|
||||
return sd_login_monitor_get_fd(si->mon);
|
||||
}
|
||||
|
||||
const char *session_info_get_active_session(struct session_info *si)
|
||||
{
|
||||
int r;
|
||||
char *old_session = si->session;
|
||||
|
||||
si->session = NULL;
|
||||
r = sd_seat_get_active("seat0", &si->session, NULL);
|
||||
/* ENOENT happens when a seat is switching from one session to another */
|
||||
if (r < 0 && r != -ENOENT)
|
||||
syslog(LOG_ERR, "Error getting active session: %s",
|
||||
strerror(-r));
|
||||
|
||||
if (si->verbose && si->session &&
|
||||
(!old_session || strcmp(old_session, si->session)))
|
||||
syslog(LOG_INFO, "Active session: %s", si->session);
|
||||
|
||||
sd_login_monitor_flush(si->mon);
|
||||
g_free(old_session);
|
||||
|
||||
si_dbus_match_rule_update(si);
|
||||
return si->session;
|
||||
}
|
||||
|
||||
char *session_info_session_for_pid(struct session_info *si, uint32_t pid)
|
||||
{
|
||||
int i;
|
||||
int r;
|
||||
GStrv sessions = NULL;
|
||||
char *session = NULL;
|
||||
uid_t uid;
|
||||
|
||||
r = sd_pid_get_session(pid, &session);
|
||||
if (r >= 0) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* If we could not get a session for the pid then the agent is probably
|
||||
* running in a systemd managed session. In that case we simply assume
|
||||
* it is actually part of the newest graphical session we can find. */
|
||||
r = sd_pid_get_owner_uid(pid, &uid);
|
||||
if (r < 0) {
|
||||
syslog(LOG_ERR, "Error getting owner UID for pid %u: %s",
|
||||
pid, strerror(-r));
|
||||
goto out;
|
||||
}
|
||||
|
||||
r = sd_uid_get_sessions(uid, 0, &sessions);
|
||||
if (r < 0) {
|
||||
syslog(LOG_ERR, "Error getting sessions for UID %d: %s",
|
||||
(int) uid, strerror(-r));
|
||||
goto out;
|
||||
}
|
||||
|
||||
for (i = 0; sessions[i] != NULL; i++) {
|
||||
char *session_type = NULL;
|
||||
|
||||
r = sd_session_get_type(sessions[i], &session_type);
|
||||
|
||||
if (r < 0) {
|
||||
syslog(LOG_ERR, "Error getting session type for session %s: %s",
|
||||
sessions[i], strerror(-r));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (g_strcmp0(session_type, "wayland") == 0 ||
|
||||
g_strcmp0(session_type, "x11") == 0 ||
|
||||
g_strcmp0(session_type, "mir") == 0) {
|
||||
|
||||
/* We prefer the newest session (i.e. last entry) from the
|
||||
* user, assuming that any old session that still exist has
|
||||
* just not yet died properly. */
|
||||
if (session != NULL)
|
||||
free (session);
|
||||
session = g_strdup(sessions[i]);
|
||||
}
|
||||
|
||||
free(session_type);
|
||||
}
|
||||
|
||||
g_strfreev(sessions);
|
||||
|
||||
out:
|
||||
if (session != NULL && si->verbose) {
|
||||
syslog(LOG_INFO, "Session for pid %u: %s", pid, session);
|
||||
}
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
gboolean session_info_session_is_locked(struct session_info *si)
|
||||
{
|
||||
gboolean locked;
|
||||
|
||||
g_return_val_if_fail (si != NULL, FALSE);
|
||||
|
||||
si_dbus_read_signals(si);
|
||||
si_dbus_read_properties(si);
|
||||
|
||||
locked = (si->session_is_locked || si->session_locked_hint);
|
||||
if (si->verbose) {
|
||||
syslog(LOG_DEBUG, "(systemd-login) session is locked: %s",
|
||||
locked ? "yes" : "no");
|
||||
}
|
||||
return locked;
|
||||
}
|
||||
|
||||
/* This function should only be called after session_info_get_active_session
|
||||
* in order to verify if active session belongs to user (non greeter) */
|
||||
gboolean session_info_is_user(struct session_info *si)
|
||||
{
|
||||
gchar *class = NULL;
|
||||
gboolean ret;
|
||||
|
||||
g_return_val_if_fail (si != NULL, TRUE);
|
||||
g_return_val_if_fail (si->session != NULL, TRUE);
|
||||
|
||||
if (sd_session_get_class(si->session, &class) != 0) {
|
||||
syslog(LOG_WARNING, "Unable to get class from session: %s",
|
||||
si->session);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (si->verbose)
|
||||
syslog(LOG_DEBUG, "(systemd-login) class for %s is %s",
|
||||
si->session, class);
|
||||
|
||||
ret = (g_strcmp0(class, "user") == 0);
|
||||
g_free(class);
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/* vdagentd-uinput.c vdagentd uinput handling code
|
||||
|
||||
Copyright 2010-2012 Red Hat, Inc.
|
||||
Copyright 2010-2016 Red Hat, Inc.
|
||||
|
||||
Red Hat Authors:
|
||||
Hans de Goede <[email protected]>
|
||||
@@ -8,20 +8,18 @@
|
||||
|
||||
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
|
||||
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
|
||||
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/>.
|
||||
*/
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <syslog.h>
|
||||
@@ -31,7 +29,8 @@
|
||||
#include <linux/input.h>
|
||||
#include <linux/uinput.h>
|
||||
#include <spice/vd_agent.h>
|
||||
#include "vdagentd-uinput.h"
|
||||
#include <glib.h>
|
||||
#include "uinput.h"
|
||||
|
||||
struct vdagentd_uinput {
|
||||
const char *devname;
|
||||
@@ -42,22 +41,21 @@ struct vdagentd_uinput {
|
||||
struct vdagentd_guest_xorg_resolution *screen_info;
|
||||
int screen_count;
|
||||
VDAgentMouseState last;
|
||||
int fake;
|
||||
};
|
||||
|
||||
struct vdagentd_uinput *vdagentd_uinput_create(const char *devname,
|
||||
int width, int height,
|
||||
struct vdagentd_guest_xorg_resolution *screen_info, int screen_count,
|
||||
int debug)
|
||||
int debug, int fake)
|
||||
{
|
||||
struct vdagentd_uinput *uinput;
|
||||
|
||||
uinput = calloc(1, sizeof(*uinput));
|
||||
if (!uinput)
|
||||
return NULL;
|
||||
|
||||
uinput = g_new0(struct vdagentd_uinput, 1);
|
||||
uinput->devname = devname;
|
||||
uinput->fd = -1; /* Gets opened by vdagentd_uinput_update_size() */
|
||||
uinput->debug = debug;
|
||||
uinput->fake = fake;
|
||||
|
||||
vdagentd_uinput_update_size(&uinput, width, height,
|
||||
screen_info, screen_count);
|
||||
@@ -74,8 +72,7 @@ void vdagentd_uinput_destroy(struct vdagentd_uinput **uinputp)
|
||||
|
||||
if (uinput->fd != -1)
|
||||
close(uinput->fd);
|
||||
free(uinput);
|
||||
*uinputp = NULL;
|
||||
g_clear_pointer(uinputp, g_free);
|
||||
}
|
||||
|
||||
void vdagentd_uinput_update_size(struct vdagentd_uinput **uinputp,
|
||||
@@ -94,7 +91,14 @@ void vdagentd_uinput_update_size(struct vdagentd_uinput **uinputp,
|
||||
.absmax [ ABS_Y ] = height - 1,
|
||||
#endif
|
||||
};
|
||||
int rc;
|
||||
int i, rc;
|
||||
|
||||
if (uinput->debug) {
|
||||
syslog(LOG_DEBUG, "updating uinput size to %dx%d, screen positions:", width, height);
|
||||
for (i = 0; i < screen_count; i++) {
|
||||
syslog(LOG_DEBUG, " screen %d: +%d+%d", i, screen_info[i].x, screen_info[i].y);
|
||||
}
|
||||
}
|
||||
|
||||
uinput->screen_info = screen_info;
|
||||
uinput->screen_count = screen_count;
|
||||
@@ -112,13 +116,18 @@ void vdagentd_uinput_update_size(struct vdagentd_uinput **uinputp,
|
||||
return;
|
||||
#endif
|
||||
|
||||
uinput->fd = open(uinput->devname, O_RDWR);
|
||||
uinput->fd = open(uinput->devname, uinput->fake ? O_WRONLY : O_RDWR);
|
||||
if (uinput->fd == -1) {
|
||||
syslog(LOG_ERR, "open %s: %m", uinput->devname);
|
||||
vdagentd_uinput_destroy(uinputp);
|
||||
return;
|
||||
}
|
||||
|
||||
if (uinput->fake) {
|
||||
/* fake device doesn't understand any ioctls and only writes events */
|
||||
return;
|
||||
}
|
||||
|
||||
rc = write(uinput->fd, &device, sizeof(device));
|
||||
if (rc != sizeof(device)) {
|
||||
syslog(LOG_ERR, "write %s: %m", uinput->devname);
|
||||
@@ -131,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);
|
||||
@@ -166,6 +177,18 @@ static void uinput_send_event(struct vdagentd_uinput **uinputp,
|
||||
}
|
||||
}
|
||||
|
||||
static struct vdagentd_guest_xorg_resolution* lookup_screen_info(struct vdagentd_uinput *uinput, int display_id)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < uinput->screen_count; i++) {
|
||||
if (uinput->screen_info[i].display_id == display_id) {
|
||||
return &uinput->screen_info[i];
|
||||
}
|
||||
}
|
||||
syslog(LOG_WARNING, "Unable to find output index for display id %d", display_id);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void vdagentd_uinput_do_mouse(struct vdagentd_uinput **uinputp,
|
||||
VDAgentMouseState *mouse)
|
||||
{
|
||||
@@ -179,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 },
|
||||
@@ -187,13 +212,17 @@ void vdagentd_uinput_do_mouse(struct vdagentd_uinput **uinputp,
|
||||
int i, down;
|
||||
|
||||
if (*uinputp) {
|
||||
if (mouse->display_id >= uinput->screen_count) {
|
||||
syslog(LOG_WARNING, "mouse event for unknown monitor (%d >= %d)",
|
||||
mouse->display_id, uinput->screen_count);
|
||||
struct vdagentd_guest_xorg_resolution *screen_info = lookup_screen_info(uinput, mouse->display_id);
|
||||
if (screen_info == NULL) {
|
||||
syslog(LOG_WARNING, "mouse event for unknown monitor %d",
|
||||
mouse->display_id);
|
||||
return;
|
||||
}
|
||||
mouse->x += uinput->screen_info[mouse->display_id].x;
|
||||
mouse->y += uinput->screen_info[mouse->display_id].y;
|
||||
if (uinput->debug)
|
||||
syslog(LOG_DEBUG, "mouse-event: mon %d %dx%d", mouse->display_id,
|
||||
mouse->x, mouse->y);
|
||||
mouse->x += screen_info->x;
|
||||
mouse->y += screen_info->y;
|
||||
#ifdef WITH_STATIC_UINPUT
|
||||
mouse->x = mouse->x * 32767 / (uinput->width - 1);
|
||||
mouse->y = mouse->y * 32767 / (uinput->height - 1);
|
||||
@@ -8,12 +8,12 @@
|
||||
|
||||
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
|
||||
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
|
||||
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
|
||||
@@ -30,7 +30,7 @@ struct vdagentd_uinput;
|
||||
struct vdagentd_uinput *vdagentd_uinput_create(const char *devname,
|
||||
int width, int height,
|
||||
struct vdagentd_guest_xorg_resolution *screen_info, int screen_count,
|
||||
int debug);
|
||||
int debug, int fake);
|
||||
void vdagentd_uinput_destroy(struct vdagentd_uinput **uinputp);
|
||||
|
||||
void vdagentd_uinput_do_mouse(struct vdagentd_uinput **uinputp,
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,322 @@
|
||||
/* vdagent-virtio-port.c virtio port communication code
|
||||
|
||||
Copyright 2010 Red Hat, Inc.
|
||||
|
||||
Red Hat Authors:
|
||||
Hans de Goede <[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 <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <syslog.h>
|
||||
#include <gio/gio.h>
|
||||
#include <glib-unix.h>
|
||||
|
||||
#include "vdagent-connection.h"
|
||||
#include "virtio-port.h"
|
||||
|
||||
|
||||
struct vdagent_virtio_port_buf {
|
||||
uint8_t *buf;
|
||||
size_t size;
|
||||
size_t write_pos;
|
||||
};
|
||||
|
||||
/* Data to keep track of the assembling of vdagent messages per chunk port,
|
||||
for de-multiplexing the messages */
|
||||
struct vdagent_virtio_port_chunk_port_data {
|
||||
int message_header_read;
|
||||
int message_data_pos;
|
||||
VDAgentMessage message_header;
|
||||
uint8_t *message_data;
|
||||
};
|
||||
|
||||
struct _VirtioPort {
|
||||
VDAgentConnection parent_instance;
|
||||
|
||||
/* Per chunk port data */
|
||||
struct vdagent_virtio_port_chunk_port_data port_data[VDP_END_PORT];
|
||||
|
||||
struct vdagent_virtio_port_buf write_buf;
|
||||
|
||||
/* Callbacks */
|
||||
vdagent_virtio_port_read_callback read_callback;
|
||||
VDAgentConnErrorCb error_cb;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE(VirtioPort, virtio_port, VDAGENT_TYPE_CONNECTION)
|
||||
|
||||
static void vdagent_virtio_port_do_chunk(VDAgentConnection *conn,
|
||||
gpointer header_data,
|
||||
gpointer chunk_data);
|
||||
|
||||
static gsize conn_handle_header(VDAgentConnection *conn,
|
||||
gpointer header_buf)
|
||||
{
|
||||
VirtioPort *self = VIRTIO_PORT(conn);
|
||||
VDIChunkHeader *header = header_buf;
|
||||
GError *err;
|
||||
|
||||
header->size = GUINT32_FROM_LE(header->size);
|
||||
header->port = GUINT32_FROM_LE(header->port);
|
||||
|
||||
if (header->size > VD_AGENT_MAX_DATA_SIZE) {
|
||||
err = g_error_new(G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"chunk size %u too large", header->size);
|
||||
self->error_cb(conn, err);
|
||||
return 0;
|
||||
}
|
||||
if (header->port >= VDP_END_PORT) {
|
||||
err = g_error_new(G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"chunk port %u out of range", header->port);
|
||||
self->error_cb(conn, err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return header->size;
|
||||
}
|
||||
|
||||
static void virtio_port_init(VirtioPort *self)
|
||||
{
|
||||
}
|
||||
|
||||
static void virtio_port_finalize(GObject *obj)
|
||||
{
|
||||
VirtioPort *self = VIRTIO_PORT(obj);
|
||||
guint i;
|
||||
|
||||
g_free(self->write_buf.buf);
|
||||
|
||||
for (i = 0; i < VDP_END_PORT; i++) {
|
||||
g_free(self->port_data[i].message_data);
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS(virtio_port_parent_class)->finalize(obj);
|
||||
}
|
||||
|
||||
static void virtio_port_class_init(VirtioPortClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
|
||||
VDAgentConnectionClass *conn_class = VDAGENT_CONNECTION_CLASS(klass);
|
||||
|
||||
gobject_class->finalize = virtio_port_finalize;
|
||||
|
||||
conn_class->handle_header = conn_handle_header;
|
||||
conn_class->handle_message = vdagent_virtio_port_do_chunk;
|
||||
}
|
||||
|
||||
VirtioPort *vdagent_virtio_port_create(const char *portname,
|
||||
vdagent_virtio_port_read_callback read_callback,
|
||||
VDAgentConnErrorCb error_cb)
|
||||
{
|
||||
VirtioPort *vport;
|
||||
GIOStream *io_stream;
|
||||
GError *err = NULL;
|
||||
|
||||
io_stream = vdagent_file_open(portname, &err);
|
||||
if (err) {
|
||||
syslog(LOG_ERR, "%s: %s", __func__, err->message);
|
||||
g_clear_error(&err);
|
||||
io_stream = vdagent_socket_connect(portname, &err);
|
||||
if (err) {
|
||||
syslog(LOG_ERR, "%s: %s", __func__, err->message);
|
||||
g_error_free(err);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
vport = g_object_new(VIRTIO_TYPE_PORT, NULL);
|
||||
|
||||
/* When calling vdagent_connection_new(),
|
||||
* @wait_on_opening MUST be set to TRUE:
|
||||
*
|
||||
* When we open the virtio serial port, the following happens:
|
||||
* 1) The linux kernel virtio_console driver sends a
|
||||
* VIRTIO_CONSOLE_PORT_OPEN message to qemu
|
||||
* 2) qemu's spicevmc chardev driver calls qemu_spice_add_interface to
|
||||
* register the agent chardev with the spice-server
|
||||
* 3) spice-server then calls the spicevmc chardev driver's state
|
||||
* callback to let it know it is ready to receive data
|
||||
* 4) The state callback sends a CHR_EVENT_OPENED to the virtio-console
|
||||
* chardev backend
|
||||
* 5) The virtio-console chardev backend sends VIRTIO_CONSOLE_PORT_OPEN
|
||||
* to the linux kernel virtio_console driver
|
||||
*
|
||||
* Until steps 1 - 5 have completed the linux kernel virtio_console
|
||||
* driver sees the virtio serial port as being in a disconnected state
|
||||
* and read will return 0 ! So if we blindly assume that a read 0 means
|
||||
* that the channel is closed we will hit a race here.
|
||||
*/
|
||||
vdagent_connection_setup(VDAGENT_CONNECTION(vport),
|
||||
io_stream,
|
||||
TRUE,
|
||||
sizeof(VDIChunkHeader),
|
||||
error_cb);
|
||||
|
||||
vport->read_callback = read_callback;
|
||||
vport->error_cb = error_cb;
|
||||
|
||||
return vport;
|
||||
}
|
||||
|
||||
void vdagent_virtio_port_write_start(
|
||||
VirtioPort *vport,
|
||||
uint32_t port_nr,
|
||||
uint32_t message_type,
|
||||
uint32_t message_opaque,
|
||||
uint32_t data_size)
|
||||
{
|
||||
struct vdagent_virtio_port_buf *new_wbuf;
|
||||
VDIChunkHeader *chunk_header;
|
||||
VDAgentMessage *message_header;
|
||||
|
||||
g_return_if_fail(vport->write_buf.buf == NULL);
|
||||
|
||||
new_wbuf = &vport->write_buf;
|
||||
new_wbuf->write_pos = 0;
|
||||
new_wbuf->size = sizeof(*chunk_header) + sizeof(*message_header) + data_size;
|
||||
new_wbuf->buf = g_malloc(new_wbuf->size);
|
||||
|
||||
chunk_header = (VDIChunkHeader *) (new_wbuf->buf + new_wbuf->write_pos);
|
||||
chunk_header->port = GUINT32_TO_LE(port_nr);
|
||||
chunk_header->size = GUINT32_TO_LE(sizeof(*message_header) + data_size);
|
||||
new_wbuf->write_pos += sizeof(*chunk_header);
|
||||
|
||||
message_header = (VDAgentMessage *) (new_wbuf->buf + new_wbuf->write_pos);
|
||||
message_header->protocol = GUINT32_TO_LE(VD_AGENT_PROTOCOL);
|
||||
message_header->type = GUINT32_TO_LE(message_type);
|
||||
message_header->opaque = GUINT64_TO_LE(message_opaque);
|
||||
message_header->size = GUINT32_TO_LE(data_size);
|
||||
new_wbuf->write_pos += sizeof(*message_header);
|
||||
}
|
||||
|
||||
int vdagent_virtio_port_write_append(VirtioPort *vport,
|
||||
const uint8_t *data, uint32_t size)
|
||||
{
|
||||
struct vdagent_virtio_port_buf *wbuf;
|
||||
|
||||
if (size == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
wbuf = &vport->write_buf;
|
||||
if (!wbuf->buf) {
|
||||
syslog(LOG_ERR, "can't append without a buffer");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (wbuf->size - wbuf->write_pos < size) {
|
||||
syslog(LOG_ERR, "can't append to full buffer");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(wbuf->buf + wbuf->write_pos, data, size);
|
||||
wbuf->write_pos += size;
|
||||
|
||||
if (wbuf->write_pos == wbuf->size) {
|
||||
vdagent_connection_write(VDAGENT_CONNECTION(vport), wbuf->buf, wbuf->size);
|
||||
wbuf->buf = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void vdagent_virtio_port_write(
|
||||
VirtioPort *vport,
|
||||
uint32_t port_nr,
|
||||
uint32_t message_type,
|
||||
uint32_t message_opaque,
|
||||
const uint8_t *data,
|
||||
uint32_t data_size)
|
||||
{
|
||||
vdagent_virtio_port_write_start(vport, port_nr, message_type,
|
||||
message_opaque, data_size);
|
||||
vdagent_virtio_port_write_append(vport, data, data_size);
|
||||
}
|
||||
|
||||
void vdagent_virtio_port_reset(VirtioPort *vport, int port)
|
||||
{
|
||||
if (port >= VDP_END_PORT) {
|
||||
syslog(LOG_ERR, "vdagent_virtio_port_reset port out of range");
|
||||
return;
|
||||
}
|
||||
g_free(vport->port_data[port].message_data);
|
||||
memset(&vport->port_data[port], 0, sizeof(vport->port_data[0]));
|
||||
}
|
||||
|
||||
static void vdagent_virtio_port_do_chunk(VDAgentConnection *conn,
|
||||
gpointer header_data,
|
||||
gpointer chunk_data)
|
||||
{
|
||||
int avail, read, pos = 0;
|
||||
VirtioPort *vport = VIRTIO_PORT(conn);
|
||||
VDIChunkHeader *chunk_header = header_data;
|
||||
struct vdagent_virtio_port_chunk_port_data *port =
|
||||
&vport->port_data[chunk_header->port];
|
||||
|
||||
if (port->message_header_read < sizeof(port->message_header)) {
|
||||
read = sizeof(port->message_header) - port->message_header_read;
|
||||
if (read > chunk_header->size) {
|
||||
read = chunk_header->size;
|
||||
}
|
||||
memcpy((uint8_t *)&port->message_header + port->message_header_read,
|
||||
chunk_data, read);
|
||||
port->message_header_read += read;
|
||||
if (port->message_header_read == sizeof(port->message_header)) {
|
||||
|
||||
port->message_header.protocol = GUINT32_FROM_LE(port->message_header.protocol);
|
||||
port->message_header.type = GUINT32_FROM_LE(port->message_header.type);
|
||||
port->message_header.opaque = GUINT64_FROM_LE(port->message_header.opaque);
|
||||
port->message_header.size = GUINT32_FROM_LE(port->message_header.size);
|
||||
|
||||
if (port->message_header.size) {
|
||||
port->message_data = g_malloc(port->message_header.size);
|
||||
}
|
||||
}
|
||||
pos = read;
|
||||
}
|
||||
|
||||
if (port->message_header_read == sizeof(port->message_header)) {
|
||||
read = port->message_header.size - port->message_data_pos;
|
||||
avail = chunk_header->size - pos;
|
||||
|
||||
if (avail > read) {
|
||||
GError *err = g_error_new(G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
"chunk larger than message, lost sync?");
|
||||
vport->error_cb(VDAGENT_CONNECTION(vport), err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (avail < read)
|
||||
read = avail;
|
||||
|
||||
if (read) {
|
||||
memcpy(port->message_data + port->message_data_pos,
|
||||
chunk_data + pos, read);
|
||||
port->message_data_pos += read;
|
||||
}
|
||||
|
||||
if (port->message_data_pos == port->message_header.size) {
|
||||
if (vport->read_callback) {
|
||||
vport->read_callback(vport, chunk_header->port,
|
||||
&port->message_header, port->message_data);
|
||||
}
|
||||
port->message_header_read = 0;
|
||||
port->message_data_pos = 0;
|
||||
g_clear_pointer(&port->message_data, g_free);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/* virtio-port.h virtio port communication header
|
||||
|
||||
Copyright 2010 - 2016 Red Hat, Inc.
|
||||
|
||||
Red Hat Authors:
|
||||
Hans de Goede <[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 __VIRTIO_PORT_H
|
||||
#define __VIRTIO_PORT_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <spice/vd_agent.h>
|
||||
#include <glib-object.h>
|
||||
#include "vdagent-connection.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define VIRTIO_TYPE_PORT virtio_port_get_type()
|
||||
G_DECLARE_FINAL_TYPE(VirtioPort, virtio_port, VIRTIO, PORT, VDAgentConnection)
|
||||
|
||||
/* Callbacks with this type will be called when a complete message has been
|
||||
received. */
|
||||
typedef void (*vdagent_virtio_port_read_callback)(
|
||||
VirtioPort *vport,
|
||||
int port_nr,
|
||||
VDAgentMessage *message_header,
|
||||
uint8_t *data);
|
||||
|
||||
/* Create a vdagent virtio port object for port portname */
|
||||
VirtioPort *vdagent_virtio_port_create(const char *portname,
|
||||
vdagent_virtio_port_read_callback read_callback,
|
||||
VDAgentConnErrorCb error_cb);
|
||||
|
||||
/* Queue a message for delivery, either bit by bit, or all at once */
|
||||
void vdagent_virtio_port_write_start(
|
||||
VirtioPort *vport,
|
||||
uint32_t port_nr,
|
||||
uint32_t message_type,
|
||||
uint32_t message_opaque,
|
||||
uint32_t data_size);
|
||||
|
||||
int vdagent_virtio_port_write_append(
|
||||
VirtioPort *vport,
|
||||
const uint8_t *data,
|
||||
uint32_t size);
|
||||
|
||||
void vdagent_virtio_port_write(
|
||||
VirtioPort *vport,
|
||||
uint32_t port_nr,
|
||||
uint32_t message_type,
|
||||
uint32_t message_opaque,
|
||||
const uint8_t *data,
|
||||
uint32_t data_size);
|
||||
|
||||
void vdagent_virtio_port_reset(VirtioPort *vport, int port);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
||||
@@ -18,9 +18,7 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_PCIACCESS
|
||||
#include <pciaccess.h>
|
||||
@@ -30,7 +28,7 @@
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <syslog.h>
|
||||
#include "vdagentd-xorg-conf.h"
|
||||
#include "xorg-conf.h"
|
||||
|
||||
#define FPRINTF(...) \
|
||||
do { \
|
||||
@@ -56,8 +54,8 @@ void vdagentd_write_xorg_conf(VDAgentMonitorsConfig *monitor_conf)
|
||||
.subvendor_id = PCI_MATCH_ANY,
|
||||
.subdevice_id = PCI_MATCH_ANY,
|
||||
};
|
||||
const char *xorg_conf = "/var/run/spice-vdagentd/xorg.conf.spice";
|
||||
const char *xorg_conf_old = "/var/run/spice-vdagentd/xorg.conf.spice.old";
|
||||
const char *xorg_conf = "/run/spice-vdagentd/xorg.conf.spice";
|
||||
const char *xorg_conf_old = "/run/spice-vdagentd/xorg.conf.spice.old";
|
||||
|
||||
r = rename(xorg_conf, xorg_conf_old);
|
||||
if (r && errno != ENOENT) {
|
||||
@@ -116,13 +114,11 @@ void vdagentd_write_xorg_conf(VDAgentMonitorsConfig *monitor_conf)
|
||||
FPRINTF("\tDriver\t\t\"qxl\"\n");
|
||||
FPRINTF("\tBusID\t\t\"PCI:%02d:%02d:%d\"\n",
|
||||
dev->bus, dev->dev, dev->func);
|
||||
FPRINTF("\tOption\t\t\"NumHeads\"\t\"1\"\n");
|
||||
FPRINTF("EndSection\n\n");
|
||||
} while ((dev = pci_device_next(it)));
|
||||
|
||||
if (i < monitor_conf->num_of_monitors) {
|
||||
syslog(LOG_WARNING,
|
||||
"Client has %d monitors, but only %d qxl devices found",
|
||||
monitor_conf->num_of_monitors, i);
|
||||
FPRINTF("# Client has %d monitors, but only %d qxl devices found\n",
|
||||
monitor_conf->num_of_monitors, i);
|
||||
FPRINTF("# Only generation %d \"Screen\" sections\n\n", i);
|
||||
@@ -7,12 +7,12 @@
|
||||
|
||||
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
|
||||
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
|
||||
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
|
||||
@@ -0,0 +1,262 @@
|
||||
/* test-device-info.c tests to see whether the functionality for converting a
|
||||
* device address to a xrandr output are working properly
|
||||
*
|
||||
* Copyright 2018 Red Hat, Inc.
|
||||
*
|
||||
* Red Hat Authors:
|
||||
* Jonathon Jongsma <[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/>.
|
||||
*/
|
||||
|
||||
// just include the source file for testing
|
||||
#include "vdagent/device-info.c"
|
||||
|
||||
#define assert_device(dev, domain_, bus_, slot_, function_) \
|
||||
{ \
|
||||
PciDevice* dev_ = (dev); \
|
||||
assert(dev_ != NULL); \
|
||||
assert(dev_->domain == domain_); \
|
||||
assert(dev_->bus == bus_); \
|
||||
assert(dev_->slot == slot_); \
|
||||
assert(dev_->function == function_); \
|
||||
}
|
||||
|
||||
static void test_compare_addresses()
|
||||
{
|
||||
{
|
||||
PciDevice da1 = {1, 0, 3, 0};
|
||||
PciDevice da2 = {1, 1, 1, 0};
|
||||
PciDevice da3 = {1, 2, 3, 0};
|
||||
PciAddress a1 = {1, NULL};
|
||||
a1.domain = 0;
|
||||
a1.devices = g_list_append(a1.devices, &da1);
|
||||
a1.devices = g_list_append(a1.devices, &da2);
|
||||
a1.devices = g_list_append(a1.devices, &da3);
|
||||
|
||||
PciDevice db1 = {1, 0, 3, 0};
|
||||
PciDevice db2 = {1, 1, 1, 0};
|
||||
PciDevice db3 = {1, 2, 3, 0};
|
||||
PciAddress a2 = {1, NULL};
|
||||
a2.domain = 0;
|
||||
a2.devices = g_list_append(a2.devices, &db1);
|
||||
a2.devices = g_list_append(a2.devices, &db2);
|
||||
a2.devices = g_list_append(a2.devices, &db3);
|
||||
|
||||
assert(compare_addresses(&a1, &a2));
|
||||
}
|
||||
{
|
||||
PciDevice da1 = {1, 0, 3, 0};
|
||||
PciDevice da2 = {1, 1, 1, 0};
|
||||
PciDevice da3 = {1, 2, 3, 0};
|
||||
PciAddress a1 = {1, NULL};
|
||||
a1.domain = 0;
|
||||
a1.devices = g_list_append(a1.devices, &da1);
|
||||
a1.devices = g_list_append(a1.devices, &da2);
|
||||
a1.devices = g_list_append(a1.devices, &da3);
|
||||
|
||||
// a 'spice' format PCI address will not provide domain or bus for each
|
||||
// device, only slot and function. So first two numbers for each device
|
||||
// will always be set to 0
|
||||
PciDevice db1 = {0, 0, 3, 0};
|
||||
PciDevice db2 = {0, 0, 1, 0};
|
||||
PciDevice db3 = {0, 0, 3, 0};
|
||||
PciAddress a2 = {1, NULL};
|
||||
a2.domain = 0;
|
||||
a2.devices = g_list_append(a2.devices, &db1);
|
||||
a2.devices = g_list_append(a2.devices, &db2);
|
||||
a2.devices = g_list_append(a2.devices, &db3);
|
||||
|
||||
assert(compare_addresses(&a1, &a2));
|
||||
}
|
||||
// different number of devices
|
||||
{
|
||||
PciDevice da1 = {0, 0, 3, 0};
|
||||
PciDevice da2 = {0, 1, 1, 0};
|
||||
PciDevice da3 = {0, 2, 3, 0};
|
||||
PciAddress a1 = {0, NULL};
|
||||
a1.domain = 0;
|
||||
a1.devices = g_list_append(a1.devices, &da1);
|
||||
a1.devices = g_list_append(a1.devices, &da2);
|
||||
a1.devices = g_list_append(a1.devices, &da3);
|
||||
|
||||
PciDevice db1 = {0, 0, 3, 0};
|
||||
PciDevice db2 = {0, 1, 1, 0};
|
||||
PciAddress a2 = {0, NULL};
|
||||
a2.domain = 0;
|
||||
a2.devices = g_list_append(a2.devices, &db1);
|
||||
a2.devices = g_list_append(a2.devices, &db2);
|
||||
|
||||
assert(!compare_addresses(&a1, &a2));
|
||||
}
|
||||
// mismatched function
|
||||
{
|
||||
PciDevice da1 = {0, 0, 2, 0};
|
||||
PciAddress a1 = {0, NULL};
|
||||
a1.domain = 0;
|
||||
a1.devices = g_list_append(a1.devices, &da1);
|
||||
|
||||
PciDevice db1 = {0, 0, 2, 1};
|
||||
PciAddress a2 = {0, NULL};
|
||||
a2.domain = 0;
|
||||
a2.devices = g_list_append(a2.devices, &db1);
|
||||
|
||||
assert(!compare_addresses(&a1, &a2));
|
||||
}
|
||||
// mismatched slot
|
||||
{
|
||||
PciDevice da1 = {0, 0, 2, 0};
|
||||
PciAddress a1 = {0, NULL};
|
||||
a1.domain = 0;
|
||||
a1.devices = g_list_append(a1.devices, &da1);
|
||||
|
||||
PciDevice db1 = {0, 0, 1, 0};
|
||||
PciAddress a2 = {0, NULL};
|
||||
a2.domain = 0;
|
||||
a2.devices = g_list_append(a2.devices, &db1);
|
||||
|
||||
assert(!compare_addresses(&a1, &a2));
|
||||
}
|
||||
// mismatched domain
|
||||
{
|
||||
PciDevice da1 = {0, 0, 2, 0};
|
||||
PciAddress a1 = {0, NULL};
|
||||
a1.domain = 1;
|
||||
a1.devices = g_list_append(a1.devices, &da1);
|
||||
|
||||
PciDevice db1 = {0, 0, 2, 0};
|
||||
PciAddress a2 = {0, NULL};
|
||||
a2.domain = 0;
|
||||
a2.devices = g_list_append(a2.devices, &db1);
|
||||
|
||||
assert(!compare_addresses(&a1, &a2));
|
||||
}
|
||||
}
|
||||
|
||||
static void test_spice_parsing()
|
||||
{
|
||||
PciAddress *addr = parse_pci_address_from_spice("pci/0000/02.0");
|
||||
assert(addr != NULL);
|
||||
assert(addr->domain == 0);
|
||||
assert(g_list_length(addr->devices) == 1);
|
||||
assert_device(addr->devices->data, 0, 0, 2, 0);
|
||||
pci_address_free(addr);
|
||||
|
||||
addr = parse_pci_address_from_spice("pci/ffff/ff.f");
|
||||
assert(addr != NULL);
|
||||
assert(addr->domain == 65535);
|
||||
assert(g_list_length(addr->devices) == 1);
|
||||
assert_device(addr->devices->data, 0, 0, 255, 15);
|
||||
pci_address_free(addr);
|
||||
|
||||
addr = parse_pci_address_from_spice("pci/0000/02.1/03.0");
|
||||
assert(addr != NULL);
|
||||
assert(addr->domain == 0);
|
||||
assert(g_list_length(addr->devices) == 2);
|
||||
assert_device(addr->devices->data, 0, 0, 2, 1);
|
||||
assert_device(addr->devices->next->data, 0, 0, 3, 0);
|
||||
pci_address_free(addr);
|
||||
|
||||
addr = parse_pci_address_from_spice("pci/000a/01.0/02.1/03.0");
|
||||
assert(addr != NULL);
|
||||
assert(addr->domain == 10);
|
||||
assert(g_list_length(addr->devices) == 3);
|
||||
assert_device(addr->devices->data, 0, 0, 1, 0);
|
||||
assert_device(addr->devices->next->data, 0, 0, 2, 1);
|
||||
assert_device(addr->devices->next->next->data, 0, 0, 3, 0);
|
||||
pci_address_free(addr);
|
||||
|
||||
addr = parse_pci_address_from_spice("pcx/0000/02.1/03.0");
|
||||
assert(addr == NULL);
|
||||
|
||||
addr = parse_pci_address_from_spice("0000/02.0");
|
||||
assert(addr == NULL);
|
||||
|
||||
addr = parse_pci_address_from_spice("0000/02.1/03.0");
|
||||
assert(addr == NULL);
|
||||
}
|
||||
|
||||
static void test_sysfs_parsing()
|
||||
{
|
||||
PciAddress *addr = parse_pci_address_from_sysfs_path("../../devices/pci0000:00/0000:00:02.0/drm/card0");
|
||||
assert(addr != NULL);
|
||||
assert(addr->domain == 0);
|
||||
assert(g_list_length(addr->devices) == 1);
|
||||
assert_device(addr->devices->data, 0, 0, 2, 0);
|
||||
pci_address_free(addr);
|
||||
|
||||
addr = parse_pci_address_from_sysfs_path("../../devices/pciffff:ff/ffff:ff:ff.f/drm/card0");
|
||||
assert(addr != NULL);
|
||||
assert(addr->domain == 65535);
|
||||
assert(g_list_length(addr->devices) == 1);
|
||||
assert_device(addr->devices->data, 65535, 255, 255, 15);
|
||||
pci_address_free(addr);
|
||||
|
||||
addr = parse_pci_address_from_sysfs_path("../../devices/pci0000:00/0000:00:03.0/0000:01:01.0/0000:02:03.0/virtio2/drm/card0");
|
||||
assert(addr != NULL);
|
||||
assert(addr->domain == 0);
|
||||
assert(g_list_length(addr->devices) == 3);
|
||||
assert_device(addr->devices->data, 0, 0, 3, 0);
|
||||
assert_device(addr->devices->next->data, 0, 1, 1, 0);
|
||||
assert_device(addr->devices->next->next->data, 0, 2, 3, 0);
|
||||
pci_address_free(addr);
|
||||
}
|
||||
|
||||
// verify that we parse the BDF notation correctly
|
||||
static bool test_bdf(const char* string, int domain, uint8_t bus, uint8_t slot, uint8_t function)
|
||||
{
|
||||
PciDevice pci_dev;
|
||||
return (parse_pci_device(string, NULL, &pci_dev)
|
||||
&& (pci_dev.domain == domain)
|
||||
&& (pci_dev.bus == bus)
|
||||
&& (pci_dev.slot == slot)
|
||||
&& (pci_dev.function == function));
|
||||
}
|
||||
|
||||
static void test_bdf_parsing()
|
||||
{
|
||||
// valid input
|
||||
assert(test_bdf("0000:00:02.1", 0, 0, 2, 1));
|
||||
assert(test_bdf("00:00:02.1", 0, 0, 2, 1));
|
||||
assert(test_bdf("0000:00:03.0", 0, 0, 3, 0));
|
||||
assert(test_bdf("0000:00:1d.1", 0, 0, 29, 1));
|
||||
assert(test_bdf("0000:09:02.1", 0, 9, 2, 1));
|
||||
assert(test_bdf("0000:1d:02.1", 0, 29, 2, 1));
|
||||
assert(test_bdf("0000:00:02.d", 0, 0, 2, 13));
|
||||
assert(test_bdf("000f:00:02.d", 15, 0, 2, 13));
|
||||
assert(test_bdf("000f:00:02.d", 15, 0, 2, 13));
|
||||
assert(test_bdf("000f:00:02.d", 15, 0, 2, 13));
|
||||
assert(test_bdf("000f:00:02.d", 15, 0, 2, 13));
|
||||
assert(test_bdf("ffff:ff:ff.f", 65535, 255, 255, 15));
|
||||
assert(test_bdf("0:0:2.1", 0, 0, 2, 1));
|
||||
|
||||
// invalid input
|
||||
assert(!test_bdf("0000:00:02:0", 0, 0, 2, 0));
|
||||
assert(!test_bdf("-0001:00:02.1", -1, 0, 2, 1));
|
||||
assert(!test_bdf("0000.00.02.0", 0, 0, 2, 0));
|
||||
assert(!test_bdf("000f:00:02", 15, 0, 2, 0));
|
||||
assert(!test_bdf("000f:00", 15, 0, 0, 0));
|
||||
assert(!test_bdf("000f", 15, 0, 0, 0));
|
||||
assert(!test_bdf("random string", 0, 0, 0, 0));
|
||||
assert(!test_bdf("12345", 12345, 0, 0, 0));
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
test_bdf_parsing();
|
||||
test_sysfs_parsing();
|
||||
test_spice_parsing();
|
||||
test_compare_addresses();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
/* test-file-xfers.c - test file transfer
|
||||
|
||||
Copyright 2019 Red Hat, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <config.h>
|
||||
|
||||
#undef NDEBUG
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include <spice/vd_agent.h>
|
||||
|
||||
#include "file-xfers.h"
|
||||
|
||||
static void test_file(const char *file_name, const char *out)
|
||||
{
|
||||
char *fn = g_strdup(file_name);
|
||||
int fd = vdagent_file_xfers_create_file("./test-dir", &fn);
|
||||
if (out) {
|
||||
g_assert_cmpint(fd, !=, -1);
|
||||
g_assert_cmpstr(fn, ==, out);
|
||||
close(fd);
|
||||
g_assert_cmpint(access(out, W_OK), ==, 0);
|
||||
} else {
|
||||
g_assert_cmpint(fd, ==, -1);
|
||||
}
|
||||
g_free(fn);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
assert(system("rm -rf test-dir && mkdir test-dir") == 0);
|
||||
|
||||
// create a file
|
||||
test_file("test.txt", "./test-dir/test.txt");
|
||||
|
||||
// create a file with an existing name
|
||||
for (int i = 1; i < 64; ++i) {
|
||||
char out_name[64];
|
||||
sprintf(out_name, "./test-dir/test (%d).txt", i);
|
||||
test_file("test.txt", out_name);
|
||||
}
|
||||
|
||||
// check too much files with the same name
|
||||
test_file("test.txt", NULL);
|
||||
|
||||
// create a file in a subdirectory not existing
|
||||
test_file("subdir/test.txt", "./test-dir/subdir/test.txt");
|
||||
|
||||
// create a file in a directory with no permissions
|
||||
assert(system("ln -s /proc/1 test-dir/baddir") == 0);
|
||||
test_file("baddir/test2.txt", NULL);
|
||||
|
||||
// try to create a file with a path where there's a file (should fail)
|
||||
test_file("test.txt/out", NULL);
|
||||
|
||||
// create a file without extension in a directory with extension
|
||||
test_file("sub.dir/test", "./test-dir/sub.dir/test");
|
||||
|
||||
// create a file with same name above, should not strip the filename
|
||||
test_file("sub.dir/test", "./test-dir/sub.dir/test (1)");
|
||||
|
||||
assert(system("rm -rf test-dir") == 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -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