Beispiel #1
0
/*
 * text_to_process: sends the given text to the given process.  If the given
 * process index is not valid, an error is reported and 1 is returned.
 * Otherwise 0 is returned. 
 * Added show, to remove some bad recursion, phone, april 1993
 */
int 		text_to_process (int proc_index, const char *text, int show)
{
	Process	*	proc;
	char	*	my_buffer;
	size_t	size;

	if (valid_process_index(proc_index) == 0)
		return 1;

	proc = process_list[proc_index];

	message_to(proc->refnum);
	if (show)
		put_it("%s%s", get_prompt_by_refnum(proc->refnum), text);
	message_to(-1);

	size = strlen(text) + 2;
	my_buffer = alloca(size);
	snprintf(my_buffer, size, "%s\n", text);
	write(proc->p_stdin, my_buffer, strlen(my_buffer));
	set_prompt_by_refnum(proc->refnum, empty_string);

	return (0);
}
Beispiel #2
0
/*
 * do_processes: given a set of read-descriptors (as returned by a call to
 * select()), this will determine which of the process has produced output
 * and will hadle it appropriately
 */
void do_processes(fd_set * rd)
{
    int i, flag;
    char exec_buffer[INPUT_BUFFER_SIZE + 1];
    char *ptr;
    Process *proc;
    int old_timeout;

    if (process_list == NULL)
        return;
    old_timeout = dgets_timeout(1);
    for (i = 0; i < process_list_size; i++) {
        if ((proc = process_list[i]) && proc->p_stdout != -1) {
            if (FD_ISSET(proc->p_stdout, rd)) {

                /*
                 * This switch case indented back to allow for 80 columns,
                 * phone, jan 1993.
                 */
                switch (dgets(exec_buffer, INPUT_BUFFER_SIZE, proc->p_stdout, NULL)) {
                case 0:
                    if (proc->p_stderr == -1) {
                        proc->p_stdin = exec_close(proc->p_stdin);
                        proc->p_stdout = exec_close(proc->p_stdout);
                        if (proc->exited)
                            delete_process(i);
                    } else
                        proc->p_stdout = exec_close(proc->p_stdout);
                    break;
                case -1:
                    if (proc->logical)
                        flag = do_hook(EXEC_PROMPT_LIST, "%s %s", proc->logical, exec_buffer);
                    else
                        flag = do_hook(EXEC_PROMPT_LIST, "%d %s", i, exec_buffer);
                    set_prompt_by_refnum(proc->refnum, exec_buffer);
                    update_input(UPDATE_ALL);
                    /* if (flag == 0) */
                    break;
                default:
                    message_to(proc->refnum);
                    proc->counter++;
                    ptr = exec_buffer + strlen(exec_buffer) - 1;
                    if ((*ptr == '\n') || (*ptr == '\r')) {
                        *ptr = (char) 0;
                        ptr = exec_buffer + strlen(exec_buffer) - 1;
                        if ((*ptr == '\n') || (*ptr == '\r'))
                            *ptr = (char) 0;
                    }

                    if (proc->logical)
                        flag = do_hook(EXEC_LIST, "%s %s", proc->logical, exec_buffer);
                    else
                        flag = do_hook(EXEC_LIST, "%d %s", i, exec_buffer);

                    if (flag) {
                        if (proc->redirect) {
                            int server;

                            server = from_server;
                            from_server = proc->server;
                            send_text(proc->who, stripansicodes(exec_buffer), proc->redirect, 1, 1);
                            from_server = server;
                        } else
                            put_it("%s", stripansicodes(exec_buffer));
                    }
                    message_to(0);
                    break;
                }

                /* end of special intendation */

            }
        }
        if (process_list && i < process_list_size && (proc = process_list[i]) && proc->p_stderr != -1) {
            if (FD_ISSET(proc->p_stderr, rd)) {

                /* Do the intendation on this switch as well */

                switch (dgets(exec_buffer, INPUT_BUFFER_SIZE, proc->p_stderr, NULL)) {
                case 0:
                    if (proc->p_stdout == -1) {
                        proc->p_stderr = exec_close(proc->p_stderr);
                        proc->p_stdin = exec_close(proc->p_stdin);
                        if (proc->exited)
                            delete_process(i);
                    } else
                        proc->p_stderr = exec_close(proc->p_stderr);
                    break;
                case -1:
                    if (proc->logical)
                        flag = do_hook(EXEC_PROMPT_LIST, "%s %s", proc->logical, exec_buffer);
                    else
                        flag = do_hook(EXEC_PROMPT_LIST, "%d %s", i, exec_buffer);
                    set_prompt_by_refnum(proc->refnum, exec_buffer);
                    update_input(UPDATE_ALL);
                    if (flag == 0)
                        break;
                default:
                    message_to(proc->refnum);
                    (proc->counter)++;
                    ptr = exec_buffer + strlen(exec_buffer) - 1;
                    if ((*ptr == '\n') || (*ptr == '\r')) {
                        *ptr = (char) 0;
                        ptr = exec_buffer + strlen(exec_buffer) - 1;
                        if ((*ptr == '\n') || (*ptr == '\r'))
                            *ptr = (char) 0;
                    }

                    if (proc->logical)
                        flag = do_hook(EXEC_ERRORS_LIST, "%s %s", proc->logical, exec_buffer);
                    else
                        flag = do_hook(EXEC_ERRORS_LIST, "%d %s", i, exec_buffer);

                    if (flag) {
                        if (proc->redirect) {
                            int server;

                            server = from_server;
                            from_server = proc->server;
                            send_text(proc->who, stripansicodes(exec_buffer), process_list[i]->redirect, 1, 1);
                            from_server = server;
                        } else
                            put_it("%s", stripansicodes(exec_buffer));
                    }
                    message_to(0);
                    break;
                }

                /* End of indentation for 80 columns */

            }
        }
    }

    check_process_limits();
    (void) dgets_timeout(old_timeout);
}
Beispiel #3
0
/*
 * This is the back end to do_processes, saves some repeated code
 */
