mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Introduce usage of __builtin_unreachable() and noreturn (#248)
This commit adds an UNREACHABLE() macro that expands to either the __builtin_unreachable() compiler builtin (for release builds) or abort(3) (for development builds). This is used to mark code paths that are never to be reached. It also adds the 'noreturn' attribute to functions that never return: path_exec(), sh_done() and sh_syntax(). The UNREACHABLE() macro is not added after calling these. The purpose of these is: * to slightly improve GCC/Clang compiler optimizations; * to fix a few compiler warnings; * to add code clarity. Changes of note: src/cmd/ksh93/sh/io.c: outexcept(): - Avoid using __builtin_unreachable() here since errormsg can return despite using ERROR_system(1), as shp->jmplist->mode is temporarily set to 0. See: https://github.com/att/ast/issues/1336 src/cmd/ksh93/tests/io.sh: - Add a regression test for the ksh2020 bug referenced above. src/lib/libast/features/common: - Detect the existence of either the C11 stdnoreturn.h header or the GCC noreturn attribute, preferring the former when available. - Test for the existence of __builtin_unreachable(). Use it for release builds. On development builds, use abort() instead, which crahses reliably for debugging when unreachable code is reached. Co-authored-by: Martijn Dekker <martijn@inlv.org>
This commit is contained in:
parent
56913f8c2a
commit
c4f980eb29
87 changed files with 1170 additions and 122 deletions
|
@ -256,19 +256,25 @@ int b_alarm(int argc,char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
argc -= opt_info.index;
|
||||
argv += opt_info.index;
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(argc==0)
|
||||
{
|
||||
print_alarms(shp->st.timetrap);
|
||||
return(0);
|
||||
}
|
||||
if(argc!=2)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
np = nv_open(argv[0],shp->var_tree,NV_NOARRAY|NV_VARNAME|NV_NOASSIGN);
|
||||
if(!nv_isnull(np))
|
||||
nv_unset(np);
|
||||
|
|
|
@ -60,7 +60,10 @@ int b_cd(int argc, char *argv[],Shbltin_t *context)
|
|||
static char *oldpwd;
|
||||
Namval_t *opwdnod, *pwdnod;
|
||||
if(sh_isoption(SH_RESTRICTED))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_restricted+4);
|
||||
UNREACHABLE();
|
||||
}
|
||||
while((rval = optget(argv,sh_optcd))) switch(rval)
|
||||
{
|
||||
case 'L':
|
||||
|
@ -74,13 +77,16 @@ int b_cd(int argc, char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
argc -= opt_info.index;
|
||||
dir = argv[0];
|
||||
if(error_info.errors>0 || argc >2)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(oldpwd && oldpwd!=shp->pwd && oldpwd!=e_dot)
|
||||
free(oldpwd);
|
||||
oldpwd = path_pwd(shp,0);
|
||||
|
@ -98,7 +104,10 @@ int b_cd(int argc, char *argv[],Shbltin_t *context)
|
|||
else if(*dir == '-' && dir[1]==0)
|
||||
dir = nv_getval(opwdnod);
|
||||
if(!dir || *dir==0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),argc==2?e_subst+4:e_direct);
|
||||
UNREACHABLE();
|
||||
}
|
||||
/*
|
||||
* If sh_subshell() in subshell.c cannot use fchdir(2) to restore the PWD using a saved file descriptor,
|
||||
* we must fork any virtual subshell now to avoid the possibility of ending up in the wrong PWD on exit.
|
||||
|
@ -193,6 +202,7 @@ int b_cd(int argc, char *argv[],Shbltin_t *context)
|
|||
if(saverrno)
|
||||
errno = saverrno;
|
||||
errormsg(SH_DICT,ERROR_system(1),"%s:",dir);
|
||||
UNREACHABLE();
|
||||
}
|
||||
success:
|
||||
if(dir == nv_getval(opwdnod) || argc==2)
|
||||
|
@ -204,6 +214,7 @@ success:
|
|||
{
|
||||
dir = stakptr(PATH_OFFSET);
|
||||
errormsg(SH_DICT,ERROR_system(1),"%s:",dir);
|
||||
UNREACHABLE();
|
||||
}
|
||||
stakseek(dir-stakptr(0));
|
||||
}
|
||||
|
@ -245,12 +256,18 @@ int b_pwd(int argc, char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(*(cp = path_pwd(shp,0)) != '/')
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1), e_pwd);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(flag)
|
||||
{
|
||||
cp = strcpy(stakseek(strlen(cp)+PATH_MAX),cp);
|
||||
|
|
|
@ -61,7 +61,10 @@ int b_return(register int n, register char *argv[],Shbltin_t *context)
|
|||
}
|
||||
done:
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
pp->mode = (**argv=='e'?SH_JMPEXIT:SH_JMPFUN);
|
||||
argv += opt_info.index;
|
||||
n = (arg = *argv) ? (int)strtol(arg, (char**)0, 10) : shp->savexit;
|
||||
|
@ -98,14 +101,20 @@ int b_break(register int n, register char *argv[],Shbltin_t *context)
|
|||
return(2);
|
||||
}
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
n=1;
|
||||
if(arg= *argv)
|
||||
{
|
||||
n = (int)strtol(arg,&arg,10);
|
||||
if(n<=0 || *arg)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_nolabels,*argv);
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
if(shp->st.loopcnt)
|
||||
{
|
||||
|
|
|
@ -150,6 +150,7 @@ static void put_enum(Namval_t* np,const char *val,int flags,Namfun_t *fp)
|
|||
i++;
|
||||
}
|
||||
error(ERROR_exit(1), "%s: invalid value %s",nv_name(np),val);
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
static char* get_enum(register Namval_t* np, Namfun_t *fp)
|
||||
|
@ -196,8 +197,8 @@ int b_enum(int argc, char** argv, Shbltin_t *context)
|
|||
iflag = 'i';
|
||||
continue;
|
||||
case '?':
|
||||
error(ERROR_USAGE|4, "%s", opt_info.arg);
|
||||
break;
|
||||
error(ERROR_usage(2), "%s", opt_info.arg);
|
||||
UNREACHABLE();
|
||||
case ':':
|
||||
error(2, "%s", opt_info.arg);
|
||||
break;
|
||||
|
@ -213,7 +214,10 @@ int b_enum(int argc, char** argv, Shbltin_t *context)
|
|||
while(cp = *argv++)
|
||||
{
|
||||
if(!(np = nv_open(cp, (void*)0, NV_VARNAME|NV_NOADD)) || !(ap=nv_arrayptr(np)) || ap->fun || (sz=ap->nelem&(((1L<<ARRAY_BITS)-1))) < 2)
|
||||
error(ERROR_exit(1), "%s must name an array containing at least two elements",cp);
|
||||
{
|
||||
error(ERROR_exit(1), "%s must name an array containing at least two elements",cp);
|
||||
UNREACHABLE();
|
||||
}
|
||||
n = staktell();
|
||||
sfprintf(stkstd,"%s.%s%c",NV_CLASS,np->nvname,0);
|
||||
tp = nv_open(stakptr(n), shp->var_tree, NV_VARNAME);
|
||||
|
|
|
@ -84,12 +84,15 @@ int b_getopts(int argc,char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
argc -= opt_info.index;
|
||||
if(error_info.errors || argc<2)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
error_info.context->flags |= ERROR_SILENT;
|
||||
error_info.id = options;
|
||||
options = argv[0];
|
||||
|
@ -126,7 +129,10 @@ int b_getopts(int argc,char *argv[],Shbltin_t *context)
|
|||
{
|
||||
case '?':
|
||||
if(mode==0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
||||
UNREACHABLE();
|
||||
}
|
||||
opt_info.option[1] = '?';
|
||||
/* FALLTHROUGH */
|
||||
case ':':
|
||||
|
@ -160,7 +166,10 @@ int b_getopts(int argc,char *argv[],Shbltin_t *context)
|
|||
optget(com,options);
|
||||
opt_info.index = flag;
|
||||
if(!mode && strchr(options,' '))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
opt_info.arg = 0;
|
||||
options = value;
|
||||
|
|
|
@ -57,7 +57,10 @@ int b_hist(int argc,char *argv[], Shbltin_t *context)
|
|||
Histloc_t location;
|
||||
NOT_USED(argc);
|
||||
if(!sh_histinit((void*)shp))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_histopen);
|
||||
UNREACHABLE();
|
||||
}
|
||||
hp = shp->gd->hist_ptr;
|
||||
while((flag = optget(argv,sh_opthist))) switch(flag)
|
||||
{
|
||||
|
@ -95,10 +98,13 @@ int b_hist(int argc,char *argv[], Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += (opt_info.index-1);
|
||||
#if SHOPT_HISTEXPAND
|
||||
if(pflag)
|
||||
|
@ -147,7 +153,10 @@ int b_hist(int argc,char *argv[], Shbltin_t *context)
|
|||
/* search for last line starting with string */
|
||||
location = hist_find(hp,argv[1],hist_max(hp)-1,0,-1);
|
||||
if((range[++flag] = location.hist_command) < 0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_found,argv[1]);
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv++;
|
||||
}
|
||||
if(flag <0)
|
||||
|
@ -174,9 +183,15 @@ int b_hist(int argc,char *argv[], Shbltin_t *context)
|
|||
range[1] = flag;
|
||||
/* check for valid ranges */
|
||||
if(range[1]<index2 || range[0]>=flag)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_badrange,range[0],range[1]);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(edit && *edit=='-' && range[0]!=range[1])
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_eneedsarg);
|
||||
UNREACHABLE();
|
||||
}
|
||||
/* now list commands from range[flag] to range[1-flag] */
|
||||
incr = 1;
|
||||
flag = rflag>0;
|
||||
|
@ -190,9 +205,15 @@ int b_hist(int argc,char *argv[], Shbltin_t *context)
|
|||
else
|
||||
{
|
||||
if(!(fname=pathtmp(NIL(char*),0,0,NIL(int*))))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_create,"");
|
||||
UNREACHABLE();
|
||||
}
|
||||
if((fdo=open(fname,O_CREAT|O_RDWR,S_IRUSR|S_IWUSR)) < 0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_create,fname);
|
||||
UNREACHABLE();
|
||||
}
|
||||
outfile= sfnew(NIL(Sfio_t*),shp->outbuff,IOBSIZE,fdo,SF_WRITE);
|
||||
arg = "\n";
|
||||
nflag++;
|
||||
|
@ -219,7 +240,10 @@ int b_hist(int argc,char *argv[], Shbltin_t *context)
|
|||
{
|
||||
arg = (char*)e_defedit;
|
||||
if(*arg!='/')
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),"ed not found set FCEDIT");
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
if(*arg != '-')
|
||||
{
|
||||
|
@ -246,7 +270,10 @@ int b_hist(int argc,char *argv[], Shbltin_t *context)
|
|||
Sfio_t *iop = sfnew(NIL(Sfio_t*),buff,IOBSIZE,fdo,SF_READ);
|
||||
/* read in and run the command */
|
||||
if(shp->hist_depth++ > HIST_RECURSE)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_toodeep,"history");
|
||||
UNREACHABLE();
|
||||
}
|
||||
sh_eval(iop,1);
|
||||
shp->hist_depth--;
|
||||
}
|
||||
|
@ -284,7 +311,10 @@ static void hist_subst(const char *command,int fd,char *replace)
|
|||
string[c] = 0;
|
||||
*newp++ = 0;
|
||||
if((sp=sh_substitute(string,replace,newp))==0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_subst,command);
|
||||
UNREACHABLE();
|
||||
}
|
||||
*(newp-1) = '=';
|
||||
sh_eval(sfopen(NIL(Sfio_t*),sp,"s"),1);
|
||||
}
|
||||
|
|
|
@ -113,18 +113,27 @@ int b_exec(int argc,char *argv[], Shbltin_t *context)
|
|||
return(2);
|
||||
}
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(*argv[0]=='r' && argv[opt_info.index]) /* 'redirect' supports no args */
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(2),"%s: %s",e_badsyntax,argv[opt_info.index]);
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
if(!*argv)
|
||||
return(0);
|
||||
|
||||
/* from here on, it's 'exec' with args, so we're replacing the shell */
|
||||
if(sh_isoption(SH_RESTRICTED))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_restricted,argv[0]);
|
||||
UNREACHABLE();
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
register struct argnod *arg=logdata.sh->envlist;
|
||||
register Namval_t* np;
|
||||
register char *cp;
|
||||
|
@ -157,7 +166,6 @@ int b_exec(int argc,char *argv[], Shbltin_t *context)
|
|||
sh_sigreset(2);
|
||||
sh_freeup(logdata.sh);
|
||||
path_exec(logdata.sh,pname,argv,NIL(struct argnod*));
|
||||
sh_done(logdata.sh,0);
|
||||
}
|
||||
return(1);
|
||||
}
|
||||
|
@ -175,11 +183,14 @@ int b_let(int argc,char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
if(error_info.errors || !*argv)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
while(arg= *argv++)
|
||||
r = !sh_arith(shp,arg);
|
||||
return(r);
|
||||
|
@ -200,7 +211,10 @@ int b_eval(int argc,char *argv[], Shbltin_t *context)
|
|||
return(2);
|
||||
}
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
if(*argv && **argv)
|
||||
{
|
||||
|
@ -236,9 +250,15 @@ int b_dot_cmd(register int n,char *argv[],Shbltin_t *context)
|
|||
argv += opt_info.index;
|
||||
script = *argv;
|
||||
if(error_info.errors || !script)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(shp->dot_depth+1 > DOTMAX)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_toodeep,script);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(!(np=shp->posix_fun))
|
||||
{
|
||||
/* check for KornShell style function first */
|
||||
|
@ -254,7 +274,10 @@ int b_dot_cmd(register int n,char *argv[],Shbltin_t *context)
|
|||
np = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_found,script);
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -262,7 +285,10 @@ int b_dot_cmd(register int n,char *argv[],Shbltin_t *context)
|
|||
if(!np)
|
||||
{
|
||||
if((fd=path_open(shp,script,path_get(shp,script))) < 0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_open,script);
|
||||
UNREACHABLE();
|
||||
}
|
||||
filename = path_fullname(shp,stkptr(shp->stk,PATH_OFFSET));
|
||||
}
|
||||
}
|
||||
|
@ -362,11 +388,17 @@ int b_shift(register int n, register char *argv[], Shbltin_t *context)
|
|||
return(2);
|
||||
}
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
n = ((arg= *argv)?(int)sh_arith(shp,arg):1);
|
||||
if(n<0 || shp->st.dolc<n)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_number,arg);
|
||||
UNREACHABLE();
|
||||
}
|
||||
else
|
||||
{
|
||||
shp->st.dolv += n;
|
||||
|
@ -385,10 +417,13 @@ int b_wait(int n,register char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s",opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
job_bwait(argv);
|
||||
return(shp->exitval);
|
||||
|
@ -416,20 +451,26 @@ int b_bg(register int n,register char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s",opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
if(!sh_isstate(SH_MONITOR))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_no_jctl);
|
||||
return(1);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(flag=='d' && *argv==0)
|
||||
argv = (char**)0;
|
||||
if(job_walk(sfstdout,job_switch,flag,argv))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_no_job);
|
||||
UNREACHABLE();
|
||||
}
|
||||
return(shp->exitval);
|
||||
}
|
||||
|
||||
|
@ -453,15 +494,21 @@ int b_jobs(register int n,char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s",opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(*argv==0)
|
||||
argv = (char**)0;
|
||||
if(job_walk(sfstdout,job_list,flag,argv))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_no_job);
|
||||
UNREACHABLE();
|
||||
}
|
||||
job_wait((pid_t)0);
|
||||
return(shp->exitval);
|
||||
}
|
||||
|
@ -527,12 +574,16 @@ int b_times(int argc, char *argv[], Shbltin_t *context)
|
|||
case ':':
|
||||
errormsg(SH_DICT, 2, "%s", opt_info.arg);
|
||||
errormsg(SH_DICT, ERROR_usage(2), "%s", optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
default:
|
||||
errormsg(SH_DICT, ERROR_usage(0), "%s", opt_info.arg);
|
||||
return(2);
|
||||
}
|
||||
if (argv[opt_info.index])
|
||||
{
|
||||
errormsg(SH_DICT, ERROR_exit(2), e_toomanyops);
|
||||
UNREACHABLE();
|
||||
}
|
||||
/* Get & print the times */
|
||||
print_cpu_times();
|
||||
return(0);
|
||||
|
@ -555,21 +606,30 @@ int b_universe(int argc, char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s",opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
argc -= opt_info.index;
|
||||
if(error_info.errors || argc>1)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(arg = argv[0])
|
||||
{
|
||||
if(!astconf("UNIVERSE",0,arg))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1), e_badname,arg);
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!(arg=astconf("UNIVERSE",0,0)))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_nouniverse);
|
||||
UNREACHABLE();
|
||||
}
|
||||
else
|
||||
sfputr(sfstdout,arg,'\n');
|
||||
}
|
||||
|
|
|
@ -421,13 +421,16 @@ int b_mkservice(int argc, char** argv, Shbltin_t *context)
|
|||
continue;
|
||||
case '?':
|
||||
error(ERROR_usage(2), opt_info.arg);
|
||||
continue;
|
||||
UNREACHABLE();
|
||||
}
|
||||
break;
|
||||
}
|
||||
argv += opt_info.index;
|
||||
if (error_info.errors || !(var = *argv++) || !(path = *argv++) || *argv)
|
||||
{
|
||||
error(ERROR_usage(2), optusage(NiL));
|
||||
UNREACHABLE();
|
||||
}
|
||||
sp = sh_newof(0, Service_t, 1, 0);
|
||||
sp->acceptf = Accept;
|
||||
sp->actionf = Action;
|
||||
|
@ -440,6 +443,7 @@ int b_mkservice(int argc, char** argv, Shbltin_t *context)
|
|||
{
|
||||
free((void*)sp);
|
||||
error(ERROR_exit(1), "%s: cannot start service", path);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if((sp->fd = fcntl(fd, F_DUPFD, 10))>=10)
|
||||
close(fd);
|
||||
|
@ -472,13 +476,16 @@ int b_eloop(int argc, char** argv, Shbltin_t *context)
|
|||
continue;
|
||||
case '?':
|
||||
error(ERROR_usage(2), opt_info.arg);
|
||||
continue;
|
||||
UNREACHABLE();
|
||||
}
|
||||
break;
|
||||
}
|
||||
argv += opt_info.index;
|
||||
if (error_info.errors || *argv)
|
||||
{
|
||||
error(ERROR_usage(2), optusage(NiL));
|
||||
UNREACHABLE();
|
||||
}
|
||||
while(1)
|
||||
{
|
||||
if(waitnotify(-1, timeout, 0)==0)
|
||||
|
|
|
@ -214,7 +214,10 @@ int b_print(int argc, char *argv[], Shbltin_t *context)
|
|||
case 's':
|
||||
/* print to history file */
|
||||
if(!sh_histinit((void*)shp))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_history);
|
||||
UNREACHABLE();
|
||||
}
|
||||
fd = sffileno(shp->gd->hist_ptr->histfp);
|
||||
sh_onstate(SH_HISTORY);
|
||||
sflag++;
|
||||
|
@ -266,13 +269,19 @@ int b_print(int argc, char *argv[], Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
if(error_info.errors || (argc<0 && !(format = *argv++)))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(vflag && format)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"-%c and -f are mutually exclusive",vflag);
|
||||
UNREACHABLE();
|
||||
}
|
||||
skip:
|
||||
if(format)
|
||||
format = genformat(format);
|
||||
|
@ -293,6 +302,7 @@ skip2:
|
|||
if(fd==1)
|
||||
return(1);
|
||||
errormsg(SH_DICT,ERROR_system(1),msg);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(!(outfile=shp->sftable[fd]))
|
||||
{
|
||||
|
@ -545,7 +555,10 @@ static ssize_t fmtbase64(Sfio_t *iop, char *string, int alt)
|
|||
if(!np || nv_isnull(np))
|
||||
{
|
||||
if(sh_isoption(SH_NOUNSET))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_notset,string);
|
||||
UNREACHABLE();
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
if(nv_isattr(np,NV_INTEGER))
|
||||
|
@ -755,7 +768,10 @@ static int extend(Sfio_t* sp, void* v, Sffmt_t* fe)
|
|||
break;
|
||||
default:
|
||||
if(!strchr("DdXxoUu",format))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_formspec,format);
|
||||
UNREACHABLE();
|
||||
}
|
||||
fe->fmt = 'd';
|
||||
value->ll = 0;
|
||||
break;
|
||||
|
@ -934,7 +950,7 @@ static int extend(Sfio_t* sp, void* v, Sffmt_t* fe)
|
|||
fe->fmt = 'd';
|
||||
fe->size = sizeof(value->ll);
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_formspec,format);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
if (format == '.')
|
||||
value->i = value->ll;
|
||||
|
@ -980,13 +996,19 @@ static int extend(Sfio_t* sp, void* v, Sffmt_t* fe)
|
|||
case 'P':
|
||||
s = fmtmatch(value->s);
|
||||
if(!s || *s==0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_badregexp,value->s);
|
||||
UNREACHABLE();
|
||||
}
|
||||
value->s = s;
|
||||
break;
|
||||
case 'R':
|
||||
s = fmtre(value->s);
|
||||
if(!s || *s==0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_badregexp,value->s);
|
||||
UNREACHABLE();
|
||||
}
|
||||
value->s = s;
|
||||
break;
|
||||
case 'Q':
|
||||
|
|
|
@ -109,7 +109,10 @@ int b_read(int argc,char *argv[], Shbltin_t *context)
|
|||
break;
|
||||
case 'p':
|
||||
if((fd = shp->cpipe[0])<=0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_query);
|
||||
UNREACHABLE();
|
||||
}
|
||||
break;
|
||||
case 'n': case 'N':
|
||||
flags &= ((1<<D_FLAG)-1);
|
||||
|
@ -129,7 +132,10 @@ int b_read(int argc,char *argv[], Shbltin_t *context)
|
|||
case 'u':
|
||||
fd = (int)opt_info.num;
|
||||
if(opt_info.num<0 || opt_info.num>INT_MAX || (fd>=shp->gd->lim.open_max && !sh_iovalidfd(shp,fd)))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_file,opt_info.arg); /* reject invalid file descriptors */
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(sh_inuse(shp,fd))
|
||||
fd = -1;
|
||||
break;
|
||||
|
@ -141,15 +147,21 @@ int b_read(int argc,char *argv[], Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(!((r=shp->fdstatus[fd])&IOREAD) || !(r&(IOSEEK|IONOSEEK)))
|
||||
r = sh_iocheckfd(shp,fd);
|
||||
if(fd<0 || !(r&IOREAD))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_file+4);
|
||||
UNREACHABLE();
|
||||
}
|
||||
/* look for prompt */
|
||||
if((name = *argv) && (name=strchr(name,'?')) && (r&IOTTY))
|
||||
r = strlen(name++);
|
||||
|
@ -485,7 +497,10 @@ int sh_readline(register Shell_t *shp,char **names, volatile int fd, int flags,s
|
|||
{
|
||||
c = sfvalue(iop)+1;
|
||||
if(!sferror(iop) && sfgetc(iop) >=0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_overlimit,"line length");
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
if(timeslot)
|
||||
timerdel(timeslot);
|
||||
|
|
|
@ -270,7 +270,7 @@ int b___regress__(int argc, char** argv, Shbltin_t *context)
|
|||
{
|
||||
case '?':
|
||||
errormsg(SH_DICT, ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
case ':':
|
||||
errormsg(SH_DICT, 2, "%s", opt_info.arg);
|
||||
break;
|
||||
|
@ -332,7 +332,10 @@ int b___regress__(int argc, char** argv, Shbltin_t *context)
|
|||
break;
|
||||
}
|
||||
if (error_info.errors || *(argv + opt_info.index))
|
||||
{
|
||||
errormsg(SH_DICT, ERROR_usage(2), "%s", optusage(NiL));
|
||||
UNREACHABLE();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -60,10 +60,13 @@ int b_sleep(register int argc,char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT, ERROR_usage(2), "%s", optusage(NULL));
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
if(cp = *argv)
|
||||
{
|
||||
|
@ -93,16 +96,25 @@ int b_sleep(register int argc,char *argv[],Shbltin_t *context)
|
|||
ns = tmxdate(pp, &last, now);
|
||||
}
|
||||
if(*last)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_number,*argv);
|
||||
UNREACHABLE();
|
||||
}
|
||||
d = ns - now;
|
||||
d /= TMX_RESOLUTION;
|
||||
}
|
||||
skip:
|
||||
if(argv[1])
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_oneoperand);
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
else if(!sflag)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_oneoperand);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(d > .10)
|
||||
{
|
||||
time(&tloc);
|
||||
|
|
|
@ -141,7 +141,10 @@ int b_test(int argc, char *argv[],Shbltin_t *context)
|
|||
{
|
||||
cp = argv[--argc];
|
||||
if(!c_eq(cp, ']'))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(2),e_missing,"']'");
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
if(argc <= 1)
|
||||
{
|
||||
|
@ -192,6 +195,7 @@ int b_test(int argc, char *argv[],Shbltin_t *context)
|
|||
goto done;
|
||||
}
|
||||
errormsg(SH_DICT,ERROR_exit(2),e_badop,cp);
|
||||
UNREACHABLE();
|
||||
}
|
||||
exitval = (test_binop(tdata.sh,op,argv[1],argv[3])^(argc!=5));
|
||||
goto done;
|
||||
|
@ -218,7 +222,7 @@ int b_test(int argc, char *argv[],Shbltin_t *context)
|
|||
av[2] = 0;
|
||||
optget(av,sh_opttest);
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s",opt_info.arg);
|
||||
return(2);
|
||||
UNREACHABLE();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -276,6 +280,7 @@ static int expr(struct test *tp,register int flag)
|
|||
if(flag==0)
|
||||
break;
|
||||
errormsg(SH_DICT,ERROR_exit(2),e_badsyntax);
|
||||
UNREACHABLE();
|
||||
}
|
||||
return(r);
|
||||
}
|
||||
|
@ -290,6 +295,7 @@ static char *nxtarg(struct test *tp,int mt)
|
|||
return(0);
|
||||
}
|
||||
errormsg(SH_DICT,ERROR_exit(2),e_argument);
|
||||
UNREACHABLE();
|
||||
}
|
||||
return(tp->av[tp->ap++]);
|
||||
}
|
||||
|
@ -308,7 +314,10 @@ static int e3(struct test *tp)
|
|||
op = expr(tp,1);
|
||||
cp = nxtarg(tp,0);
|
||||
if(!cp || !c_eq(cp, ')'))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(2),e_missing,"')'");
|
||||
UNREACHABLE();
|
||||
}
|
||||
return(op);
|
||||
}
|
||||
cp = nxtarg(tp,1);
|
||||
|
@ -340,6 +349,7 @@ static int e3(struct test *tp)
|
|||
if(op==0 || !strchr(test_opchars+10,op))
|
||||
return(1);
|
||||
errormsg(SH_DICT,ERROR_exit(2),e_argument);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(strchr(test_opchars,op))
|
||||
return(test_unop(tp->sh,op,cp));
|
||||
|
@ -354,7 +364,10 @@ skip:
|
|||
if(!(op&TEST_BINOP))
|
||||
cp = nxtarg(tp,0);
|
||||
if(!op)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(2),e_badop,binop);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(op==TEST_AND || op==TEST_OR)
|
||||
tp->ap--;
|
||||
return(test_binop(tp->sh,op,arg,cp));
|
||||
|
@ -491,8 +504,7 @@ int test_unop(Shell_t *shp,register int op,register const char *arg)
|
|||
static char a[3] = "-?";
|
||||
a[1]= op;
|
||||
errormsg(SH_DICT,ERROR_exit(2),e_badop,a);
|
||||
/* NOTREACHED */
|
||||
return(0);
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -553,8 +565,7 @@ int test_binop(Shell_t *shp,register int op,const char *left,const char *right)
|
|||
errormsg(SH_DICT, ERROR_exit(2), op==TEST_END ? e_badop : e_unsupported_op, shtab_testops[i].sh_name);
|
||||
}
|
||||
}
|
||||
/* NOTREACHED */
|
||||
return(0);
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -60,11 +60,13 @@ int b_trap(int argc,char *argv[],Shbltin_t *context)
|
|||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(0), "%s", opt_info.arg);
|
||||
return(2);
|
||||
break;
|
||||
}
|
||||
argv += opt_info.index;
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s", optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(arg = *argv)
|
||||
{
|
||||
char *action = arg;
|
||||
|
@ -91,7 +93,10 @@ int b_trap(int argc,char *argv[],Shbltin_t *context)
|
|||
}
|
||||
}
|
||||
if(!argv[0])
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_condition);
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
while(arg = *argv++)
|
||||
{
|
||||
|
@ -217,14 +222,17 @@ int b_kill(int argc,char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
endopts:
|
||||
argv += opt_info.index;
|
||||
if(*argv && strcmp(*argv,"--")==0 && strcmp(*(argv-1),"--")!=0)
|
||||
argv++;
|
||||
if(error_info.errors || flag==(L_FLAG|S_FLAG) || (!(*argv) && !(flag&L_FLAG)))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s", optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
/* just in case we send a kill -9 $$ */
|
||||
sfsync(sfstderr);
|
||||
if(flag&L_FLAG)
|
||||
|
@ -241,6 +249,7 @@ endopts:
|
|||
{
|
||||
shp->exitval = 2;
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_nosignal,signame);
|
||||
UNREACHABLE();
|
||||
}
|
||||
sfprintf(sfstdout,"%d\n",sig);
|
||||
}
|
||||
|
@ -250,7 +259,10 @@ endopts:
|
|||
if(flag&S_FLAG)
|
||||
{
|
||||
if((sig=sig_number(shp,signame)) < 0 || sig > shp->gd->sigmax)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_nosignal,signame);
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
if(job_walk(sfstdout,job_kill,sig,argv))
|
||||
shp->exitval = 1;
|
||||
|
@ -273,16 +285,28 @@ int b_suspend(int argc,char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(error_info.errors) /* no options supported (except AST --man, etc.) */
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s", optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(argv[opt_info.index]) /* no operands supported */
|
||||
{
|
||||
errormsg(SH_DICT, ERROR_exit(2), e_toomanyops);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(sh_isoption(SH_LOGIN_SHELL))
|
||||
{
|
||||
errormsg(SH_DICT, ERROR_exit(1), "cannot suspend a login shell");
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(kill(context->shp->gd->pid, SIGSTOP) != 0)
|
||||
{
|
||||
errormsg(SH_DICT, ERROR_exit(1), "could not signal main shell at PID %d", context->shp->gd->pid);
|
||||
UNREACHABLE();
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
#endif /* defined(JOBS) && defined(SIGSTOP) */
|
||||
|
|
|
@ -107,7 +107,10 @@ int b_readonly(int argc,char *argv[],Shbltin_t *context)
|
|||
return(2);
|
||||
}
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),optusage(NIL(char*)));
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += (opt_info.index-1);
|
||||
if(*command=='r')
|
||||
flag = (NV_ASSIGN|NV_RDONLY|NV_VARNAME);
|
||||
|
@ -166,7 +169,10 @@ int b_alias(int argc,register char *argv[],Shbltin_t *context)
|
|||
return(2);
|
||||
}
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage(NIL(char*)));
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += (opt_info.index-1);
|
||||
}
|
||||
/* 'alias -t', 'hash' */
|
||||
|
@ -222,7 +228,10 @@ int b_typeset(int argc,register char *argv[],Shbltin_t *context)
|
|||
else if(argv[0][0] == 'n') /* <n>ameref == typeset -n */
|
||||
new_argv[1] = "-n";
|
||||
else
|
||||
{
|
||||
errormsg(SH_DICT, ERROR_exit(128), "internal error");
|
||||
UNREACHABLE();
|
||||
}
|
||||
for (n = 1; n <= argc; n++)
|
||||
new_argv[n + 1] = argv[n];
|
||||
argc++;
|
||||
|
@ -305,7 +314,10 @@ int b_typeset(int argc,register char *argv[],Shbltin_t *context)
|
|||
if(tdata.argnum==0)
|
||||
tdata.argnum = (int)opt_info.num;
|
||||
if(tdata.argnum < 0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1), e_badfield, tdata.argnum);
|
||||
UNREACHABLE();
|
||||
}
|
||||
isadjust = 1;
|
||||
if(n=='Z')
|
||||
flag |= NV_ZFILL;
|
||||
|
@ -317,7 +329,10 @@ int b_typeset(int argc,register char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case 'M':
|
||||
if((tdata.wctname = opt_info.arg) && !nv_mapchar((Namval_t*)0,tdata.wctname))
|
||||
{
|
||||
errormsg(SH_DICT, ERROR_exit(1),e_unknownmap, tdata.wctname);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(tdata.wctname && strcmp(tdata.wctname,e_tolower)==0)
|
||||
flag |= NV_UTOL;
|
||||
else
|
||||
|
@ -452,9 +467,15 @@ endargs:
|
|||
flag |= NV_STATICF;
|
||||
}
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s", optusage(NIL(char*)));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(sizeof(char*)<8 && tdata.argnum > SHRT_MAX)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(2),"option argument cannot be greater than %d",SHRT_MAX);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(isfloat)
|
||||
flag |= NV_DOUBLE;
|
||||
if(sflag)
|
||||
|
@ -496,7 +517,10 @@ endargs:
|
|||
#endif /* SHOPT_NAMESPACE */
|
||||
stkseek(stkp,offset);
|
||||
if(!tdata.tp)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),"%s: unknown type",tdata.prefix);
|
||||
UNREACHABLE();
|
||||
}
|
||||
else if(nv_isnull(tdata.tp))
|
||||
nv_newtype(tdata.tp);
|
||||
tdata.tp->nvenv = tdata.help;
|
||||
|
@ -512,7 +536,10 @@ endargs:
|
|||
if(!tdata.sh->mktype)
|
||||
tdata.help = 0;
|
||||
if(tdata.aflag=='+' && (flag&(NV_ARRAY|NV_IARRAY|NV_COMVAR)) && argv[1])
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_nounattr);
|
||||
UNREACHABLE();
|
||||
}
|
||||
return(setall(argv,flag,troot,&tdata));
|
||||
}
|
||||
|
||||
|
@ -632,7 +659,10 @@ static int setall(char **argv,register int flag,Dt_t *troot,struct tdata *tp
|
|||
{
|
||||
/* Function names cannot be special builtin */
|
||||
if((np=nv_search(name,shp->bltin_tree,0)) && nv_isattr(np,BLT_SPC))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_badfun,name);
|
||||
UNREACHABLE();
|
||||
}
|
||||
#if SHOPT_NAMESPACE
|
||||
if(shp->namespace)
|
||||
np = sh_fsearch(shp,name,NV_ADD|HASH_NOSCOPE);
|
||||
|
@ -705,7 +735,10 @@ static int setall(char **argv,register int flag,Dt_t *troot,struct tdata *tp
|
|||
if(nv_isnull(np) && !nv_isarray(np) && nv_isattr(np,NV_NOFREE))
|
||||
nv_offattr(np,NV_NOFREE);
|
||||
else if(tp->tp && !nv_isattr(np,NV_MINIMAL|NV_EXPORT) && (mp=(Namval_t*)np->nvenv) && (ap=nv_arrayptr(mp)) && (ap->nelem&ARRAY_TREE))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_typecompat,nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
else if((ap=nv_arrayptr(np)) && nv_aindex(np)>0 && ap->nelem==1 && nv_getval(np)==Empty)
|
||||
{
|
||||
ap->nelem++;
|
||||
|
@ -713,7 +746,10 @@ static int setall(char **argv,register int flag,Dt_t *troot,struct tdata *tp
|
|||
ap->nelem--;
|
||||
}
|
||||
else if(iarray && ap && ap->fun)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),"cannot change associative array %s to indexed array",nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
else if( (iarray||(flag&NV_ARRAY)) && nv_isvtree(np) && !nv_type(np))
|
||||
_nv_unset(np,NV_EXPORT);
|
||||
if(tp->pflag)
|
||||
|
@ -804,7 +840,10 @@ static int setall(char **argv,register int flag,Dt_t *troot,struct tdata *tp
|
|||
Namfun_t *fp;
|
||||
char *cp;
|
||||
if(!tp->wctname)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_mapchararg,nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
cp = (char*)nv_mapchar(np,0);
|
||||
if(fp=nv_mapchar(np,tp->wctname))
|
||||
{
|
||||
|
@ -828,7 +867,10 @@ static int setall(char **argv,register int flag,Dt_t *troot,struct tdata *tp
|
|||
if (tp->aflag == '-')
|
||||
{
|
||||
if((flag&NV_EXPORT) && (strchr(name,'.') || nv_isvtree(np)))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_badexport,name);
|
||||
UNREACHABLE();
|
||||
}
|
||||
#if SHOPT_BSH
|
||||
if(flag&NV_EXPORT)
|
||||
nv_offattr(np,NV_IMPORT);
|
||||
|
@ -849,7 +891,10 @@ static int setall(char **argv,register int flag,Dt_t *troot,struct tdata *tp
|
|||
else
|
||||
{
|
||||
if((flag&NV_RDONLY) && (curflag&NV_RDONLY))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_readonly,nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
newflag = curflag & ~flag;
|
||||
}
|
||||
if (tp->aflag && (tp->argnum || (curflag!=newflag)))
|
||||
|
@ -1071,18 +1116,27 @@ int b_builtin(int argc,char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s", optusage(NIL(char*)));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(arg || *argv)
|
||||
{
|
||||
if(sh_isoption(SH_RESTRICTED))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_restricted,argv[-opt_info.index]);
|
||||
UNREACHABLE();
|
||||
}
|
||||
#if SHOPT_PFSH
|
||||
if(sh_isoption(SH_PFSH))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_pfsh,argv[-opt_info.index]);
|
||||
UNREACHABLE();
|
||||
}
|
||||
#endif
|
||||
if(tdata.sh->subshell && !tdata.sh->subshare)
|
||||
sh_subfork();
|
||||
|
@ -1244,7 +1298,10 @@ static int unall(int argc, char **argv, register Dt_t *troot, Shell_t* shp)
|
|||
}
|
||||
argv += opt_info.index;
|
||||
if(error_info.errors || (*argv==0 &&!all))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage(NIL(char*)));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(!troot)
|
||||
return(1);
|
||||
r = 0;
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
NOT_USED(argv);
|
||||
NOT_USED(context);
|
||||
errormsg(SH_DICT,ERROR_exit(2),e_nosupport);
|
||||
return(0);
|
||||
UNREACHABLE();
|
||||
}
|
||||
#else
|
||||
|
||||
|
@ -106,7 +106,7 @@ int b_ulimit(int argc,char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
opt_info.disc = 0;
|
||||
/* default to -f */
|
||||
|
@ -121,7 +121,10 @@ int b_ulimit(int argc,char *argv[],Shbltin_t *context)
|
|||
/* only one option at a time for setting */
|
||||
label = (hit&(hit-1));
|
||||
if(error_info.errors || (limit && label) || argc>opt_info.index+1)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(mode==0)
|
||||
mode = (HARD|SOFT);
|
||||
for(tp = shtab_limits; tp->option && hit; tp++,hit>>=1)
|
||||
|
@ -145,26 +148,41 @@ int b_ulimit(int argc,char *argv[],Shbltin_t *context)
|
|||
else if((i=strton(limit,&last,NiL,0))==INFINITY || *last)
|
||||
{
|
||||
if((i=sh_strnum(limit,&last,2))==INFINITY || *last)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_number,limit);
|
||||
UNREACHABLE();
|
||||
}
|
||||
i *= unit;
|
||||
}
|
||||
}
|
||||
if(nosupport)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_readonly,tp->name);
|
||||
UNREACHABLE();
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef _lib_getrlimit
|
||||
if(getrlimit(n,&rlp) <0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_number,limit);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(mode&HARD)
|
||||
rlp.rlim_max = i;
|
||||
if(mode&SOFT)
|
||||
rlp.rlim_cur = i;
|
||||
if(setrlimit(n,&rlp) <0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_overlimit,limit);
|
||||
UNREACHABLE();
|
||||
}
|
||||
#else
|
||||
if((i=vlimit(n,i)) < 0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_number,limit);
|
||||
UNREACHABLE();
|
||||
}
|
||||
#endif /* _lib_getrlimit */
|
||||
}
|
||||
}
|
||||
|
@ -174,7 +192,10 @@ int b_ulimit(int argc,char *argv[],Shbltin_t *context)
|
|||
{
|
||||
#ifdef _lib_getrlimit
|
||||
if(getrlimit(n,&rlp) <0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_number,limit);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(mode&HARD)
|
||||
i = rlp.rlim_max;
|
||||
if(mode&SOFT)
|
||||
|
@ -185,7 +206,10 @@ int b_ulimit(int argc,char *argv[],Shbltin_t *context)
|
|||
# endif /* _lib_ulimit */
|
||||
i = -1;
|
||||
if((i=vlimit(n,i)) < 0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_number,limit);
|
||||
UNREACHABLE();
|
||||
}
|
||||
#endif /* _lib_getrlimit */
|
||||
}
|
||||
if(label)
|
||||
|
|
|
@ -53,10 +53,13 @@ int b_umask(int argc,char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s",opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
if(mask = *argv)
|
||||
{
|
||||
|
@ -68,7 +71,10 @@ int b_umask(int argc,char *argv[],Shbltin_t *context)
|
|||
if (c>='0' && c<='7')
|
||||
flag = (flag<<3) + (c-'0');
|
||||
else
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_number,*argv);
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -80,6 +86,7 @@ int b_umask(int argc,char *argv[],Shbltin_t *context)
|
|||
{
|
||||
umask(flag);
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_format,mask);
|
||||
UNREACHABLE();
|
||||
}
|
||||
flag = (~c&0777);
|
||||
}
|
||||
|
|
|
@ -58,7 +58,10 @@ int b_command(register int argc,char *argv[],Shbltin_t *context)
|
|||
{
|
||||
case 'p':
|
||||
if(sh_isoption(SH_RESTRICTED))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_restricted,"-p");
|
||||
UNREACHABLE();
|
||||
}
|
||||
sh_onstate(SH_DEFPATH);
|
||||
break;
|
||||
case 'v':
|
||||
|
@ -79,7 +82,7 @@ int b_command(register int argc,char *argv[],Shbltin_t *context)
|
|||
if(argc==0)
|
||||
return(0);
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(argc==0)
|
||||
{
|
||||
|
@ -91,7 +94,10 @@ int b_command(register int argc,char *argv[],Shbltin_t *context)
|
|||
}
|
||||
argv += opt_info.index;
|
||||
if(error_info.errors || !*argv)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s", optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
return(whence(shp,argv, flags));
|
||||
}
|
||||
|
||||
|
@ -128,11 +134,14 @@ int b_whence(int argc,char *argv[],Shbltin_t *context)
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv += opt_info.index;
|
||||
if(error_info.errors || !*argv)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
return(whence(shp, argv, flags));
|
||||
}
|
||||
|
||||
|
|
|
@ -1060,7 +1060,6 @@ static int cntlmode(Vi_t *vp)
|
|||
refresh(vp,CONTROL);
|
||||
vp->repeat = 1;
|
||||
}
|
||||
/* NOTREACHED */
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
|
|
@ -108,8 +108,8 @@ struct checkpt
|
|||
)
|
||||
#define sh_popcontext(shp,bp) (shp->jmplist=(bp)->prev, errorpop(&((bp)->err)))
|
||||
|
||||
extern noreturn void sh_done(void*,int);
|
||||
extern void sh_fault(int);
|
||||
extern void sh_done(void*,int);
|
||||
extern void sh_sigclear(int);
|
||||
extern void sh_sigdone(void);
|
||||
extern void sh_siginit(void*);
|
||||
|
|
|
@ -82,7 +82,7 @@ extern Pathcomp_t *path_absolute(Shell_t*, const char*, Pathcomp_t*, int);
|
|||
extern char *path_basename(const char*);
|
||||
extern char *path_fullname(Shell_t*,const char*);
|
||||
extern int path_expand(Shell_t*,const char*, struct argnod**);
|
||||
extern void path_exec(Shell_t*,const char*,char*[],struct argnod*);
|
||||
extern noreturn void path_exec(Shell_t*,const char*,char*[],struct argnod*);
|
||||
extern pid_t path_spawn(Shell_t*,const char*,char*[],char*[],Pathcomp_t*,int);
|
||||
#if defined(__EXPORT__) && defined(_BLD_DLL) && defined(_BLD_shell)
|
||||
# define extern __EXPORT__
|
||||
|
|
|
@ -149,7 +149,7 @@ extern int sh_lex(Lex_t*);
|
|||
extern Shnode_t *sh_dolparen(Lex_t*);
|
||||
extern Lex_t *sh_lexopen(Lex_t*, Shell_t*, int);
|
||||
extern void sh_lexskip(Lex_t*,int,int,int);
|
||||
extern void sh_syntax(Lex_t*);
|
||||
extern noreturn void sh_syntax(Lex_t*);
|
||||
#if SHOPT_KIA
|
||||
extern int kiaclose(Lex_t *);
|
||||
extern unsigned long kiaentity(Lex_t*, const char*,int,int,int,int,unsigned long,int,int,const char*);
|
||||
|
|
|
@ -171,7 +171,10 @@ int sh_argopts(int argc,register char *argv[], void *context)
|
|||
}
|
||||
o &= 0xff;
|
||||
if(sh_isoption(SH_RESTRICTED) && !f && o==SH_RESTRICTED)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1), e_restricted, opt_info.arg);
|
||||
UNREACHABLE();
|
||||
}
|
||||
break;
|
||||
case -5: /* --posix must be handled explicitly to stop AST optget(3) overriding it */
|
||||
if(opt_info.num)
|
||||
|
@ -270,7 +273,10 @@ int sh_argopts(int argc,register char *argv[], void *context)
|
|||
else
|
||||
{
|
||||
if ((o == SH_RESTRICTED) && sh_isoption(SH_RESTRICTED))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_restricted,"r"); /* set -r cannot be unset */
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(o==SH_POSIX && !defaultflag)
|
||||
{
|
||||
#if SHOPT_BRACEPAT
|
||||
|
@ -286,7 +292,10 @@ int sh_argopts(int argc,register char *argv[], void *context)
|
|||
}
|
||||
}
|
||||
if(error_info.errors)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage(NIL(char*)));
|
||||
UNREACHABLE();
|
||||
}
|
||||
/* check for '-' or '+' argument */
|
||||
if((cp=argv[opt_info.index]) && cp[1]==0 && (*cp=='+' || *cp=='-') &&
|
||||
strcmp(argv[opt_info.index-1],"--"))
|
||||
|
@ -325,6 +334,7 @@ int sh_argopts(int argc,register char *argv[], void *context)
|
|||
{
|
||||
errormsg(SH_DICT,2,e_cneedsarg);
|
||||
errormsg(SH_DICT,ERROR_usage(2),optusage(NIL(char*)));
|
||||
UNREACHABLE();
|
||||
}
|
||||
argc--;
|
||||
}
|
||||
|
@ -334,11 +344,20 @@ int sh_argopts(int argc,register char *argv[], void *context)
|
|||
if(ap->kiafile)
|
||||
{
|
||||
if(!argv[0])
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"-R requires scriptname");
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(!(lp->kiafile=sfopen(NIL(Sfio_t*),ap->kiafile,"w+")))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(3),e_create,ap->kiafile);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(!(lp->kiatmp=sftmp(2*SF_BUFSIZE)))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(3),e_tmpcreate);
|
||||
UNREACHABLE();
|
||||
}
|
||||
sfputr(lp->kiafile,";vdb;CIAO/ksh",'\n');
|
||||
lp->kiabegin = sftell(lp->kiafile);
|
||||
lp->entity_tree = dtopen(&_Nvdisc,Dtbag);
|
||||
|
@ -735,7 +754,10 @@ struct argnod *sh_argprocsub(Shell_t *shp,struct argnod *argp)
|
|||
break;
|
||||
}
|
||||
if(!shp->fifo)
|
||||
{
|
||||
errormsg(SH_DICT, ERROR_SYSTEM|ERROR_PANIC, "process substitution: FIFO creation failed");
|
||||
UNREACHABLE();
|
||||
}
|
||||
chmod(shp->fifo,S_IRUSR|S_IWUSR); /* mkfifo + chmod works regardless of umask */
|
||||
sfputr(shp->stk,shp->fifo,0);
|
||||
#endif /* SHOPT_DEVFD */
|
||||
|
|
|
@ -421,7 +421,10 @@ static Sfdouble_t arith(const char **ptr, struct lval *lvalue, int type, Sfdoubl
|
|||
else
|
||||
c = *str;
|
||||
if(c=='.' && radix!='.')
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),"%s: radix point '.' requires LC_NUMERIC=C",val);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(c==radix || c=='e' || c == 'E' || lastbase == 16 && (c == 'p' || c == 'P'))
|
||||
{
|
||||
lvalue->isfloat=1;
|
||||
|
@ -542,7 +545,10 @@ Sfdouble_t sh_strnum(register const char *str, char** ptr, int mode)
|
|||
if(!last || *last!='.' || last[1]!='.')
|
||||
d = strval(shp,str,&last,arith,mode);
|
||||
if(!ptr && *last && mode>0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_lexbadchar,*last,str);
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
} else if (!d && *str=='-') {
|
||||
d = -0.0;
|
||||
|
@ -564,6 +570,9 @@ void *sh_arithcomp(Shell_t *shp,register char *str)
|
|||
Arith_t *ep;
|
||||
ep = arith_compile(shp,str,(char**)&ptr,arith,ARITH_COMP|1);
|
||||
if(*ptr)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_lexbadchar,*ptr,str);
|
||||
UNREACHABLE();
|
||||
}
|
||||
return((void*)ep);
|
||||
}
|
||||
|
|
|
@ -229,7 +229,10 @@ static union Value *array_getup(Namval_t *np, Namarr_t *arp, int update)
|
|||
else
|
||||
{
|
||||
if(ap->cur >= ap->maxi)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_subscript,nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
up = &(ap->val[ap->cur]);
|
||||
nofree = array_isbit(ap->bits,ap->cur,ARRAY_NOFREE);
|
||||
}
|
||||
|
@ -367,7 +370,10 @@ static Namval_t *array_find(Namval_t *np,Namarr_t *arp, int flag)
|
|||
if(!(ap->header.nelem&ARRAY_SCAN) && ap->cur >= ap->maxi)
|
||||
ap = array_grow(np, ap, (int)ap->cur);
|
||||
if(ap->cur>=ap->maxi)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_subscript,nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
up = &(ap->val[ap->cur]);
|
||||
if((!up->cp||up->cp==Empty) && nv_type(np) && nv_isvtree(np))
|
||||
{
|
||||
|
@ -810,7 +816,10 @@ static struct index_array *array_grow(Namval_t *np, register struct index_array
|
|||
register int i;
|
||||
register int newsize = arsize(arp,maxi+1);
|
||||
if (maxi >= ARRAY_MAX)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_subscript, fmtbase((long)maxi,10,0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
i = (newsize-1)*sizeof(union Value*)+newsize;
|
||||
ap = new_of(struct index_array,i);
|
||||
memset((void*)ap,0,sizeof(*ap)+i);
|
||||
|
@ -895,7 +904,10 @@ int nv_atypeindex(Namval_t *np, const char *tname)
|
|||
{
|
||||
struct index_array *ap = (struct index_array*)nv_arrayptr(np);
|
||||
if(!nv_hasdisc(tp,&ENUM_disc))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_notenum,tp->nvname);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(!ap)
|
||||
ap = array_grow(np,ap,1);
|
||||
ap->xp = sh_calloc(NV_MINSZ,1);
|
||||
|
@ -907,7 +919,7 @@ int nv_atypeindex(Namval_t *np, const char *tname)
|
|||
return(1);
|
||||
}
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_unknowntype, n,tname);
|
||||
return(0);
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
Namarr_t *nv_arrayptr(register Namval_t *np)
|
||||
|
@ -1187,7 +1199,7 @@ Namval_t *nv_putsub(Namval_t *np,register char *sp,register long mode)
|
|||
if(size >= ARRAY_MAX || (size < 0))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_subscript, nv_name(np));
|
||||
return(NIL(Namval_t*));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(!ap || size>=ap->maxi)
|
||||
{
|
||||
|
@ -1406,6 +1418,7 @@ static int array_fixed_init(Namval_t *np, char *sub, char *cp)
|
|||
{
|
||||
free((void*)ap);
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_subscript, nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
cp[-1] = ']';
|
||||
}
|
||||
|
@ -1442,18 +1455,27 @@ static char *array_fixed(Namval_t *np, char *sub, char *cp,int mode)
|
|||
size = (int)sh_arith(&sh,(char*)sub);
|
||||
fp->cur[n] = size;
|
||||
if(size >= fp->max[n] || (size < 0))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_subscript, nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
*cp++ = ']';
|
||||
sz = fp->curi + fp->cur[n]*fp->incr[n];
|
||||
for(n++,ep=cp;*ep=='['; ep=cp,n++)
|
||||
{
|
||||
if(n >= fp->ndim)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_subscript, nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
cp = nv_endsubscript(np,ep,0);
|
||||
cp[-1]=0;
|
||||
size = (int)sh_arith(&sh,(char*)ep+1);
|
||||
if(size >= fp->max[n] || (size < 0))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_subscript, nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
fp->cur[n] = size;
|
||||
cp[-1] = ']';
|
||||
sz += fp->cur[n]*fp->incr[n];
|
||||
|
@ -1793,7 +1815,10 @@ void nv_setvec(register Namval_t *np,int append,register int argc,register char
|
|||
{
|
||||
ap = (struct index_array*)nv_arrayptr(np);
|
||||
if(ap && is_associative(ap))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),"cannot append indexed array to associative array %s",nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
if(append)
|
||||
{
|
||||
|
|
|
@ -599,7 +599,7 @@ static void array_notify(Namval_t *np, void *data)
|
|||
* This is the exit routine for the shell
|
||||
*/
|
||||
|
||||
void sh_done(void *ptr, register int sig)
|
||||
noreturn void sh_done(void *ptr, register int sig)
|
||||
{
|
||||
Shell_t *shp = (Shell_t*)ptr;
|
||||
register char *t;
|
||||
|
|
|
@ -221,11 +221,11 @@ static int rand_shift;
|
|||
/*
|
||||
* out of memory routine for stak routines
|
||||
*/
|
||||
static char *nomemory(int unused)
|
||||
static noreturn char *nomemory(int unused)
|
||||
{
|
||||
NOT_USED(unused);
|
||||
errormsg(SH_DICT, ERROR_SYSTEM|ERROR_PANIC, "out of memory");
|
||||
return(NIL(char*));
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -371,7 +371,10 @@ static void put_restricted(register Namval_t* np,const char *val,int flags,Namfu
|
|||
Pathcomp_t *pp;
|
||||
char *name = nv_name(np);
|
||||
if(!(flags&NV_RDONLY) && sh_isoption(SH_RESTRICTED))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_restricted,nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(np==PATHNOD || (path_scoped=(strcmp(name,PATHNOD->nvname)==0)))
|
||||
{
|
||||
/* Clear the hash table */
|
||||
|
@ -1195,7 +1198,10 @@ static void put_mode(Namval_t* np, const char* val, int flag, Namfun_t* nfp)
|
|||
else
|
||||
mode = strperm(val, &last,0);
|
||||
if(*last)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),"%s: invalid mode string",val);
|
||||
UNREACHABLE();
|
||||
}
|
||||
nv_putv(np,(char*)&mode,NV_INTEGER,nfp);
|
||||
}
|
||||
else
|
||||
|
@ -1472,7 +1478,10 @@ Shell_t *sh_init(register int argc,register char *argv[], Shinit_f userinit)
|
|||
#ifdef SHELLMAGIC
|
||||
/* careful of #! setuid scripts with name beginning with - */
|
||||
if(shp->login_sh && argv[1] && strcmp(argv[0],argv[1])==0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_prohibited);
|
||||
UNREACHABLE();
|
||||
}
|
||||
#endif /*SHELLMAGIC*/
|
||||
}
|
||||
else
|
||||
|
@ -1700,7 +1709,10 @@ found:
|
|||
shp->last_table = SH_STATS;
|
||||
}
|
||||
else
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_notelem,n,name,nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
return(nq);
|
||||
}
|
||||
|
||||
|
|
|
@ -510,6 +510,11 @@ static int outexcept(register Sfio_t *iop,int type,void *data,Sfdisc_t *handle)
|
|||
sfpurge(iop);
|
||||
sfpool(iop,NIL(Sfio_t*),SF_WRITE);
|
||||
errno = save;
|
||||
/*
|
||||
* Note: UNREACHABLE() is avoided here because this errormsg() call will return.
|
||||
* The ERROR_system flag causes sh_exit() to be called, but if shp->jmplist->mode
|
||||
* is 0 (see above), then sh_exit() neither exits nor longjmps. See fault.c.
|
||||
*/
|
||||
errormsg(SH_DICT,ERROR_system(1),e_badwrite,sffileno(iop));
|
||||
active = 0;
|
||||
((struct checkpt*)shp->jmplist)->mode = mode;
|
||||
|
@ -616,6 +621,7 @@ static void io_preserve(Shell_t* shp, register Sfio_t *sp, register int f2)
|
|||
shp->toomany = 1;
|
||||
((struct checkpt*)shp->jmplist)->mode = SH_JMPERREXIT;
|
||||
errormsg(SH_DICT,ERROR_system(1),e_toomany);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(f2 >= shp->gd->lim.open_max)
|
||||
sh_iovalidfd(shp,f2);
|
||||
|
@ -669,7 +675,10 @@ int sh_iorenumber(Shell_t *shp, register int f1,register int f2)
|
|||
{
|
||||
shp->fdstatus[f2] = (shp->fdstatus[f1]&~IOCLEX);
|
||||
if((f2 = sh_fcntl(f1,F_DUPFD, f2)) < 0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_file+4);
|
||||
UNREACHABLE();
|
||||
}
|
||||
else if(f2 <= 2)
|
||||
sh_iostream(shp,f2);
|
||||
}
|
||||
|
@ -872,7 +881,10 @@ int sh_chkopen(register const char *name)
|
|||
{
|
||||
register int fd = sh_open(name,O_RDONLY,0);
|
||||
if(fd < 0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_open,name);
|
||||
UNREACHABLE();
|
||||
}
|
||||
return(fd);
|
||||
}
|
||||
|
||||
|
@ -902,7 +914,10 @@ int sh_pipe(register int pv[])
|
|||
Shell_t *shp = sh_getinterp();
|
||||
int fd[2];
|
||||
if(pipe(fd)<0 || (pv[0]=fd[0])<0 || (pv[1]=fd[1])<0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_pipe);
|
||||
UNREACHABLE();
|
||||
}
|
||||
pv[0] = sh_iomovefd(pv[0]);
|
||||
pv[1] = sh_iomovefd(pv[1]);
|
||||
shp->fdstatus[pv[0]] = IONOSEEK|IOREAD;
|
||||
|
@ -925,7 +940,10 @@ int sh_pipe(register int pv[])
|
|||
Shell_t *shp = sh_getinterp();
|
||||
int fd[2];
|
||||
if(pipe(fd)<0 || (pv[0]=fd[0])<0 || (pv[1]=fd[1])<0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_pipe);
|
||||
UNREACHABLE();
|
||||
}
|
||||
pv[0] = sh_iomovefd(pv[0]);
|
||||
pv[1] = sh_iomovefd(pv[1]);
|
||||
shp->fdstatus[pv[0]] = IONOSEEK|IOREAD;
|
||||
|
@ -1118,7 +1136,10 @@ int sh_redirect(Shell_t *shp,struct ionod *iop, int flag)
|
|||
if(fn==1)
|
||||
{
|
||||
if(shp->subshare && flag==2)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),"cannot redirect stdout inside shared-state comsub");
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(shp->subshell && (flag==2 || isstring))
|
||||
sh_subfork();
|
||||
}
|
||||
|
@ -1170,13 +1191,19 @@ int sh_redirect(Shell_t *shp,struct ionod *iop, int flag)
|
|||
{
|
||||
np = nv_open(iop->iovname,shp->var_tree,NV_NOASSIGN|NV_VARNAME);
|
||||
if(nv_isattr(np,NV_RDONLY))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_readonly, nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
io_op[0] = '}';
|
||||
if((iof&IOLSEEK) || ((iof&IOMOV) && *fname=='-'))
|
||||
fn = nv_getnum(np);
|
||||
}
|
||||
if(fn>=shp->gd->lim.open_max && !sh_iovalidfd(shp,fn))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_file+4);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(iof&IOLSEEK)
|
||||
{
|
||||
io_op[2] = '#';
|
||||
|
@ -1272,7 +1299,10 @@ int sh_redirect(Shell_t *shp,struct ionod *iop, int flag)
|
|||
else if(iof&IORDW)
|
||||
{
|
||||
if(sh_isoption(SH_RESTRICTED))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_restricted,fname);
|
||||
UNREACHABLE();
|
||||
}
|
||||
io_op[2] = '>';
|
||||
o_mode = O_RDWR|O_CREAT;
|
||||
if(iof&IOREWRITE)
|
||||
|
@ -1286,7 +1316,10 @@ int sh_redirect(Shell_t *shp,struct ionod *iop, int flag)
|
|||
fd=sh_chkopen(fname);
|
||||
}
|
||||
else if(sh_isoption(SH_RESTRICTED))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_restricted,fname);
|
||||
UNREACHABLE();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(iof&IOAPP)
|
||||
|
@ -1315,6 +1348,7 @@ int sh_redirect(Shell_t *shp,struct ionod *iop, int flag)
|
|||
{
|
||||
errno = EEXIST;
|
||||
errormsg(SH_DICT,ERROR_system(1),e_exists,fname);
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -1325,7 +1359,10 @@ int sh_redirect(Shell_t *shp,struct ionod *iop, int flag)
|
|||
if(flag!=SH_SHOWME)
|
||||
{
|
||||
if((fd=sh_open(tname?tname:fname,o_mode,RW_ALL)) <0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),((o_mode&O_CREAT)?e_create:e_open),fname);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(perm>0)
|
||||
#if _lib_fchmod
|
||||
fchmod(fd,perm);
|
||||
|
@ -1507,8 +1544,7 @@ int sh_redirect(Shell_t *shp,struct ionod *iop, int flag)
|
|||
return(indx);
|
||||
fail:
|
||||
errormsg(SH_DICT,ERROR_system(1),message,fname);
|
||||
/* NOTREACHED */
|
||||
return(0);
|
||||
UNREACHABLE();
|
||||
}
|
||||
/*
|
||||
* Create a tmp file for the here-document
|
||||
|
@ -1522,7 +1558,10 @@ static int io_heredoc(Shell_t *shp,register struct ionod *iop, const char *name,
|
|||
return(sh_open(e_devnull,O_RDONLY));
|
||||
/* create an unnamed temporary file */
|
||||
if(!(outfile=sftmp(0)))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_tmpcreate);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(iop->iofile&IOSTRG)
|
||||
{
|
||||
if(traceon)
|
||||
|
@ -1656,6 +1695,7 @@ void sh_iosave(Shell_t *shp, register int origfd, int oldtop, char *name)
|
|||
shp->toomany=1;
|
||||
((struct checkpt*)shp->jmplist)->mode = SH_JMPERREXIT;
|
||||
errormsg(SH_DICT,ERROR_system(1),e_toomany);
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
filemap[shp->topfd].tname = name;
|
||||
|
@ -2643,7 +2683,10 @@ Sfio_t *sh_pathopen(const char *cp)
|
|||
n = path_open(shp,cp,"");
|
||||
#endif
|
||||
if(n < 0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_open,cp);
|
||||
UNREACHABLE();
|
||||
}
|
||||
return(sh_iostream(shp,n));
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,10 @@ pid_t pid_fromstring(char *str)
|
|||
else
|
||||
pid = (pid_t)strtol(str, &last, 10);
|
||||
if(errno==ERANGE || *last)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),"%s: invalid process id",str);
|
||||
UNREACHABLE();
|
||||
}
|
||||
return(pid);
|
||||
}
|
||||
|
||||
|
@ -841,7 +844,10 @@ 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);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(*jobid == '%')
|
||||
pw = job_bystring(jobid);
|
||||
else
|
||||
|
@ -1152,7 +1158,10 @@ static struct process *job_byname(char *name)
|
|||
if(hist_match(shgd->hist_ptr,pw->p_name,cp,flag)>=0)
|
||||
{
|
||||
if(pz)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_jobusage,name-1);
|
||||
UNREACHABLE();
|
||||
}
|
||||
pz = pw;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -405,6 +405,7 @@ int sh_lex(Lex_t* lp)
|
|||
errno = ENOEXEC;
|
||||
error_info.id = shp->readscript;
|
||||
errormsg(SH_DICT,ERROR_system(ERROR_NOEXEC),e_exec,cp);
|
||||
UNREACHABLE();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1190,7 +1191,10 @@ int sh_lex(Lex_t* lp)
|
|||
if(n>0 && n==']')
|
||||
{
|
||||
if(mode==ST_NAME)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(SYNBAD),e_lexsyntax1, shp->inlineno, "[]", "empty subscript");
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(!epatchar || epatchar=='%')
|
||||
continue;
|
||||
}
|
||||
|
@ -1634,6 +1638,7 @@ static int comsub(register Lex_t *lp, int endtok)
|
|||
lp->lastline = line;
|
||||
lp->lasttok = endtok;
|
||||
sh_syntax(lp);
|
||||
/* UNREACHABLE */
|
||||
case IOSEEKSYM:
|
||||
if(fcgetc(c)!='#' && c>0)
|
||||
fcseek(-LEN);
|
||||
|
@ -1668,7 +1673,10 @@ done:
|
|||
lp->lex = save;
|
||||
lp->assignok = (endchar(lp)==RBRACT?assignok:0);
|
||||
if(lp->heredoc && !inheredoc)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(SYNBAD),e_lexsyntax5,lp->sh->inlineno,lp->heredoc->ioname);
|
||||
UNREACHABLE();
|
||||
}
|
||||
return(messages);
|
||||
}
|
||||
|
||||
|
@ -2094,7 +2102,7 @@ static char *fmttoken(Lex_t *lp, register int sym, char *tok)
|
|||
* print a bad syntax message
|
||||
*/
|
||||
|
||||
void sh_syntax(Lex_t *lp)
|
||||
noreturn void sh_syntax(Lex_t *lp)
|
||||
{
|
||||
register Shell_t *shp = lp->sh;
|
||||
register const char *cp = sh_translate(e_unexpected);
|
||||
|
@ -2131,6 +2139,7 @@ void sh_syntax(Lex_t *lp)
|
|||
errormsg(SH_DICT,ERROR_exit(SYNBAD),e_lexsyntax1,lp->lastline,tokstr,cp);
|
||||
else
|
||||
errormsg(SH_DICT,ERROR_exit(SYNBAD),e_lexsyntax2,tokstr,cp);
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
static char *stack_shift(Stk_t *stkp, register char *sp,char *dp)
|
||||
|
|
|
@ -98,6 +98,7 @@ typedef struct _mac_
|
|||
#define M_NAMECOUNT 7 /* ${#var*} */
|
||||
#define M_TYPE 8 /* ${@var} */
|
||||
|
||||
static noreturn void mac_error(Namval_t*);
|
||||
static int substring(const char*, const char*, int[], int);
|
||||
static void copyto(Mac_t*, int, int);
|
||||
static void comsubst(Mac_t*, Shnode_t*, int);
|
||||
|
@ -107,7 +108,6 @@ static void tilde_expand2(Shell_t*,int);
|
|||
static char *sh_tilde(Shell_t*,const char*);
|
||||
static char *special(Shell_t *,int);
|
||||
static void endfield(Mac_t*,int);
|
||||
static void mac_error(Namval_t*);
|
||||
static char *mac_getstring(char*);
|
||||
static int charlen(const char*,int);
|
||||
#if SHOPT_MULTIBYTE
|
||||
|
@ -184,7 +184,10 @@ char *sh_mactrim(Shell_t *shp, char *str, register int mode)
|
|||
if((mode=path_expand(shp,str,&arglist))==1)
|
||||
str = arglist->argval;
|
||||
else if(mode>1)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_ambiguous,str);
|
||||
UNREACHABLE();
|
||||
}
|
||||
sh_trim(str);
|
||||
}
|
||||
*mp = savemac;
|
||||
|
@ -712,7 +715,10 @@ static void copyto(register Mac_t *mp,int endch, int newquote)
|
|||
if(first[c-2]=='.')
|
||||
offset = stktell(stkp);
|
||||
if(isastchar(*cp) && cp[1]==']')
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_badsubscript,*cp);
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
first = fcseek(c);
|
||||
mp->pattern = 4;
|
||||
|
@ -1198,7 +1204,10 @@ retry1:
|
|||
d=fcget();
|
||||
fcseek(-1);
|
||||
if(!(d && strchr(":+-?=",d)))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_notset,ltos(c));
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case S_ALP:
|
||||
|
@ -1469,7 +1478,10 @@ retry1:
|
|||
{
|
||||
/* The parameter is unset. */
|
||||
if(sh_isoption(SH_NOUNSET) && !isastchar(mode) && (type==M_VNAME || type==M_SIZE))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_notset,id);
|
||||
UNREACHABLE();
|
||||
}
|
||||
v = 0;
|
||||
if(type==M_VNAME)
|
||||
{
|
||||
|
@ -1598,7 +1610,10 @@ retry1:
|
|||
int newops = (c=='#' || c == '%' || c=='/');
|
||||
offset = stktell(stkp);
|
||||
if(newops && sh_isoption(SH_NOUNSET) && *id && id!=idbuff && (!np || nv_isnull(np)))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_notset,id);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(c=='/' ||c==':' || ((!v || (nulflg && *v==0)) ^ (c=='+'||c=='#'||c=='%')))
|
||||
{
|
||||
int newquote = mp->quote;
|
||||
|
@ -1999,6 +2014,7 @@ retry2:
|
|||
errormsg(SH_DICT,ERROR_exit(1),e_nullset,id);
|
||||
else
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_notset,id);
|
||||
UNREACHABLE();
|
||||
}
|
||||
else if(c=='=')
|
||||
{
|
||||
|
@ -2030,6 +2046,7 @@ retry2:
|
|||
nv_close(np);
|
||||
}
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_notset,id);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(np)
|
||||
nv_close(np);
|
||||
|
@ -2799,6 +2816,7 @@ static char *special(Shell_t *shp,register int c)
|
|||
c_str[0]=(char)c;
|
||||
c_str[1]='\0';
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_notset,c_str);
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
return(NIL(char*));
|
||||
|
@ -2807,11 +2825,12 @@ static char *special(Shell_t *shp,register int c)
|
|||
/*
|
||||
* Handle macro expansion errors
|
||||
*/
|
||||
static void mac_error(Namval_t *np)
|
||||
static noreturn void mac_error(Namval_t *np)
|
||||
{
|
||||
if(np)
|
||||
nv_close(np);
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_subst,fcfirst());
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -263,7 +263,10 @@ int sh_main(int ac, char *av[], Shinit_f userinit)
|
|||
#endif
|
||||
fdin = (int)strtol(name+8, (char**)0, 10);
|
||||
if(fstat(fdin,&statb)<0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_open,name);
|
||||
UNREACHABLE();
|
||||
}
|
||||
#if !_WINIX
|
||||
/*
|
||||
* try to undo effect of solaris 2.5+
|
||||
|
@ -317,7 +320,10 @@ int sh_main(int ac, char *av[], Shinit_f userinit)
|
|||
errno = EISDIR;
|
||||
error_info.id = av[0];
|
||||
if(sp || errno!=ENOENT)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(ERROR_NOEXEC),e_open,name);
|
||||
UNREACHABLE();
|
||||
}
|
||||
/* try sh -c 'name "$@"' */
|
||||
sh_onoption(SH_CFLAG);
|
||||
shp->comdiv = (char*)sh_malloc(strlen(name)+7);
|
||||
|
@ -350,8 +356,6 @@ int sh_main(int ac, char *av[], Shinit_f userinit)
|
|||
nv_putval(IFSNOD,(char*)e_sptbnl,NV_RDONLY);
|
||||
exfile(shp,iop,fdin);
|
||||
sh_done(shp,0);
|
||||
/* NOTREACHED */
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -204,6 +204,7 @@ Namval_t *nv_addnode(Namval_t* np, int remove)
|
|||
nv_delete(sp->nodes[0],root,NV_NOFREE);
|
||||
dtinsert(root,sp->rp);
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_redef,sp->nodes[0]->nvname);
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
for(i=0; i < sp->numnodes; i++)
|
||||
|
@ -352,7 +353,10 @@ void nv_setlist(register struct argnod *arg,register int flags, Namval_t *typ)
|
|||
tp->com.comtyp = COMSCAN;
|
||||
}
|
||||
if(nv_isattr(np,NV_RDONLY) && np->nvfun && !(flags&NV_RDONLY))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_readonly, nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(nv_isattr(np,NV_NOFREE) && nv_isnull(np))
|
||||
nv_offattr(np,NV_NOFREE);
|
||||
if(nv_istable(np))
|
||||
|
@ -413,6 +417,7 @@ void nv_setlist(register struct argnod *arg,register int flags, Namval_t *typ)
|
|||
{
|
||||
shp->mktype = 0;
|
||||
errormsg(SH_DICT,ERROR_exit(1),"%s: not a known type name",argv[0]);
|
||||
UNREACHABLE();
|
||||
}
|
||||
#endif /* SHOPT_TYPEDEF */
|
||||
if(!(arg->argflag&ARG_APPEND))
|
||||
|
@ -500,7 +505,10 @@ void nv_setlist(register struct argnod *arg,register int flags, Namval_t *typ)
|
|||
if(nv_isarray(np))
|
||||
{
|
||||
if((sub=nv_aimax(np)) < 0 && nv_arrayptr(np))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_badappend,nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(sub>=0)
|
||||
sub++;
|
||||
}
|
||||
|
@ -928,7 +936,10 @@ Namval_t *nv_create(const char *name, Dt_t *root, int flags, Namfun_t *dp)
|
|||
}
|
||||
shp->first_root = root;
|
||||
if(nv_isref(np) && (c=='[' || c=='.' || !(flags&NV_ASSIGN)))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_noref,nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(sub && c==0)
|
||||
{
|
||||
if(flags&NV_ARRAY)
|
||||
|
@ -1544,6 +1555,7 @@ skip:
|
|||
else if(c=='[')
|
||||
msg = e_noarray;
|
||||
errormsg(SH_DICT,ERROR_exit(1),msg,name);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(fun.nofree&1)
|
||||
stakseek(offset);
|
||||
|
@ -1578,7 +1590,10 @@ void nv_putval(register Namval_t *np, const char *string, int flags)
|
|||
Namarr_t *ap;
|
||||
#endif /* SHOPT_FIXEDARRAY */
|
||||
if(!(flags&NV_RDONLY) && nv_isattr (np, NV_RDONLY))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_readonly, nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
/*
|
||||
* The following could cause the shell to fork if assignment
|
||||
* would cause a side effect
|
||||
|
@ -2459,7 +2474,10 @@ void _nv_unset(register Namval_t *np,int flags)
|
|||
Namarr_t *ap;
|
||||
#endif /* SHOPT_FIXEDARRAY */
|
||||
if(!(flags&NV_RDONLY) && nv_isattr (np,NV_RDONLY))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_readonly, nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(is_afunction(np) && np->nvalue.ip)
|
||||
{
|
||||
register struct slnod *slp = (struct slnod*)(np->nvenv);
|
||||
|
@ -2882,7 +2900,10 @@ Sfdouble_t nv_getnum(register Namval_t *np)
|
|||
nv_optimize(np);
|
||||
#endif /* SHOPT_OPTIMIZE */
|
||||
if(nv_istable(np))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_number,nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(np->nvfun && np->nvfun->disc)
|
||||
{
|
||||
if(!nv_local)
|
||||
|
@ -2972,7 +2993,10 @@ void nv_newattr (register Namval_t *np, unsigned newatts, int size)
|
|||
|
||||
/* check for restrictions */
|
||||
if(sh_isoption(SH_RESTRICTED) && ((sp=nv_name(np))==nv_name(PATHNOD) || sp==nv_name(SHELLNOD) || sp==nv_name(ENVNOD) || sp==nv_name(FPATHNOD)))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_restricted,nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
/* handle attributes that do not change data separately */
|
||||
n = np->nvflag;
|
||||
trans = !(n&NV_INTEGER) && (n&(NV_LTOU|NV_UTOL)); /* transcode to lower or upper case */
|
||||
|
@ -3267,11 +3291,17 @@ int nv_rename(register Namval_t *np, int flags)
|
|||
if(!(cp=nv_getval(np)))
|
||||
{
|
||||
if(flags&NV_MOVE)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_varname,"");
|
||||
UNREACHABLE();
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
if(lastdot(cp,0) && nv_isattr(np,NV_MINIMAL))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_varname,nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
arraynr = cp[strlen(cp)-1] == ']';
|
||||
if(nv_isarray(np) && !(mp=nv_opensub(np)))
|
||||
index=nv_aindex(np);
|
||||
|
@ -3393,7 +3423,10 @@ void nv_setref(register Namval_t *np, Dt_t *hp, int flags)
|
|||
if(nv_isref(np))
|
||||
return;
|
||||
if(nv_isarray(np))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_badref,nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(!(cp=nv_getval(np)))
|
||||
{
|
||||
_nv_unset(np,0);
|
||||
|
@ -3401,7 +3434,10 @@ void nv_setref(register Namval_t *np, Dt_t *hp, int flags)
|
|||
return;
|
||||
}
|
||||
if((ep = lastdot(cp,0)) && nv_isattr(np,NV_MINIMAL))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_badref,nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(hp)
|
||||
hpnext = dtvnext(hp);
|
||||
if((nr=nv_open(cp, hp?hp:shp->var_tree, flags|NV_NOSCOPE|NV_NOADD|NV_NOFAIL)))
|
||||
|
@ -3417,10 +3453,16 @@ void nv_setref(register Namval_t *np, Dt_t *hp, int flags)
|
|||
if(nr==np)
|
||||
{
|
||||
if(shp->namespace && nv_dict(shp->namespace)==hp)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_selfref,nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
/* bind to earlier scope, or add to global scope */
|
||||
if(!(hp=dtvnext(hp)) || (nq=nv_search((char*)np,hp,NV_ADD|HASH_BUCKET))==np)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_selfref,nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(nv_isarray(nq))
|
||||
nv_putsub(nq,(char*)0,ARRAY_UNDEF);
|
||||
}
|
||||
|
@ -3449,6 +3491,7 @@ void nv_setref(register Namval_t *np, Dt_t *hp, int flags)
|
|||
_nv_unset(np,NV_RDONLY);
|
||||
nv_onattr(np,NV_REF);
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_globalref,nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
shp->instance = 1;
|
||||
if(nq && !ep && (ap=nv_arrayptr(nq)) && !(ap->nelem&(ARRAY_UNDEF|ARRAY_SCAN)))
|
||||
|
|
|
@ -600,7 +600,10 @@ static char *setdisc(register Namval_t* np,register const char *event,Namval_t *
|
|||
{
|
||||
Namval_t *tp = nv_type(np);
|
||||
if(tp && (np = (Namval_t*)vp->bltins[type]) && nv_isattr(np,NV_STATICF))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_staticfun,name,tp->nvname);
|
||||
UNREACHABLE();
|
||||
}
|
||||
vp->bltins[type] = action;
|
||||
}
|
||||
else
|
||||
|
@ -1204,7 +1207,10 @@ Namval_t *sh_addbuiltin(const char *path, Shbltin_f bltin, void *extra)
|
|||
if(extra == (void*)1)
|
||||
{
|
||||
if(nv_isattr(np,BLT_SPC))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),"cannot delete: %s%s",name,is_spcbuiltin);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(np->nvfun && !nv_isattr(np,NV_NOFREE))
|
||||
free((void*)np->nvfun);
|
||||
dtdelete(sh.bltin_tree,np);
|
||||
|
@ -1254,7 +1260,10 @@ Namval_t *sh_addbuiltin(const char *path, Shbltin_f bltin, void *extra)
|
|||
cp=nv_setdisc(nq,cp+1,np,(Namfun_t*)nq);
|
||||
nv_close(nq);
|
||||
if(!cp)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_baddisc,name);
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
if(extra == (void*)1)
|
||||
return(0);
|
||||
|
|
|
@ -411,7 +411,10 @@ static Namfun_t *clone_type(Namval_t* np, Namval_t *mp, int flags, Namfun_t *fp)
|
|||
if(nr)
|
||||
{
|
||||
if(nv_isattr(nq,NV_RDONLY) && (nq->nvalue.cp || nv_isattr(nq,NV_INTEGER)))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_readonly, nq->nvname);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(nv_isref(nq))
|
||||
nq = nv_refnode(nq);
|
||||
if((size = nv_datasize(nr,(size_t*)0)) && size==nv_datasize(nq,(size_t*)0))
|
||||
|
@ -455,7 +458,10 @@ static Namfun_t *clone_type(Namval_t* np, Namval_t *mp, int flags, Namfun_t *fp)
|
|||
nv_delete(nr,sh.last_root,0);
|
||||
}
|
||||
else if(nv_isattr(nq,NV_RDONLY) && !nq->nvalue.cp && !nv_isattr(nq,NV_INTEGER))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_required,nq->nvname,nv_name(mp));
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
}
|
||||
if(nv_isattr(mp,NV_BINARY))
|
||||
|
@ -515,6 +521,7 @@ found:
|
|||
return(nq);
|
||||
}
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_notelem,n,name,nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
return(nq);
|
||||
}
|
||||
|
@ -841,6 +848,7 @@ Namval_t *nv_mktype(Namval_t **nodes, int numnodes)
|
|||
cp = nodes[0]->nvname;
|
||||
_nv_unset(nodes[0],NV_RDONLY);
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_badtypedef,cp);
|
||||
UNREACHABLE();
|
||||
}
|
||||
n=strlen(nodes[1]->nvname);
|
||||
for(nnodes=1,i=1; i <numnodes; i++)
|
||||
|
@ -1299,6 +1307,7 @@ int nv_settype(Namval_t* np, Namval_t *tp, int flags)
|
|||
if(tp==tq)
|
||||
return(0);
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_redef,nv_name(np));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if((ap=nv_arrayptr(np)) && ap->nelem>0)
|
||||
{
|
||||
|
@ -1428,7 +1437,10 @@ Namval_t *nv_mkstruct(const char *name, int rsize, Fields_t *fields)
|
|||
tp = nv_open(stakptr(offset), sh.var_tree, NV_VARNAME|NV_NOADD|NV_NOFAIL);
|
||||
stakseek(r);
|
||||
if(!tp)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_unknowntype,strlen(fp->type),fp->type);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(dp = (Namtype_t*)nv_hasdisc(tp,&type_disc))
|
||||
{
|
||||
nnodes += dp->numnodes;
|
||||
|
|
|
@ -354,7 +354,10 @@ void *sh_parse(Shell_t *shp, Sfio_t *iop, int flag)
|
|||
fcrestore(&sav_input);
|
||||
lexp->arg = sav_arg;
|
||||
if(version > SHCOMP_HDR_VERSION)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_lexversion);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(sffileno(iop)==shp->infd || (flag&SH_FUNEVAL))
|
||||
shp->binscript = 1;
|
||||
sfgetc(iop);
|
||||
|
@ -795,7 +798,10 @@ static Shnode_t *funct(Lex_t *lexp)
|
|||
int c=-1;
|
||||
t->funct.functargs = ac = (struct comnod*)simple(lexp,SH_NOIO|SH_FUNDEF,NIL(struct ionod*));
|
||||
if(ac->comset || (ac->comtyp&COMSCAN))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(3),e_lexsyntax4,lexp->sh->inlineno);
|
||||
UNREACHABLE();
|
||||
}
|
||||
argv0 = argv = ((struct dolnod*)ac->comarg)->dolval+ARG_SPARE;
|
||||
while(cp= *argv++)
|
||||
{
|
||||
|
@ -804,7 +810,10 @@ static Shnode_t *funct(Lex_t *lexp)
|
|||
while(c=mbchar(cp), isaname(c));
|
||||
}
|
||||
if(c)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(3),e_lexsyntax4,lexp->sh->inlineno);
|
||||
UNREACHABLE();
|
||||
}
|
||||
nargs = argv-argv0;
|
||||
size += sizeof(struct dolnod)+(nargs+ARG_SPARE)*sizeof(char*);
|
||||
if(shp->shcomp && memcmp(".sh.math.",t->funct.functnam,9)==0)
|
||||
|
@ -1272,7 +1281,10 @@ static Shnode_t *item(Lex_t *lexp,int flag)
|
|||
while(argp)
|
||||
{
|
||||
if(strcmp(argp->argval,lexp->arg->argval)==0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(3),e_lexsyntax3,lexp->sh->inlineno,argp->argval);
|
||||
UNREACHABLE();
|
||||
}
|
||||
argp = argp->argnxt.ap;
|
||||
}
|
||||
lexp->arg->argnxt.ap = label_list;
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
|
||||
static int canexecute(Shell_t*,char*,int);
|
||||
static void funload(Shell_t*,int,const char*);
|
||||
static void exscript(Shell_t*,char*, char*[], char**);
|
||||
static void noreturn exscript(Shell_t*,char*, char*[], char**);
|
||||
static int path_chkpaths(Shell_t*,Pathcomp_t*,Pathcomp_t*,Pathcomp_t*,int);
|
||||
static void path_checkdup(Shell_t *shp,register Pathcomp_t*);
|
||||
static Pathcomp_t *defpath_init(Shell_t *shp);
|
||||
|
@ -489,7 +489,10 @@ static int path_opentype(Shell_t *shp,const char *name, register Pathcomp_t *pp,
|
|||
if(!fun && strchr(name,'/'))
|
||||
{
|
||||
if(sh_isoption(SH_RESTRICTED))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_restricted,name);
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
nextpp = pp;
|
||||
|
@ -602,7 +605,10 @@ static void funload(Shell_t *shp,int fno, const char *name)
|
|||
if(!loopdetect_tree)
|
||||
loopdetect_tree = dtopen(&_Nvdisc,Dtoset);
|
||||
else if(nv_search(pname,loopdetect_tree,0))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(ERROR_NOEXEC),"autoload loop: %s in %s",name,pname);
|
||||
UNREACHABLE();
|
||||
}
|
||||
np_loopdetect = nv_search(pname,loopdetect_tree,NV_ADD);
|
||||
sh_onstate(SH_NOALIAS);
|
||||
shp->readscript = (char*)name;
|
||||
|
@ -630,7 +636,10 @@ static void funload(Shell_t *shp,int fno, const char *name)
|
|||
sh_setstate(savestates);
|
||||
nv_delete(np_loopdetect,loopdetect_tree,0);
|
||||
if(pname)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(ERROR_NOEXEC),e_funload,name,pname);
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -991,7 +1000,7 @@ char *path_relative(Shell_t *shp,register const char* file)
|
|||
return((char*)file);
|
||||
}
|
||||
|
||||
void path_exec(Shell_t *shp,register const char *arg0,register char *argv[],struct argnod *local)
|
||||
noreturn void path_exec(Shell_t *shp,register const char *arg0,register char *argv[],struct argnod *local)
|
||||
{
|
||||
char **envp;
|
||||
const char *opath;
|
||||
|
@ -1004,7 +1013,10 @@ void path_exec(Shell_t *shp,register const char *arg0,register char *argv[],stru
|
|||
slash=1;
|
||||
/* name containing / not allowed for restricted shell */
|
||||
if(sh_isoption(SH_RESTRICTED))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_restricted,arg0);
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
else
|
||||
pp=path_get(shp,arg0);
|
||||
|
@ -1035,6 +1047,7 @@ void path_exec(Shell_t *shp,register const char *arg0,register char *argv[],stru
|
|||
errormsg(SH_DICT,ERROR_exit(ERROR_NOENT),e_found,arg0);
|
||||
else
|
||||
errormsg(SH_DICT,ERROR_system(ERROR_NOEXEC),e_exec,arg0);
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
pid_t path_spawn(Shell_t *shp,const char *opath,register char **argv, char **envp, Pathcomp_t *libpath, int spawn)
|
||||
|
@ -1191,6 +1204,7 @@ pid_t path_spawn(Shell_t *shp,const char *opath,register char **argv, char **env
|
|||
((struct checkpt*)shp->jmplist)->mode = SH_JMPEXIT;
|
||||
}
|
||||
exscript(shp,path,argv,envp);
|
||||
UNREACHABLE();
|
||||
case EACCES:
|
||||
{
|
||||
struct stat statb;
|
||||
|
@ -1200,7 +1214,10 @@ pid_t path_spawn(Shell_t *shp,const char *opath,register char **argv, char **env
|
|||
errno = EISDIR;
|
||||
#ifdef S_ISSOCK
|
||||
if(S_ISSOCK(statb.st_mode))
|
||||
{
|
||||
exscript(shp,path,argv,envp);
|
||||
UNREACHABLE();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -1226,12 +1243,16 @@ pid_t path_spawn(Shell_t *shp,const char *opath,register char **argv, char **env
|
|||
{
|
||||
pid = path_xargs(shp,opath, &argv[0] ,envp,spawn);
|
||||
if(pid<0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(ERROR_NOEXEC),"command -x: could not execute %s",path);
|
||||
UNREACHABLE();
|
||||
}
|
||||
return(pid);
|
||||
}
|
||||
/* FALLTHROUGH */
|
||||
default:
|
||||
errormsg(SH_DICT,ERROR_system(ERROR_NOEXEC),e_exec,path);
|
||||
UNREACHABLE();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1241,7 +1262,7 @@ pid_t path_spawn(Shell_t *shp,const char *opath,register char **argv, char **env
|
|||
* Assume file is a Shell script and execute it.
|
||||
*/
|
||||
|
||||
static void exscript(Shell_t *shp,register char *path,register char *argv[],char **envp)
|
||||
static noreturn void exscript(Shell_t *shp,register char *path,register char *argv[],char **envp)
|
||||
{
|
||||
register Sfio_t *sp;
|
||||
path = path_relative(shp,path);
|
||||
|
@ -1303,7 +1324,10 @@ static void exscript(Shell_t *shp,register char *path,register char *argv[],char
|
|||
* The following code is just for compatibility
|
||||
*/
|
||||
if((n=open(path,O_RDONLY,0)) < 0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(ERROR_NOEXEC),e_exec,path);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(savet)
|
||||
*argv++ = savet;
|
||||
openok:
|
||||
|
@ -1311,7 +1335,10 @@ static void exscript(Shell_t *shp,register char *path,register char *argv[],char
|
|||
}
|
||||
#else
|
||||
if((shp->infd = sh_open(path,O_RDONLY,0)) < 0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(ERROR_NOEXEC),e_exec,path);
|
||||
UNREACHABLE();
|
||||
}
|
||||
#endif
|
||||
shp->infd = sh_iomovefd(shp->infd);
|
||||
#if SHOPT_ACCT
|
||||
|
|
|
@ -97,14 +97,17 @@ int main(int argc, char *argv[])
|
|||
break;
|
||||
case '?':
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",opt_info.arg);
|
||||
break;
|
||||
UNREACHABLE();
|
||||
}
|
||||
shp = sh_init(argc,argv,(Shinit_f)0);
|
||||
shp->shcomp = 1;
|
||||
argv += opt_info.index;
|
||||
argc -= opt_info.index;
|
||||
if(error_info.errors || argc>2)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_usage(2),"%s",optusage((char*)0));
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(cp= *argv)
|
||||
{
|
||||
argv++;
|
||||
|
@ -116,7 +119,10 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
struct stat statb;
|
||||
if(!(out = sfopen((Sfio_t*)0,cp,"w")))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),"%s: cannot create",cp);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(fstat(sffileno(out),&statb) >=0)
|
||||
chmod(cp,(statb.st_mode&~S_IFMT)|S_IXUSR|S_IXGRP|S_IXOTH);
|
||||
}
|
||||
|
@ -145,12 +151,18 @@ int main(int argc, char *argv[])
|
|||
if((t->tre.tretyp&(COMMSK|COMSCAN))==0 && t->com.comnamp && strcmp(nv_name((Namval_t*)t->com.comnamp),"alias")==0)
|
||||
sh_exec(t,0);
|
||||
if(!dflag && sh_tdump(out,t) < 0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),"dump failed");
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
else if(sfeof(in))
|
||||
break;
|
||||
if(sferror(in))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),"I/O error");
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(t && ((t->tre.tretyp&COMMSK)==TCOM) && (np=t->com.comnamp) && (cp=nv_name(np)))
|
||||
{
|
||||
if(strcmp(cp,"exit")==0)
|
||||
|
|
|
@ -1024,7 +1024,7 @@ Sfdouble_t strval(Shell_t *shp,const char *s,char **end,Sfdouble_t(*conv)(const
|
|||
}
|
||||
level=0;
|
||||
errormsg(SH_DICT,ERROR_exit(1),message,ep->name);
|
||||
return(0);
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
#undef extern
|
||||
|
|
|
@ -131,7 +131,10 @@ void sh_subtmpfile(char comsub_flag)
|
|||
close(1);
|
||||
}
|
||||
else if(errno!=EBADF)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_toomany);
|
||||
UNREACHABLE();
|
||||
}
|
||||
/* popping a discipline forces a /tmp file create */
|
||||
if(comsub_flag != 1)
|
||||
sfdisc(sfstdout,SF_POPDISC);
|
||||
|
@ -149,7 +152,10 @@ void sh_subtmpfile(char comsub_flag)
|
|||
write(fds[1],sfsetbuf(sfstdout,(Void_t*)sfstdout,0),(size_t)off);
|
||||
sfclose(sfstdout);
|
||||
if((sh_fcntl(fds[1],F_DUPFD, 1)) != 1)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_file+4);
|
||||
UNREACHABLE();
|
||||
}
|
||||
sh_close(fds[1]);
|
||||
}
|
||||
else
|
||||
|
@ -661,6 +667,7 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_t *t, volatile int flags, int comsub)
|
|||
{
|
||||
sfswap(sp->saveout,sfstdout);
|
||||
errormsg(SH_DICT,ERROR_system(1),e_tmpcreate);
|
||||
UNREACHABLE();
|
||||
}
|
||||
sfswap(iop,sfstdout);
|
||||
sfset(sfstdout,SF_READ,0);
|
||||
|
@ -747,6 +754,7 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_t *t, volatile int flags, int comsub)
|
|||
shp->toomany = 1;
|
||||
((struct checkpt*)shp->jmplist)->mode = SH_JMPERREXIT;
|
||||
errormsg(SH_DICT,ERROR_system(1),e_toomany);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(fd >= shp->gd->lim.open_max)
|
||||
sh_iovalidfd(shp,fd);
|
||||
|
@ -932,14 +940,17 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_t *t, volatile int flags, int comsub)
|
|||
shp->toomany = 1;
|
||||
errno = saveerrno;
|
||||
errormsg(SH_DICT,ERROR_system(1),e_redirect);
|
||||
UNREACHABLE();
|
||||
case 2:
|
||||
/* reinit PWD as it will be wrong */
|
||||
shp->pwd = NULL;
|
||||
path_pwd(shp,0);
|
||||
errno = saveerrno;
|
||||
errormsg(SH_DICT,ERROR_system(1),"Failed to restore PWD upon exiting subshell");
|
||||
UNREACHABLE();
|
||||
default:
|
||||
errormsg(SH_DICT,ERROR_system(1),"Subshell error %d",fatalerror);
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
if(shp->ignsig)
|
||||
|
|
|
@ -72,7 +72,10 @@ static double setalarm(register double t)
|
|||
tnew.it_interval.tv_sec = 0;
|
||||
tnew.it_interval.tv_usec = 0;
|
||||
if(setitimer(ITIMER_REAL,&tnew,&told) < 0)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_system(1),e_alarm);
|
||||
UNREACHABLE();
|
||||
}
|
||||
t = told.it_value.tv_sec + 1.e-6*told.it_value.tv_usec;
|
||||
#else
|
||||
unsigned seconds = (unsigned)t;
|
||||
|
|
|
@ -133,7 +133,10 @@ static void get_cpu_times(Shell_t *shp, struct timeval *tv_usr, struct timeval *
|
|||
double dtime;
|
||||
|
||||
if(times(&cpu_times) == (clock_t)-1)
|
||||
{
|
||||
errormsg(SH_DICT, ERROR_exit(1), "times(3) failed: %s", strerror(errno));
|
||||
UNREACHABLE();
|
||||
}
|
||||
|
||||
dtime = (double)cpu_times.tms_utime / shp->gd->lim.clk_tck;
|
||||
tv1.tv_sec = dtime / 60;
|
||||
|
@ -1307,8 +1310,11 @@ int sh_exec(register const Shnode_t *t, int flags)
|
|||
if(!com[1])
|
||||
type = 2;
|
||||
else
|
||||
{
|
||||
errormsg(SH_DICT, ERROR_exit(2), "%s: %s: %s",
|
||||
SYSREDIR->nvname, e_badsyntax, com[1]);
|
||||
UNREACHABLE();
|
||||
}
|
||||
else
|
||||
type = (execflg && !shp->subshell && !shp->st.trapcom[0]);
|
||||
shp->redir0 = 1;
|
||||
|
@ -1749,8 +1755,11 @@ int sh_exec(register const Shnode_t *t, int flags)
|
|||
if(fn<0)
|
||||
{
|
||||
if((errno = save_errno) != ENOENT)
|
||||
{
|
||||
errormsg(SH_DICT, ERROR_SYSTEM|ERROR_PANIC,
|
||||
"process substitution: FIFO open failed");
|
||||
UNREACHABLE();
|
||||
}
|
||||
sh_done(shp,0);
|
||||
}
|
||||
sh_iorenumber(shp,fn,fd);
|
||||
|
@ -2408,7 +2417,10 @@ int sh_exec(register const Shnode_t *t, int flags)
|
|||
#else
|
||||
bt = times(&before);
|
||||
if(bt == (clock_t)-1)
|
||||
{
|
||||
errormsg(SH_DICT, ERROR_exit(1), "times(3) failed: %s", strerror(errno));
|
||||
UNREACHABLE();
|
||||
}
|
||||
#endif
|
||||
job.waitall = 1;
|
||||
sh_onstate(SH_TIMING);
|
||||
|
@ -2431,7 +2443,10 @@ int sh_exec(register const Shnode_t *t, int flags)
|
|||
#ifndef timeofday
|
||||
at = times(&after) - bt;
|
||||
if(at == (clock_t)-1)
|
||||
{
|
||||
errormsg(SH_DICT, ERROR_exit(1), "times(3) failed: %s", strerror(errno));
|
||||
UNREACHABLE();
|
||||
}
|
||||
tm[0] = at;
|
||||
#else
|
||||
get_cpu_times(shp, &after_usr, &after_sys);
|
||||
|
@ -2479,7 +2494,10 @@ int sh_exec(register const Shnode_t *t, int flags)
|
|||
int offset = stktell(stkp);
|
||||
int flags=NV_NOASSIGN|NV_NOARRAY|NV_VARNAME;
|
||||
if(cp)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_ident,fname);
|
||||
UNREACHABLE();
|
||||
}
|
||||
sfputc(stkp,'.');
|
||||
sfputr(stkp,fname,0);
|
||||
np = nv_open(stkptr(stkp,offset),shp->var_tree,flags);
|
||||
|
@ -2525,7 +2543,10 @@ int sh_exec(register const Shnode_t *t, int flags)
|
|||
fname = stkptr(stkp,offset);
|
||||
}
|
||||
else if((mp=nv_search(fname,shp->bltin_tree,0)) && nv_isattr(mp,BLT_SPC))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_badfun,fname);
|
||||
UNREACHABLE();
|
||||
}
|
||||
#if SHOPT_NAMESPACE
|
||||
if(shp->namespace && !shp->prefix && *fname!='.')
|
||||
np = sh_fsearch(shp,fname,NV_ADD|HASH_NOSCOPE);
|
||||
|
@ -2537,7 +2558,10 @@ int sh_exec(register const Shnode_t *t, int flags)
|
|||
if(!shp->mktype)
|
||||
cp = nv_setdisc(npv,cp,np,(Namfun_t*)npv);
|
||||
if(!cp)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_baddisc,fname);
|
||||
UNREACHABLE();
|
||||
}
|
||||
}
|
||||
if(np->nvalue.rp)
|
||||
{
|
||||
|
@ -2871,6 +2895,7 @@ pid_t _sh_fork(Shell_t *shp,register pid_t parent,int flags,int *jobid)
|
|||
{
|
||||
forkcnt=1000L;
|
||||
errormsg(SH_DICT,ERROR_system(ERROR_NOEXEC),e_nofork);
|
||||
UNREACHABLE();
|
||||
}
|
||||
timeout = (void*)sh_timeradd(forkcnt, 0, timed_out, NIL(void*));
|
||||
nochild = job_wait((pid_t)1);
|
||||
|
@ -3222,7 +3247,10 @@ int sh_funscope(int argn, char *argv[],int(*fun)(void*),void *arg,int execflg)
|
|||
if(shp->topscope != (Shscope_t*)shp->st.self)
|
||||
sh_setscope(shp->topscope);
|
||||
if(--shp->fn_depth==1 && jmpval==SH_JMPERRFN)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_toodeep,argv[0]);
|
||||
UNREACHABLE();
|
||||
}
|
||||
sh_popcontext(shp,buffp);
|
||||
sh_unscope(shp);
|
||||
shp->namespace = nspace;
|
||||
|
@ -3420,7 +3448,10 @@ static void coproc_init(Shell_t *shp, int pipes[])
|
|||
{
|
||||
int outfd;
|
||||
if(shp->coutpipe>=0 && shp->cpid)
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_pexists);
|
||||
UNREACHABLE();
|
||||
}
|
||||
shp->cpid = 0;
|
||||
if(shp->cpipe[0]<=0 || shp->cpipe[1]<=0)
|
||||
{
|
||||
|
@ -3536,7 +3567,10 @@ static pid_t sh_ntfork(Shell_t *shp,const Shnode_t *t,char *argv[],int *jobid,in
|
|||
}
|
||||
}
|
||||
else if(sh_isoption(SH_RESTRICTED))
|
||||
{
|
||||
errormsg(SH_DICT,ERROR_exit(1),e_restricted,path);
|
||||
UNREACHABLE();
|
||||
}
|
||||
if(!path)
|
||||
{
|
||||
spawnpid = -1;
|
||||
|
@ -3598,8 +3632,10 @@ static pid_t sh_ntfork(Shell_t *shp,const Shnode_t *t,char *argv[],int *jobid,in
|
|||
{
|
||||
case ENOENT:
|
||||
errormsg(SH_DICT,ERROR_system(ERROR_NOENT),e_found+4);
|
||||
UNREACHABLE();
|
||||
default:
|
||||
errormsg(SH_DICT,ERROR_system(ERROR_NOEXEC),e_exec+4);
|
||||
UNREACHABLE();
|
||||
}
|
||||
job_unlock();
|
||||
}
|
||||
|
|
|
@ -774,5 +774,16 @@ got=$(procsub_delay <(echo hi) <(echo there) <(echo world))
|
|||
got=$(umask 777; set +x; { cat <(echo ok); } 2>&1)
|
||||
[[ $got == ok ]] || err_exit "process substitution failed with umask 777 (got $(printf %q "$got"))"
|
||||
|
||||
# ======
|
||||
# https://github.com/att/ast/issues/1336
|
||||
# Use the /proc psuedo filesystem on Linux as a convenient way to force a write I/O error.
|
||||
if [[ $(uname) == Linux ]]
|
||||
then
|
||||
actual=$($SHELL -c 'echo > /proc/self/uid_map; echo okay' 2>&1)
|
||||
expect='write.*failed.*okay'
|
||||
[[ "$actual" =~ $expect ]] || err_exit "I/O failure not handled" \
|
||||
"(expected $(printf %q "$expect"), got $(printf %q "$actual"))"
|
||||
fi
|
||||
|
||||
# ======
|
||||
exit $((Errors<125?Errors:125))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue