properly fix umask handling
authorJohn Crispin <blogic@openwrt.org>
Wed, 3 Jul 2013 17:16:09 +0000 (19:16 +0200)
committerJohn Crispin <blogic@openwrt.org>
Wed, 3 Jul 2013 18:28:03 +0000 (20:28 +0200)
https://dev.openwrt.org/ticket/13752
https://dev.openwrt.org/ticket/13794

Signed-off-by: John Crispin <blogic@openwrt.org>
hotplug.c
main.c
mkdev.c

index c2276ed..21efcf5 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)
diff --git a/main.c b/main.c
index 71531e3..6610c37 100644 (file)
--- a/main.c
+++ b/main.c
@@ -68,7 +68,6 @@ int main(int argc, char **argv)
                        return usage(argv[0]);
                }
        }
-       umask(0);
        uloop_init();
        procd_signal();
        if (getpid() != 1)
diff --git a/mkdev.c b/mkdev.c
index d507939..0f55554 100644 (file)
--- a/mkdev.c
+++ b/mkdev.c
@@ -47,12 +47,15 @@ static bool find_pattern(const char *name)
 
 static void make_dev(const char *path, bool block, int major, int minor)
 {
+       unsigned int oldumask = umask(0);
        unsigned int _mode = mode | (block ? S_IFBLK : S_IFCHR);
+
        DEBUG(2, "Creating %s device %s(%d,%d)\n",
                block ? "block" : "character",
                path, major, minor);
 
        mknod(path, _mode, makedev(major, minor));
+       umask(oldumask);
 }
 
 static void find_devs(bool block)