static void 	handle_filedesc (Process *proc, int *fd, int hook_nonl, int hook_nl)
{
	char 	exec_buffer[IO_BUFFER_SIZE + 1];
	ssize_t	len;

	switch ((len = dgets(*fd, exec_buffer, IO_BUFFER_SIZE, 0, NULL))) /* No buffering! */
	{
		case -1:	/* Something died */
		{
			*fd = new_close(*fd);
			if (proc->p_stdout == -1 && proc->p_stderr == -1)
				proc->dumb = 1;
			break;
		}
		case 0:		/* We didnt get a full line */
		{
			/* 
			 * XXX XXX Major, world class hack here XXX XXX 
			 * Since this problem has been addressed already
			 * by newio2.c, it doesn't matter if we just fix the
			 * symptom here since this code is all obsolete.
			 */
			if (exec_buffer[0] == '\n')
			{
				exec_buffer[0] = 0;
				goto this_sucks;
			}

			     if (hook_nl == EXEC_LIST && proc->stdoutpc && *proc->stdoutpc)
				parse_line("EXEC", proc->stdoutpc, 
						exec_buffer, 0, 0);
			else if (hook_nl == EXEC_ERRORS_LIST && proc->stderrpc && *proc->stderrpc)
				parse_line("EXEC", proc->stderrpc, 
						exec_buffer, 0, 0);
			else if (proc->logical)
				do_hook(hook_nonl, "%s %s", 
					proc->logical, exec_buffer);
			else
				do_hook(hook_nonl, "%d %s", 
					proc->index, exec_buffer);

			set_prompt_by_refnum(proc->refnum, exec_buffer);
			break;
		}
		default:	/* We got a full line */
this_sucks:
		{
			int ofs;

			ofs = from_server;
			from_server = proc->server;
			if (proc->refnum)
				message_to(proc->refnum);
			proc->counter++;

			while (len > 0 && (exec_buffer[len] == '\n' ||
					   exec_buffer[len] == '\r'))
			{
				exec_buffer[len--] = 0;
			}

			if (proc->redirect) 
				redirect_text(proc->server, proc->who, 
					exec_buffer, proc->redirect, 1);

			if (hook_nl == EXEC_LIST && proc->stdoutc && *proc->stdoutc)
				parse_line("EXEC", proc->stdoutc, 
						exec_buffer, 0, 0);
			else if (hook_nl == EXEC_ERRORS_LIST && proc->stderrc && *proc->stderrc)
				parse_line("EXEC", proc->stderrc, 
						exec_buffer, 0, 0);
			else if (proc->logical)
			{
				if ((do_hook(hook_nl, "%s %s", 
						proc->logical, exec_buffer)))
					if (!proc->redirect)
						put_it("%s", exec_buffer);
			}
			else
			{
				if ((do_hook(hook_nl, "%d %s", 
						proc->index, exec_buffer)))
					if (!proc->redirect)
						put_it("%s", exec_buffer);
			}

			message_to(-1);
			from_server = ofs;
		}
	}
}