procd: Replace strerror(errno) with %m.
[project/procd.git] / plug / hotplug.c
index ae972f6..d09af62 100644 (file)
@@ -15,6 +15,7 @@
 #include <sys/stat.h>
 #include <sys/socket.h>
 #include <sys/types.h>
+#include <sys/sysmacros.h>
 
 #include <linux/types.h>
 #include <linux/netlink.h>
@@ -391,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;
@@ -430,11 +431,12 @@ static void handle_button_complete(struct blob_attr *msg, struct blob_attr *data
        if (!timeout)
                return;
 
-       b = malloc(sizeof(*b));
-       if (!b || !name)
+       if (!name)
                return;
 
-       memset(b, 0, sizeof(*b));
+       b = calloc(1, sizeof(*b));
+       if (!b)
+               return;
 
        b->data = malloc(blob_pad_len(data));
        b->name = strdup(name);
@@ -488,15 +490,13 @@ static void rule_handle_command(struct json_script_ctx *ctx, const char *name,
        int rem, i;
 
        if (debug > 3) {
-               DEBUG(4, "Command: %s", name);
+               DEBUG(4, "Command: %s\n", name);
                blobmsg_for_each_attr(cur, data, rem)
-                       DEBUG(4, " %s", (char *) blobmsg_data(cur));
-               DEBUG(4, "\n");
+                       DEBUG(4, " %s\n", (char *) blobmsg_data(cur));
 
-               DEBUG(4, "Message:");
+               DEBUG(4, "Message:\n");
                blobmsg_for_each_attr(cur, vars, rem)
-                       DEBUG(4, " %s=%s", blobmsg_name(cur), (char *) blobmsg_data(cur));
-               DEBUG(4, "\n");
+                       DEBUG(4, " %s=%s\n", blobmsg_name(cur), (char *) blobmsg_data(cur));
        }
 
        for (i = 0; i < ARRAY_SIZE(handlers); i++)
@@ -582,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;