From: Ilya Leoshkevich <iii@linux.ibm.com>
In case an emulated process execve()s another emulated process, bind()
will fail, because the socket already exists. So try deleting it. Use
the existing unix_listen() function which does this. Link qemu-user
with qemu-sockets.c and add the monitor_get_fd() stub.
Note that it is not possible to handle this in do_execv(): deleting
gdbserver_user_state.socket_path before safe_execve() is not correct,
because the latter may fail, and afterwards we may lose control.
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20250117001542.8290-3-iii@linux.ibm.com>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20250207153112.3939799-12-alex.bennee@linaro.org>
diff --git a/gdbstub/user.c b/gdbstub/user.c
index fd29d595f4..8225b70280 100644
--- a/gdbstub/user.c
+++ b/gdbstub/user.c
@@ -315,12 +315,10 @@ static bool gdb_accept_socket(int gdb_fd)
return true;
}
-static int gdbserver_open_socket(const char *path)
+static int gdbserver_open_socket(const char *path, Error **errp)
{
g_autoptr(GString) buf = g_string_new("");
- struct sockaddr_un sockaddr = {};
char *pid_placeholder;
- int fd, ret;
pid_placeholder = strstr(path, "%d");
if (pid_placeholder != NULL) {
@@ -330,28 +328,7 @@ static int gdbserver_open_socket(const char *path)
path = buf->str;
}
- fd = socket(AF_UNIX, SOCK_STREAM, 0);
- if (fd < 0) {
- perror("create socket");
- return -1;
- }
-
- sockaddr.sun_family = AF_UNIX;
- pstrcpy(sockaddr.sun_path, sizeof(sockaddr.sun_path) - 1, path);
- ret = bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr));
- if (ret < 0) {
- perror("bind socket");
- close(fd);
- return -1;
- }
- ret = listen(fd, 1);
- if (ret < 0) {
- perror("listen socket");
- close(fd);
- return -1;
- }
-
- return fd;
+ return unix_listen(path, errp);
}
static bool gdb_accept_tcp(int gdb_fd)
@@ -424,7 +401,7 @@ bool gdbserver_start(const char *port_or_path, Error **errp)
if (port > 0) {
gdb_fd = gdbserver_open_port(port, errp);
} else {
- gdb_fd = gdbserver_open_socket(port_or_path);
+ gdb_fd = gdbserver_open_socket(port_or_path, errp);
}
if (gdb_fd < 0) {
diff --git a/stubs/monitor-fd.c b/stubs/monitor-fd.c
new file mode 100644
index 0000000000..9bb6749885
--- /dev/null
+++ b/stubs/monitor-fd.c
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#include "qemu/osdep.h"
+#include "monitor/monitor.h"
+
+int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp)
+{
+ abort();
+}
diff --git a/stubs/meson.build b/stubs/meson.build
index a8b3aeb564..b0fee37e05 100644
--- a/stubs/meson.build
+++ b/stubs/meson.build
@@ -61,6 +61,8 @@ if have_user
if not have_system
stub_ss.add(files('qdev.c'))
endif
+
+ stub_ss.add(files('monitor-fd.c'))
endif
if have_system
diff --git a/util/meson.build b/util/meson.build
index 5d8bef9891..780b5977a8 100644
--- a/util/meson.build
+++ b/util/meson.build
@@ -84,6 +84,8 @@ if have_block or have_ga
util_ss.add(files('qemu-coroutine.c', 'qemu-coroutine-lock.c', 'qemu-coroutine-io.c'))
util_ss.add(files(f'coroutine-@coroutine_backend@.c'))
util_ss.add(files('thread-pool.c', 'qemu-timer.c'))
+endif
+if have_block or have_ga or have_user
util_ss.add(files('qemu-sockets.c'))
endif
if have_block
--
2.39.5
Hi Alex and Paolo, I hit an compiling error with "./configure --enable-rust" at this patch: [69/124] Compiling Rust source ../rust/qemu-api/tests/tests.rs FAILED: rust/qemu-api/rust-qemu-api-integration rustc -C linker=cc -C link-arg=-m64 --color=auto -C debug-assertions=yes -C overflow-checks=no --crate-type bin -D warnings --edition=2021 -C opt-level=2 -g -D unexpected_cfgs -A unknown_lints -D unsafe_op_in_unsafe_fn --cfg MESON -C default-linker-libraries --crate-name rust_qemu_api_integration --emit dep-info=rust/qemu-api/rust-qemu-api-integration.d --emit link=rust/qemu-api/rust-qemu-api-integration --out-dir rust/qemu-api/rust-qemu-api-integration.p -C metadata=81e2432@@rust-qemu-api-integration@exe --test --extern qemu_api=rust/qemu-api/libqemu_api.rlib --extern qemu_api_macros=rust/qemu-api-macros/libqemu_api_macros.so -Clink-arg=-Wl,--whole-archive -Clink-arg=rust/qemu-api/librust_qemu_api_objs.a -Clink-arg=-Wl,--no-whole-archive -Clink-arg=-Wl,--whole-archive -Clink-arg=libqemuutil.a -Clink-arg=-Wl,--no-whole-archive -Clink-arg=subprojects/libvhost-user/libvhost-user-glib.a -Clink-arg=subprojects/libvhost-user/libvhost-user.a -Clink-arg=-lnuma -Clink-arg=/usr/lib/x86_64-linux-gnu/libgio-2.0.so -Clink-arg=/usr/lib/x86_64-linux-gnu/libgobject-2.0.so -Clink-arg=/usr/lib/x86_64-linux-gnu/libglib-2.0.so -Clink-arg=/usr/lib/x86_64-linux-gnu/libgmodule-2.0.so -Clink-arg=-pthread -Clink-arg=-pthread -Clink-arg=-pthread -Clink-arg=-pthread -Lrust/qemu-api -Lrust/qemu-api-macros -L. -Lsubprojects/libvhost-user -C 'link-arg=-Wl,-rpath,$ORIGIN/../qemu-api-macros:/home/liuzhao/.rustup/toolchains/1.63.0-x86_64-unknown-linux-gnu/lib' -C link-arg=-Wl,-rpath-link,/media/liuzhao/data/qemu-cook/build/rust/qemu-api-macros:/home/liuzhao/.rustup/toolchains/1.63.0-x86_64-unknown-linux-gnu/lib ../rust/qemu-api/tests/tests.rs error: linking with `cc` failed: exit status: 1 | = note: "cc" "-m64" "/tmp/rustcRWVJWs/symbols.o" "rust/qemu-api/rust-qemu-api-integration.p/rust_qemu_api_integration.rust_qemu_api_integration.e9408ebc-cgu.0.rcgu.o" "rust/qemu-api/rust-qemu-api-integration.p/rust_qemu_api_integration.rust_qemu_api_integration.e9408ebc-cgu.1.rcgu.o" "rust/qemu-api/rust-qemu-api-integration.p/rust_qemu_api_integration.rust_qemu_api_integration.e9408ebc-cgu.10.rcgu.o" "rust/qemu-api/rust-qemu-api-integration.p/rust_qemu_api_integration.rust_qemu_api_integration.e9408ebc-cgu.11.rcgu.o" "rust/qemu-api/rust-qemu-api-integration.p/rust_qemu_api_integration.rust_qemu_api_integration.e9408ebc-cgu.12.rcgu.o" "rust/qemu-api/rust-qemu-api-integration.p/rust_qemu_api_integration.rust_qemu_api_integration.e9408ebc-cgu.13.rcgu.o" "rust/qemu-api/rust-qemu-api-integration.p/rust_qemu_api_integration.rust_qemu_api_integration.e9408ebc-cgu.14.rcgu.o" "rust/qemu-api/rust-qemu-api-integration.p/rust_qemu_api_integration.rust_qemu_api_integration.e9408ebc-cgu.2.rcgu.o" "rust/qemu-api/rust-qemu-api-integration.p/rust_qemu_api_integration.rust_qemu_api_integration.e9408ebc-cgu.3.rcgu.o" "rust/qemu-api/rust-qemu-api-integration.p/rust_qemu_api_integration.rust_qemu_api_integration.e9408ebc-cgu.4.rcgu.o" "rust/qemu-api/rust-qemu-api-integration.p/rust_qemu_api_integration.rust_qemu_api_integration.e9408ebc-cgu.5.rcgu.o" "rust/qemu-api/rust-qemu-api-integration.p/rust_qemu_api_integration.rust_qemu_api_integration.e9408ebc-cgu.6.rcgu.o" "rust/qemu-api/rust-qemu-api-integration.p/rust_qemu_api_integration.rust_qemu_api_integration.e9408ebc-cgu.7.rcgu.o" "rust/qemu-api/rust-qemu-api-integration.p/rust_qemu_api_integration.rust_qemu_api_integration.e9408ebc-cgu.8.rcgu.o" "rust/qemu-api/rust-qemu-api-integration.p/rust_qemu_api_integration.rust_qemu_api_integration.e9408ebc-cgu.9.rcgu.o" "rust/qemu-api/rust-qemu-api-integration.p/rust_qemu_api_integration.29ovwebebub0plh7.rcgu.o" "-Wl,--as-needed" "-L" "rust/qemu-api" "-L" "rust/qemu-api-macros" "-L" "." "-L" "subprojects/libvhost-user" "-L" "/home/liuzhao/.rustup/toolchains/1.63.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/liuzhao/.rustup/toolchains/1.63.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libtest-50b9616eedb811b7.rlib" "/home/liuzhao/.rustup/toolchains/1.63.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgetopts-754da76e30d40e26.rlib" "/home/liuzhao/.rustup/toolchains/1.63.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunicode_width-abff7c50c58df25c.rlib" "/home/liuzhao/.rustup/toolchains/1.63.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_std-89f1a8c8e39f4a91.rlib" "/media/liuzhao/data/qemu-cook/build/rust/qemu-api/libqemu_api.rlib" "-Wl,--start-group" "/home/liuzhao/.rustup/toolchains/1.63.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-8f1929c73c3f8167.rlib" "/home/liuzhao/.rustup/toolchains/1.63.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-e359d865975ccf21.rlib" "/home/liuzhao/.rustup/toolchains/1.63.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-b886fd10c5a7c7c0.rlib" "/home/liuzhao/.rustup/toolchains/1.63.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-9d7c322d48daa475.rlib" "/home/liuzhao/.rustup/toolchains/1.63.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-08ae1606a951cabe.rlib" "/home/liuzhao/.rustup/toolchains/1.63.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-682a81c4b2133b72.rlib" "/home/liuzhao/.rustup/toolchains/1.63.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-a73b3512c88de071.rlib" "/home/liuzhao/.rustup/toolchains/1.63.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-7b5ec4c918d9f957.rlib" "/home/liuzhao/.rustup/toolchains/1.63.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-65c63cf3af0af657.rlib" "/home/liuzhao/.rustup/toolchains/1.63.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-4a53f0a2785abc6a.rlib" "/home/liuzhao/.rustup/toolchains/1.63.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-868e2d515c28d027.rlib" "/home/liuzhao/.rustup/toolchains/1.63.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-394ad2d73aede76a.rlib" "/home/liuzhao/.rustup/toolchains/1.63.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-19c77e4dc3dcb87e.rlib" "/home/liuzhao/.rustup/toolchains/1.63.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-fb44a42088c9369a.rlib" "/home/liuzhao/.rustup/toolchains/1.63.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-61a7402e61a5b0e0.rlib" "/home/liuzhao/.rustup/toolchains/1.63.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-63f8356c87a0d0e8.rlib" "/home/liuzhao/.rustup/toolchains/1.63.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-a506e577d917828c.rlib" "/home/liuzhao/.rustup/toolchains/1.63.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-fc1fb63210fdafad.rlib" "-Wl,--end-group" "/home/liuzhao/.rustup/toolchains/1.63.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-c21be34a5cae8449.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/home/liuzhao/.rustup/toolchains/1.63.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "rust/qemu-api/rust-qemu-api-integration" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-Wl,-O1" "-m64" "-Wl,--whole-archive" "rust/qemu-api/librust_qemu_api_objs.a" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "libqemuutil.a" "-Wl,--no-whole-archive" "subprojects/libvhost-user/libvhost-user-glib.a" "subprojects/libvhost-user/libvhost-user.a" "-lnuma" "/usr/lib/x86_64-linux-gnu/libgio-2.0.so" "/usr/lib/x86_64-linux-gnu/libgobject-2.0.so" "/usr/lib/x86_64-linux-gnu/libglib-2.0.so" "/usr/lib/x86_64-linux-gnu/libgmodule-2.0.so" "-pthread" "-pthread" "-pthread" "-pthread" "-Wl,-rpath,$ORIGIN/../qemu-api-macros:/home/liuzhao/.rustup/toolchains/1.63.0-x86_64-unknown-linux-gnu/lib" "-Wl,-rpath-link,/media/liuzhao/data/qemu-cook/build/rust/qemu-api-macros:/home/liuzhao/.rustup/toolchains/1.63.0-x86_64-unknown-linux-gnu/lib" = note: /usr/bin/ld: libqemuutil.a.p/stubs_monitor-fd.c.o: in function `monitor_get_fd': /media/liuzhao/data/qemu-cook/build/../stubs/monitor-fd.c:7: multiple definition of `monitor_get_fd'; libqemuutil.a.p/stubs_monitor-internal.c.o:/media/liuzhao/data/qemu-cook/build/../stubs/monitor-internal.c:6: first defined here collect2: error: ld returned 1 exit status error: aborting due to previous error --- I tried to analyze the reasons as follows: * stubs/monitor-fd.c introduces the same monitor_get_fd() stub as the stubs/monitor-internal.c did. * rust-qemu-api-integration used the "link_whole" keyword instead of "link_with". Then the two duplicate monitor_get_fd() eventually meet in rust-qemu-api-integration. To fix this issue, dropping stubs/monitor-fd.c and only linking stubs/monitor-internal.c could work! (And I don't think of the reason to redefine monitor_get_fd() in another file.) In addition, could we change the "link_whole" to "link_with" when compile rust-qemu-api-integration? Thanks, Zhao
© 2016 - 2025 Red Hat, Inc.