changeset 257:951110c37fee

Add TOYFLAG_UMASK.
author Rob Landley <rob@landley.net>
date Tue, 12 Feb 2008 19:05:44 -0600
parents 20f1e3da0492
children e64dec29965d
files main.c toys.h toys/mdev.c toys/mkfifo.c toys/touch.c toys/toysh.c
diffstat 6 files changed, 7 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/main.c	Tue Feb 12 18:41:34 2008 -0600
+++ b/main.c	Tue Feb 12 19:05:44 2008 -0600
@@ -70,6 +70,7 @@
 	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.
--- a/toys.h	Tue Feb 12 18:41:34 2008 -0600
+++ b/toys.h	Tue Feb 12 19:05:44 2008 -0600
@@ -61,6 +61,7 @@
 #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 @@
 	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).
--- a/toys/mdev.c	Tue Feb 12 18:41:34 2008 -0600
+++ b/toys/mdev.c	Tue Feb 12 19:05:44 2008 -0600
@@ -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 @@
 	}
 
 	sprintf(temp, "/dev/%s", device_name);
-	umask(0);
 	if (mknod(temp, mode | type, makedev(major, minor)) && errno != EEXIST)
 		perror_exit("mknod %s failed", temp);
 
--- a/toys/mkfifo.c	Tue Feb 12 18:41:34 2008 -0600
+++ b/toys/mkfifo.c	Tue Feb 12 19:05:44 2008 -0600
@@ -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 @@
 			error_exit("Invalid mode");
 	} else mode = 0644;
 
-	umask(0);
 	for (i = 0; (arg = toys.optargs[i]); i++)
 		if (mkfifo(arg, mode))
 			perror_exit(arg);
--- a/toys/touch.c	Tue Feb 12 18:41:34 2008 -0600
+++ b/toys/touch.c	Tue Feb 12 19:05:44 2008 -0600
@@ -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 @@
 
 		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;
 			}
--- a/toys/toysh.c	Tue Feb 12 18:41:34 2008 -0600
+++ b/toys/toysh.c	Tue Feb 12 19:05:44 2008 -0600
@@ -296,6 +296,7 @@
 		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;