18 #include <sys/types.h> 19 #include <sys/socket.h> 20 #include <sys/ioctl.h> 22 #include <netinet/in.h> 33 static RETSIGTYPE sigchild();
45 static struct proc *running =
NULL;
46 static int numchanged = 0;
63 "No spice-3 binary is available for the aspice command.\n");
72 output = wl->wl_next->wl_word;
79 if ((inp = fopen(deck,
"r")) ==
NULL) {
84 fprintf(
cp_err,
"Error: bad deck %s\n", deck);
88 for (t = s; *t && (*t !=
'\n'); t++)
91 out_printf(
"Starting spice run for:\n%s\n", s);
94 (void) fclose(fopen(raw,
"w"));
97 if (!(freopen(deck,
"r", stdin))) {
101 if (!(freopen(output,
"w", stdout))) {
105 (void) dup2(fileno(stdout), fileno(stderr));
107 (void) execl(spicepath, spicepath,
"-r", raw, 0);
115 p =
alloc(
struct proc);
117 p->pr_name =
copy(s);
118 p->pr_rawfile =
copy(raw);
119 p->pr_inpfile =
copy(deck);
120 p->pr_outfile =
copy(output);
121 p->pr_saveout = saveout;
123 p->pr_next = running;
126 (void) signal(SIGCHLD, sigchild);
129 (void) signal(SIGCLD, sigchild);
143 for (p = running;
p; p = p->pr_next)
144 out_printf(
"%d\t%.70s\n", p->pr_pid, p->pr_name);
154 fprintf(
cp_err,
"%d jobs done now\n", numchanged);
174 static bool here =
false;
176 if (!numchanged || here)
181 while (numchanged > 0) {
185 "ft_checkkids: Internal Error: should be %d jobs done but there aren't any.\n",
192 for (p = running;
p; p = p->pr_next) {
193 if (p->pr_pid == pid)
199 "ft_checkkids: Internal Error: Process %d not a job!\n",
205 running = p->pr_next;
207 lp->pr_next = p->pr_next;
208 out_printf(
"Job finished: %.60s\n", p->pr_name);
211 (void)
unlink(p->pr_rawfile);
212 if (!(fp = fopen(p->pr_outfile,
"r"))) {
221 (void)
unlink(p->pr_outfile);
226 (void) ioctl(0, TIOCSTI,
"\022");
241 char rhost[64], *user, host[64], program[128], buf[
BSIZE_SP];
246 struct sockaddr_in server;
247 FILE *inp, *serv, *out;
258 if (*rhost ==
'\0') {
260 "Error: there is no remote spice host for this site.\n");
262 pw = getpwuid(getuid());
264 fprintf(
cp_err,
"Who the heck are you, anyway??\n");
268 if (gethostname(host, 64) > 0) {
273 sp = getservbyname(
"spice",
"tcp");
275 fprintf(
cp_err,
"Error: spice/tcp: unknown service\n");
278 pp = getprotobyname(
"tcp");
280 fprintf(
cp_err,
"Error: tcp: unknown protocol\n");
283 hp = gethostbyname(rhost);
285 fprintf(
cp_err,
"Error: unknown host %s\n", rhost);
288 bzero((
char *) &server,
sizeof (
struct sockaddr_in));
289 bcopy(hp->h_addr, (
char *) &server.sin_addr, hp->h_length);
290 server.sin_family = hp->h_addrtype;
291 server.sin_port = sp->s_port;
294 s = socket(AF_INET, SOCK_STREAM, pp->p_proto);
300 if (connect(s, (
struct sockaddr *) &server,
301 sizeof (
struct sockaddr)) < 0) {
308 (void) sprintf(buf,
"%s %s %s", user, host, program);
310 (
void) sprintf(buf,
"%s %s", user, host);
311 (void) write(s, buf, strlen(buf) + 1);
313 fprintf(
cp_err,
"Connection (void) closed\n");
318 if (
eq(buf,
"toomany")) {
320 "\nSorry, %s is too loaded now -- please try another machine\n",
323 "\tthat has a spice server running, or try again later.\n");
326 }
else if (!
eq(buf,
"ok")) {
327 fprintf(
cp_err,
"Error: remote spiced says %s\n", buf);
335 if (!(inp = fopen(wl->wl_word,
"r"))) {
340 while ((i = fread(buf, 1,
BSIZE_SP, inp)) > 0)
341 (void) write(s, buf, i);
344 (void) write(s,
"@\n", 3);
348 fprintf(
cp_err,
"Error: no circuits loaded\n");
354 inp = fdopen(s,
"w");
362 serv = fdopen(s,
"r");
369 if (!(out = fopen(outfile,
"w"))) {
374 while (i = fread(buf, 1,
BSIZE_SP, serv))
375 (
void) fwrite(buf, 1, i, out);
392 fprintf(
cp_err,
"Asynchronous spice jobs are not available.\n");
401 fprintf(
cp_err,
"Asynchronous spice jobs are not available.\n");
405 #define SUBMIT "/bin/csh /usr/bin/rspice" 416 if (wl && !wl->wl_next) {
420 fprintf(
cp_err,
"Error: you must supply the input deck name.\n");
428 (void) sprintf(buf,
"%s %s %s %s",
SUBMIT, input, output, raw);
434 if (!(fp = fopen(output,
"r"))) {
static char buf[MAXPROMPT]
void inp_list(FILE *fp, struct line *l1, struct line *l2, int i)
bool cp_getvar(char *n, int t, char *r)
static struct sHtxt * input()
void com_aspice(wordlist *wl)
int bzero(char *ptr, int num)
void com_rspice(wordlist *wl)
void com_jobs(wordlist *wl)
void bcopy(char *from, char *to, int num)