int process_uevent_message(int sock) { char buffer[64 * 1024]; char *s = buffer, *p; char *end; int count, param_idx = 0, ret; struct uevent *event; count = recv(sock, buffer, sizeof(buffer), 0); if (count < 0) { LOGE("Error receiving uevent (%s)", strerror(errno)); return -errno; } event = malloc(sizeof(struct uevent)); if (!event) { LOGE("Error allcating memroy (%s)", strerror(errno)); return -errno; } memset(event, 0, sizeof(struct uevent)); end = s + count; for (p = s; *p != '@'; p++) ; p++; event->path = strdup(p); s += strlen(s) + 1; LOGE("UEVENT %s\n",s); while (s < end) { if (!strncmp(s, "ACTION=", strlen("ACTION="))) { char *a = s + strlen("ACTION="); if (!strcmp(a, "add")) event->action = action_add; else if (!strcmp(a, "change")) event->action = action_change; else if (!strcmp(a, "remove")) event->action = action_remove; } else if (!strncmp(s, "SEQNUM=", strlen("SEQNUM="))) event->seqnum = atoi(s + strlen("SEQNUM=")); else if (!strncmp(s, "SUBSYSTEM=", strlen("SUBSYSTEM="))) event->subsystem = strdup(s + strlen("SUBSYSTEM=")); else event->param[param_idx++] = strdup(s); s += strlen(s) + 1; } ret = dispatch_uevent(event); #if DEBUG_UEVENT dump_uevent(event); #endif free_uevent(event); return ret; }
static int dispatch_uevent(struct uevent *event) { int i; #if DEBUG_UEVENT dump_uevent(event); #endif for (i = 0; dispatch_table[i].subsystem != NULL; i++) { if (!strcmp(dispatch_table[i].subsystem, event->subsystem)) return dispatch_table[i].dispatch(event); } #if DEBUG_UEVENT LOG_VOL("No uevent handlers registered for '%s' subsystem", event->subsystem); #endif return 0; }