/***************************************************************************
* This program is Copyright (C) 1986, 1987, 1988 by Jonathan Payne. JOVE *
* is provided to you without charge, and with no warranty. You may give *
* away copies of JOVE, including sources, provided that this notice is *
* included in all the files. *
***************************************************************************/
/* This is a server for jove sub processes. It runs the command and
signals jove when there is some output ready to send to jove. By the
time we get here, out standard output goes to jove's process input. */
#ifdef PIPEPROCS /* the whole file! */
#define HEADSIZE ((sizeof header.pid) + sizeof (header.nbytes))
header
.nbytes
= strlen(str
);
proc_write(&header
, header
.nbytes
+ HEADSIZE
);
ioctl(JovesInput
, FIONREAD
, (char *) &nbytes
);
ioctl(1, FIONREAD
, (char *) &nbytes
);
(void) signal(SIGALRM
, p_inform
);
while ((header
.nbytes
= read(InputFD
, header
.buf
, sizeof header
.buf
)) > 0) {
n
= HEADSIZE
+ header
.nbytes
;
/* tty_fd = open("/dev/tty", 1); */
error("Cannot pipe jove portsrv.\n");
/* for (i = 0; i < argc; i++) {
write(tty_fd, "*argv++ = ", 10);
write(tty_fd, argv[i], strlen(argv[i]));
error("portsrv: cannot fork.\n");
/* We'll intercept childs output in p[0] */
(void) setpgrp(getpid(), getpid());
execv(argv
[2], &argv
[3]);
/* don't want this guy to read anything jove sends to
our soon to be created child */
JovesInput
= atoi(argv
[1]);
(void) signal(SIGINT
, SIG_IGN
);
(void) signal(SIGQUIT
, SIG_IGN
);
/* tell jove the pid of the real child as opposed to us */
header
.nbytes
= sizeof (int);
*(int *) header
.buf
= pid
;
(void) write(1, (char *) &header
, sizeof pid
+ HEADSIZE
);
p_inform(); /* Inform jove */
/* read proc's output and send it to jove */
header
.nbytes
= EOF
; /* tell jove we are finished */
(void) write(1, (char *) &header
, HEADSIZE
);
/* try to exit like our child did ... */
while (wait2(&w
.w_status
, 0) != pid
)
while (wait3(&w
.w_status
, 0, 0) != pid
)
kill(getpid(), w
.w_termsig
);