File: tg-socketpair_flags.diff

package info (click to toggle)
glibc 2.24-11%2Bdeb9u3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 225,316 kB
  • sloc: ansic: 996,116; asm: 261,826; sh: 10,483; makefile: 9,849; cpp: 4,169; python: 3,971; perl: 2,254; awk: 1,753; pascal: 1,521; yacc: 291; sed: 80
file content (84 lines) | stat: -rw-r--r-- 2,786 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
From: Thomas Schwinge <thomas@schwinge.name>
Subject: [PATCH] socketpair_flags

2008-12-17  Thomas Schwinge  <tschwinge@gnu.org>

	SOCK_CLOEXEC and SOCK_NONBLOCK for socketpair on GNU Hurd.
	* sysdeps/mach/hurd/socketpair.c (__socketpair): Handle SOCK_CLOEXEC
	and SOCK_NONBLOCK.

---
 sysdeps/mach/hurd/socketpair.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/sysdeps/mach/hurd/socketpair.c b/sysdeps/mach/hurd/socketpair.c
index 47f50d2..a16dd80 100644
--- a/sysdeps/mach/hurd/socketpair.c
+++ b/sysdeps/mach/hurd/socketpair.c
@@ -17,6 +17,7 @@
 
 #include <errno.h>
 #include <fcntl.h>
+#include <fcntl-internal.h>
 #include <sys/socket.h>
 #include <unistd.h>
 
@@ -34,6 +35,11 @@ __socketpair (int domain, int type, int protocol, int fds[2])
   error_t err;
   socket_t server, sock1, sock2;
   int d1, d2;
+  int flags = sock_to_o_flags (type & ~SOCK_TYPE_MASK);
+  type &= SOCK_TYPE_MASK;
+
+  if (flags & ~(O_CLOEXEC | O_NONBLOCK))
+    return __hurd_fail (EINVAL);
 
   if (fds == NULL)
     return __hurd_fail (EINVAL);
@@ -56,6 +62,14 @@ __socketpair (int domain, int type, int protocol, int fds[2])
 	return -1;
       err = __socket_create (server, type, protocol, &sock1);
     }
+  /* TODO: do we need special ERR massaging here, like it is done in
+     __socket?  */
+  if (! err)
+    {
+      if (flags & O_NONBLOCK)
+	err = __io_set_some_openmodes (sock1, O_NONBLOCK);
+      /* TODO: do we need special ERR massaging after the previous call?  */
+    }
   if (err)
     return __hurd_fail (err);
   if (err = __socket_create (server, type, protocol, &sock2))
@@ -63,7 +77,12 @@ __socketpair (int domain, int type, int protocol, int fds[2])
       __mach_port_deallocate (__mach_task_self (), sock1);
       return __hurd_fail (err);
     }
-  if (err = __socket_connect2 (sock1, sock2))
+  if (flags & O_NONBLOCK)
+    err = __io_set_some_openmodes (sock2, O_NONBLOCK);
+  /* TODO: do we need special ERR massaging after the previous call?  */
+  if (! err)
+    err = __socket_connect2 (sock1, sock2);
+  if (err)
     {
       __mach_port_deallocate (__mach_task_self (), sock1);
       __mach_port_deallocate (__mach_task_self (), sock2);
@@ -72,13 +91,13 @@ __socketpair (int domain, int type, int protocol, int fds[2])
 
   /* Put the sockets into file descriptors.  */
 
-  d1 = _hurd_intern_fd (sock1, O_IGNORE_CTTY, 1);
+  d1 = _hurd_intern_fd (sock1, O_IGNORE_CTTY | flags, 1);
   if (d1 < 0)
     {
       __mach_port_deallocate (__mach_task_self (), sock2);
       return -1;
     }
-  d2 = _hurd_intern_fd (sock2, O_IGNORE_CTTY, 1);
+  d2 = _hurd_intern_fd (sock2, O_IGNORE_CTTY | flags, 1);
   if (d2 < 0)
     {
       err = errno;
-- 
tg: (a7a0166..) t/socketpair_flags (depends on: t/socket_flags)