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