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