xref: /titanic_50/usr/src/lib/libshell/common/include/jobs.h (revision 7c2fbfb345896881c631598ee3852ce9ce33fb07)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1982-2008 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
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_exitmin;	/* minimum exit value for xargs */
68 	unsigned short	p_flag;		/* flags - see below */
69 	int		p_env;		/* subshell environment number */
70 #ifdef JOBS
71 	off_t		p_name;		/* history file offset for command */
72 	struct termios	p_stty;		/* terminal state for job */
73 #endif /* JOBS */
74 };
75 
76 struct jobs
77 {
78 	struct process	*pwlist;	/* head of process list */
79 	pid_t		curpgid;	/* current process gid id */
80 	pid_t		parent;		/* set by fork() */
81 	pid_t		mypid;		/* process id of shell */
82 	pid_t		mypgid;		/* process group id of shell */
83 	pid_t		mytgid;		/* terminal group id of shell */
84 	unsigned int	in_critical;	/* >0 => in critical region */
85 	int		savesig;	/* active signal */
86 	int		numpost;	/* number of posted jobs */
87 	short		fd;		/* tty descriptor number */
88 #ifdef JOBS
89 	int		suspend;	/* suspend character */
90 	int		linedisc;	/* line dicipline */
91 #endif /* JOBS */
92 	char		jobcontrol;	/* turned on for real job control */
93 	char		waitsafe;	/* wait will not block */
94 	char		waitall;	/* wait for all jobs in pipe */
95 	char		toclear;	/* job table needs clearing */
96 	unsigned char	*freejobs;	/* free jobs numbers */
97 };
98 
99 /* flags for joblist */
100 #define JOB_LFLAG	1
101 #define JOB_NFLAG	2
102 #define JOB_PFLAG	4
103 #define JOB_NLFLAG	8
104 
105 extern struct jobs job;
106 
107 #ifdef JOBS
108 
109 #if !_std_malloc
110 #include <vmalloc.h>
111 #if VMALLOC_VERSION >= 20070911L
112 #define vmbusy()	(vmstat(0,0)!=0)
113 #endif
114 #endif
115 #ifndef vmbusy
116 #define vmbusy()	0
117 #endif
118 
119 
120 #define job_lock()	(job.in_critical++)
121 #define job_unlock()	do{if(!--job.in_critical&&job.savesig&&!vmbusy())job_reap(job.savesig);}while(0)
122 
123 extern const char	e_jobusage[];
124 extern const char	e_done[];
125 extern const char	e_running[];
126 extern const char	e_coredump[];
127 extern const char	e_no_proc[];
128 extern const char	e_no_job[];
129 extern const char	e_jobsrunning[];
130 extern const char	e_nlspace[];
131 extern const char	e_access[];
132 extern const char	e_terminate[];
133 extern const char	e_no_jctl[];
134 extern const char	e_signo[];
135 #ifdef SIGTSTP
136    extern const char	e_no_start[];
137 #endif /* SIGTSTP */
138 #ifdef NTTYDISC
139    extern const char	e_newtty[];
140    extern const char	e_oldtty[];
141 #endif /* NTTYDISC */
142 #endif	/* JOBS */
143 
144 /*
145  * The following are defined in jobs.c
146  */
147 
148 extern void	job_clear(void);
149 extern void	job_bwait(char**);
150 extern int	job_walk(Sfio_t*,int(*)(struct process*,int),int,char*[]);
151 extern int	job_kill(struct process*,int);
152 extern int	job_wait(pid_t);
153 extern int	job_post(pid_t,pid_t);
154 extern void	*job_subsave(void);
155 extern void	job_subrestore(void*);
156 #ifdef JOBS
157 	extern void	job_init(Shell_t*,int);
158 	extern int	job_close(Shell_t*);
159 	extern int	job_list(struct process*,int);
160 	extern int	job_terminate(struct process*,int);
161 	extern int	job_switch(struct process*,int);
162 	extern void	job_fork(pid_t);
163 	extern int	job_reap(int);
164 #else
165 #	define job_init(s,flag)
166 #	define job_close(s)	(0)
167 #	define job_fork(p)
168 #endif	/* JOBS */
169 
170 
171 #endif /* !JOB_NFLAG */
172