summaryrefslogtreecommitdiff
path: root/shell/hush.c
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/hush.c
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/hush.c')
-rw-r--r--shell/hush.c39
1 files changed, 24 insertions, 15 deletions
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 */