aboutsummaryrefslogtreecommitdiff
path: root/util/oslib-posix.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/oslib-posix.c')
-rw-r--r--util/oslib-posix.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/util/oslib-posix.c b/util/oslib-posix.c
index 4ff577e..3c14b72 100644
--- a/util/oslib-posix.c
+++ b/util/oslib-posix.c
@@ -250,21 +250,19 @@ void qemu_anon_ram_free(void *ptr, size_t size)
#endif
}
-void qemu_socket_set_block(int fd)
+bool qemu_set_blocking(int fd, bool block, Error **errp)
{
- g_unix_set_fd_nonblocking(fd, false, NULL);
-}
+ g_autoptr(GError) err = NULL;
-int qemu_socket_try_set_nonblock(int fd)
-{
- return g_unix_set_fd_nonblocking(fd, true, NULL) ? 0 : -errno;
-}
+ if (!g_unix_set_fd_nonblocking(fd, !block, &err)) {
+ error_setg_errno(errp, errno,
+ "Can't set file descriptor %d %s: %s", fd,
+ block ? "blocking" : "non-blocking",
+ err->message);
+ return false;
+ }
-void qemu_socket_set_nonblock(int fd)
-{
- int f;
- f = qemu_socket_try_set_nonblock(fd);
- assert(f == 0);
+ return true;
}
int socket_set_fast_reuse(int fd)
@@ -307,6 +305,15 @@ int qemu_socketpair(int domain, int type, int protocol, int sv[2])
return ret;
}
+void qemu_clear_cloexec(int fd)
+{
+ int f;
+ f = fcntl(fd, F_GETFD);
+ assert(f != -1);
+ f = fcntl(fd, F_SETFD, f & ~FD_CLOEXEC);
+ assert(f != -1);
+}
+
char *
qemu_get_local_state_dir(void)
{