Merge changes I087d0074,I8a51924e
* changes:
Permit 0 length writes.
Let SocketClient users write binary data to clients.
diff --git a/include/sysutils/SocketClient.h b/include/sysutils/SocketClient.h
index e7fb177..2fcc331 100644
--- a/include/sysutils/SocketClient.h
+++ b/include/sysutils/SocketClient.h
@@ -28,8 +28,12 @@
uid_t getUid() const { return mUid; }
gid_t getGid() const { return mGid; }
+ // Send null-terminated C strings:
int sendMsg(int code, const char *msg, bool addErrno);
int sendMsg(const char *msg);
+
+ // Sending binary data:
+ int sendData(const void *data, int len);
};
typedef android::List<SocketClient *> SocketClientCollection;
diff --git a/libsysutils/src/SocketClient.cpp b/libsysutils/src/SocketClient.cpp
index 8e5f154..c9c7417 100644
--- a/libsysutils/src/SocketClient.cpp
+++ b/libsysutils/src/SocketClient.cpp
@@ -50,14 +50,26 @@
}
// Send the message including null character
+ if (sendData(msg, strlen(msg) + 1) != 0) {
+ SLOGW("Unable to send msg '%s'", msg);
+ return -1;
+ }
+ return 0;
+}
+
+int SocketClient::sendData(const void* data, int len) {
int rc = 0;
- const char *p = msg;
- int brtw = strlen(msg) + 1;
+ const char *p = (const char*) data;
+ int brtw = len;
+
+ if (len == 0) {
+ return 0;
+ }
pthread_mutex_lock(&mWriteMutex);
- while(brtw) {
- if ((rc = write(mSocket,p, brtw)) < 0) {
- SLOGW("Unable to send msg '%s' (%s)", msg, strerror(errno));
+ while (brtw > 0) {
+ if ((rc = write(mSocket, p, brtw)) < 0) {
+ SLOGW("write error (%s)", strerror(errno));
pthread_mutex_unlock(&mWriteMutex);
return -1;
} else if (!rc) {
diff --git a/rootdir/init.rc b/rootdir/init.rc
index d1b27d0..90c017b 100644
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -320,6 +320,7 @@
service netd /system/bin/netd
socket netd stream 0660 root system
+ socket dnsproxyd stream 0660 root inet
service debuggerd /system/bin/debuggerd