18 char curdir
[PATH_MAX
];
20 _PROTOTYPE(int main
, (int argc
, char *argv
[]));
21 _PROTOTYPE(void test6a
, (void));
22 _PROTOTYPE(void test6b
, (void));
23 _PROTOTYPE(void test6c
, (void));
24 _PROTOTYPE(void e
, (int n
));
25 _PROTOTYPE(void quit
, (void));
34 if (geteuid() == 0 || getuid() == 0) {
35 printf("Test 6 cannot run as root; test aborted\n");
39 if (argc
== 2) m
= atoi(argv
[1]);
44 getcwd(curdir
, PATH_MAX
);
45 system("rm -rf DIR_06; mkdir DIR_06");
48 for (i
= 0; i
< 70; i
++) {
49 if (m
& 00001) test6a();
50 if (m
& 00002) test6b();
51 if (m
& 00004) test6c();
55 return(-1); /* impossible */
60 /* Test sbrk() and brk(). */
62 char *addr
, *addr2
, *addr3
;
63 int i
, del
, click
, click2
;
67 addr
= sbrk(0); /* force break to a click boundary */
68 for (i
= 0; i
< 10; i
++) sbrk(7 * i
);
69 for (i
= 0; i
< 10; i
++) sbrk(-7 * i
);
70 if (sbrk(0) != addr
) e(1);
72 if (brk(addr
) != 0) e(2);
73 if (sbrk(0) != addr
) e(3);
80 } while (addr2
== addr
);
83 if (sbrk(0) != addr
) e(4);
85 if (sbrk(0) != addr
) e(5);
92 } while (addr3
== addr
);
93 click2
= addr
- addr3
;
95 if (sbrk(0) != addr
) e(6);
97 if (sbrk(0) != addr
) e(8);
98 if (click
!= click2
) e(9);
100 brk(addr
+ 2 * click
);
101 if (sbrk(0) != addr
+ 2 * click
) e(10);
103 if (sbrk(0) != addr
+ 5 * click
) e(11);
105 if (sbrk(0) != addr
) e(12);
113 signal(SIGQUIT
, SIG_IGN
);
115 for (i
= 0; i
< 5000; i
++)
116 if (zilch
[i
] != 0) err
++;
118 kill(getpid(), SIGQUIT
);
123 /* Test mknod, chdir, chmod, chown, access. */
129 if (getuid() != 0) return;
130 for (j
= 0; j
< 2; j
++) {
133 if (chdir("/") < 0) e(1);
134 if (mknod("dir", 040700, 0) < 0) e(2);
135 if (link("/", "/dir/..") < 0) e(3);
136 if (mknod("T3a", 0777, 0) < 0) e(4);
137 if (mknod("/dir/T3b", 0777, 0) < 0) e(5);
138 if (mknod("dir/T3c", 0777, 0) < 0) e(6);
139 if ((i
= open("/dir/T3b", 0)) < 0) e(7);
140 if (close(i
) < 0) e(8);
141 if ((i
= open("dir/T3c", O_RDONLY
)) < 0) e(9);
142 if (close(i
) < 0) e(10);
143 if (chdir("dir") < 0) e(11);
144 if ((i
= open("T3b", 0)) < 0) e(12);
145 if (close(i
) < 0) e(13);
146 if ((i
= open("../T3a", O_RDONLY
)) < 0) e(14);
147 if (close(i
) < 0) e(15);
148 if ((i
= open("../dir/../dir/../dir/../dir/../dir/T3c", O_RDONLY
)) < 0)
150 if (close(i
) < 0) e(17);
152 if (chmod("../dir/../dir/../dir/../dir/../T3a", 0123) < 0) e(18);
153 if (stat("../dir/../dir/../dir/../T3a", &s
) < 0) e(19);
154 if ((s
.st_mode
& 077777) != 0123) e(20);
155 if (chmod("../dir/../dir/../T3a", 0456) < 0) e(21);
156 if (stat("../T3a", &s
) < 0) e(22);
157 if ((s
.st_mode
& 077777) != 0456) e(23);
158 if (chown("../dir/../dir/../T3a", 20, 30) < 0) e(24);
159 if (stat("../T3a", &s
) < 0) e(25);
160 if (s
.st_uid
!= 20) e(26);
161 if (s
.st_gid
!= 30) e(27);
163 if ((i
= open("/T3c", O_RDONLY
)) >= 0) e(28);
164 if ((i
= open("/T3a", O_RDONLY
)) < 0) e(29);
165 if (close(i
) < 0) e(30);
167 if (access("/T3a", 4) < 0) e(31);
168 if (access("/dir/T3b", 4) < 0) e(32);
169 if (access("/dir/T3d", 4) >= 0) e(33);
171 if (unlink("T3b") < 0) e(34);
172 if (unlink("T3c") < 0) e(35);
173 if (unlink("..") < 0) e(36);
174 if (chdir("/") < 0) e(37);
175 if (unlink("dir") < 0) e(38);
176 if (unlink("/T3a") < 0) e(39);
185 int err_num
= errno
; /* save errno in case printf clobbers it */
187 printf("Subtest %d, error %d errno=%d ", subtest
, n
, errno
);
188 errno
= err_num
; /* restore errno, just in case */
190 if (errct
++ > MAX_ERROR
) {
191 printf("Too many errors; test aborted\n");
193 system("rm -rf DIR*");
202 system("rm -rf DIR*");
205 system("rm -rf DIR*");
210 printf("%d errors\n", errct
);