about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2014-06-06 15:30:28 -0400
committerRich Felker <dalias@aerifal.cx>2014-06-06 15:30:28 -0400
commit1cacc01dc0623ac6443e19580222331812bddbbc (patch)
treead6e8282c111a7ddba9e80ecd5eb0567b0d52da7
parent1d348566e6ab446d9c452b1b93aede74368b6618 (diff)
downloadmusl-1cacc01dc0623ac6443e19580222331812bddbbc.tar.gz
musl-1cacc01dc0623ac6443e19580222331812bddbbc.tar.xz
musl-1cacc01dc0623ac6443e19580222331812bddbbc.zip
optimize SOCK_CLOEXEC fallback for socket function
the fcntl function is heavy, so make the syscall directly instead.
also, avoid the code size and runtime overhead of querying the old
flags, since it's reasonable to assume nothing will be set on a
newly-created socket. this code is only used on old kernels which lack
proper atomic close-on-exec support, so future changes that might
invalidate such an assumption do not need to be considered.
-rw-r--r--src/network/socket.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/network/socket.c b/src/network/socket.c
index 51be30ee..a2e92d90 100644
--- a/src/network/socket.c
+++ b/src/network/socket.c
@@ -13,9 +13,9 @@ int socket(int domain, int type, int protocol)
 			protocol, 0, 0, 0);
 		if (s < 0) return s;
 		if (type & SOCK_CLOEXEC)
-			fcntl(s, F_SETFD, FD_CLOEXEC);
+			__syscall(SYS_fcntl, s, F_SETFD, FD_CLOEXEC);
 		if (type & SOCK_NONBLOCK)
-			fcntl(s, F_SETFL, fcntl(s, F_GETFL) | O_NONBLOCK);
+			__syscall(SYS_fcntl, s, F_SETFL, O_NONBLOCK);
 	}
 	return s;
 }