libsysutils: reimplement NetlinkEvent::findParam in the proper way

The original implementation can not find correct parameters for certain
cases. For example, if you have both foo_bar and foo, try to find foo
may be mismatched. The correct way is to match with "=".

Change-Id: I403b1a7b889583a57a4f3a14e575181ce93b10ff
This commit is contained in:
Chih-Wei Huang 2010-07-14 14:00:41 +08:00
parent 07b3d09e84
commit 80ec37aa15
1 changed files with 5 additions and 7 deletions

View File

@ -93,13 +93,11 @@ bool NetlinkEvent::decode(char *buffer, int size) {
}
const char *NetlinkEvent::findParam(const char *paramName) {
int i;
for (i = 0; i < NL_PARAMS_MAX; i++) {
if (!mParams[i])
break;
if (!strncmp(mParams[i], paramName, strlen(paramName)))
return &mParams[i][strlen(paramName) + 1];
size_t len = strlen(paramName);
for (int i = 0; mParams[i] && i < NL_PARAMS_MAX; ++i) {
const char *ptr = mParams[i] + len;
if (!strncmp(mParams[i], paramName, len) && *ptr == '=')
return ++ptr;
}
SLOGE("NetlinkEvent::FindParam(): Parameter '%s' not found", paramName);