Mark sockets on creation (socket()) and accept4().

Remove the separate syscall for accept() and implement it as accept4(..., 0).

Change-Id: Ib0b8f5d7c5013b91eae6bbc3847852eb355c7714
diff --git a/libc/bionic/NetdClient.cpp b/libc/bionic/NetdClient.cpp
index 36796a2..5b0f4fd 100644
--- a/libc/bionic/NetdClient.cpp
+++ b/libc/bionic/NetdClient.cpp
@@ -40,18 +40,19 @@
         // default implementations of functions that it would've overridden.
         return;
     }
-    netdClientInitFunction(netdClientHandle, "netdClientInitAccept", &__netdClientDispatch.accept);
+    netdClientInitFunction(netdClientHandle, "netdClientInitAccept4",
+                           &__netdClientDispatch.accept4);
     netdClientInitFunction(netdClientHandle, "netdClientInitConnect",
                            &__netdClientDispatch.connect);
     netdClientInitFunction(netdClientHandle, "netdClientInitNetIdForResolv",
                            &__netdClientDispatch.netIdForResolv);
+    netdClientInitFunction(netdClientHandle, "netdClientInitSocket", &__netdClientDispatch.socket);
 }
 
 static pthread_once_t netdClientInitOnce = PTHREAD_ONCE_INIT;
 
 extern "C" __LIBC_HIDDEN__ void netdClientInit() {
     if (pthread_once(&netdClientInitOnce, netdClientInitImpl)) {
-        __libc_format_log(ANDROID_LOG_ERROR, "netdClient",
-                          "Unable to initialize netd_client component.");
+        __libc_format_log(ANDROID_LOG_ERROR, "netdClient", "Failed to initialize netd_client");
     }
 }
diff --git a/libc/bionic/NetdClientDispatch.cpp b/libc/bionic/NetdClientDispatch.cpp
index 17bbd9d..67fa197 100644
--- a/libc/bionic/NetdClientDispatch.cpp
+++ b/libc/bionic/NetdClientDispatch.cpp
@@ -22,8 +22,9 @@
 #define __socketcall
 #endif
 
-extern "C" __socketcall int __accept(int, sockaddr*, socklen_t*);
+extern "C" __socketcall int __accept4(int, sockaddr*, socklen_t*, int);
 extern "C" __socketcall int __connect(int, const sockaddr*, socklen_t);
+extern "C" __socketcall int __socket(int, int, int);
 
 static unsigned fallBackNetIdForResolv(unsigned netId) {
     return netId;
@@ -32,7 +33,8 @@
 // This structure is modified only at startup (when libc.so is loaded) and never
 // afterwards, so it's okay that it's read later at runtime without a lock.
 __LIBC_HIDDEN__ NetdClientDispatch __netdClientDispatch __attribute__((aligned(32))) = {
-    __accept,
+    __accept4,
     __connect,
+    __socket,
     fallBackNetIdForResolv,
 };
diff --git a/libc/bionic/accept.cpp b/libc/bionic/accept.cpp
index 8073234..7f7aa06 100644
--- a/libc/bionic/accept.cpp
+++ b/libc/bionic/accept.cpp
@@ -14,10 +14,8 @@
  * limitations under the License.
  */
 
-#include "private/NetdClientDispatch.h"
-
 #include <sys/socket.h>
 
 int accept(int sockfd, sockaddr* addr, socklen_t* addrlen) {
-    return __netdClientDispatch.accept(sockfd, addr, addrlen);
+    return accept4(sockfd, addr, addrlen, 0);
 }
diff --git a/libc/bionic/accept4.cpp b/libc/bionic/accept4.cpp
new file mode 100644
index 0000000..9f58dc1
--- /dev/null
+++ b/libc/bionic/accept4.cpp
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "private/NetdClientDispatch.h"
+
+#include <sys/socket.h>
+
+int accept4(int sockfd, sockaddr* addr, socklen_t* addrlen, int flags) {
+    return __netdClientDispatch.accept4(sockfd, addr, addrlen, flags);
+}
diff --git a/libc/bionic/socket.cpp b/libc/bionic/socket.cpp
new file mode 100644
index 0000000..2f9e145
--- /dev/null
+++ b/libc/bionic/socket.cpp
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "private/NetdClientDispatch.h"
+
+#include <sys/socket.h>
+
+int socket(int domain, int type, int protocol) {
+    return __netdClientDispatch.socket(domain, type, protocol);
+}