summaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorGuoyi Tu2022-08-23 09:50:39 +0200
committerMarc-André Lureau2022-09-29 12:38:05 +0200
commit3c63b4e94a16db730a8185278479b592f7de8b7f (patch)
treea08567d342967dd463abc5ab8a997a8013096ca2 /util
parentchardev: fix segfault in finalize (diff)
downloadqemu-3c63b4e94a16db730a8185278479b592f7de8b7f.tar.gz
qemu-3c63b4e94a16db730a8185278479b592f7de8b7f.tar.xz
qemu-3c63b4e94a16db730a8185278479b592f7de8b7f.zip
oslib-posix: Introduce qemu_socketpair()
qemu_socketpair() will create a pair of connected sockets with FD_CLOEXEC set Signed-off-by: Guoyi Tu <tugy@chinatelecom.cn> Reviewed-by: Christian Schoenebeck <qemu_oss@crudebyte.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <17fa1eff729eeabd9a001f4639abccb127ceec81.1661240709.git.tugy@chinatelecom.cn>
Diffstat (limited to 'util')
-rw-r--r--util/oslib-posix.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index d55af69c11..827a7aadba 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -253,6 +253,25 @@ void qemu_set_cloexec(int fd)
assert(f != -1);
}
+int qemu_socketpair(int domain, int type, int protocol, int sv[2])
+{
+ int ret;
+
+#ifdef SOCK_CLOEXEC
+ ret = socketpair(domain, type | SOCK_CLOEXEC, protocol, sv);
+ if (ret != -1 || errno != EINVAL) {
+ return ret;
+ }
+#endif
+ ret = socketpair(domain, type, protocol, sv);;
+ if (ret == 0) {
+ qemu_set_cloexec(sv[0]);
+ qemu_set_cloexec(sv[1]);
+ }
+
+ return ret;
+}
+
char *
qemu_get_local_state_dir(void)
{