mirror of
				git://git.code.sf.net/p/cdesktopenv/code
				synced 2025-03-09 15:50:02 +00:00 
			
		
		
		
	Remove unused libcoshell
The coshell(1) command, which is required for libcoshell to be
useful, is not known to be shipped by any distribution. It was
removed by the ksh-community fork and hence also by 93u+m (in
2940b3f5). The coshell facility as a whole is obsolete and
insecure. For a long time now, the statically linked libcoshell
library has been 40+ kilobytes of dead weight in the ksh binary.
Prior discussion (ksh2020): https://github.com/att/ast/issues/619
src/lib/libcoshell/*:
- Removed.
src/cmd/ksh93/*:
- Remove the SHOPT_COSHELL compiler option (which was enabled) and
  a lot of code that was conditional upon #ifdef SHOPT_COSHELL.
- init.c: e_version[]: Removing SHOPT_COSHELL changed the "J"
  feature identifier in ${.sh.version} to a lowercase "j", which
  was conditional upon SHOPT_BGX (background job extensions).
  But src/cmd/ksh93/RELEASE documents (at 08-12-04, on line 1188):
    | +SHOPT_BGX enables background job extensions. Noted by "J" in
    |  the version string when enabled. [...]
  That is the only available documentation. So change that "j" back
  to a "J", leaving the version string unchanged after this commit.
- jobs.c: job_walk(): We need to keep one 'job_waitsafe(SIGCHLD);'
  call that was conditional upon SHOPT_COSHELL; removing it caused
  a regression test failure in tests/sigchld.sh, 'SIGCHLD blocked
  for script at end of pipeline' (which means that until now, a ksh
  compiled without libcoshell had broken SIGCHLD handling.)
bin/package, src/cmd/INIT/package.sh:
- Don't export COSHELL variable.
			
			
This commit is contained in:
		
							parent
							
								
									fbc6cd4286
								
							
						
					
					
						commit
						3613da4240
					
				
					 39 changed files with 87 additions and 4635 deletions
				
			
		| 
						 | 
				
			
			@ -91,14 +91,9 @@ char e_version[]	= "\n@(#)$Id: Version "
 | 
			
		|||
#define ATTRS		1
 | 
			
		||||
			"B"
 | 
			
		||||
#endif
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
#define ATTRS		1
 | 
			
		||||
			"J"
 | 
			
		||||
#else
 | 
			
		||||
#if SHOPT_BGX
 | 
			
		||||
#define ATTRS		1
 | 
			
		||||
			"j"
 | 
			
		||||
#endif
 | 
			
		||||
			"J"
 | 
			
		||||
#endif
 | 
			
		||||
#if SHOPT_ACCT
 | 
			
		||||
#define ATTRS		1
 | 
			
		||||
| 
						 | 
				
			
			@ -199,9 +194,6 @@ typedef struct _init_
 | 
			
		|||
	Namfun_t	SH_VERSION_init;
 | 
			
		||||
	struct match	SH_MATCH_init;
 | 
			
		||||
	Namfun_t	SH_MATH_init;
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
	Namfun_t	SH_JOBPOOL_init;
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
#ifdef _hdr_locale
 | 
			
		||||
	Namfun_t	LC_TYPE_init;
 | 
			
		||||
	Namfun_t	LC_NUM_init;
 | 
			
		||||
| 
						 | 
				
			
			@ -1028,10 +1020,6 @@ static char *setdisc_any(Namval_t *np, const char *event, Namval_t *action, Namf
 | 
			
		|||
 | 
			
		||||
static const Namdisc_t SH_MATH_disc  = { 0, 0, get_math, 0, setdisc_any, create_math, };
 | 
			
		||||
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
static const Namdisc_t SH_JOBPOOL_disc  = { 0, 0, 0, 0, setdisc_any, 0, };
 | 
			
		||||
#endif /*  SHOPT_COSHELL */
 | 
			
		||||
 | 
			
		||||
#if SHOPT_NAMESPACE
 | 
			
		||||
    static char* get_nspace(Namval_t* np, Namfun_t *fp)
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			@ -1792,11 +1780,6 @@ static Init_t *nv_init(Shell_t *shp)
 | 
			
		|||
	ip->SH_MATCH_init.hdr.nofree = 1;
 | 
			
		||||
	ip->SH_MATH_init.disc = &SH_MATH_disc;
 | 
			
		||||
	ip->SH_MATH_init.nofree = 1;
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
	ip->SH_JOBPOOL_init.disc = &SH_JOBPOOL_disc;
 | 
			
		||||
	ip->SH_JOBPOOL_init.nofree = 1;
 | 
			
		||||
	nv_stack(SH_JOBPOOL, &ip->SH_JOBPOOL_init);
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
	ip->SH_VERSION_init.disc = &SH_VERSION_disc;
 | 
			
		||||
	ip->SH_VERSION_init.nofree = 1;
 | 
			
		||||
	ip->LINENO_init.disc = &LINENO_disc;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -317,7 +317,6 @@ inetopen(const char* path, int flags, Inetintr_f onintr, void* handle)
 | 
			
		|||
#else
 | 
			
		||||
 | 
			
		||||
#undef	O_SERVICE
 | 
			
		||||
