/***************************************************************************
* 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 file is "included" into iproc.c -- it is not compiled separately!
#define DEAD 1 /* Dead but haven't informed user yet */
#define STOPPED 2 /* Job stopped */
#define RUNNING 3 /* Just running */
#define NEW 4 /* This process is brand new */
/* If process is dead, flags says how. */
#define isdead(p) ((p) == NULL || proc_state((p)) == DEAD || (p)->p_toproc == -1)
#define makedead(p) { proc_state((p)) = DEAD; }
#define proc_buf(p) ((p)->p_buffer->b_name)
#define proc_cmd(p) ((p)->p_name)
#define proc_state(p) ((p)->p_state)
private Process
*procs
= 0;
for (p
= procs
; p
!= 0; p
= p
->p_next
)
if ((p
= proc_pid(pid
)) == 0) {
writef("\riproc: unknown pid (%d)", pid
);
if (proc_state(p
) == NEW
) {
/* pid of real child, not of portsrv */
(void) f_readn(ProcInput
, (char *) &rpid
, sizeof (int));
if (nbytes
== EOF
) { /* okay to clean up this process */
f_readn(ProcInput
, &status
, sizeof (int));
} while (pid
!= p
->p_portpid
);
n
= min((sizeof ibuf
) - 1, nbytes
);
f_readn(ProcInput
, ibuf
, n
);
ibuf
[n
] = 0; /* Null terminate for convenience */
proc_kill(curbuf
->b_process
, SIGKILL
);
proc_kill(curbuf
->b_process
, SIGINT
);
proc_kill(curbuf
->b_process
, SIGQUIT
);
(void) close(p
->p_toproc
);
p
->p_toproc
= -1; /* writes will fail */
proc_write(p
, buf
, nbytes
)
(void) write(p
->p_toproc
, buf
, nbytes
);
proc_strt(char *bufname
, int clobber
, ...)
private /*VARARGS3*/ void
proc_strt(bufname
, clobber
, va_alist
)
isprocbuf(bufname
); /* make sure BUFNAME is either nonexistant
or is of type B_PROCESS */
complain("[Fork failed.]");
(void) dup2(toproc
[0], 0);
(void) dup2(ProcOutput
, 1);
(void) dup2(ProcOutput
, 2);
writef("execl failed\n");
newp
= (Process
*) malloc(sizeof *newp
);
while (cp
= va_arg(ap
, char *))
swritef(&cmdbuf
[strlen(cmdbuf
)], "%s ", cp
);
newp
->p_name
= copystr(cmdbuf
);
newbuf
= do_select((Window
*) 0, bufname
);
newbuf
->b_type
= B_PROCESS
;
newbuf
->b_process
= newp
; /* sorta circular, eh? */
pop_wind(bufname
, clobber
, B_PROCESS
);
/* Pop_wind() after everything is set up; important!
Bindings won't work right unless newbuf->b_process is already
set up BEFORE NEWBUF is first SetBuf()'d. */
newp
->p_mark
= MakeMark(curline
, curchar
, M_FLOATER
);
newp
->p_toproc
= toproc
[1];
ProcInput
= fd_open("process-input", F_READ
|F_LOCKED
, p
[0],
if ((kbd_pid
= fork()) == -1) {
printf("Cannot fork kbd process!\n");
signal(SIGALRM
, SIG_IGN
);
execl(Kbd_Proc
, "kbd", 0);
write(2, "kdb exec failed\n", 16);
private int kbd_state
= OFF
;
/* kbd_strt() and kbd_stop() return true if they changed the state
of the keyboard process. E.g., kbd_strt() returns TRUE if the
kbd process was previously stopped. This is so kbd starting and
stopping in pairs works - see finish() in jove.c. */