home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR24 / BASH_112.ZIP / BASH-112.TAR / bash-1.12 / jobs.h < prev    next >
C/C++ Source or Header  |  1993-02-14  |  7KB  |  241 lines

  1. /* jobs.h -- structures and stuff used by the jobs.c file. */
  2. #include "quit.h"
  3.  
  4. /* Defines controlling the fashion in which jobs are listed. */
  5. #define JLIST_STANDARD 0
  6. #define JLIST_LONG     1
  7. #define JLIST_PID_ONLY 2
  8. #define JLIST_CHANGED_ONLY 3
  9.  
  10. /* Cadmus machines are brain-dead from the moment of fission, like all
  11.    bacteria. */
  12. #if defined (cadmus) || defined (BrainDeath)
  13. #  undef HAVE_WAIT_H
  14. #endif /* BrainDeath */
  15.  
  16. /* HP/UX 6.x sys/wait.h is a complete loss when it comes to the WIF macros.
  17.    Pretend we don't have a wait.h. */
  18. #if defined (hpux) && !defined (_POSIX_VERSION)
  19. #undef HAVE_WAIT_H
  20. #endif
  21.  
  22. #if defined (HAVE_WAIT_H)
  23. #include <sys/wait.h>
  24. #else
  25.  
  26. #include "endian.h"
  27.  
  28. #if !defined (_POSIX_VERSION)
  29. #if defined (LITTLE_ENDIAN)
  30. union wait
  31.   {
  32.     int    w_status;        /* used in syscall */
  33.  
  34.     /* Terminated process status. */
  35.     struct
  36.       {
  37.     unsigned short
  38.       w_Termsig  : 7,    /* termination signal */
  39.       w_Coredump : 1,    /* core dump indicator */
  40.       w_Retcode  : 8,    /* exit code if w_termsig==0 */
  41.       w_Fill1    : 16;    /* high 16 bits unused */
  42.       } w_T;
  43.  
  44.     /* Stopped process status.  Returned
  45.        only for traced children unless requested
  46.        with the WUNTRACED option bit. */
  47.     struct
  48.       {
  49.     unsigned short
  50.       w_Stopval : 8,    /* == W_STOPPED if stopped */
  51.       w_Stopsig : 8,    /* actually zero on XENIX */
  52.       w_Fill2   : 16;    /* high 16 bits unused */
  53.       } w_S;
  54.   };
  55.  
  56. #else  /* if !LITTLE_ENDIAN */
  57.  
  58. /* This is for big-endian machines like the IBM RT, HP 9000, or Sun-3 */
  59.  
  60. union wait
  61.   {
  62.     int    w_status;        /* used in syscall */
  63.  
  64.     /* Terminated process status. */
  65.     struct
  66.       {
  67.     unsigned short w_Fill1    : 16;    /* high 16 bits unused */
  68.     unsigned       w_Retcode  : 8;    /* exit code if w_termsig==0 */
  69.     unsigned       w_Coredump : 1;    /* core dump indicator */
  70.     unsigned       w_Termsig  : 7;    /* termination signal */
  71.       } w_T;
  72.  
  73.     /* Stopped process status.  Returned
  74.        only for traced children unless requested
  75.        with the WUNTRACED option bit. */
  76.     struct
  77.       {
  78.     unsigned short w_Fill2   : 16;    /* high 16 bits unused */
  79.     unsigned       w_Stopsig : 8;    /* signal that stopped us */
  80.     unsigned       w_Stopval : 8;    /* == W_STOPPED if stopped */
  81.       } w_S;
  82.   };
  83.  
  84. #endif /* LITTLE_ENDIAN */
  85.  
  86. #define    w_termsig w_T.w_Termsig
  87. #define w_coredump w_T.w_Coredump
  88. #define w_retcode w_T.w_Retcode
  89. #define w_stopval w_S.w_Stopval
  90. #define w_stopsig w_S.w_Stopsig
  91.  
  92. /* Note that sys/wait.h defines these for Posix systems. */
  93. #define    WSTOPPED 0177
  94. #define WIFSTOPPED(x) (((x) . w_stopval) == WSTOPPED)
  95. #define WIFEXITED(x) ((! (WIFSTOPPED (x))) && (((x) . w_termsig) == 0))
  96. #define WIFSIGNALED(x) ((! (WIFSTOPPED (x))) && (((x) . w_termsig) != 0))
  97.  
  98. #endif /* _POSIX_VERSION */
  99. #endif  /* !HAVE_WAIT_H */
  100.  
  101. #if !defined (_POSIX_VERSION) && !defined(__EMX__)        /* 2/93 ROB */
  102. #define pid_t int
  103. typedef union wait WAIT;
  104. #else
  105. #if defined(__EMX__)
  106. #define pid_t int
  107. #endif
  108. typedef int WAIT;
  109. #endif /* _POSIX_VERSION */
  110.  
  111. /* How to get the status of a job.  For Posix, this is just an int, but for
  112.    other systems we have to crack the union wait. */
  113. #if defined (_POSIX_VERSION)
  114. #define WSTATUS(t)  (t)
  115. #else
  116. #define WSTATUS(t)  (t.w_status)
  117. #endif
  118.  
  119. /* Make sure that parameters to wait3 are defined. */
  120. #if !defined (WNOHANG)
  121. #define WNOHANG 1
  122. #define WUNTRACED 2
  123. #endif /* WNOHANG */
  124.  
  125. /* More Posix P1003.1 definitions.  In these definitions, `s' is a
  126.    `union wait' (the 1003.1 spec says they are `int'). */
  127. #if !defined (WSTOPSIG)
  128. #define WSTOPSIG(s)    ((s).w_stopsig)
  129. #define WTERMSIG(s)    ((s).w_termsig)
  130. #define WEXITSTATUS(s)    ((s).w_retcode)
  131. #endif /* WSTOPSIG */
  132.  
  133. #if !defined (WIFCORED)
  134. #if !defined (_POSIX_VERSION) && !defined(__EMX__)        /* 2/93 ROB */
  135. #define WIFCORED(s)    ((s).w_coredump)
  136. #else
  137. #define WIFCORED(s)    ((s) & 0200)
  138. #endif /* _POSIX_VERSION */
  139. #endif /* WIFCORED */
  140.  
  141. /* I looked it up.  For pretty_print_job ().  The real answer is 24. */
  142. #define LONGEST_SIGNAL_DESC 24
  143.  
  144. /* We keep an array of jobs.  Each entry in the array is a linked list
  145.    of processes that are piped together.  The first process encountered is
  146.    the group leader. */
  147.  
  148. /* Each child of the shell is remembered in a STRUCT PROCESS.  A chain of
  149.    such structures is a pipeline.  The chain is circular. */
  150. typedef struct process {
  151.   struct process *next;    /* Next process in the pipeline.  A circular chain. */
  152.   pid_t pid;        /* Process ID. */
  153.   WAIT status;        /* The status of this command as returned by wait. */
  154.   int running;        /* Non-zero if this process is running. */
  155.   char *command;    /* The particular program that is running. */
  156. } PROCESS;
  157.  
  158. /* A description of a pipeline's state. */
  159. typedef enum { JRUNNING, JSTOPPED, JDEAD, JMIXED } JOB_STATE;
  160. #define JOBSTATE(job) (jobs[(job)]->state)
  161.  
  162. typedef struct job {
  163.   char *wd;        /* The working directory at time of invocation. */
  164.   PROCESS *pipe;    /* The pipeline of processes that make up this job. */
  165.   pid_t pgrp;        /* The process ID of the process group (necessary). */
  166.   int foreground;    /* Non-zero if this is running in the foreground. */
  167.   int notified;        /* Non-zero if already notified about job state. */
  168.   JOB_STATE state;    /* The state that this job is in. */
  169.   int job_control;    /* Non-zero if this job started under job control. */
  170. #ifdef JOB_CONTROL
  171.   COMMAND *deferred;    /* Commands that will execute when this job is done. */
  172. #endif
  173. } JOB;
  174.  
  175. #define NO_JOB -1    /* An impossible job array index. */
  176. #define DUP_JOB -2    /* A possible return value for get_job_spec (). */
  177.  
  178. /* A value which cannot be a process ID. */
  179. #define NO_PID (pid_t)-1
  180.  
  181. #if !defined (_POSIX_VERSION) && !defined (sigmask)
  182. #define sigmask(x) (1 << ((x)-1))
  183. #endif /* !POSIX && !sigmask */
  184.  
  185. #ifndef SIGABRT
  186. #define SIGABRT SIGIOT
  187. #endif
  188.  
  189. #ifndef SIGCHLD
  190. #define SIGCHLD SIGCLD
  191. #endif
  192.  
  193. #if !defined (_POSIX_VERSION)
  194. #if !defined (SIG_BLOCK)
  195. #define SIG_BLOCK 2
  196. #define SIG_SETMASK 3
  197. #endif /* SIG_BLOCK */
  198.  
  199. /* Type of a signal set. */
  200. #define sigset_t int
  201.  
  202. /* Make sure there is nothing inside the signal set. */
  203. #define sigemptyset(set) (*(set) = 0)
  204.  
  205. /* Add SIG to the contents of SET. */
  206. #define sigaddset(set, sig) *(set) |= sigmask (sig)
  207.  
  208. /* Suspend the process until the reception of one of the signals
  209.    not present in SET. */
  210. #define sigsuspend(set) sigpause (*(set))
  211.  
  212. /* END of POSIX 1003.1 definitions. */
  213. #endif /* _POSIX_VERSION */
  214.  
  215. /* These definitions are used both in POSIX and non-POSIX implementations. */
  216.  
  217. #define BLOCK_SIGNAL(sig, nvar, ovar) \
  218.   sigemptyset (&nvar); \
  219.   sigaddset (&nvar, sig); \
  220.   sigemptyset (&ovar); \
  221.   sigprocmask (SIG_BLOCK, &nvar, &ovar)
  222.  
  223. #if defined (_POSIX_VERSION)
  224. #define BLOCK_CHILD(nvar, ovar) BLOCK_SIGNAL (SIGCHLD, nvar, ovar)
  225. #define UNBLOCK_CHILD(ovar) sigprocmask (SIG_SETMASK, &ovar, (sigset_t *) NULL)
  226. #else /* !_POSIX_VERSION */
  227. #define BLOCK_CHILD(nvar, ovar) ovar = sigblock (sigmask (SIGCHLD))
  228. #define UNBLOCK_CHILD(ovar) sigsetmask (ovar)
  229. #endif /* !_POSIX_VERSION */
  230.  
  231. /* System calls. */
  232. extern pid_t fork (), getpid (), getpgrp ();
  233.  
  234. /* Stuff from the jobs.c file. */
  235. extern pid_t  original_pgrp, shell_pgrp, pipeline_pgrp;
  236. extern pid_t last_made_pid, last_asynchronous_pid, make_child ();
  237. extern int current_job, previous_job;
  238. extern int asynchronous_notification;
  239. extern JOB **jobs;
  240. extern int job_slots;
  241.