aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2020-11-03 14:40:40 +0000
committerPeter Maydell <peter.maydell@linaro.org>2020-11-03 14:40:40 +0000
commitad262888993f795db68fd7c2bdfa72f467fe0096 (patch)
tree50f03093d7fcdcc52549f1a3baf2a520e8b21f97 /util
parent83851c7c60c90e9fb6a23ff48076387a77bc33cd (diff)
parent8acefc79deaab1c7ee2ab07b540b0e3edf0f9f47 (diff)
downloadqemu-ad262888993f795db68fd7c2bdfa72f467fe0096.zip
qemu-ad262888993f795db68fd7c2bdfa72f467fe0096.tar.gz
qemu-ad262888993f795db68fd7c2bdfa72f467fe0096.tar.bz2
Merge remote-tracking branch 'remotes/berrange-gitlab/tags/sock-next-pull-request' into staging
- Fix inverted logic in abstract socket QAPI support - Only report abstract socket support in QAPI on Linux hosts - Expand test coverage - Misc other code cleanups # gpg: Signature made Tue 03 Nov 2020 14:00:53 GMT # gpg: using RSA key DAF3A6FDB26B62912D0E8E3FBE86EBB415104FDF # gpg: Good signature from "Daniel P. Berrange <dan@berrange.com>" [full] # gpg: aka "Daniel P. Berrange <berrange@redhat.com>" [full] # Primary key fingerprint: DAF3 A6FD B26B 6291 2D0E 8E3F BE86 EBB4 1510 4FDF * remotes/berrange-gitlab/tags/sock-next-pull-request: sockets: Make abstract UnixSocketAddress depend on CONFIG_LINUX sockets: Bypass "replace empty @path" for abstract unix sockets char-socket: Fix qemu_chr_socket_address() for abstract sockets sockets: Fix socket_sockaddr_to_address_unix() for abstract sockets sockets: Fix default of UnixSocketAddress member @tight test-util-sockets: Test the complete abstract socket matrix test-util-sockets: Synchronize properly, don't sleep(1) test-util-sockets: Factor out test_socket_unix_abstract_one() test-util-sockets: Clean up SocketAddress construction test-util-sockets: Correct to set has_abstract, has_tight test-util-sockets: Plug file descriptor leak Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'util')
-rw-r--r--util/qemu-sockets.c54
1 files changed, 42 insertions, 12 deletions
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index 38f8217..8af0278 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -860,10 +860,29 @@ static int vsock_parse(VsockSocketAddress *addr, const char *str,
#ifndef _WIN32
+static bool saddr_is_abstract(UnixSocketAddress *saddr)
+{
+#ifdef CONFIG_LINUX
+ return saddr->abstract;
+#else
+ return false;
+#endif
+}
+
+static bool saddr_is_tight(UnixSocketAddress *saddr)
+{
+#ifdef CONFIG_LINUX
+ return !saddr->has_tight || saddr->tight;
+#else
+ return false;
+#endif
+}
+
static int unix_listen_saddr(UnixSocketAddress *saddr,
int num,
Error **errp)
{
+ bool abstract = saddr_is_abstract(saddr);
struct sockaddr_un un;
int sock, fd;
char *pathbuf = NULL;
@@ -877,7 +896,7 @@ static int unix_listen_saddr(UnixSocketAddress *saddr,
return -1;
}
- if (saddr->path && saddr->path[0]) {
+ if (saddr->path[0] || abstract) {
path = saddr->path;
} else {
const char *tmpdir = getenv("TMPDIR");
@@ -887,10 +906,10 @@ static int unix_listen_saddr(UnixSocketAddress *saddr,
pathlen = strlen(path);
if (pathlen > sizeof(un.sun_path) ||
- (saddr->abstract && pathlen > (sizeof(un.sun_path) - 1))) {
+ (abstract && pathlen > (sizeof(un.sun_path) - 1))) {
error_setg(errp, "UNIX socket path '%s' is too long", path);
error_append_hint(errp, "Path must be less than %zu bytes\n",
- saddr->abstract ? sizeof(un.sun_path) - 1 :
+ abstract ? sizeof(un.sun_path) - 1 :
sizeof(un.sun_path));
goto err;
}
@@ -912,7 +931,7 @@ static int unix_listen_saddr(UnixSocketAddress *saddr,
close(fd);
}
- if (!saddr->abstract && unlink(path) < 0 && errno != ENOENT) {
+ if (!abstract && unlink(path) < 0 && errno != ENOENT) {
error_setg_errno(errp, errno,
"Failed to unlink socket %s", path);
goto err;
@@ -922,10 +941,10 @@ static int unix_listen_saddr(UnixSocketAddress *saddr,
un.sun_family = AF_UNIX;
addrlen = sizeof(un);
- if (saddr->abstract) {
+ if (abstract) {
un.sun_path[0] = '\0';
memcpy(&un.sun_path[1], path, pathlen);
- if (saddr->tight) {
+ if (saddr_is_tight(saddr)) {
addrlen = offsetof(struct sockaddr_un, sun_path) + 1 + pathlen;
}
} else {
@@ -952,6 +971,7 @@ err:
static int unix_connect_saddr(UnixSocketAddress *saddr, Error **errp)
{
+ bool abstract = saddr_is_abstract(saddr);
struct sockaddr_un un;
int sock, rc;
size_t pathlen;
@@ -970,10 +990,10 @@ static int unix_connect_saddr(UnixSocketAddress *saddr, Error **errp)
pathlen = strlen(saddr->path);
if (pathlen > sizeof(un.sun_path) ||
- (saddr->abstract && pathlen > (sizeof(un.sun_path) - 1))) {
+ (abstract && pathlen > (sizeof(un.sun_path) - 1))) {
error_setg(errp, "UNIX socket path '%s' is too long", saddr->path);
error_append_hint(errp, "Path must be less than %zu bytes\n",
- saddr->abstract ? sizeof(un.sun_path) - 1 :
+ abstract ? sizeof(un.sun_path) - 1 :
sizeof(un.sun_path));
goto err;
}
@@ -982,10 +1002,10 @@ static int unix_connect_saddr(UnixSocketAddress *saddr, Error **errp)
un.sun_family = AF_UNIX;
addrlen = sizeof(un);
- if (saddr->abstract) {
+ if (abstract) {
un.sun_path[0] = '\0';
memcpy(&un.sun_path[1], saddr->path, pathlen);
- if (saddr->tight) {
+ if (saddr_is_tight(saddr)) {
addrlen = offsetof(struct sockaddr_un, sun_path) + 1 + pathlen;
}
} else {
@@ -1270,10 +1290,20 @@ socket_sockaddr_to_address_unix(struct sockaddr_storage *sa,
addr = g_new0(SocketAddress, 1);
addr->type = SOCKET_ADDRESS_TYPE_UNIX;
- if (su->sun_path[0]) {
- addr->u.q_unix.path = g_strndup(su->sun_path, sizeof(su->sun_path));
+#ifdef CONFIG_LINUX
+ if (!su->sun_path[0]) {
+ /* Linux abstract socket */
+ addr->u.q_unix.path = g_strndup(su->sun_path + 1,
+ sizeof(su->sun_path) - 1);
+ addr->u.q_unix.has_abstract = true;
+ addr->u.q_unix.abstract = true;
+ addr->u.q_unix.has_tight = true;
+ addr->u.q_unix.tight = salen < sizeof(*su);
+ return addr;
}
+#endif
+ addr->u.q_unix.path = g_strndup(su->sun_path, sizeof(su->sun_path));
return addr;
}
#endif /* WIN32 */