parsing netlink messaag:
bool NetlinkEvent::decode(char *buffer, int size) {
char *s = buffer;
char *end;
int param_idx = 0;
int i;
int first = 1;
end = s + size;
while (s < end) {
if (first) {
char *p;
for (p = s; *p != '@'; p++);
p++;
mPath = strdup(p);
first = 0;
} else {
if (!strncmp(s, "ACTION=", strlen("ACTION="))) {
char *a = s + strlen("ACTION=");
if (!strcmp(a, "add"))
mAction = NlActionAdd;
else if (!strcmp(a, "remove"))
mAction = NlActionRemove;
else if (!strcmp(a, "change"))
mAction = NlActionChange;
} else if (!strncmp(s, "SEQNUM=", strlen("SEQNUM=")))
mSeq = atoi(s + strlen("SEQNUM="));
else if (!strncmp(s, "SUBSYSTEM=", strlen("SUBSYSTEM=")))
mSubsystem = strdup(s + strlen("SUBSYSTEM="));
else
mParams[param_idx++] = strdup(s);
}
s+= strlen(s) + 1;
}
return true;
}
可以順便知道kobject, uevent 的 message 內容。在 Documentation/device-mapper/dm-uevent.txt 有例子:
UEVENT[1192521009.711215] change@/block/dm-3 ACTION=change DEVPATH=/block/dm-3 SUBSYSTEM=block DM_TARGET=multipath DM_ACTION=PATH_FAILED DM_SEQNUM=1 DM_PATH=8:32 DM_NR_VALID_PATHS=0 DM_NAME=mpath2 DM_UUID=mpath-35333333000002328 MINOR=3 MAJOR=253 SEQNUM=1130
沒有留言:
張貼留言