int process_uevent_message(int socket) { char buffer[64 * 1024]; // Thank god we're not in the kernel :) int count; char *s = buffer; char *end; struct uevent *event; int param_idx = 0; int i; int first = 1; int rc = 0; if ((count = recv(socket, buffer, sizeof(buffer), 0)) < 0) { LOGE("Error receiving uevent (%s)", strerror(errno)); return -errno; } if (!(event = malloc(sizeof(struct uevent)))) { LOGE("Error allocating memory (%s)", strerror(errno)); return -errno; } memset(event, 0, sizeof(struct uevent)); end = s + count; while (s < end) { if (first) { char *p; for (p = s; *p != '@'; p++); p++; event->path = strdup(p); first = 0; } else { 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; } rc = dispatch_uevent(event); free_uevent(event); return rc; }
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; }
int simulate_uevent(char *subsys, char *path, char *action, char **params) { struct uevent *event; char tmp[255]; int i, rc; if (!(event = malloc(sizeof(struct uevent)))) { LOGE("Error allocating memory (%s)", strerror(errno)); return -errno; } memset(event, 0, sizeof(struct uevent)); event->subsystem = strdup(subsys); if (!strcmp(action, "add")) event->action = action_add; else if (!strcmp(action, "change")) event->action = action_change; else if (!strcmp(action, "remove")) event->action = action_remove; else { LOGE("Invalid action '%s'", action); return -1; } event->path = strdup(path); for (i = 0; i < UEVENT_PARAMS_MAX; i++) { if (!params[i]) break; event->param[i] = strdup(params[i]); } rc = dispatch_uevent(event); free_uevent(event); return rc; }