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