aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2009-04-18 02:06:54 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2009-04-18 02:06:54 +0000
commiteb85849b50a3c8af6ef0d3dbbf0fd1387e37d1f8 (patch)
treea970e91569040c0a431f3dbe649f732ff9be0717 /shell
parent6b9e05392b4457f0ea808810761f8fb9efdffc44 (diff)
downloadbusybox-w32-eb85849b50a3c8af6ef0d3dbbf0fd1387e37d1f8.tar.gz
busybox-w32-eb85849b50a3c8af6ef0d3dbbf0fd1387e37d1f8.tar.bz2
busybox-w32-eb85849b50a3c8af6ef0d3dbbf0fd1387e37d1f8.zip
hush: deal with umask TODO (symbolic modes)
function old new delta builtin_umask 79 125 +46
Diffstat (limited to 'shell')
-rw-r--r--shell/ash.c3
-rw-r--r--shell/hush.c39
2 files changed, 26 insertions, 16 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 4acc30110..c53b080a4 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -12646,6 +12646,8 @@ umaskcmd(int argc UNUSED_PARAM, char **argv)
12646 S_IROTH, S_IWOTH, S_IXOTH 12646 S_IROTH, S_IWOTH, S_IXOTH
12647 }; 12647 };
12648 12648
12649 /* TODO: use bb_parse_mode() instead */
12650
12649 char *ap; 12651 char *ap;
12650 mode_t mask; 12652 mode_t mask;
12651 int i; 12653 int i;
@@ -12712,7 +12714,6 @@ umaskcmd(int argc UNUSED_PARAM, char **argv)
12712 * 12714 *
12713 * Public domain. 12715 * Public domain.
12714 */ 12716 */
12715
12716struct limits { 12717struct limits {
12717 uint8_t cmd; /* RLIMIT_xxx fit into it */ 12718 uint8_t cmd; /* RLIMIT_xxx fit into it */
12718 uint8_t factor_shift; /* shift by to get rlim_{cur,max} values */ 12719 uint8_t factor_shift; /* shift by to get rlim_{cur,max} values */
diff --git a/shell/hush.c b/shell/hush.c
index 72589fd7f..edb67747e 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -6742,24 +6742,33 @@ static int builtin_source(char **argv)
6742 6742
6743static int builtin_umask(char **argv) 6743static int builtin_umask(char **argv)
6744{ 6744{
6745 mode_t new_umask; 6745 int rc;
6746 const char *arg = argv[1]; 6746 mode_t mask;
6747 if (arg) { 6747
6748//TODO: umask may take chmod-like symbolic masks 6748 mask = umask(0);
6749 new_umask = bb_strtou(arg, NULL, 8); 6749 if (argv[1]) {
6750 if (errno) { 6750 mode_t old_mask = mask;
6751 //Message? bash examples: 6751
6752 //bash: umask: 'q': invalid symbolic mode operator 6752 mask ^= 0777;
6753 //bash: umask: 999: octal number out of range 6753 rc = bb_parse_mode(argv[1], &mask);
6754 return EXIT_FAILURE; 6754 mask ^= 0777;
6755 if (rc == 0) {
6756 mask = old_mask;
6757 /* bash messages:
6758 * bash: umask: 'q': invalid symbolic mode operator
6759 * bash: umask: 999: octal number out of range
6760 */
6761 bb_error_msg("%s: '%s' invalid mode", argv[0], argv[1]);
6755 } 6762 }
6756 } else { 6763 } else {
6757 new_umask = umask(0); 6764 rc = 1;
6758 printf("%.3o\n", (unsigned) new_umask); 6765 /* Mimic bash */
6759 /* fall through and restore new_umask which we set to 0 */ 6766 printf("%04o\n", (unsigned) mask);
6767 /* fall through and restore mask which we set to 0 */
6760 } 6768 }
6761 umask(new_umask); 6769 umask(mask);
6762 return EXIT_SUCCESS; 6770
6771 return !rc; /* rc != 0 - success */
6763} 6772}
6764 6773
6765/* http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#unset */ 6774/* http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#unset */