• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <sys/socket.h>
2 #include <fcntl.h>
3 #include <errno.h>
4 #include "syscall.h"
5 #ifdef OHOS_FDTRACK_HOOK_ENABLE
6 #include "musl_fdtrack_hook.h"
7 #endif
8 
socketpair(int domain,int type,int protocol,int fd[2])9 int socketpair(int domain, int type, int protocol, int fd[2])
10 {
11 	int r = socketcall(socketpair, domain, type, protocol, fd, 0, 0);
12 	if (r<0 && (errno==EINVAL || errno==EPROTONOSUPPORT)
13 	    && (type&(SOCK_CLOEXEC|SOCK_NONBLOCK))) {
14 		r = socketcall(socketpair, domain,
15 			type & ~(SOCK_CLOEXEC|SOCK_NONBLOCK),
16 			protocol, fd, 0, 0);
17 		if (r < 0) return r;
18 		if (type & SOCK_CLOEXEC) {
19 			__syscall(SYS_fcntl, fd[0], F_SETFD, FD_CLOEXEC);
20 			__syscall(SYS_fcntl, fd[1], F_SETFD, FD_CLOEXEC);
21 		}
22 		if (type & SOCK_NONBLOCK) {
23 			__syscall(SYS_fcntl, fd[0], F_SETFL, O_NONBLOCK);
24 			__syscall(SYS_fcntl, fd[1], F_SETFL, O_NONBLOCK);
25 		}
26 	}
27 #ifdef OHOS_FDTRACK_HOOK_ENABLE
28 	if (!r) {
29 		FDTRACK_START_HOOK(fd[0]);
30 		FDTRACK_START_HOOK(fd[1]);
31 	}
32 #endif
33 	return r;
34 }
35