Commit | Line | Data |
---|---|---|
bebb0ee6 BJ |
1 | # |
2 | /* | |
3 | * pix - pi then px | |
4 | * | |
5 | * Bill Joy UCB August 26, 1977 | |
6 | */ | |
7 | ||
8 | #define ERRS 1 | |
9 | ||
10 | char *name; | |
11 | ||
12 | int onintr(); | |
13 | ||
14 | #define ETXTBSY 26 | |
15 | ||
16 | main(argc, argv) | |
17 | int argc; | |
18 | char *argv[]; | |
19 | { | |
20 | register char **av; | |
21 | register int ac; | |
22 | int i, io, pid, status; | |
23 | extern errno; | |
24 | ||
25 | do | |
26 | io = open("/dev/null", 0); | |
27 | while (io >= 0 && io < 3); | |
28 | for (io = 3; io < 15; io++) | |
29 | close(io); | |
30 | if ((signal(2, 1) & 01) == 0) | |
31 | signal(2, onintr); | |
32 | for (ac = 1; ac < argc; ac++) | |
33 | if (dotted(argv[ac], 'p')) { | |
34 | ac++; | |
35 | break; | |
36 | } | |
37 | name = "-o/tmp/pixaXXXXX" + 2; | |
38 | mktemp(name); | |
39 | for (;;) { | |
40 | io = creat(name, 0400); | |
41 | if (io > 0) | |
42 | break; | |
43 | if (name[8] == 'z') { | |
44 | perror(name); | |
45 | exit(1); | |
46 | } | |
47 | name[8]++; | |
48 | } | |
49 | pid = fork(); | |
50 | if (pid == -1) { | |
51 | write(2, "No more processes\n", 18); | |
52 | onintr(); | |
53 | } | |
54 | if (pid == 0) { | |
55 | if (io != 3) { | |
56 | write(2, "Impossible error in pix\n", 24); | |
57 | onintr(); | |
58 | } | |
59 | argv[ac] = 0; | |
60 | argv[0] = name - 2; | |
61 | #ifdef CORY | |
62 | /* Temporary to allow accounting to distinguish pix's and pi's */ | |
63 | do | |
64 | execv("/usr/bin/pix-pi", argv); | |
65 | while (errno == ETXTBSY); | |
66 | #endif | |
67 | do | |
68 | execv("/usr/ucb/pi", argv); | |
69 | while (errno == ETXTBSY); | |
70 | do | |
71 | execv("/usr/bin/pi", argv); | |
72 | while (errno == ETXTBSY); | |
73 | write(2, "Can't find pi\n", 14); | |
74 | onintr(); | |
75 | } | |
76 | close(io); | |
77 | do | |
78 | i = wait(&status); | |
79 | while (i != pid && i != -1); | |
80 | if (i == -1 || (status & 0377)) | |
81 | onintr(); | |
82 | if (status != 0) { | |
83 | if ((status >> 8) == ERRS) | |
84 | write(2, "Execution suppressed due to compilation errors\n", 47); | |
85 | onintr(); | |
86 | } | |
87 | ac--; | |
88 | argv[ac] = name - 2; | |
89 | argv[argc] = 0; | |
90 | #ifdef CORY | |
91 | /* Temporary to allow accounting to distinguish pix's and px's */ | |
92 | do | |
93 | execv("/usr/bin/pix-px", &argv[ac]); | |
94 | while (errno == ETXTBSY); | |
95 | #endif | |
96 | do | |
97 | execv("/usr/ucb/px", &argv[ac]); | |
98 | while (errno == ETXTBSY); | |
99 | do | |
100 | execv("/usr/bin/px", &argv[ac]); | |
101 | while (errno == ETXTBSY); | |
102 | write(2, "Can't find px\n", 14); | |
103 | onintr(); | |
104 | } | |
105 | ||
106 | dotted(cp, ch) | |
107 | char *cp, ch; | |
108 | { | |
109 | register int i; | |
110 | ||
111 | i = strlen(cp); | |
112 | return (i > 1 && cp[i - 2] == '.' && cp[i - 1] == ch); | |
113 | } | |
114 | ||
115 | onintr() | |
116 | { | |
117 | ||
118 | signal(2, 1); | |
119 | unlink(name); | |
120 | exit(1); | |
121 | } |