syslog: fix incorrect use of sizeof() in vsnprintf()
[project/procd.git] / hotplug.c
index c2276ed..422e849 100644 (file)
--- a/hotplug.c
+++ b/hotplug.c
@@ -80,6 +80,7 @@ static void mkdir_p(char *dir)
 
 static void handle_makedev(struct blob_attr *msg, struct blob_attr *data)
 {
+       unsigned int oldumask = umask(0);
        static struct blobmsg_policy mkdev_policy[2] = {
                { .type = BLOBMSG_TYPE_STRING },
                { .type = BLOBMSG_TYPE_STRING },
@@ -104,6 +105,7 @@ static void handle_makedev(struct blob_attr *msg, struct blob_attr *data)
                                m | strtoul(blobmsg_data(tb[1]), NULL, 8),
                                makedev(atoi(major), atoi(minor)));
        }
+       umask(oldumask);
 }
 
 static void handle_rm(struct blob_attr *msg, struct blob_attr *data)
@@ -122,7 +124,7 @@ static void handle_exec(struct blob_attr *msg, struct blob_attr *data)
 {
        char *argv[8];
        struct blob_attr *cur;
-       int rem;
+       int rem, fd;
        int i = 0;
 
        blobmsg_for_each_attr(cur, msg, rem)
@@ -136,9 +138,14 @@ static void handle_exec(struct blob_attr *msg, struct blob_attr *data)
        }
 
        if (debug < 2) {
-               close(STDIN_FILENO);
-               close(STDOUT_FILENO);
-               close(STDERR_FILENO);
+               fd = open("/dev/null", O_RDWR);
+               if (fd > -1) {
+                       dup2(fd, STDIN_FILENO);
+                       dup2(fd, STDOUT_FILENO);
+                       dup2(fd, STDERR_FILENO);
+                       if (fd > STDERR_FILENO)
+                               close(fd);
+               }
        }
 
        if (i > 0) {
@@ -261,6 +268,7 @@ static void queue_next(void)
 
        queue_proc.pid = fork();
        if (!queue_proc.pid) {
+               uloop_done();
                c->handler(c->msg, c->data);
                exit(0);
        }