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