#undef	SHOPT_COSHELL
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -924,57 +923,6 @@ int	sh_pipe(register int pv[])
 | 
			
		|||
   }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
    int sh_coaccept(Shell_t *shp,int *pv,int out)
 | 
			
		||||
    {
 | 
			
		||||
	int fd = accept(pv[0],(struct sockaddr*)0,(socklen_t*)0);
 | 
			
		||||
	sh_close(pv[0]);
 | 
			
		||||
	pv[0] = -1;
 | 
			
		||||
	if(fd<0)
 | 
			
		||||
		errormsg(SH_DICT,ERROR_system(1),e_pipe);
 | 
			
		||||
	if((pv[out]=sh_fcntl(fd,F_DUPFD,10)) >=10)
 | 
			
		||||
		sh_close(fd);
 | 
			
		||||
	else
 | 
			
		||||
		pv[out] = sh_iomovefd(fd);
 | 
			
		||||
	if(fcntl(pv[out],F_SETFD,FD_CLOEXEC) >=0)
 | 
			
		||||
		shp->fdstatus[pv[out]] |= IOCLEX;
 | 
			
		||||
	shp->fdstatus[pv[out]] = (out?IOWRITE:IOREAD);
 | 
			
		||||
	shp->fdstatus[pv[out]] |= IONOSEEK;
 | 
			
		||||
	sh_subsavefd(pv[out]);
 | 
			
		||||
#if defined(SHUT_RD) && defined(SHUT_WR)
 | 
			
		||||
	shutdown(pv[out],out?SHUT_RD:SHUT_WR);
 | 
			
		||||
#endif
 | 
			
		||||
	return(0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    int sh_copipe(Shell_t *shp, int *pv, int out)
 | 
			
		||||
    {
 | 
			
		||||
	int			r,port=20000;
 | 
			
		||||
	struct sockaddr_in	sin;
 | 
			
		||||
	socklen_t		slen;
 | 
			
		||||
	if ((pv[out] = socket (AF_INET, SOCK_STREAM, 0)) < 0)
 | 
			
		||||
		errormsg(SH_DICT,ERROR_system(1),e_pipe);
 | 
			
		||||
	do
 | 
			
		||||
	{
 | 
			
		||||
		sin.sin_family = AF_INET;
 | 
			
		||||
		sin.sin_port = htons(++port);
 | 
			
		||||
		sin.sin_addr.s_addr = INADDR_ANY;
 | 
			
		||||
		slen = sizeof (sin);
 | 
			
		||||
	}
 | 
			
		||||
	while ((r=bind (pv[out], (struct sockaddr *) &sin, slen)) == -1 && errno==EADDRINUSE);
 | 
			
		||||
	if(r<0 ||  listen(pv[out],5) <0)
 | 
			
		||||
	{
 | 
			
		||||
		close(pv[out]);
 | 
			
		||||
		errormsg(SH_DICT,ERROR_system(1),e_pipe);
 | 
			
		||||
	}
 | 
			
		||||
	fcntl(pv[out],F_SETFD,FD_CLOEXEC);
 | 
			
		||||
	shp->fdstatus[pv[out]] |= IOCLEX;
 | 
			
		||||
	pv[1-out] = -1;
 | 
			
		||||
	pv[2] = port;
 | 
			
		||||
	return(0);
 | 
			
		||||
    }
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
 | 
			
		||||
static int pat_seek(void *handle, const char *str, size_t sz)
 | 
			
		||||
{
 | 
			
		||||
	char **bp = (char**)handle;
 | 
			
		||||
| 
						 | 
				
			
			@ -1199,14 +1147,6 @@ int	sh_redirect(Shell_t *shp,struct ionod *iop, int flag)
 | 
			
		|||
		}
 | 
			
		||||
		errno=0;
 | 
			
		||||
		np = 0;
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
		if(shp->inpool)
 | 
			
		||||
		{
 | 
			
		||||
			if(!(iof&(IODOC|IOLSEEK|IOMOV)))
 | 
			
		||||
				sh_coaddfile(shp,fname);
 | 
			
		||||
			continue;
 | 
			
		||||
		}
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
		if(iop->iovname)
 | 
			
		||||
		{
 | 
			
		||||
			np = nv_open(iop->iovname,shp->var_tree,NV_NOASSIGN|NV_VARNAME);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -253,82 +253,6 @@ static struct jobsave *jobsave_create(pid_t pid)
 | 
			
		|||
	return(jp);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
    pid_t sh_copid(struct cosh *csp)
 | 
			
		||||
    {
 | 
			
		||||
	return(COPID_BIT|(csp->id<<16)|csp->cojob->id);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    char  *sh_pid2str(Shell_t *shp,pid_t pid)
 | 
			
		||||
    {
 | 
			
		||||
	struct cosh  *csp=0;
 | 
			
		||||
	if(pid&COPID_BIT)
 | 
			
		||||
	{
 | 
			
		||||
		int id = (pid>>16) &0x3f;
 | 
			
		||||
		for(csp=job.colist; csp; csp = csp->next)
 | 
			
		||||
		{
 | 
			
		||||
			if(csp->id == id)
 | 
			
		||||
				break;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if(csp)
 | 
			
		||||
		sfprintf(shp->strbuf,"%s.%d%c",csp->name,pid&0xff,0);
 | 
			
		||||
	else
 | 
			
		||||
		sfprintf(shp->strbuf,"%d%c",pid,0);
 | 
			
		||||
	return(sfstruse(shp->strbuf));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    int job_cowalk(int (*fun)(struct process*,int),int arg,char *name)
 | 
			
		||||
    {
 | 
			
		||||
	Shell_t		*shp = sh_getinterp();
 | 
			
		||||
	struct cosh	*csp;
 | 
			
		||||
	struct process	*pw,*pwnext;
 | 
			
		||||
	pid_t		val;
 | 
			
		||||
	int		n,r=0;
 | 
			
		||||
	char		*cp = strchr(name,'.');
 | 
			
		||||
	if(!cp)
 | 
			
		||||
		n = strlen(name);
 | 
			
		||||
	else
 | 
			
		||||
		n = cp-name;
 | 
			
		||||
	for(csp=(struct cosh*)job.colist;csp;csp=csp->next)
 | 
			
		||||
	{
 | 
			
		||||
		if(memcmp(name,csp->name,n)==0 && csp->name[n]==0)
 | 
			
		||||
			break;
 | 
			
		||||
	}
 | 
			
		||||
	if(!csp)
 | 
			
		||||
		errormsg(SH_DICT,ERROR_exit(1),e_jobusage,name);
 | 
			
		||||
	if(cp)
 | 
			
		||||
	{
 | 
			
		||||
		n = pid_fromstring(cp+1);
 | 
			
		||||
		val = (csp->id<<16)|n|COPID_BIT;
 | 
			
		||||
	}
 | 
			
		||||
	job_reap(SIGCHLD);
 | 
			
		||||
	for(n=0,pw=job.pwlist; pw; pw=pwnext)
 | 
			
		||||
	{
 | 
			
		||||
		pwnext = pw->p_nxtjob;
 | 
			
		||||
		if((cp && val==pw->p_pid) || (pw->p_cojob && pw->p_cojob->local==(void*)csp))
 | 
			
		||||
		{
 | 
			
		||||
			if(fun)
 | 
			
		||||
			{
 | 
			
		||||
				if(pw->p_flag&P_DONE)
 | 
			
		||||
					continue;
 | 
			
		||||
				r |= (*fun)(pw,arg);
 | 
			
		||||
			}
 | 
			
		||||
			else
 | 
			
		||||
				job_wait(-pw->p_pid);
 | 
			
		||||
			n++;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if(!n)
 | 
			
		||||
		shp->exitval = fun?1:ERROR_NOENT;
 | 
			
		||||
	else if(fun)
 | 
			
		||||
		shp->exitval = r;
 | 
			
		||||
	return(r);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Reap one job
 | 
			
		||||
 * When called with sig==0, it does a blocking wait
 | 
			
		||||
| 
						 | 
				
			
			@ -345,18 +269,6 @@ int job_reap(register int sig)
 | 
			
		|||
	Waitevent_f waitevent = shp->gd->waitevent;
 | 
			
		||||
	static int wcontinued = WCONTINUED;
 | 
			
		||||
	int was_ttywait_on;
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
	Cojob_t		*cjp;
 | 
			
		||||
	int		cojobs;
 | 
			
		||||
	long		cotimeout = sig?0:-1;
 | 
			
		||||
	for(pw=job.pwlist;pw;pw=pw->p_nxtjob)
 | 
			
		||||
	{
 | 
			
		||||
		if(pw->p_cojob && !(pw->p_flag&P_DONE))
 | 
			
		||||
			break;
 | 
			
		||||
	}
 | 
			
		||||
	cojobs = (pw!=0);
 | 
			
		||||
	pid = 0;
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
	if (vmbusy())
 | 
			
		||||
	{
 | 
			
		||||
		errormsg(SH_DICT,ERROR_warn(0),"vmbusy() inside job_reap() -- should not happen");
 | 
			
		||||
| 
						 | 
				
			
			@ -385,33 +297,9 @@ int job_reap(register int sig)
 | 
			
		|||
			if(waitevent && (*waitevent)(-1,-1L,0))
 | 
			
		||||
				flags |= WNOHANG;
 | 
			
		||||
		}
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
		if(cojobs)
 | 
			
		||||
		{
 | 
			
		||||
			if(cjp = cowait(0,0,cotimeout))
 | 
			
		||||
			{
 | 
			
		||||
				struct cosh *csp;
 | 
			
		||||
				csp = (struct cosh*)(cjp->coshell->data);
 | 
			
		||||
				csp->cojob = cjp;
 | 
			
		||||
				pid = sh_copid(csp);
 | 
			
		||||
				if(cjp->status < 256)
 | 
			
		||||
					wstat = cjp->status <<8;
 | 
			
		||||
				else
 | 
			
		||||
					wstat = cjp->status-256;
 | 
			
		||||
				cotimeout = 0;
 | 
			
		||||
				goto cojob;
 | 
			
		||||
			}
 | 
			
		||||
			else if(copending(0)==0)
 | 
			
		||||
				cojobs = 0;
 | 
			
		||||
			cotimeout = 0;
 | 
			
		||||
		}
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
		pid = waitpid((pid_t)-1,&wstat,flags);
 | 
			
		||||
		if(!was_ttywait_on)
 | 
			
		||||
			sh_offstate(SH_TTYWAIT);
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
	cojob:
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
 | 
			
		||||
		/*
 | 
			
		||||
		 * some systems (linux 2.6) may return EINVAL
 | 
			
		||||
| 
						 | 
				
			
			@ -563,10 +451,6 @@ int job_reap(register int sig)
 | 
			
		|||
		}
 | 
			
		||||
#endif
 | 
			
		||||
	}
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
	if(!was_ttywait_on)
 | 
			
		||||
		sh_offstate(SH_TTYWAIT); /* only required after 'goto cojob' in the while loop */
 | 
			
		||||
#endif
 | 
			
		||||
	if(errno==ECHILD)
 | 
			
		||||
	{
 | 
			
		||||
		errno = oerrno;
 | 
			
		||||
| 
						 | 
				
			
			@ -894,13 +778,6 @@ void job_bwait(char **jobs)
 | 
			
		|||
			else
 | 
			
		||||
				return;
 | 
			
		||||
		}
 | 
			
		||||
#   if SHOPT_COSHELL
 | 
			
		||||
		else if(isalpha(*jp))
 | 
			
		||||
		{
 | 
			
		||||
			job_cowalk(NULL,0,jp);
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
#   endif /* SHOPT_COSHELL */
 | 
			
		||||
		else
 | 
			
		||||
#endif /* JOBS */
 | 
			
		||||
			pid = pid_fromstring(jp);
 | 
			
		||||
| 
						 | 
				
			
			@ -924,9 +801,7 @@ int job_walk(Sfio_t *file,int (*fun)(struct process*,int),int arg,char *joblist[
 | 
			
		|||
	by_number = 0;
 | 
			
		||||
	job_lock();
 | 
			
		||||
	pw = job.pwlist;
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
	job_waitsafe(SIGCHLD);
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
	if(jobs==0)
 | 
			
		||||
	{
 | 
			
		||||
		/* do all jobs */
 | 
			
		||||
| 
						 | 
				
			
			@ -952,15 +827,6 @@ int job_walk(Sfio_t *file,int (*fun)(struct process*,int),int arg,char *joblist[
 | 
			
		|||
		job_string = jobid;
 | 
			
		||||
		if(*jobid==0)
 | 
			
		||||
			errormsg(SH_DICT,ERROR_exit(1),e_jobusage,job_string);
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
		if(isalpha(*jobid))
 | 
			
		||||
		{
 | 
			
		||||
			r = job_cowalk(fun,arg,jobid);
 | 
			
		||||
			by_number = 0;
 | 
			
		||||
			job_unlock();
 | 
			
		||||
			return(r);
 | 
			
		||||
		}
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
		if(*jobid == '%')
 | 
			
		||||
			pw = job_bystring(jobid);
 | 
			
		||||
		else
 | 
			
		||||
| 
						 | 
				
			
			@ -1015,11 +881,7 @@ int job_list(struct process *pw,register int flag)
 | 
			
		|||
		return(0);
 | 
			
		||||
	if((flag&JOB_PFLAG))
 | 
			
		||||
	{
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
		sfprintf(outfile,"%s\n",sh_pid2str(shp,px->p_pgrp?px->p_pgrp:px->p_pid));
 | 
			
		||||
#else
 | 
			
		||||
		sfprintf(outfile,"%d\n",px->p_pgrp?px->p_pgrp:px->p_pid);
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
		return(0);
 | 
			
		||||
	}
 | 
			
		||||
	if((px->p_flag&P_DONE) && job.waitall && !(flag&JOB_LFLAG))
 | 
			
		||||
| 
						 | 
				
			
			@ -1039,11 +901,7 @@ int job_list(struct process *pw,register int flag)
 | 
			
		|||
	{
 | 
			
		||||
		n = 0;
 | 
			
		||||
		if(flag&JOB_LFLAG)
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
			sfprintf(outfile,"%s\t",sh_pid2str(shp,px->p_pid));
 | 
			
		||||
#else
 | 
			
		||||
			sfprintf(outfile,"%d\t",px->p_pid);
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
		if(px->p_flag&P_SIGNALLED)
 | 
			
		||||
			msg = job_sigmsg((int)(px->p_exit));
 | 
			
		||||
		else if(px->p_flag&P_NOTIFY)
 | 
			
		||||
| 
						 | 
				
			
			@ -1133,11 +991,6 @@ int job_kill(register struct process *pw,register int sig)
 | 
			
		|||
	job_lock();
 | 
			
		||||
	errno = ECHILD;
 | 
			
		||||
	pid = pw->p_pid;
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
	if(pw->p_cojob)
 | 
			
		||||
		r = cokill(pw->p_cojob->coshell,pw->p_cojob,sig);
 | 
			
		||||
	else
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
	if(by_number)
 | 
			
		||||
	{
 | 
			
		||||
		if(pid==0 && job.jobcontrol)
 | 
			
		||||
| 
						 | 
				
			
			@ -1364,14 +1217,6 @@ int job_post(Shell_t *shp,pid_t pid, pid_t join)
 | 
			
		|||
		pw->p_nxtproc = 0;
 | 
			
		||||
	}
 | 
			
		||||
	pw->p_exitval = job.exitval; 
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
	pw->p_cojob = 0;
 | 
			
		||||
	if(shp->coshell && (pid&COPID_BIT))
 | 
			
		||||
	{
 | 
			
		||||
		pw->p_cojob = ((struct cosh*)shp->coshell)->cojob;
 | 
			
		||||
		job.curpgid = sh_isstate(SH_MONITOR)?pid:0;
 | 
			
		||||
	}
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
	job.pwlist = pw;
 | 
			
		||||
	pw->p_shp = shp;
 | 
			
		||||
	pw->p_env = shp->curenv;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2062,10 +2062,6 @@ static void comsubst(Mac_t *mp,register Shnode_t* t, int type)
 | 
			
		|||
	mp->shp->argaddr = 0;
 | 
			
		||||
	savemac = *mp;
 | 
			
		||||
	mp->shp->st.staklist=0;
 | 
			
		||||
#ifdef SHOPT_COSHELL
 | 
			
		||||
	if(mp->shp->inpool)
 | 
			
		||||
		return;
 | 
			
		||||
#endif /*SHOPT_COSHELL */
 | 
			
		||||
	if(type)
 | 
			
		||||
	{
 | 
			
		||||
		sp = 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -2770,11 +2766,7 @@ static char *special(Shell_t *shp,register int c)
 | 
			
		|||
		return(ltos(shp->st.dolc));
 | 
			
		||||
	    case '!':
 | 
			
		||||
		if(shp->bckpid)
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
			return(sh_pid2str(shp,shp->bckpid));
 | 
			
		||||
#else
 | 
			
		||||
			return(ltos(shp->bckpid));
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
		break;
 | 
			
		||||
	    case '$':
 | 
			
		||||
		if(nv_isnull(SH_DOLLARNOD))
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1060,10 +1060,6 @@ Namval_t *nv_search(const char *name, Dt_t *root, int mode)
 | 
			
		|||
			root = sh.var_base;
 | 
			
		||||
		np = dtmatch(root,(void*)name);
 | 
			
		||||
	}
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
	if(sh.inpool)
 | 
			
		||||
		mode |= HASH_NOSCOPE;
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
	if(!np && (mode&NV_ADD))
 | 
			
		||||
	{
 | 
			
		||||
		if(sh.namespace && !(mode&HASH_NOSCOPE) && root==sh.var_tree)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -573,19 +573,11 @@ static Shnode_t	*term(Lex_t *lexp,register int flag)
 | 
			
		|||
			t->par.partyp |= COMSCAN;
 | 
			
		||||
		t->par.partre = term(lexp,0);
 | 
			
		||||
	}
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
	else if((t=item(lexp,SH_NL|SH_EMPTY|(flag&SH_SEMI))) && (lexp->token=='|' || lexp->token==PIPESYM2))
 | 
			
		||||
#else
 | 
			
		||||
	else if((t=item(lexp,SH_NL|SH_EMPTY|(flag&SH_SEMI))) && lexp->token=='|')
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
	{
 | 
			
		||||
		register Shnode_t	*tt;
 | 
			
		||||
		int showme = t->tre.tretyp&FSHOWME;
 | 
			
		||||
		t = makeparent(lexp,TFORK|FPOU,t);
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
		if(lexp->token==PIPESYM2)
 | 
			
		||||
			t->tre.tretyp |= FALTPIPE;
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
		if(tt=term(lexp,SH_NL))
 | 
			
		||||
		{
 | 
			
		||||
			switch(tt->tre.tretyp&COMMSK)
 | 
			
		||||
| 
						 | 
				
			
			@ -1325,24 +1317,6 @@ static Shnode_t	*item(Lex_t *lexp,int flag)
 | 
			
		|||
		t->par.partyp=TPAR;
 | 
			
		||||
		break;
 | 
			
		||||
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
	    case '&':
 | 
			
		||||
		if(tok=sh_lex(lexp))
 | 
			
		||||
		{
 | 
			
		||||
			if(tok!=NL)
 | 
			
		||||
				sh_syntax(lexp);
 | 
			
		||||
			t = getnode(comnod);
 | 
			
		||||
			memset(t,0,sizeof(struct comnod));
 | 
			
		||||
			t->com.comline = sh_getlineno(lexp);
 | 
			
		||||
		}
 | 
			
		||||
		else
 | 
			
		||||
			t = (Shnode_t*)simple(lexp,SH_NOIO,NIL(struct ionod*));
 | 
			
		||||
		t->com.comtyp |= FAMP;
 | 
			
		||||
		if(lexp->token=='&' || lexp->token=='|')
 | 
			
		||||
			sh_syntax(lexp);
 | 
			
		||||
		return(t);
 | 
			
		||||
		break;
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
	    default:
 | 
			
		||||
		if(io==0)
 | 
			
		||||
			return(0);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1258,7 +1258,6 @@ static void exscript(Shell_t *shp,register char *path,register char *argv[],char
 | 
			
		|||
	path = path_relative(shp,path);
 | 
			
		||||
	shp->comdiv=0;
 | 
			
		||||
	shp->bckpid = 0;
 | 
			
		||||
	shp->coshell = 0;
 | 
			
		||||
	shp->st.ioset=0;
 | 
			
		||||
	/* clean up any cooperating processes */
 | 
			
		||||
	if(shp->cpipe[0]>0)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -101,9 +101,6 @@ static struct subshell
 | 
			
		|||
	char		subshare;
 | 
			
		||||
	char		comsub;
 | 
			
		||||
	char		pwdclose;
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
	void		*coshell;
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
} *subshell_data;
 | 
			
		||||
 | 
			
		||||
static int subenv;
 | 
			
		||||
| 
						 | 
				
			
			@ -493,10 +490,6 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_t *t, volatile int flags, int comsub)
 | 
			
		|||
	sp->options = shp->options;
 | 
			
		||||
	sp->jobs = job_subsave();
 | 
			
		||||
	sp->subdup = shp->subdup;
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
	sp->coshell = shp->coshell;
 | 
			
		||||
	shp->coshell = 0;
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
	/* make sure initialization has occurred */ 
 | 
			
		||||
	if(!shp->pathlist)
 | 
			
		||||
	{
 | 
			
		||||
| 
						 | 
				
			
			@ -759,9 +752,6 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_t *t, volatile int flags, int comsub)
 | 
			
		|||
	shp->subshare = sp->subshare;
 | 
			
		||||
	shp->comsub = sp->comsub;
 | 
			
		||||
	shp->subdup = sp->subdup;
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
	shp->coshell = sp->coshell;
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
	if(shp->subshell)
 | 
			
		||||
	{
 | 
			
		||||
		shp->subshell--;		/* decrease level of virtual subshells */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -859,177 +859,6 @@ static void unset_instance(Namval_t *nq, Namval_t *node, struct Namref *nr,long
 | 
			
		|||
	_nv_unset(SH_SUBSCRNOD,0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
uintmax_t	coused;
 | 
			
		||||
/*
 | 
			
		||||
 * print out function definition
 | 
			
		||||
 */
 | 
			
		||||
static void print_fun(register Namval_t* np, void *data)
 | 
			
		||||
{
 | 
			
		||||
	register char *format;
 | 
			
		||||
	NOT_USED(data);
 | 
			
		||||
	if(!is_afunction(np) || !np->nvalue.ip)
 | 
			
		||||
		return;
 | 
			
		||||
	if(nv_isattr(np,NV_FPOSIX))
 | 
			
		||||
		format="%s()\n{ ";
 | 
			
		||||
	else
 | 
			
		||||
		format="function %s\n{ ";
 | 
			
		||||
	sfprintf(sfstdout,format,nv_name(np));
 | 
			
		||||
	sh_deparse(sfstdout,(Shnode_t*)(nv_funtree(np)),0);
 | 
			
		||||
	sfwrite(sfstdout,"}\n",2);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void *sh_coinit(Shell_t *shp,char **argv)
 | 
			
		||||
{
 | 
			
		||||
	struct cosh	*csp = job.colist;
 | 
			
		||||
	const char 	*name = argv?argv[0]:0;
 | 
			
		||||
	int  		id, open=1;
 | 
			
		||||
	if(!name)
 | 
			
		||||
		return(0);
 | 
			
		||||
	if(*name=='-')
 | 
			
		||||
	{
 | 
			
		||||
		name++;
 | 
			
		||||
		open=0;
 | 
			
		||||
	}
 | 
			
		||||
	nv_open(name,shp->var_tree,NV_IDENT|NV_NOADD);
 | 
			
		||||
	while(csp)
 | 
			
		||||
	{
 | 
			
		||||
		if(strcmp(name,csp->name)==0)
 | 
			
		||||
		{
 | 
			
		||||
			if(open)
 | 
			
		||||
			{
 | 
			
		||||
				coattr(csp->coshell,argv[1]);
 | 
			
		||||
				return((void*)csp);
 | 
			
		||||
			}
 | 
			
		||||
			coclose(csp->coshell);
 | 
			
		||||
			return(0);
 | 
			
		||||
		}
 | 
			
		||||
		csp = csp->next;
 | 
			
		||||
	}
 | 
			
		||||
	if(!open)
 | 
			
		||||
		errormsg(SH_DICT,ERROR_exit(1),"%s: unknown namespace",name);
 | 
			
		||||
	environ[0][2]=0;
 | 
			
		||||
	csp = newof(0,struct cosh,1,strlen(name)+1);
 | 
			
		||||
	if(!(csp->coshell = coopen(NULL,CO_SHELL|CO_SILENT,argv[1])))
 | 
			
		||||
	{
 | 
			
		||||
		free((void*)csp);
 | 
			
		||||
		errormsg(SH_DICT,ERROR_exit(1),"%s: unable to create namespace",name);
 | 
			
		||||
	}
 | 
			
		||||
	csp->coshell->data = (void*)csp;
 | 
			
		||||
	csp->name = (char*)(csp+1);
 | 
			
		||||
	strcpy(csp->name,name);
 | 
			
		||||
	for(id=0; coused&(1<<id); id++);
 | 
			
		||||
	coused |= (1<<id);
 | 
			
		||||
	csp->id = id;
 | 
			
		||||
	csp->next = job.colist;
 | 
			
		||||
	job.colist = csp;
 | 
			
		||||
	return((void*)csp);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int sh_coaddfile(Shell_t *shp, char *name)
 | 
			
		||||
{
 | 
			
		||||
	Namval_t *np = dtmatch(shp->inpool,name);
 | 
			
		||||
	if(!np)
 | 
			
		||||
	{
 | 
			
		||||
		np = (Namval_t*)stakalloc(sizeof(Dtlink_t)+sizeof(char*));
 | 
			
		||||
		np->nvname = name;
 | 
			
		||||
		(Namval_t*)dtinsert(shp->inpool,np);
 | 
			
		||||
		shp->poolfiles++;
 | 
			
		||||
		return(1);
 | 
			
		||||
	}
 | 
			
		||||
	return(0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int sh_coexec(Shell_t *shp,const Shnode_t *t, int filt)
 | 
			
		||||
{
 | 
			
		||||
	struct cosh	*csp = ((struct cosh*)shp->coshell);
 | 
			
		||||
	Cojob_t		*cjp;
 | 
			
		||||
	char		*str,*trap,host[PATH_MAX];
 | 
			
		||||
	int		lineno,sig,trace = sh_isoption(SH_XTRACE);
 | 
			
		||||
	int		verbose = sh_isoption(SH_VERBOSE);
 | 
			
		||||
	sh_offoption(SH_XTRACE);
 | 
			
		||||
	sh_offoption(SH_VERBOSE);
 | 
			
		||||
	if(!shp->strbuf2)
 | 
			
		||||
		shp->strbuf2 = sfstropen();
 | 
			
		||||
	sfswap(shp->strbuf2,sfstdout);
 | 
			
		||||
	sh_trap("typeset -p\nprint cd \"$PWD\"\nprint .sh.dollar=$$\nprint umask $(umask)",0);
 | 
			
		||||
	for(sig=shp->st.trapmax;--sig>0;)
 | 
			
		||||
	{
 | 
			
		||||
		if((trap=shp->st.trapcom[sig]) && *trap==0)
 | 
			
		||||
			sfprintf(sfstdout,"trap '' %d\n",sig);
 | 
			
		||||
	}
 | 
			
		||||
	if(t->tre.tretyp==TFIL)
 | 
			
		||||
		lineno = ((struct forknod*)t->lst.lstlef)->forkline;
 | 
			
		||||
	else
 | 
			
		||||
		lineno = t->fork.forkline;
 | 
			
		||||
	if(filt)
 | 
			
		||||
	{
 | 
			
		||||
		if(gethostname(host,sizeof(host)) < 0)
 | 
			
		||||
			errormsg(SH_DICT,ERROR_system(1),e_pipe);
 | 
			
		||||
		if(shp->inpipe[2]>=20000)
 | 
			
		||||
			sfprintf(sfstdout,"command exec < /dev/tcp/%s/%d || print -u2 'cannot create pipe'\n",host,shp->inpipe[2]);
 | 
			
		||||
		sfprintf(sfstdout,"command exec > /dev/tcp/%s/%d || print -u2 'cannot create pipe'\n",host,shp->outpipe[2]);
 | 
			
		||||
		if(filt==3)
 | 
			
		||||
			t = t->fork.forktre;
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
		t = t->fork.forktre;
 | 
			
		||||
	nv_scan(shp->fun_tree, print_fun, (void*)0,0, 0);
 | 
			
		||||
	if(1)
 | 
			
		||||
	{
 | 
			
		||||
		Dt_t *top = shp->var_tree;
 | 
			
		||||
		sh_scope(shp,(struct argnod*)0,0);
 | 
			
		||||
		shp->inpool = dtopen(&_Nvdisc,Dtset);
 | 
			
		||||
		sh_exec(t,filt==1||filt==2?SH_NOFORK:0);
 | 
			
		||||
		if(shp->poolfiles)
 | 
			
		||||
		{
 | 
			
		||||
			Namval_t *np;
 | 
			
		||||
			sfprintf(sfstdout,"[[ ${.sh} == *pool* ]] && .sh.pool.files=(\n");
 | 
			
		||||
			for(np=(Namval_t*)dtfirst(shp->inpool);np;np=(Namval_t*)dtnext(shp->inpool,np))
 | 
			
		||||
			{
 | 
			
		||||
				sfprintf(sfstdout,"\t%s\n",sh_fmtq(np->nvname));
 | 
			
		||||
			}
 | 
			
		||||
			sfputr(sfstdout,")",'\n');
 | 
			
		||||
			;
 | 
			
		||||
		}
 | 
			
		||||
		dtclose(shp->inpool);
 | 
			
		||||
		shp->inpool = 0;
 | 
			
		||||
		shp->poolfiles = 0;
 | 
			
		||||
		sh_unscope(shp);
 | 
			
		||||
		shp->var_tree = top;
 | 
			
		||||
	}
 | 
			
		||||
	sfprintf(sfstdout,"typeset -f .sh.pool.init && .sh.pool.init\n");
 | 
			
		||||
	sfprintf(sfstdout,"LINENO=%d\n",lineno);
 | 
			
		||||
	if(trace)
 | 
			
		||||
		sh_onoption(SH_XTRACE);
 | 
			
		||||
	if(verbose)
 | 
			
		||||
		sh_onoption(SH_VERBOSE);
 | 
			
		||||
	sh_trap("set +o",0);
 | 
			
		||||
	sh_deparse(sfstdout,t,filt==1||filt==2?FALTPIPE:0);
 | 
			
		||||
	sfputc(sfstdout,0);
 | 
			
		||||
	sfswap(shp->strbuf2,sfstdout);
 | 
			
		||||
	str = sfstruse(shp->strbuf2);
 | 
			
		||||
	if(cjp=coexec(csp->coshell,str,0,NULL,NULL,NULL))
 | 
			
		||||
	{
 | 
			
		||||
		csp->cojob = cjp;
 | 
			
		||||
		cjp->local = shp->coshell;
 | 
			
		||||
		if(filt)
 | 
			
		||||
		{
 | 
			
		||||
			if(filt>1)
 | 
			
		||||
				sh_coaccept(shp,shp->inpipe,1);
 | 
			
		||||
			sh_coaccept(shp,shp->outpipe,0);
 | 
			
		||||
			if(filt > 2)
 | 
			
		||||
			{
 | 
			
		||||
				shp->coutpipe = shp->inpipe[1];
 | 
			
		||||
				shp->fdptrs[shp->coutpipe] = &shp->coutpipe;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		return(sh_copid(csp));
 | 
			
		||||
	}
 | 
			
		||||
	return(-1);
 | 
			
		||||
}
 | 
			
		||||
#endif /*SHOPT_COSHELL*/
 | 
			
		||||
 | 
			
		||||
#if SHOPT_FILESCAN
 | 
			
		||||
    static Sfio_t *openstream(Shell_t *shp, struct ionod *iop, int *save)
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			@ -1203,31 +1032,6 @@ int sh_exec(register const Shnode_t *t, int flags)
 | 
			
		|||
			else
 | 
			
		||||
				shp->xargmin = 0;
 | 
			
		||||
			argn -= command;
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
			if(argn && shp->inpool)
 | 
			
		||||
			{
 | 
			
		||||
				if(io=t->tre.treio)
 | 
			
		||||
					sh_redirect(shp,io,0);
 | 
			
		||||
				if(!np || !is_abuiltin(np) || *np->nvname=='/' || np==SYSCD)
 | 
			
		||||
				{
 | 
			
		||||
					char **argv, *cp;
 | 
			
		||||
					for(argv=com+1; cp= *argv; argv++)
 | 
			
		||||
					{
 | 
			
		||||
						if(cp && *cp && *cp!='-')
 | 
			
		||||
							sh_coaddfile(shp,*argv);
 | 
			
		||||
					}
 | 
			
		||||
					break;
 | 
			
		||||
				}
 | 
			
		||||
				if(np->nvalue.bfp!=SYSTYPESET->nvalue.bfp)
 | 
			
		||||
					break;
 | 
			
		||||
			}
 | 
			
		||||
			if(t->tre.tretyp&FAMP)
 | 
			
		||||
			{
 | 
			
		||||
				shp->coshell = sh_coinit(shp,com);
 | 
			
		||||
				com0 = 0;
 | 
			
		||||
				break;
 | 
			
		||||
			}
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
			if(np && is_abuiltin(np))
 | 
			
		||||
			{
 | 
			
		||||
				if(!command)
 | 
			
		||||
| 
						 | 
				
			
			@ -1721,13 +1525,6 @@ int sh_exec(register const Shnode_t *t, int flags)
 | 
			
		|||
			register pid_t parent;
 | 
			
		||||
			int no_fork,jobid;
 | 
			
		||||
			int pipes[3];
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
			if(shp->inpool)
 | 
			
		||||
			{
 | 
			
		||||
				sh_exec(t->fork.forktre,0);
 | 
			
		||||
				break;
 | 
			
		||||
			}
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
			if(shp->subshell)
 | 
			
		||||
			{
 | 
			
		||||
				sh_subtmpfile(shp);
 | 
			
		||||
| 
						 | 
				
			
			@ -1774,34 +1571,8 @@ int sh_exec(register const Shnode_t *t, int flags)
 | 
			
		|||
				if(type&FCOOP)
 | 
			
		||||
				{
 | 
			
		||||
					pipes[2] = 0;
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
					if(shp->coshell)
 | 
			
		||||
					{
 | 
			
		||||
						if(shp->cpipe[0]<0 || shp->cpipe[1] < 0)
 | 
			
		||||
						{
 | 
			
		||||
							sh_copipe(shp,shp->outpipe=shp->cpipe,0);
 | 
			
		||||
							shp->fdptrs[shp->cpipe[0]] = shp->cpipe;
 | 
			
		||||
						}
 | 
			
		||||
						sh_copipe(shp,shp->inpipe=pipes,0);
 | 
			
		||||
						parent = sh_coexec(shp,t,3);
 | 
			
		||||
						shp->cpid = parent;
 | 
			
		||||
						jobid = job_post(shp,parent,0);
 | 
			
		||||
						goto skip;
 | 
			
		||||
					}
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
					coproc_init(shp,pipes);
 | 
			
		||||
				}
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
				if((type&(FAMP|FINT)) == (FAMP|FINT))
 | 
			
		||||
				{
 | 
			
		||||
					if(shp->coshell)
 | 
			
		||||
					{
 | 
			
		||||
						parent = sh_coexec(shp,t,0);
 | 
			
		||||
						jobid = job_post(shp,parent,0);
 | 
			
		||||
						goto skip;
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
#if SHOPT_AMP
 | 
			
		||||
				if((type&(FAMP|FINT)) == (FAMP|FINT))
 | 
			
		||||
					parent = sh_ntfork(shp,t,com,&jobid,ntflag);
 | 
			
		||||
| 
						 | 
				
			
			@ -1835,9 +1606,6 @@ int sh_exec(register const Shnode_t *t, int flags)
 | 
			
		|||
#endif /* SHOPT_SPAWN */
 | 
			
		||||
#endif
 | 
			
		||||
			}
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
		skip:
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
			if(job.parent=parent)
 | 
			
		||||
			/* This is the parent branch of fork
 | 
			
		||||
			 * It may or may not wait for the child
 | 
			
		||||
| 
						 | 
				
			
			@ -1882,11 +1650,7 @@ int sh_exec(register const Shnode_t *t, int flags)
 | 
			
		|||
					{
 | 
			
		||||
						/* print job number */
 | 
			
		||||
#ifdef JOBS
 | 
			
		||||
#   if SHOPT_COSHELL
 | 
			
		||||
						sfprintf(sfstderr,"[%d]\t%s\n",jobid,sh_pid2str(shp,parent));
 | 
			
		||||
#   else
 | 
			
		||||
						sfprintf(sfstderr,"[%d]\t%d\n",jobid,parent);
 | 
			
		||||
#   endif /* SHOPT_COSHELL */
 | 
			
		||||
#else
 | 
			
		||||
						sfprintf(sfstderr,"%d\n",parent);
 | 
			
		||||
#endif /* JOBS */
 | 
			
		||||
| 
						 | 
				
			
			@ -1944,20 +1708,12 @@ int sh_exec(register const Shnode_t *t, int flags)
 | 
			
		|||
#endif /* !SHOPT_DEVFD */
 | 
			
		||||
				if(type&FPIN)
 | 
			
		||||
				{
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
					if(shp->inpipe[2]>20000)
 | 
			
		||||
						sh_coaccept(shp,shp->inpipe,0);
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
					sh_iorenumber(shp,shp->inpipe[0],0);
 | 
			
		||||
					if(!(type&FPOU) || (type&FCOOP))
 | 
			
		||||
						sh_close(shp->inpipe[1]);
 | 
			
		||||
				}
 | 
			
		||||
				if(type&FPOU)
 | 
			
		||||
				{
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
					if(shp->outpipe[2]>20000)
 | 
			
		||||
						sh_coaccept(shp,shp->outpipe,1);
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
					sh_iorenumber(shp,shp->outpipe[1],1);
 | 
			
		||||
					sh_pclose(shp->outpipe);
 | 
			
		||||
				}
 | 
			
		||||
| 
						 | 
				
			
			@ -2025,14 +1781,6 @@ int sh_exec(register const Shnode_t *t, int flags)
 | 
			
		|||
			int 	jmpval, waitall;
 | 
			
		||||
			int 	simple = (t->fork.forktre->tre.tretyp&COMMSK)==TCOM;
 | 
			
		||||
			struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt));
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
			if(shp->inpool)
 | 
			
		||||
			{
 | 
			
		||||
				sh_redirect(shp,t->fork.forkio,0);
 | 
			
		||||
				sh_exec(t->fork.forktre,0);
 | 
			
		||||
				break;
 | 
			
		||||
			}
 | 
			
		||||
#endif /*SHOPT_COSHELL */
 | 
			
		||||
			if(shp->subshell)
 | 
			
		||||
				execflg = 0;
 | 
			
		||||
			sh_pushcontext(shp,buffp,SH_JMPIO);
 | 
			
		||||
| 
						 | 
				
			
			@ -2103,13 +1851,6 @@ int sh_exec(register const Shnode_t *t, int flags)
 | 
			
		|||
		    }
 | 
			
		||||
 | 
			
		||||
		    case TPAR:
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
			if(shp->inpool)
 | 
			
		||||
			{
 | 
			
		||||
				sh_exec(t->par.partre,0);
 | 
			
		||||
				break;
 | 
			
		||||
			}
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
			echeck = 1;
 | 
			
		||||
			flags &= ~OPTIMIZE_FLAG;
 | 
			
		||||
			if(!shp->subshell && !shp->st.trapcom[0] && !shp->st.trap[SH_ERRTRAP] && (flags&sh_state(SH_NOFORK)))
 | 
			
		||||
| 
						 | 
				
			
			@ -2169,28 +1910,7 @@ int sh_exec(register const Shnode_t *t, int flags)
 | 
			
		|||
			int	savejobid = job.curjobid;
 | 
			
		||||
			int	*exitval=0,*saveexitval = job.exitval;
 | 
			
		||||
			pid_t	savepgid = job.curpgid;
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
			int	copipe=0;
 | 
			
		||||
			Shnode_t	*tt;
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
			job.exitval = 0;
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
			if(shp->inpool)
 | 
			
		||||
			{
 | 
			
		||||
				do
 | 
			
		||||
				{
 | 
			
		||||
					sh_exec(t->lst.lstlef, 0);
 | 
			
		||||
					t = t->lst.lstrit;
 | 
			
		||||
					if(flags && (t->tre.tretyp!=TFIL || !(t->lst.lstlef->tre.tretyp&FALTPIPE)))
 | 
			
		||||
						goto coskip1;
 | 
			
		||||
				}
 | 
			
		||||
				while(t->tre.tretyp==TFIL);
 | 
			
		||||
				sh_exec(t,0);
 | 
			
		||||
			coskip1:
 | 
			
		||||
				break;
 | 
			
		||||
			}
 | 
			
		||||
			pvo[2] = pvn[2] = 0;
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
			job.curjobid = 0;
 | 
			
		||||
			if(shp->subshell)
 | 
			
		||||
			{
 | 
			
		||||
| 
						 | 
				
			
			@ -2218,42 +1938,7 @@ int sh_exec(register const Shnode_t *t, int flags)
 | 
			
		|||
			do
 | 
			
		||||
			{
 | 
			
		||||
				/* create the pipe */
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
				tt = t->lst.lstrit;
 | 
			
		||||
				if(shp->coshell && !showme)
 | 
			
		||||
				{
 | 
			
		||||
					if(t->lst.lstlef->tre.tretyp&FALTPIPE)
 | 
			
		||||
					{
 | 
			
		||||
						sh_copipe(shp,pvn,0);
 | 
			
		||||
						type = sh_coexec(shp,t,1+copipe);
 | 
			
		||||
						pvn[1] = -1;
 | 
			
		||||
						pipejob=1;
 | 
			
		||||
						if(type>0)
 | 
			
		||||
						{
 | 
			
		||||
							job_post(shp,type,0);
 | 
			
		||||
							type = 0;
 | 
			
		||||
						}
 | 
			
		||||
						copipe = 1;
 | 
			
		||||
						pvo[0] = pvn[0];
 | 
			
		||||
						while(tt->tre.tretyp==TFIL && tt->lst.lstlef->tre.tretyp&FALTPIPE)
 | 
			
		||||
							tt = tt->lst.lstrit;
 | 
			
		||||
						t = tt;
 | 
			
		||||
						continue;
 | 
			
		||||
					}
 | 
			
		||||
					else if(tt->tre.tretyp==TFIL && tt->lst.lstlef->tre.tretyp&FALTPIPE)
 | 
			
		||||
					{
 | 
			
		||||
						sh_copipe(shp,pvn,0);
 | 
			
		||||
						pvo[2] = pvn[2];
 | 
			
		||||
						copipe = 0;
 | 
			
		||||
						goto coskip2;
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
				sh_pipe(pvn);
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
				pvn[2] = 0;
 | 
			
		||||
			coskip2:
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
				/* execute out part of pipe no wait */
 | 
			
		||||
				(t->lst.lstlef)->tre.tretyp |= showme;
 | 
			
		||||
				type = sh_exec(t->lst.lstlef, errorflg);
 | 
			
		||||
| 
						 | 
				
			
			@ -2337,15 +2022,6 @@ int sh_exec(register const Shnode_t *t, int flags)
 | 
			
		|||
		    }
 | 
			
		||||
 | 
			
		||||
		    case TAND:
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
			if(shp->inpool)
 | 
			
		||||
			{
 | 
			
		||||
			andor:
 | 
			
		||||
				sh_exec(t->lst.lstlef,0);
 | 
			
		||||
				sh_exec(t->lst.lstrit,0);
 | 
			
		||||
				break;
 | 
			
		||||
			}
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
			if(type&TTEST)
 | 
			
		||||
				skipexitset++;
 | 
			
		||||
			if(sh_exec(t->lst.lstlef,OPTIMIZE)==0)
 | 
			
		||||
| 
						 | 
				
			
			@ -2353,10 +2029,6 @@ int sh_exec(register const Shnode_t *t, int flags)
 | 
			
		|||
			break;
 | 
			
		||||
 | 
			
		||||
		    case TORF:
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
			if(shp->inpool)
 | 
			
		||||
				goto andor;
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
			if(type&TTEST)
 | 
			
		||||
				skipexitset++;
 | 
			
		||||
			if(sh_exec(t->lst.lstlef,OPTIMIZE)!=0)
 | 
			
		||||
| 
						 | 
				
			
			@ -2374,9 +2046,6 @@ int sh_exec(register const Shnode_t *t, int flags)
 | 
			
		|||
			char *cp, *trap, *nullptr = 0;
 | 
			
		||||
			int nameref, refresh=1;
 | 
			
		||||
			char *av[5];
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
			int poolfiles;
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
#if SHOPT_OPTIMIZE
 | 
			
		||||
			int  jmpval = ((struct checkpt*)shp->jmplist)->mode;
 | 
			
		||||
			struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt));
 | 
			
		||||
| 
						 | 
				
			
			@ -2464,15 +2133,6 @@ int sh_exec(register const Shnode_t *t, int flags)
 | 
			
		|||
					av[4] = 0;
 | 
			
		||||
					sh_debug(shp,trap,(char*)0,(char*)0,av,0);
 | 
			
		||||
				}
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
				if(shp->inpool)
 | 
			
		||||
				{
 | 
			
		||||
					poolfiles = shp->poolfiles;
 | 
			
		||||
					sh_exec(t->for_.fortre,0);
 | 
			
		||||
					if(poolfiles==shp->poolfiles)
 | 
			
		||||
						break;
 | 
			
		||||
				}
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
				sh_exec(t->for_.fortre,flag);
 | 
			
		||||
				flag &= ~OPTIMIZE_FLAG;
 | 
			
		||||
				if(t->tre.tretyp&COMSCAN)
 | 
			
		||||
| 
						 | 
				
			
			@ -2516,31 +2176,6 @@ int sh_exec(register const Shnode_t *t, int flags)
 | 
			
		|||
			struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt));
 | 
			
		||||
			void *optlist = shp->optlist;
 | 
			
		||||
#endif /* SHOPT_OPTIMIZE */
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
			if(shp->inpool)
 | 
			
		||||
			{
 | 
			
		||||
				int poolfiles;
 | 
			
		||||
#   if SHOPT_FILESCAN
 | 
			
		||||
				if(type==TWH && tt->tre.tretyp==TCOM && !tt->com.comarg && tt->com.comio)
 | 
			
		||||
				{
 | 
			
		||||
					sh_redirect(shp,tt->com.comio,0);
 | 
			
		||||
					break;
 | 
			
		||||
				}
 | 
			
		||||
#   endif /* SHOPT_FILESCAN */
 | 
			
		||||
				sh_exec(tt,0);
 | 
			
		||||
				do
 | 
			
		||||
				{
 | 
			
		||||
					if((sh_exec(tt,0)==0)!=(type==TWH))
 | 
			
		||||
						break;
 | 
			
		||||
					poolfiles = shp->poolfiles;
 | 
			
		||||
					sh_exec(t->wh.dotre,0);
 | 
			
		||||
					if(t->wh.whinc)
 | 
			
		||||
						sh_exec((Shnode_t*)t->wh.whinc,0);
 | 
			
		||||
				}
 | 
			
		||||
				while(poolfiles != shp->poolfiles);
 | 
			
		||||
				break;
 | 
			
		||||
			}
 | 
			
		||||
#endif /*SHOPT_COSHELL */
 | 
			
		||||
#if SHOPT_OPTIMIZE
 | 
			
		||||
			shp->optlist = 0;
 | 
			
		||||
			sh_tclear(t->wh.whtre);
 | 
			
		||||
| 
						 | 
				
			
			@ -2635,15 +2270,6 @@ int sh_exec(register const Shnode_t *t, int flags)
 | 
			
		|||
		    }
 | 
			
		||||
 | 
			
		||||
		    case TIF:
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
			if(shp->inpool)
 | 
			
		||||
			{
 | 
			
		||||
				sh_exec(t->if_.thtre,0);
 | 
			
		||||
				if(t->if_.eltre)
 | 
			
		||||
					sh_exec(t->if_.eltre, 0);
 | 
			
		||||
				break;
 | 
			
		||||
			}
 | 
			
		||||
#endif /*SHOPT_COSHELL */
 | 
			
		||||
			if(sh_exec(t->if_.iftre,OPTIMIZE)==0)
 | 
			
		||||
				sh_exec(t->if_.thtre,flags);
 | 
			
		||||
			else if(t->if_.eltre)
 | 
			
		||||
| 
						 | 
				
			
			@ -2670,13 +2296,6 @@ int sh_exec(register const Shnode_t *t, int flags)
 | 
			
		|||
			while(t)
 | 
			
		||||
			{
 | 
			
		||||
				register struct argnod	*rex=(struct argnod*)t->reg.regptr;
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
				if(shp->inpool)
 | 
			
		||||
				{
 | 
			
		||||
					sh_exec(t->reg.regcom,0);
 | 
			
		||||
					continue;
 | 
			
		||||
				}
 | 
			
		||||
#endif /*SHOPT_COSHELL */
 | 
			
		||||
				while(rex)
 | 
			
		||||
				{
 | 
			
		||||
					register char *s;
 | 
			
		||||
| 
						 | 
				
			
			@ -2718,14 +2337,6 @@ int sh_exec(register const Shnode_t *t, int flags)
 | 
			
		|||
			struct tms before,after;
 | 
			
		||||
			clock_t at, bt, tm[3];
 | 
			
		||||
#endif
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
			if(shp->inpool)
 | 
			
		||||
			{
 | 
			
		||||
				if(t->par.partre)
 | 
			
		||||
					sh_exec(t->par.partre,0);
 | 
			
		||||
				break;
 | 
			
		||||
			}
 | 
			
		||||
#endif /*SHOPT_COSHELL */
 | 
			
		||||
			if(type!=TTIME)
 | 
			
		||||
			{
 | 
			
		||||
				sh_exec(t->par.partre,OPTIMIZE);
 | 
			
		||||
| 
						 | 
				
			
			@ -2807,13 +2418,6 @@ int sh_exec(register const Shnode_t *t, int flags)
 | 
			
		|||
			register char *fname = ((struct functnod*)t)->functnam;
 | 
			
		||||
			register char *cp = strrchr(fname,'.');
 | 
			
		||||
			register Namval_t *npv=0,*mp;
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
			if(shp->inpool)
 | 
			
		||||
			{
 | 
			
		||||
				sh_exec(t->funct.functtre,0);
 | 
			
		||||
				break;
 | 
			
		||||
			}
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
#if SHOPT_NAMESPACE
 | 
			
		||||
			if(t->tre.tretyp==TNSPACE)
 | 
			
		||||
			{
 | 
			
		||||
| 
						 | 
				
			
			@ -2965,10 +2569,6 @@ int sh_exec(register const Shnode_t *t, int flags)
 | 
			
		|||
			register int n;
 | 
			
		||||
			register char *left;
 | 
			
		||||
			int negate = (type&TNEGATE)!=0;
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
			if(shp->inpool)
 | 
			
		||||
				break;
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
			if(type&TTEST)
 | 
			
		||||
				skipexitset++;
 | 
			
		||||
			error_info.line = t->tst.tstline-shp->st.firstline;
 | 
			
		||||
| 
						 | 
				
			
			@ -3075,11 +2675,7 @@ int sh_exec(register const Shnode_t *t, int flags)
 | 
			
		|||
		}
 | 
			
		||||
		if(!skipexitset)
 | 
			
		||||
			exitset();
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
		if(!shp->inpool && !(OPTIMIZE))
 | 
			
		||||
#else
 | 
			
		||||
		if(!(OPTIMIZE))
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
		{
 | 
			
		||||
			if(sav != stkptr(stkp,0))
 | 
			
		||||
				stkset(stkp,sav,0);
 | 
			
		||||
| 
						 | 
				
			
			@ -3952,10 +3548,6 @@ static pid_t sh_ntfork(Shell_t *shp,const Shnode_t *t,char *argv[],int *jobid,in
 | 
			
		|||
			}
 | 
			
		||||
			if(otype&FPOU)
 | 
			
		||||
			{
 | 
			
		||||
#if SHOPT_COSHELL
 | 
			
		||||
					if(shp->outpipe[2] > 20000)
 | 
			
		||||
						sh_coaccept(shp,shp->outpipe,1);
 | 
			
		||||
#endif /* SHOPT_COSHELL */
 | 
			
		||||
				sh_iosave(shp,1,buffp->topfd,(char*)0);
 | 
			
		||||
				sh_iorenumber(shp,sh_dup(shp->outpipe[1]),1);
 | 
			
		||||
				if(fcntl(shp->outpipe[0],F_SETFD,FD_CLOEXEC)>=0)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue