xref: /titanic_50/usr/src/lib/libshell/common/include/jobs.h (revision f8919bdadda3ebb97bd55cc14a16e0271ed57615)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *           Copyright (c) 1982-2007 AT&T Knowledge Ventures            *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                      by AT&T Knowledge Ventures                      *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                  David Korn <dgk@research.att.com>                   *
18 *                                                                      *
19 ***********************************************************************/
20 #pragma prototyped
21 #ifndef JOB_NFLAG
22 /*
23  *	Interface to job control for shell
24  *	written by David Korn
25  *
26  */
27 
28 #define JOBTTY	2
29 
30 #include	<ast.h>
31 #include	<sfio.h>
32 #ifndef SIGINT
33 #   include	<signal.h>
34 #endif /* !SIGINT */
35 #include	"FEATURE/options"
36 
37 #undef JOBS
38 #if defined(SIGCLD) && !defined(SIGCHLD)
39 #   define SIGCHLD	SIGCLD
40 #endif
41 #ifdef SIGCHLD
42 #   define JOBS	1
43 #   include	"terminal.h"
44 #   ifdef FIOLOOKLD
45 	/* Ninth edition */
46 	extern int tty_ld, ntty_ld;
47 #	define OTTYDISC	tty_ld
48 #	define NTTYDISC	ntty_ld
49 #   endif	/* FIOLOOKLD */
50 #else
51 #   undef SIGTSTP
52 #   undef SH_MONITOR
53 #   define SH_MONITOR	0
54 #   define job_set(x)
55 #   define job_reset(x)
56 #endif
57 
58 struct process
59 {
60 	struct process *p_nxtjob;	/* next job structure */
61 	struct process *p_nxtproc;	/* next process in current job */
62 	pid_t		p_pid;		/* process id */
63 	pid_t		p_pgrp;		/* process group */
64 	pid_t		p_fgrp;		/* process group when stopped */
65 	short		p_job;		/* job number of process */
66 	unsigned short	p_exit;		/* exit value or signal number */
67 	unsigned short	p_flag;		/* flags - see below */
68 	int		p_env;		/* subshell environment number */
69 #ifdef JOBS
70 	off_t		p_name;		/* history file offset for command */
71 	struct termios	p_stty;		/* terminal state for job */
72 #endif /* JOBS */
73 };
74 
75 struct jobs
76 {
77 	struct process	*pwlist;	/* head of process list */
78 	pid_t		curpgid;	/* current process gid id */
79 	pid_t		parent;		/* set by fork() */
80 	pid_t		mypid;		/* process id of shell */
81 	pid_t		mypgid;		/* process group id of shell */
82 	pid_t		mytgid;		/* terminal group id of shell */
83 	unsigned int	in_critical;	/* >0 => in critical region */
84 	int		savesig;	/* active signal */
85 	int		numpost;	/* number of posted jobs */
86 	short		fd;		/* tty descriptor number */
87 #ifdef JOBS
88 	int		suspend;	/* suspend character */
89 	int		linedisc;	/* line dicipline */
90 #endif /* JOBS */
91 	char		jobcontrol;	/* turned on for real job control */
92 	char		waitsafe;	/* wait will not block */
93 	char		waitall;	/* wait for all jobs in pipe */
94 	char		toclear;	/* job table needs clearing */
95 	unsigned char	*freejobs;	/* free jobs numbers */
96 };
97 
98 /* flags for joblist */
99 #define JOB_LFLAG	1
100 #define JOB_NFLAG	2
101 #define JOB_PFLAG	4
102 #define JOB_NLFLAG	8
103 
104 extern struct jobs job;
105 
106 #ifdef JOBS
107 
108 #define job_lock()	(job.in_critical++)
109 #define job_unlock()	do{if(!--job.in_critical&&job.savesig)job_reap(job.savesig);}while(0)
110 
111 extern const char	e_jobusage[];
112 extern const char	e_done[];
113 extern const char	e_running[];
114 extern const char	e_coredump[];
115 extern const char	e_no_proc[];
116 extern const char	e_no_job[];
117 extern const char	e_jobsrunning[];
118 extern const char	e_nlspace[];
119 extern const char	e_access[];
120 extern const char	e_terminate[];
121 extern const char	e_no_jctl[];
122 extern const char	e_signo[];
123 #ifdef SIGTSTP
124    extern const char	e_no_start[];
125 #endif /* SIGTSTP */
126 #ifdef NTTYDISC
127    extern const char	e_newtty[];
128    extern const char	e_oldtty[];
129 #endif /* NTTYDISC */
130 #endif	/* JOBS */
131 
132 /*
133  * The following are defined in jobs.c
134  */
135 
136 extern void	job_clear(void);
137 extern void	job_bwait(char**);
138 extern int	job_walk(Sfio_t*,int(*)(struct process*,int),int,char*[]);
139 extern int	job_kill(struct process*,int);
140 extern void	job_wait(pid_t);
141 extern int	job_post(pid_t,pid_t);
142 extern void	*job_subsave(void);
143 extern void	job_subrestore(void*);
144 #ifdef JOBS
145 	extern void	job_init(int);
146 	extern int	job_close(void);
147 	extern int	job_list(struct process*,int);
148 	extern int	job_terminate(struct process*,int);
149 	extern int	job_switch(struct process*,int);
150 	extern void	job_fork(pid_t);
151 	extern int	job_reap(int);
152 #else
153 #	define job_init(flag)
154 #	define job_close()	(0)
155 #	define job_fork(p)
156 #endif	/* JOBS */
157 
158 
159 #endif /* !JOB_NFLAG */
160