This reverts commit fccb744f41c69fec6fd92225fe907c6e69de5d44. This commit introduced dependency of linux-user on qemu-sockets.c. The latter includes handling of various socket types, while gdbstub only needs unix sockets. Including different kinds of sockets makes it more problematic to build linux-user statically.
The original issue - the need to unlink unix socket before binding - will be addressed in the next change. Signed-off-by: Michael Tokarev <[email protected]> --- gdbstub/user.c | 29 ++++++++++++++++++++++++++--- stubs/meson.build | 2 -- util/meson.build | 2 -- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/gdbstub/user.c b/gdbstub/user.c index e233c59816..5e920a9b51 100644 --- a/gdbstub/user.c +++ b/gdbstub/user.c @@ -314,10 +314,12 @@ static bool gdb_accept_socket(int gdb_fd) return true; } -static int gdbserver_open_socket(const char *path, Error **errp) +static int gdbserver_open_socket(const char *path) { g_autoptr(GString) buf = g_string_new(""); + struct sockaddr_un sockaddr = {}; const char *pid_placeholder; + int fd, ret; pid_placeholder = strstr(path, "%d"); if (pid_placeholder != NULL) { @@ -327,7 +329,28 @@ static int gdbserver_open_socket(const char *path, Error **errp) path = buf->str; } - return unix_listen(path, errp); + 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; } static bool gdb_accept_tcp(int gdb_fd) @@ -483,7 +506,7 @@ bool gdbserver_start(const char *args, Error **errp) if (port > 0) { gdb_fd = gdbserver_open_port(port, errp); } else { - gdb_fd = gdbserver_open_socket(port_or_path, errp); + gdb_fd = gdbserver_open_socket(port_or_path); } if (gdb_fd < 0) { return false; diff --git a/stubs/meson.build b/stubs/meson.build index 0b2778c568..b6b1a3844e 100644 --- a/stubs/meson.build +++ b/stubs/meson.build @@ -59,8 +59,6 @@ if have_user if not have_system stub_ss.add(files('qdev.c')) endif - - stub_ss.add(files('monitor-internal.c')) endif if have_system diff --git a/util/meson.build b/util/meson.build index 35029380a3..a925c09169 100644 --- a/util/meson.build +++ b/util/meson.build @@ -87,8 +87,6 @@ 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-@[email protected]')) 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.47.3
