qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] qemu-sockets: add abstract UNIX domain socket support
@ 2020-04-23  3:56 xiaoqiang zhao
  2020-04-23  9:00 ` Daniel P. Berrangé
  0 siblings, 1 reply; 5+ messages in thread
From: xiaoqiang zhao @ 2020-04-23  3:56 UTC (permalink / raw)
  To: qemu-devel; +Cc: xiaoqiang zhao, berrange, kraxel

unix_connect_saddr now support abstract address type

By default qemu does not support abstract UNIX domain
socket address. Add this ability to make qemu handy
when abstract address is needed.
Abstract address is marked by prefixing the address name with a '@'.

Signed-off-by: xiaoqiang zhao <zxq_yx_007@163.com>
---
 util/qemu-sockets.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
index bcc06d0e01..7ba9c497ab 100644
--- a/util/qemu-sockets.c
+++ b/util/qemu-sockets.c
@@ -939,6 +939,7 @@ static int unix_connect_saddr(UnixSocketAddress *saddr, Error **errp)
     struct sockaddr_un un;
     int sock, rc;
     size_t pathlen;
+    socklen_t serverlen;
 
     if (saddr->path == NULL) {
         error_setg(errp, "unix connect: no path specified");
@@ -963,10 +964,17 @@ static int unix_connect_saddr(UnixSocketAddress *saddr, Error **errp)
     un.sun_family = AF_UNIX;
     memcpy(un.sun_path, saddr->path, pathlen);
 
+    if (saddr->path[0] == '@') {
+        un.sun_path[0] = '\0';
+        serverlen = pathlen + offsetof(struct sockaddr_un, sun_path);
+    } else {
+        serverlen = sizeof(un);
+    }
+
     /* connect to peer */
     do {
         rc = 0;
-        if (connect(sock, (struct sockaddr *) &un, sizeof(un)) < 0) {
+        if (connect(sock, (struct sockaddr *) &un, serverlen) < 0) {
             rc = -errno;
         }
     } while (rc == -EINTR);
-- 
2.17.1




^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-04-27 13:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-23  3:56 [PATCH v2] qemu-sockets: add abstract UNIX domain socket support xiaoqiang zhao
2020-04-23  9:00 ` Daniel P. Berrangé
2020-04-23 10:51   ` xiaoqiang.zhao
2020-04-26  2:06     ` xiaoqiang.zhao
2020-04-27 13:47   ` Eric Blake

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).