diff options
-rw-r--r-- | main.c | 1 | ||||
-rw-r--r-- | toys.h | 2 | ||||
-rw-r--r-- | toys/mdev.c | 3 | ||||
-rw-r--r-- | toys/mkfifo.c | 3 | ||||
-rw-r--r-- | toys/touch.c | 4 | ||||
-rw-r--r-- | toys/toysh.c | 1 |
6 files changed, 7 insertions, 7 deletions
@@ -70,6 +70,7 @@ void toy_init(struct toy_list *which, char *argv[]) toys.argv = argv; if (NEED_OPTIONS && which->options) get_optflags(); else toys.optargs = argv+1; + if (which->flags & TOYFLAG_UMASK) toys.old_umask = umask(0); } // Run a toy. @@ -61,6 +61,7 @@ void toy_exec(char *argv[]); #define TOYMASK_LOCATION ((1<<4)-1) #define TOYFLAG_NOFORK (1<<4) +#define TOYFLAG_UMASK (1<<5) extern struct toy_list { char *name; @@ -79,6 +80,7 @@ extern struct toy_context { char **optargs; // Arguments left over from get_optflags() int optc; // Count of optargs int exithelp; // Should error_exit print a usage message first? (Option parsing.) + int old_umask; } toys; // One big temporary buffer, for use by applets (not library functions). diff --git a/toys/mdev.c b/toys/mdev.c index dff2e5c2..6e69a770 100644 --- a/toys/mdev.c +++ b/toys/mdev.c @@ -7,7 +7,7 @@ * * Not in SUSv3. -USE_MDEV(NEWTOY(mdev, "s", TOYFLAG_USR|TOYFLAG_BIN)) +USE_MDEV(NEWTOY(mdev, "s", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_UMASK)) config MDEV bool "mdev" @@ -166,7 +166,6 @@ found_device: } sprintf(temp, "/dev/%s", device_name); - umask(0); if (mknod(temp, mode | type, makedev(major, minor)) && errno != EEXIST) perror_exit("mknod %s failed", temp); diff --git a/toys/mkfifo.c b/toys/mkfifo.c index 0f57ca5d..39ec51ad 100644 --- a/toys/mkfifo.c +++ b/toys/mkfifo.c @@ -4,7 +4,7 @@ * * See http://www.opengroup.org/onlinepubs/009695399/utilities/mkfifo.html -USE_MKFIFO(NEWTOY(mkfifo, "<1m:", TOYFLAG_BIN)) +USE_MKFIFO(NEWTOY(mkfifo, "<1m:", TOYFLAG_BIN|TOYFLAG_UMASK)) config MKFIFO bool "mkfifo" @@ -40,7 +40,6 @@ void mkfifo_main(void) error_exit("Invalid mode"); } else mode = 0644; - umask(0); for (i = 0; (arg = toys.optargs[i]); i++) if (mkfifo(arg, mode)) perror_exit(arg); diff --git a/toys/touch.c b/toys/touch.c index c8cba76b..bead28fb 100644 --- a/toys/touch.c +++ b/toys/touch.c @@ -6,7 +6,7 @@ * * See http://www.opengroup.org/onlinepubs/009695399/utilities/touch.html -USE_TOUCH(NEWTOY(touch, "l#t:r:mca", TOYFLAG_BIN)) +USE_TOUCH(NEWTOY(touch, "l#t:r:mca", TOYFLAG_BIN|TOYFLAG_UMASK)) config TOUCH bool "touch" @@ -86,9 +86,7 @@ void touch_main(void) if (stat(arg, &sb)) { if (!(toys.optflags & OPT_NOCREATE)) { - int temp = umask(0); xcreate(arg, O_CREAT, 0644); - if (CFG_TOYBOX_FREE) umask(temp); if (stat(arg, &sb)) goto error; } diff --git a/toys/toysh.c b/toys/toysh.c index e2800681..17467fad 100644 --- a/toys/toysh.c +++ b/toys/toysh.c @@ -296,6 +296,7 @@ static void run_pipeline(struct pipeline *line) tl->toy_main(); cmd->pid = toys.exitval; free(toys.optargs); + if (toys.old_umask) umask(toys.old_umask); memcpy(&toys, &temp, sizeof(struct toy_context)); } else { int status; |