Skip to content

Commit

Permalink
Merge "NetlinkListener: eliminate duplicate code"
Browse files Browse the repository at this point in the history
  • Loading branch information
nickkral authored and Android (Google) Code Review committed May 11, 2011
2 parents 574ebc4 + 531312e commit 9b7ee13
Showing 1 changed file with 2 additions and 23 deletions.
25 changes: 2 additions & 23 deletions libsysutils/src/NetlinkListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#define LOG_TAG "NetlinkListener"
#include <cutils/log.h>
#include <cutils/uevent.h>

#include <sysutils/NetlinkListener.h>
#include <sysutils/NetlinkEvent.h>
Expand All @@ -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");
Expand Down

0 comments on commit 9b7ee13

Please sign in to comment.