hush: deal with umask TODO (symbolic modes)

function                                             old     new   delta
builtin_umask                                         79     125     +46
This commit is contained in:
Denis Vlasenko 2009-04-18 02:06:54 +00:00
parent 6b9e05392b
commit eb85849b50
2 changed files with 26 additions and 16 deletions

View File

@ -12646,6 +12646,8 @@ umaskcmd(int argc UNUSED_PARAM, char **argv)
S_IROTH, S_IWOTH, S_IXOTH S_IROTH, S_IWOTH, S_IXOTH
}; };
/* TODO: use bb_parse_mode() instead */
char *ap; char *ap;
mode_t mask; mode_t mask;
int i; int i;
@ -12712,7 +12714,6 @@ umaskcmd(int argc UNUSED_PARAM, char **argv)
* *
* Public domain. * Public domain.
*/ */
struct limits { struct limits {
uint8_t cmd; /* RLIMIT_xxx fit into it */ uint8_t cmd; /* RLIMIT_xxx fit into it */
uint8_t factor_shift; /* shift by to get rlim_{cur,max} values */ uint8_t factor_shift; /* shift by to get rlim_{cur,max} values */

View File

@ -6742,24 +6742,33 @@ static int builtin_source(char **argv)
static int builtin_umask(char **argv) static int builtin_umask(char **argv)
{ {
mode_t new_umask; int rc;
const char *arg = argv[1]; mode_t mask;
if (arg) {
//TODO: umask may take chmod-like symbolic masks mask = umask(0);
new_umask = bb_strtou(arg, NULL, 8); if (argv[1]) {
if (errno) { mode_t old_mask = mask;
//Message? bash examples:
//bash: umask: 'q': invalid symbolic mode operator mask ^= 0777;
//bash: umask: 999: octal number out of range rc = bb_parse_mode(argv[1], &mask);
return EXIT_FAILURE; mask ^= 0777;
if (rc == 0) {
mask = old_mask;
/* bash messages:
* bash: umask: 'q': invalid symbolic mode operator
* bash: umask: 999: octal number out of range
*/
bb_error_msg("%s: '%s' invalid mode", argv[0], argv[1]);
} }
} else { } else {
new_umask = umask(0); rc = 1;
printf("%.3o\n", (unsigned) new_umask); /* Mimic bash */
/* fall through and restore new_umask which we set to 0 */ printf("%04o\n", (unsigned) mask);
/* fall through and restore mask which we set to 0 */
} }
umask(new_umask); umask(mask);
return EXIT_SUCCESS;
return !rc; /* rc != 0 - success */
} }
/* http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#unset */ /* http://www.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#unset */