#include "shell.h"
#include "jobs.h"
#include "execute_cmd.h"
+#include "trap.h"
#include "builtins/builtext.h" /* for wait_builtin */
+#include "builtins/common.h"
#define DEFAULT_CHILD_MAX 32
extern int errno;
#endif /* !errno */
-extern int interactive, interactive_shell, login_shell;
-extern int subshell_environment;
-extern int last_command_exit_value, last_command_exit_signal;
-extern int interrupt_immediately;
-extern sh_builtin_func_t *this_shell_builtin;
#if defined (HAVE_POSIX_SIGNALS)
extern sigset_t top_level_mask;
#endif
-extern procenv_t wait_intr_buf;
-extern int wait_signal_received;
+
+extern void set_original_signal __P((int, SigHandler *));
volatile pid_t last_made_pid = NO_PID;
volatile pid_t last_asynchronous_pid = NO_PID;
+static int queue_sigchld, waiting_for_child; /* dummy declarations */
+
/* Call this when you start making children. */
int already_making_children = 0;
/* We don't have job control. */
int job_control = 0;
+int running_in_background = 0; /* can't tell without job control */
+
/* STATUS and FLAGS are only valid if pid != NO_PID
STATUS is only valid if (flags & PROC_RUNNING) == 0 */
struct proc_status {
static long child_max = -1L;
static void alloc_pid_list __P((void));
-static int find_proc_slot __P((void));
+static int find_proc_slot __P((pid_t));
static int find_index_by_pid __P((pid_t));
static int find_status_by_pid __P((pid_t));
static int process_exit_status __P((WAIT));
/* None of the newly allocated slots have process id's yet. */
for (i = old; i < pid_list_size; i++)
- pid_list[i].pid = NO_PID;
+ {
+ pid_list[i].pid = NO_PID;
+ pid_list[i].status = pid_list[i].flags = 0;
+ }
}
/* Return the offset within the PID_LIST array of an empty slot. This can
create new slots if all of the existing slots are taken. */
static int
-find_proc_slot ()
+find_proc_slot (pid)
+ pid_t pid;
{
register int i;
for (i = 0; i < pid_list_size; i++)
- if (pid_list[i].pid == NO_PID)
+ if (pid_list[i].pid == NO_PID || pid_list[i].pid == pid)
return (i);
if (i == pid_list_size)
coproc_pidchk (pid, status);
#endif
+#if defined (PROCESS_SUBSTITUTION)
+ if ((slot = find_procsub_child (pid)) >= 0)
+ set_procsub_status (slot, pid, WSTATUS (status));
+ /* XXX - also saving in list below */
+#endif
+
slot = find_index_by_pid (pid);
if (slot == NO_PID)
return;
{
int slot;
- slot = find_proc_slot ();
+ slot = find_proc_slot (pid);
pid_list[slot].pid = pid;
pid_list[slot].status = -1;
for (i = 0; i < pid_list_size; i++)
{
- if ((pid_list[i].flags & PROC_RUNNING) == 0 &&
- (pid_list[i].flags & PROC_NOTIFIED))
+ if (pid_list[i].pid != NO_PID &&
+ (pid_list[i].flags & PROC_RUNNING) == 0 &&
+ (pid_list[i].flags & PROC_NOTIFIED))
pid_list[i].pid = NO_PID;
}
}
/* Initialize the job control mechanism, and set up the tty stuff. */
+int
initialize_job_control (force)
int force;
{
if (interactive)
get_tty_state ();
+ return 0;
}
/* Setup this shell to handle C-C, etc. */
unset_bash_input (0);
#endif /* BUFFERED_INPUT */
+ CLRINTERRUPT; /* XXX - children have their own interrupt state */
+
#if defined (HAVE_POSIX_SIGNALS)
/* Restore top-level signal mask. */
sigprocmask (SIG_SETMASK, &top_level_mask, (sigset_t *)NULL);
default_tty_job_signals ()
{
#if defined (SIGTSTP)
- set_signal_handler (SIGTSTP, SIG_DFL);
- set_signal_handler (SIGTTIN, SIG_DFL);
- set_signal_handler (SIGTTOU, SIG_DFL);
+ if (signal_is_trapped (SIGTSTP) == 0 && signal_is_hard_ignored (SIGTSTP))
+ set_signal_handler (SIGTSTP, SIG_IGN);
+ else
+ set_signal_handler (SIGTSTP, SIG_DFL);
+ if (signal_is_trapped (SIGTTIN) == 0 && signal_is_hard_ignored (SIGTTIN))
+ set_signal_handler (SIGTTIN, SIG_IGN);
+ else
+ set_signal_handler (SIGTTIN, SIG_DFL);
+ if (signal_is_trapped (SIGTTOU) == 0 && signal_is_hard_ignored (SIGTTOU))
+ set_signal_handler (SIGTTOU, SIG_IGN);
+ else
+ set_signal_handler (SIGTTOU, SIG_DFL);
#endif
}
+/* Called once in a parent process. */
+void
+get_original_tty_job_signals ()
+{
+ static int fetched = 0;
+
+ if (fetched == 0)
+ {
+#if defined (SIGTSTP)
+ if (interactive_shell)
+ {
+ set_original_signal (SIGTSTP, SIG_DFL);
+ set_original_signal (SIGTTIN, SIG_DFL);
+ set_original_signal (SIGTTOU, SIG_DFL);
+ }
+ else
+ {
+ get_original_signal (SIGTSTP);
+ get_original_signal (SIGTTIN);
+ get_original_signal (SIGTTOU);
+ }
+#endif
+ fetched = 1;
+ }
+}
+
/* Wait for a single pid (PID) and return its exit status. Called by
the wait builtin. */
int
-wait_for_single_pid (pid)
+wait_for_single_pid (pid, flags)
pid_t pid;
+ int flags;
{
pid_t got_pid;
WAIT status;
- int pstatus, flags;
+ int pstatus;
pstatus = find_status_by_pid (pid);
cleanup_dead_jobs ();
}
+void
+wait_sigint_cleanup ()
+{
+}
+
/* Make OLD_SIGINT_HANDLER the SIGINT signal handler. */
#define INVALID_SIGNAL_HANDLER (SigHandler *)wait_for_background_pids
static SigHandler *old_sigint_handler = INVALID_SIGNAL_HANDLER;
static int got_tty_state;
/* Fill the contents of shell_tty_info with the current tty info. */
+int
get_tty_state ()
{
int tty;
if (check_window_size)
get_new_window_size (0, (int *)0, (int *)0);
}
+ return 0;
}
/* Make the current tty use the state in shell_tty_info. */
}
/* Give the terminal to PGRP. */
+int
give_terminal_to (pgrp, force)
pid_t pgrp;
int force;
{
+ return 0;
}
/* Stop a pipeline. */
already_making_children = 0;
}
+/* The name is kind of a misnomer, but it's what the job control code uses. */
+void
+without_job_control ()
+{
+ stop_making_children ();
+ last_made_pid = NO_PID; /* XXX */
+}
+
int
get_job_by_pid (pid, block)
pid_t pid;
fprintf (stderr, "%ld\n", (long) pid);
}
-void
+int
freeze_jobs_list ()
{
+ return 0;
}
void
{
}
+void
+set_jobs_list_frozen (s)
+ int s;
+{
+}
+
int
count_all_jobs ()
{