properly handle return codes
[project/procd.git] / plug / hotplug.c
index b50c04e..1a98e8b 100644 (file)
@@ -22,6 +22,7 @@
 #include <libubox/blobmsg_json.h>
 #include <libubox/json_script.h>
 #include <libubox/uloop.h>
+#include <json-c/json.h>
 
 #include <fcntl.h>
 #include <unistd.h>
@@ -197,7 +198,10 @@ send_to_kernel:
                ERROR("Failed to open %s\n", loadpath);
                exit(-1);
        }
-       write(load, "1", 1);
+       if (write(load, "1", 1) == -1) {
+               ERROR("Failed to write to %s\n", loadpath);
+               exit(-1);
+       }
        close(load);
 
        snprintf(syspath, sizeof(syspath), "/sys/%s/data", dev);
@@ -213,7 +217,10 @@ send_to_kernel:
                if (len <= 0)
                        break;
 
-               write(fw, buf, len);
+               if (write(fw, buf, len) == -1) {
+                       ERROR("failed to write firmware file %s/%s to %s\n", dir, file, dev);
+                       break;
+               }
        }
 
        if (src >= 0)
@@ -221,7 +228,8 @@ send_to_kernel:
        close(fw);
 
        load = open(loadpath, O_WRONLY);
-       write(load, "0", 1);
+       if (write(load, "0", 1) == -1)
+               ERROR("failed to write to %s\n", loadpath);
        close(load);
 
        DEBUG(2, "Done loading %s\n", path);
@@ -335,7 +343,7 @@ rule_handle_file(struct json_script_ctx *ctx, const char *name)
        json_object *obj;
 
        obj = json_object_from_file((char*)name);
-       if (is_error(obj))
+       if (!obj)
                return NULL;
 
        blob_buf_init(&script, 0);
@@ -463,10 +471,8 @@ void hotplug(char *rules)
                exit(1);
        }
 
-       if (setsockopt(hotplug_fd.fd, SOL_SOCKET, SO_RCVBUFFORCE, &nlbufsize, sizeof(nlbufsize))) {
+       if (setsockopt(hotplug_fd.fd, SOL_SOCKET, SO_RCVBUFFORCE, &nlbufsize, sizeof(nlbufsize)))
                ERROR("Failed to resize receive buffer: %s\n", strerror(errno));
-               exit(1);
-       }
 
        json_script_init(&jctx);
        queue_proc.cb = queue_proc_cb;