Merge "NetlinkListener: eliminate duplicate code"
This commit is contained in:
commit
9b7ee137e0
1 changed files with 2 additions and 23 deletions
|
@ -22,6 +22,7 @@
|
|||
|
||||
#define LOG_TAG "NetlinkListener"
|
||||
#include <cutils/log.h>
|
||||
#include <cutils/uevent.h>
|
||||
|
||||
#include <sysutils/NetlinkListener.h>
|
||||
#include <sysutils/NetlinkEvent.h>
|
||||
|
@ -34,35 +35,13 @@ bool NetlinkListener::onDataAvailable(SocketClient *cli)
|
|||
{
|
||||
int socket = cli->getSocket();
|
||||
ssize_t count;
|
||||
char cred_msg[CMSG_SPACE(sizeof(struct ucred))];
|
||||
struct sockaddr_nl snl;
|
||||
struct iovec iov = {mBuffer, sizeof(mBuffer)};
|
||||
struct msghdr hdr = {&snl, sizeof(snl), &iov, 1, cred_msg, sizeof(cred_msg), 0};
|
||||
|
||||
count = TEMP_FAILURE_RETRY(recvmsg(socket, &hdr, 0));
|
||||
count = TEMP_FAILURE_RETRY(uevent_checked_recv(socket, mBuffer, sizeof(mBuffer)));
|
||||
if (count < 0) {
|
||||
SLOGE("recvmsg failed (%s)", strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((snl.nl_groups != 1) || (snl.nl_pid != 0)) {
|
||||
SLOGE("ignoring non-kernel netlink multicast message");
|
||||
return false;
|
||||
}
|
||||
|
||||
struct cmsghdr * cmsg = CMSG_FIRSTHDR(&hdr);
|
||||
|
||||
if (cmsg == NULL || cmsg->cmsg_type != SCM_CREDENTIALS) {
|
||||
SLOGE("ignoring message with no sender credentials");
|
||||
return false;
|
||||
}
|
||||
|
||||
struct ucred * cred = (struct ucred *)CMSG_DATA(cmsg);
|
||||
if (cred->uid != 0) {
|
||||
SLOGE("ignoring message from non-root UID %d", cred->uid);
|
||||
return false;
|
||||
}
|
||||
|
||||
NetlinkEvent *evt = new NetlinkEvent();
|
||||
if (!evt->decode(mBuffer, count)) {
|
||||
SLOGE("Error decoding NetlinkEvent");
|
||||
|
|
Loading…
Reference in a new issue