1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
include <error.h>
include <config.h>
include <prstat.h>
# PRUPDATE -- Broadcast a message to a process, or if pid=0, to all connected
# subprocesses. Used primarily to incrementally pass SET and CHDIR commands to
# subprocesses, eliminating the need to reconnect each process. Note that the
# child process does not return "bye" in response to one of the builtin
# functions SET and CHDIR. NOTE: if a child process is marked "busy" the
# message is not sent to that process; only idle processes receive the message.
procedure prupdate (pid, message, flushout)
int pid #I process to be updated, or 0 for all procs
char message[ARB] #I message to be broadcast to each child
int flushout #I flush output
int pr, status
pointer sp, cmd, op
int gstrcpy(), prstati()
include "prc.com"
begin
call smark (sp)
call salloc (cmd, SZ_COMMAND, TY_CHAR)
# Make sure that the message string is non-null and is newline
# delimited.
op = cmd + gstrcpy (message, Memc[cmd], SZ_COMMAND)
if (op == cmd) {
call sfree (sp)
return
} else if (Memc[op-1] != '\n') {
Memc[op] = '\n'
Memc[op+1] = EOS
}
# Broadcast the message. If the child fails to process the command
# and returns the ERROR statement, the error will not be detected until
# the next user command is sent to the process (and indeed may corrupt
# the protocol). The parent should execute the SET or CHDIR prior
# to sending it to the child to make sure it is valid.
for (pr=1; pr <= MAX_CHILDPROCS; pr=pr+1)
if ((pid != NULL && pr_pid[pr] == pid) ||
(pid == NULL && pr_pid[pr] != NULL)) {
status = prstati (pr_pid[pr], PR_STATUS)
if (status == P_RUNNING) {
iferr (call putline (pr_outfd[pr], Memc[cmd]))
call erract (EA_WARN)
else if (flushout == YES)
call flush (pr_outfd[pr])
}
}
call sfree (sp)
end
|