summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/qemu/files/linux-user-Handle-SOCK_CLOEXEC-NONBLOCK-if-unavailab.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/qemu/files/linux-user-Handle-SOCK_CLOEXEC-NONBLOCK-if-unavailab.patch')
-rw-r--r--meta/recipes-devtools/qemu/files/linux-user-Handle-SOCK_CLOEXEC-NONBLOCK-if-unavailab.patch92
1 files changed, 0 insertions, 92 deletions
diff --git a/meta/recipes-devtools/qemu/files/linux-user-Handle-SOCK_CLOEXEC-NONBLOCK-if-unavailab.patch b/meta/recipes-devtools/qemu/files/linux-user-Handle-SOCK_CLOEXEC-NONBLOCK-if-unavailab.patch
deleted file mode 100644
index eb638960dd..0000000000
--- a/meta/recipes-devtools/qemu/files/linux-user-Handle-SOCK_CLOEXEC-NONBLOCK-if-unavailab.patch
+++ /dev/null
@@ -1,92 +0,0 @@
1Upstream-Status: Backport
2
3From 53d09b761f032f50c4424e8649396a9041070bae Mon Sep 17 00:00:00 2001
4From: "Edgar E. Iglesias" <edgar.iglesias@gmail.com>
5Date: Mon, 23 Sep 2013 14:11:53 +0200
6Subject: [PATCH] linux-user: Handle SOCK_CLOEXEC/NONBLOCK if unavailable on
7 host
8
9If the host lacks SOCK_CLOEXEC, bail out with -EINVAL.
10If the host lacks SOCK_ONONBLOCK, try to emulate it with fcntl()
11and O_NONBLOCK.
12
13Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
14Signed-off-by: Riku Voipio <riku.voipio@linaro.org>
15---
16 linux-user/syscall.c | 40 +++++++++++++++++++++++++++++++++++++---
17 1 file changed, 37 insertions(+), 3 deletions(-)
18
19diff --git a/linux-user/syscall.c b/linux-user/syscall.c
20index b3822b3..4a14a43 100644
21--- a/linux-user/syscall.c
22+++ b/linux-user/syscall.c
23@@ -1773,7 +1773,7 @@ static void unlock_iovec(struct iovec *vec, abi_ulong target_addr,
24 free(vec);
25 }
26
27-static inline void target_to_host_sock_type(int *type)
28+static inline int target_to_host_sock_type(int *type)
29 {
30 int host_type = 0;
31 int target_type = *type;
32@@ -1790,22 +1790,56 @@ static inline void target_to_host_sock_type(int *type)
33 break;
34 }
35 if (target_type & TARGET_SOCK_CLOEXEC) {
36+#if defined(SOCK_CLOEXEC)
37 host_type |= SOCK_CLOEXEC;
38+#else
39+ return -TARGET_EINVAL;
40+#endif
41 }
42 if (target_type & TARGET_SOCK_NONBLOCK) {
43+#if defined(SOCK_NONBLOCK)
44 host_type |= SOCK_NONBLOCK;
45+#elif !defined(O_NONBLOCK)
46+ return -TARGET_EINVAL;
47+#endif
48 }
49 *type = host_type;
50+ return 0;
51+}
52+
53+/* Try to emulate socket type flags after socket creation. */
54+static int sock_flags_fixup(int fd, int target_type)
55+{
56+#if !defined(SOCK_NONBLOCK) && defined(O_NONBLOCK)
57+ if (target_type & TARGET_SOCK_NONBLOCK) {
58+ int flags = fcntl(fd, F_GETFL);
59+ if (fcntl(fd, F_SETFL, O_NONBLOCK | flags) == -1) {
60+ close(fd);
61+ return -TARGET_EINVAL;
62+ }
63+ }
64+#endif
65+ return fd;
66 }
67
68 /* do_socket() Must return target values and target errnos. */
69 static abi_long do_socket(int domain, int type, int protocol)
70 {
71- target_to_host_sock_type(&type);
72+ int target_type = type;
73+ int ret;
74+
75+ ret = target_to_host_sock_type(&type);
76+ if (ret) {
77+ return ret;
78+ }
79
80 if (domain == PF_NETLINK)
81 return -EAFNOSUPPORT; /* do not NETLINK socket connections possible */
82- return get_errno(socket(domain, type, protocol));
83+ ret = get_errno(socket(domain, type, protocol));
84+ if (ret >= 0) {
85+ ret = sock_flags_fixup(ret, target_type);
86+ }
87+ return ret;
88 }
89
90 /* do_bind() Must return target values and target errnos. */
91--
921.8.2.1