Imported from ../bash-3.2.48.tar.gz.
[platform/upstream/bash.git] / jobs.h
diff --git a/jobs.h b/jobs.h
index fe004ca..93a42fb 100644 (file)
--- a/jobs.h
+++ b/jobs.h
@@ -1,6 +1,6 @@
 /* jobs.h -- structures and stuff used by the jobs.c file. */
 
-/* Copyright (C) 1993 Free Software Foundation, Inc.
+/* Copyright (C) 1993-2005 Free Software Foundation, Inc.
 
    This file is part of GNU Bash, the Bourne Again SHell.
 
 #define PS_DONE                0
 #define PS_RUNNING     1
 #define PS_STOPPED     2
+#define PS_RECYCLED    4
 
-/* Each child of the shell is remembered in a STRUCT PROCESS.  A chain of
-   such structures is a pipeline.  The chain is circular. */
+/* Each child of the shell is remembered in a STRUCT PROCESS.  A circular
+   chain of such structures is a pipeline. */
 typedef struct process {
   struct process *next;        /* Next process in the pipeline.  A circular chain. */
   pid_t pid;           /* Process ID. */
@@ -57,23 +58,44 @@ typedef struct process {
   char *command;       /* The particular program that is running. */
 } PROCESS;
 
+/* PALIVE really means `not exited' */
+#define PSTOPPED(p)    (WIFSTOPPED((p)->status))
+#define PRUNNING(p)    ((p)->running == PS_RUNNING)
+#define PALIVE(p)      (PRUNNING(p) || PSTOPPED(p))
+
+#define PEXITED(p)     ((p)->running == PS_DONE)
+#if defined (RECYCLES_PIDS)
+#  define PRECYCLED(p) ((p)->running == PS_RECYCLED)
+#else
+#  define PRECYCLED(p) (0)
+#endif
+#define PDEADPROC(p)   (PEXITED(p) || PRECYCLED(p))
+
+#define get_job_by_jid(ind)    (jobs[(ind)])
+
 /* A description of a pipeline's state. */
 typedef enum { JRUNNING, JSTOPPED, JDEAD, JMIXED } JOB_STATE;
-#define JOBSTATE(job) (jobs[(job)]->state)
+#define JOBSTATE(job)  (jobs[(job)]->state)
+#define J_JOBSTATE(j)  ((j)->state)
 
 #define STOPPED(j)     (jobs[(j)]->state == JSTOPPED)
 #define RUNNING(j)     (jobs[(j)]->state == JRUNNING)
 #define DEADJOB(j)     (jobs[(j)]->state == JDEAD)
 
+#define INVALID_JOB(j) ((j) < 0 || (j) >= js.j_jobslots || get_job_by_jid(j) == 0)
+
 /* Values for the FLAGS field in the JOB struct below. */
 #define J_FOREGROUND 0x01 /* Non-zero if this is running in the foreground.  */
 #define J_NOTIFIED   0x02 /* Non-zero if already notified about job state.   */
 #define J_JOBCONTROL 0x04 /* Non-zero if this job started under job control. */
 #define J_NOHUP      0x08 /* Don't send SIGHUP to job if shell gets SIGHUP. */
+#define J_STATSAVED  0x10 /* A process in this job had had status saved via $! */
+#define J_ASYNC             0x20 /* Job was started asynchronously */
 
 #define IS_FOREGROUND(j)       ((jobs[j]->flags & J_FOREGROUND) != 0)
 #define IS_NOTIFIED(j)         ((jobs[j]->flags & J_NOTIFIED) != 0)
 #define IS_JOBCONTROL(j)       ((jobs[j]->flags & J_JOBCONTROL) != 0)
+#define IS_ASYNC(j)            ((jobs[j]->flags & J_ASYNC) != 0)
 
 typedef struct job {
   char *wd;       /* The working directory at time of invocation. */
@@ -88,8 +110,45 @@ typedef struct job {
 #endif /* JOB_CONTROL */
 } JOB;
 
+struct jobstats {
+  /* limits */
+  long c_childmax;
+  /* child process statistics */
+  int c_living;                /* running or stopped child processes */
+  int c_reaped;                /* exited child processes still in jobs list */
+  int c_injobs;                /* total number of child processes in jobs list */
+  /* child process totals */
+  int c_totforked;     /* total number of children this shell has forked */
+  int c_totreaped;     /* total number of children this shell has reaped */
+  /* job counters and indices */
+  int j_jobslots;      /* total size of jobs array */
+  int j_lastj;         /* last (newest) job allocated */
+  int j_firstj;                /* first (oldest) job allocated */
+  int j_njobs;         /* number of non-NULL jobs in jobs array */
+  int j_ndead;         /* number of JDEAD jobs in jobs array */
+  /* */
+  int j_current;       /* current job */
+  int j_previous;      /* previous job */
+  /* */
+  JOB *j_lastmade;     /* last job allocated by stop_pipeline */
+  JOB *j_lastasync;    /* last async job allocated by stop_pipeline */
+};
+
+struct pidstat {
+ struct pidstat *next;
+ pid_t pid;
+ int status;
+};
+
+struct bgpids {
+  struct pidstat *list;
+  struct pidstat *end;
+  int npid;
+};
+
 #define NO_JOB  -1     /* An impossible job array index. */
 #define DUP_JOB -2     /* A possible return value for get_job_spec (). */
+#define BAD_JOBSPEC -3 /* Bad syntax for job spec. */
 
 /* A value which cannot be a process ID. */
 #define NO_PID (pid_t)-1
@@ -100,12 +159,13 @@ extern pid_t fork (), getpid (), getpgrp ();
 #endif /* !HAVE_UNISTD_H */
 
 /* Stuff from the jobs.c file. */
+extern struct jobstats js;
+
 extern pid_t original_pgrp, shell_pgrp, pipeline_pgrp;
 extern pid_t last_made_pid, last_asynchronous_pid;
-extern int current_job, previous_job;
 extern int asynchronous_notification;
+
 extern JOB **jobs;
-extern int job_slots;
 
 extern void making_children __P((void));
 extern void stop_making_children __P((void));
@@ -158,9 +218,6 @@ extern int initialize_job_control __P((int));
 extern void initialize_job_signals __P((void));
 extern int give_terminal_to __P((pid_t, int));
 
-extern void set_sigwinch_handler __P((void));
-extern void unset_sigwinch_handler __P((void));
-
 extern void unfreeze_jobs_list __P((void));
 extern int set_job_control __P((int));
 extern void without_job_control __P((void));
@@ -170,6 +227,8 @@ extern void set_sigchld_handler __P((void));
 extern void ignore_tty_job_signals __P((void));
 extern void default_tty_job_signals __P((void));
 
+extern void init_job_stats __P((void));
+
 #if defined (JOB_CONTROL)
 extern int job_control;
 #endif