forked from Stichting-MINIX-Research-Foundation/minix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest10.c
More file actions
152 lines (131 loc) · 2.49 KB
/
Copy pathtest10.c
File metadata and controls
152 lines (131 loc) · 2.49 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/* test 10 */
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
char *name[] = {"t10a", "t10b", "t10c", "t10d", "t10e", "t10f", "t10g",
"t10h", "t10i", "t10j"};
int errct;
long prog[300];
int psize;
_PROTOTYPE(int main, (void));
_PROTOTYPE(void spawn, (int n));
_PROTOTYPE(void mkfiles, (void));
_PROTOTYPE(void cr_file, (char *name, int size));
_PROTOTYPE(void rmfiles, (void));
_PROTOTYPE(void quit, (void));
int main()
{
int i, n, pid, r;
printf("Test 10 ");
fflush(stdout); /* have to flush for child's benefit */
system("rm -rf DIR_10; mkdir DIR_10; cp t10a DIR_10");
chdir("DIR_10");
pid = getpid();
/* Create files t10b ... t10h */
mkfiles();
if (getpid() == pid)
if (fork() == 0) {
execl("t10a", (char *) 0);
exit(0);
}
if (getpid() == pid)
if (fork() == 0) {
execl("t10b", (char *) 0);
exit(0);
}
if (getpid() == pid)
if (fork() == 0) {
execl("t10c", (char *) 0);
exit(0);
}
if (getpid() == pid)
if (fork() == 0) {
execl("t10d", (char *) 0);
exit(0);
}
srand(100);
for (i = 0; i < 60; i++) {
r = rand() & 07;
spawn(r);
}
for (i = 0; i < 4; i++) wait(&n);
rmfiles();
quit();
return(-1); /* impossible */
}
void spawn(n)
int n;
{
int pid, k;
if (pid = fork()) {
wait(&n); /* wait for some child (any one) */
} else {
k = execl(name[n], (char *) 0);
errct++;
printf("Child execl didn't take. file=%s errno=%d\n", name[n], errno);
rmfiles();
exit(1);
printf("Worse yet, EXIT didn't exit\n");
}
}
void mkfiles()
{
int fd;
fd = open("t10a", 0);
if (fd < 0) {
printf("Can't open t10a\n");
exit(1);
}
psize = read(fd, (char *) prog, 300 * 4);
cr_file("t10b", 1600);
cr_file("t10c", 1400);
cr_file("t10d", 2300);
cr_file("t10e", 3100);
cr_file("t10f", 2400);
cr_file("t10g", 1700);
cr_file("t10h", 1500);
cr_file("t10i", 4000);
cr_file("t10j", 2250);
close(fd);
}
void cr_file(name, size)
char *name;
int size;
{
int fd;
#if (CHIP == SPARC)
size += 4000;
#endif
prog[6] = (long) size;
fd = creat(name, 0755);
write(fd, (char *) prog, psize);
close(fd);
}
void rmfiles()
{
unlink("t10b");
unlink("t10c");
unlink("t10d");
unlink("t10e");
unlink("t10f");
unlink("t10g");
unlink("t10h");
unlink("t10i");
unlink("t10j");
}
void quit()
{
chdir("..");
system("rm -rf DIR*");
if (errct == 0) {
printf("ok\n");
exit(0);
} else {
printf("%d errors\n", errct);
exit(1);
}
}