X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fprocd.git;a=blobdiff_plain;f=plug%2Fhotplug.c;h=80e6e4db9e734b708f62d4f41a695486f654188f;hp=ffedba242bf450c96484abdea3c4cfc05c0eb0fe;hb=HEAD;hpb=3ba6b45c59b4f6df6ba16124ae41f0bb8cd47223 diff --git a/plug/hotplug.c b/plug/hotplug.c index ffedba2..80e6e4d 100644 --- a/plug/hotplug.c +++ b/plug/hotplug.c @@ -238,7 +238,7 @@ static void handle_firmware(struct blob_attr *msg, struct blob_attr *data) sprintf(path, "%s/%s", dir, file); if (stat(path, &s)) { - ERROR("Could not find firmware %s\n", path); + ERROR("Could not find firmware %s: %m\n", path); src = -1; s.st_size = 0; goto send_to_kernel; @@ -246,7 +246,7 @@ static void handle_firmware(struct blob_attr *msg, struct blob_attr *data) src = open(path, O_RDONLY); if (src < 0) { - ERROR("Failed to open %s\n", path); + ERROR("Failed to open %s: %m\n", path); s.st_size = 0; goto send_to_kernel; } @@ -255,11 +255,11 @@ send_to_kernel: snprintf(loadpath, sizeof(loadpath), "/sys/%s/loading", dev); load = open(loadpath, O_WRONLY); if (!load) { - ERROR("Failed to open %s\n", loadpath); + ERROR("Failed to open %s: %m\n", loadpath); exit(-1); } if (write(load, "1", 1) == -1) { - ERROR("Failed to write to %s\n", loadpath); + ERROR("Failed to write to %s: %m\n", loadpath); exit(-1); } close(load); @@ -267,7 +267,7 @@ send_to_kernel: snprintf(syspath, sizeof(syspath), "/sys/%s/data", dev); fw = open(syspath, O_WRONLY); if (fw < 0) { - ERROR("Failed to open %s\n", syspath); + ERROR("Failed to open %s: %m\n", syspath); exit(-1); } @@ -278,7 +278,7 @@ send_to_kernel: break; if (write(fw, buf, len) == -1) { - ERROR("failed to write firmware file %s/%s to %s\n", dir, file, dev); + ERROR("failed to write firmware file %s/%s to %s: %m\n", dir, file, dev); break; } } @@ -289,7 +289,7 @@ send_to_kernel: load = open(loadpath, O_WRONLY); if (write(load, "0", 1) == -1) - ERROR("failed to write to %s\n", loadpath); + ERROR("failed to write to %s: %m\n", loadpath); close(load); DEBUG(2, "Done loading %s\n", path); @@ -392,12 +392,12 @@ static void queue_add(struct cmd_handler *h, struct blob_attr *msg, struct blob_ &_data, blob_pad_len(data), NULL); - c->msg = _msg; - c->data = _data; - if (!c) return; + c->msg = _msg; + c->data = _data; + memcpy(c->msg, msg, blob_pad_len(msg)); memcpy(c->data, data, blob_pad_len(data)); c->handler = h->handler; @@ -434,12 +434,10 @@ static void handle_button_complete(struct blob_attr *msg, struct blob_attr *data if (!name) return; - b = malloc(sizeof(*b)); + b = calloc(1, sizeof(*b)); if (!b) return; - memset(b, 0, sizeof(*b)); - b->data = malloc(blob_pad_len(data)); b->name = strdup(name); b->seen = timeout; @@ -584,26 +582,25 @@ void hotplug_last_event(uloop_timeout_handler handler) void hotplug(char *rules) { - struct sockaddr_nl nls; + struct sockaddr_nl nls = {}; int nlbufsize = 512 * 1024; rule_file = strdup(rules); - memset(&nls,0,sizeof(struct sockaddr_nl)); nls.nl_family = AF_NETLINK; nls.nl_pid = getpid(); nls.nl_groups = -1; if ((hotplug_fd.fd = socket(PF_NETLINK, SOCK_DGRAM | SOCK_CLOEXEC, NETLINK_KOBJECT_UEVENT)) == -1) { - ERROR("Failed to open hotplug socket: %s\n", strerror(errno)); + ERROR("Failed to open hotplug socket: %m\n"); exit(1); } if (bind(hotplug_fd.fd, (void *)&nls, sizeof(struct sockaddr_nl))) { - ERROR("Failed to bind hotplug socket: %s\n", strerror(errno)); + ERROR("Failed to bind hotplug socket: %m\n"); exit(1); } if (setsockopt(hotplug_fd.fd, SOL_SOCKET, SO_RCVBUFFORCE, &nlbufsize, sizeof(nlbufsize))) - ERROR("Failed to resize receive buffer: %s\n", strerror(errno)); + ERROR("Failed to resize receive buffer: %m\n"); json_script_init(&jctx); queue_proc.cb = queue_proc_cb;