#pragma prototyped
#ifndef JOB_NFLAG
#define JOBTTY 2
#include <ast.h>
#include <sfio.h>
#ifndef SIGINT
# include <signal.h>
#endif
#include "FEATURE/options"
#if SHOPT_COSHELL
# include <coshell.h>
# define COPID_BIT (1L<<30)
struct cosh
{
struct cosh *next;
Coshell_t *coshell;
Cojob_t *cojob;
char *name;
short id;
};
extern pid_t sh_copid(struct cosh*);
extern char *sh_pid2str(Shell_t*,pid_t);
#endif
#undef JOBS
#if defined(SIGCLD) && !defined(SIGCHLD)
# define SIGCHLD SIGCLD
#endif
#ifdef SIGCHLD
# define JOBS 1
# include "terminal.h"
# ifdef FIOLOOKLD
extern int tty_ld, ntty_ld;
# define OTTYDISC tty_ld
# define NTTYDISC ntty_ld
# endif
#else
# undef SIGTSTP
# undef SH_MONITOR
# define SH_MONITOR 0
# define job_set(x)
# define job_reset(x)
#endif
struct process
{
struct process *p_nxtjob;
struct process *p_nxtproc;
Shell_t *p_shp;
#if SHOPT_COSHELL
Cojob_t *p_cojob;
#endif
pid_t p_pid;
pid_t p_pgrp;
pid_t p_fgrp;
short p_job;
unsigned short p_exit;
unsigned short p_exitmin;
unsigned short p_flag;
int p_env;
#ifdef JOBS
off_t p_name;
struct termios p_stty;
#endif
};
struct jobs
{
struct process *pwlist;
pid_t curpgid;
pid_t parent;
pid_t mypid;
pid_t mypgid;
pid_t mytgid;
unsigned int in_critical;
int savesig;
int numpost;
#ifdef SHOPT_BGX
int numbjob;
#endif
short fd;
#ifdef JOBS
int suspend;
int linedisc;
#endif
char jobcontrol;
char waitsafe;
char waitall;
char toclear;
unsigned char *freejobs;
#if SHOPT_COSHELL
struct cosh *colist;
#endif
};
#define JOB_LFLAG 1
#define JOB_NFLAG 2
#define JOB_PFLAG 4
#define JOB_NLFLAG 8
extern struct jobs job;
#ifdef JOBS
#if !_std_malloc
#include <vmalloc.h>
#if VMALLOC_VERSION >= 20070911L
#define vmbusy() (vmstat(0,0)!=0)
#endif
#endif
#ifndef vmbusy
#define vmbusy() 0
#endif
#define job_lock() (job.in_critical++)
#define job_unlock() \
do { \
int sig; \
if (!--job.in_critical && (sig = job.savesig)) \
{ \
if (!job.in_critical++ && !vmbusy()) \
job_reap(sig); \
job.in_critical--; \
} \
} while(0)
extern const char e_jobusage[];
extern const char e_done[];
extern const char e_running[];
extern const char e_coredump[];
extern const char e_no_proc[];
extern const char e_no_job[];
extern const char e_jobsrunning[];
extern const char e_nlspace[];
extern const char e_access[];
extern const char e_terminate[];
extern const char e_no_jctl[];
extern const char e_signo[];
#ifdef SIGTSTP
extern const char e_no_start[];
#endif
#ifdef NTTYDISC
extern const char e_newtty[];
extern const char e_oldtty[];
#endif
#endif
extern void job_clear(void);
extern void job_bwait(char**);
extern int job_walk(Sfio_t*,int(*)(struct process*,int),int,char*[]);
extern int job_kill(struct process*,int);
extern int job_wait(pid_t);
extern int job_post(Shell_t*,pid_t,pid_t);
extern void *job_subsave(void);
extern void job_subrestore(void*);
#ifdef SHOPT_BGX
extern void job_chldtrap(Shell_t*, const char*,int);
#endif
#ifdef JOBS
extern void job_init(Shell_t*,int);
extern int job_close(Shell_t*);
extern int job_list(struct process*,int);
extern int job_terminate(struct process*,int);
extern int job_switch(struct process*,int);
extern void job_fork(pid_t);
extern int job_reap(int);
#else
# define job_init(s,flag)
# define job_close(s) (0)
# define job_fork(p)
#endif
#endif