aboutsummaryrefslogtreecommitdiff
path: root/gdbstub/user.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdbstub/user.c')
-rw-r--r--gdbstub/user.c29
1 files changed, 3 insertions, 26 deletions
diff --git a/gdbstub/user.c b/gdbstub/user.c
index fd29d59..8225b70 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) {