]> git.ipfire.org Git - thirdparty/bash.git/blame - jobs.h
Imported from ../bash-2.0.tar.gz.
[thirdparty/bash.git] / jobs.h
CommitLineData
726f6388
JA
1/* jobs.h -- structures and stuff used by the jobs.c file. */
2
3/* Copyright (C) 1993 Free Software Foundation, Inc.
4
5 This file is part of GNU Bash, the Bourne Again SHell.
6
7 Bash is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 Bash is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License along
18 with Bash; see the file COPYING. If not, write to the Free Software
19 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20
ccc6cda3
JA
21#if !defined (_JOBS_H_)
22# define _JOBS_H_
726f6388
JA
23
24#include "quit.h"
25#include "siglist.h"
26
27#include "stdc.h"
28
29/* Defines controlling the fashion in which jobs are listed. */
ccc6cda3
JA
30#define JLIST_STANDARD 0
31#define JLIST_LONG 1
32#define JLIST_PID_ONLY 2
33#define JLIST_CHANGED_ONLY 3
34#define JLIST_NONINTERACTIVE 4
35
36/* If _POSIX_VERSION is not defined, we assume that <sys/wait.h> defines
37 a `union wait' and various macros used to manipulate it. Look in
38 bashwait.h for the things we expect to find. */
39#if defined (HAVE_SYS_WAIT_H)
726f6388 40# include <sys/wait.h>
ccc6cda3 41#else /* !HAVE_SYS_WAIT_H */
726f6388 42# if !defined (_POSIX_VERSION)
ccc6cda3
JA
43# include "bashwait.h"
44# endif
45#endif /* !HAVE_SYS_WAIT_H */
726f6388
JA
46
47/* How to get the status of a job. For Posix, this is just an
48 int, but for other systems we have to crack the union wait. */
49#if !defined (_POSIX_VERSION)
726f6388
JA
50typedef union wait WAIT;
51# define WSTATUS(t) (t.w_status)
52#else /* _POSIX_VERSION */
53typedef int WAIT;
54# define WSTATUS(t) (t)
55#endif /* _POSIX_VERSION */
56
57/* Make sure that parameters to wait3 are defined. */
58#if !defined (WNOHANG)
59# define WNOHANG 1
60# define WUNTRACED 2
61#endif /* WNOHANG */
62
63/* More Posix P1003.1 definitions. In the POSIX versions, the parameter is
64 passed as an `int', in the non-POSIX version, as `union wait'. */
65#if defined (_POSIX_VERSION)
66
67# if !defined (WSTOPSIG)
68# define WSTOPSIG(s) ((s) >> 8)
69# endif /* !WSTOPSIG */
70
71# if !defined (WTERMSIG)
72# define WTERMSIG(s) ((s) & 0177)
73# endif /* !WTERMSIG */
74
75# if !defined (WEXITSTATUS)
76# define WEXITSTATUS(s) ((s) >> 8)
77# endif /* !WEXITSTATUS */
78
79# if !defined (WIFSTOPPED)
80# define WIFSTOPPED(s) (((s) & 0177) == 0177)
81# endif /* !WIFSTOPPED */
82
83# if !defined (WIFEXITED)
84# define WIFEXITED(s) (((s) & 0377) == 0)
85# endif /* !WIFEXITED */
86
87# if !defined (WIFSIGNALED)
88# define WIFSIGNALED(s) (!WIFSTOPPED(s) && !WIFEXITED(s))
89# endif /* !WIFSIGNALED */
90
91# if !defined (WIFCORED)
92# define WIFCORED(s) ((s) & 0200)
93# endif /* !WIFCORED */
94
95#else /* !_POSIX_VERSION */
96
97# if !defined (WSTOPSIG)
98# define WSTOPSIG(s) ((s).w_stopsig)
99# endif /* !WSTOPSIG */
100
101# if !defined (WTERMSIG)
102# define WTERMSIG(s) ((s).w_termsig)
103# endif /* !WTERMSIG */
104
105# if !defined (WEXITSTATUS)
106# define WEXITSTATUS(s) ((s).w_retcode)
107# endif /* !WEXITSTATUS */
108
109# if !defined (WIFCORED)
110# define WIFCORED(s) ((s).w_coredump)
111# endif /* !WIFCORED */
112
113#endif /* !_POSIX_VERSION */
114
115/* I looked it up. For pretty_print_job (). The real answer is 24. */
116#define LONGEST_SIGNAL_DESC 24
117
118/* We keep an array of jobs. Each entry in the array is a linked list
119 of processes that are piped together. The first process encountered is
120 the group leader. */
121
122/* Each child of the shell is remembered in a STRUCT PROCESS. A chain of
123 such structures is a pipeline. The chain is circular. */
124typedef struct process {
125 struct process *next; /* Next process in the pipeline. A circular chain. */
126 pid_t pid; /* Process ID. */
127 WAIT status; /* The status of this command as returned by wait. */
128 int running; /* Non-zero if this process is running. */
129 char *command; /* The particular program that is running. */
130} PROCESS;
131
132/* A description of a pipeline's state. */
133typedef enum { JRUNNING, JSTOPPED, JDEAD, JMIXED } JOB_STATE;
134#define JOBSTATE(job) (jobs[(job)]->state)
135
ccc6cda3
JA
136#define STOPPED(j) (jobs[(j)]->state == JSTOPPED)
137#define RUNNING(j) (jobs[(j)]->state == JRUNNING)
138#define DEADJOB(j) (jobs[(j)]->state == JDEAD)
139
726f6388
JA
140/* Values for the FLAGS field in the JOB struct below. */
141#define J_FOREGROUND 0x01 /* Non-zero if this is running in the foreground. */
142#define J_NOTIFIED 0x02 /* Non-zero if already notified about job state. */
143#define J_JOBCONTROL 0x04 /* Non-zero if this job started under job control. */
ccc6cda3
JA
144#define J_NOHUP 0x08 /* Don't send SIGHUP to job if shell gets SIGHUP. */
145
146#define IS_FOREGROUND(j) ((jobs[j]->flags & J_FOREGROUND) != 0)
147#define IS_NOTIFIED(j) ((jobs[j]->flags & J_NOTIFIED) != 0)
148#define IS_JOBCONTROL(j) ((jobs[j]->flags & J_JOBCONTROL) != 0)
726f6388
JA
149
150typedef struct job {
151 char *wd; /* The working directory at time of invocation. */
152 PROCESS *pipe; /* The pipeline of processes that make up this job. */
153 pid_t pgrp; /* The process ID of the process group (necessary). */
154 JOB_STATE state; /* The state that this job is in. */
155 int flags; /* Flags word: J_NOTIFIED, J_FOREGROUND, or J_JOBCONTROL. */
156#if defined (JOB_CONTROL)
157 COMMAND *deferred; /* Commands that will execute when this job is done. */
ccc6cda3
JA
158 VFunction *j_cleanup; /* Cleanup function to call when job marked JDEAD */
159 PTR_T cleanarg; /* Argument passed to (*j_cleanup)() */
726f6388
JA
160#endif /* JOB_CONTROL */
161} JOB;
162
163#define NO_JOB -1 /* An impossible job array index. */
164#define DUP_JOB -2 /* A possible return value for get_job_spec (). */
165
166/* A value which cannot be a process ID. */
167#define NO_PID (pid_t)-1
168
726f6388 169/* System calls. */
ccc6cda3 170#if !defined (HAVE_UNISTD_H)
726f6388 171extern pid_t fork (), getpid (), getpgrp ();
ccc6cda3 172#endif /* !HAVE_UNISTD_H */
726f6388
JA
173
174/* Stuff from the jobs.c file. */
175extern pid_t original_pgrp, shell_pgrp, pipeline_pgrp;
176extern pid_t last_made_pid, last_asynchronous_pid;
177extern int current_job, previous_job;
178extern int asynchronous_notification;
179extern JOB **jobs;
180extern int job_slots;
181
182extern void making_children __P((void));
183extern void stop_making_children __P((void));
184extern void cleanup_the_pipeline __P((void));
ccc6cda3
JA
185extern void save_pipeline __P((int));
186extern void restore_pipeline __P((int));
726f6388
JA
187extern void start_pipeline __P((void));
188extern int stop_pipeline __P((int, COMMAND *));
189extern void delete_job __P((int));
ccc6cda3 190extern void nohup_job __P((int));
726f6388
JA
191
192extern void terminate_current_pipeline __P((void));
193extern void terminate_stopped_jobs __P((void));
194extern void hangup_all_jobs __P((void));
195extern void kill_current_pipeline __P((void));
196
197#if defined (__STDC__) && defined (pid_t)
198extern void describe_pid __P((int));
199#else
200extern void describe_pid __P((pid_t));
201#endif
202
ccc6cda3
JA
203extern void list_one_job __P((JOB *, int, int, int));
204extern void list_all_jobs __P((int));
205extern void list_stopped_jobs __P((int));
206extern void list_running_jobs __P((int));
726f6388
JA
207
208extern pid_t make_child __P((char *, int));
209extern int get_tty_state __P((void));
210extern int set_tty_state __P((void));
211
212extern int wait_for_single_pid __P((pid_t));
213extern void wait_for_background_pids __P((void));
214extern int wait_for __P((pid_t));
215extern int wait_for_job __P((int));
216
217extern void notify_and_cleanup __P((void));
218extern void reap_dead_jobs __P((void));
219extern int start_job __P((int, int));
220extern int kill_pid __P((pid_t, int, int));
221extern int initialize_jobs __P((void));
222extern void initialize_job_signals __P((void));
223extern int give_terminal_to __P((pid_t));
224
ccc6cda3
JA
225extern void set_sigwinch_handler __P((void));
226extern void unset_sigwinch_handler __P((void));
227
228extern void unfreeze_jobs_list __P((void));
726f6388
JA
229extern int set_job_control __P((int));
230extern void without_job_control __P((void));
231extern void end_job_control __P((void));
232extern void restart_job_control __P((void));
233extern void set_sigchld_handler __P((void));
ccc6cda3
JA
234extern void ignore_tty_job_signals __P((void));
235extern void default_tty_job_signals __P((void));
726f6388
JA
236
237#if defined (JOB_CONTROL)
238extern int job_control;
239#endif
240
ccc6cda3 241#endif /* _JOBS_H_ */