1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
--- ksh-openbsd_cvs/c_sh.c 2010-03-27 17:25:30.000000000 +0100
+++ ksh-openbsd_cvs.new/c_sh.c 2010-04-01 21:01:24.132137763 +0200
@@ -837,19 +837,13 @@ c_mknod(char **wp)
{
int argc, optc, ismkfifo = 0, ret;
char **argv;
- void *set = NULL;
- mode_t mode = 0, oldmode = 0;
+ mode_t mode = 0, old_umask = -1;
while ((optc = ksh_getopt(wp, &builtin_opt, "m:")) != -1) {
switch (optc) {
case 'm':
- set = setmode(builtin_opt.optarg);
- if (set == NULL) {
- bi_errorf("invalid file mode");
- return 1;
- }
- mode = getmode(set, DEFFILEMODE);
- free(set);
+ old_umask = umask(0);
+ mode |= strtoul(builtin_opt.optarg, NULL, 8);
break;
default:
goto usage;
@@ -866,18 +860,17 @@ c_mknod(char **wp)
} else if (argc != 4)
goto usage;
- if (set)
- oldmode = umask(0);
- else
- mode = DEFFILEMODE;
+ if (old_umask == -1)
+ mode |= DEFFILEMODE;
if (ismkfifo)
ret = domkfifo(argc, argv, mode);
else
ret = domknod(argc, argv, mode);
- if (set)
- umask(oldmode);
+ if (old_umask != -1)
+ umask(old_umask);
+
return ret;
usage:
builtin_argv0 = NULL;
|