From 25a6e9c8c285e043e72fff5f816a938510af444c4303ba1f036b9bfddacb7d60 Mon Sep 17 00:00:00 2001 From: "Dr. Werner Fink" Date: Fri, 18 Oct 2013 10:46:51 +0000 Subject: [PATCH] . OBS-URL: https://build.opensuse.org/package/show/shells/ksh?expand=0&rev=171 --- ksh.changes | 9 + ksh.spec | 15 +- ksh93-dttree-crash.dif | 22 ++ ksh93-fdstatus.dif | 591 +++++++++++++++++++++++++++++++++------- ksh93-fs3d.dif | 65 +++++ ksh93-uninitialized.dif | 345 +++++++++++++++++++++++ 6 files changed, 948 insertions(+), 99 deletions(-) create mode 100644 ksh93-fs3d.dif create mode 100644 ksh93-uninitialized.dif diff --git a/ksh.changes b/ksh.changes index 7157fff..f7f8b24 100644 --- a/ksh.changes +++ b/ksh.changes @@ -1,3 +1,12 @@ +------------------------------------------------------------------- +Fri Oct 18 10:41:05 UTC 2013 - werner@suse.de + +- Change patch ksh93-fdstatus.dif which may solve bnc#844071 +- Add patch ksh93-fs3d.dif to avoid crash due dummy function call + fs3d_mount(3ast) during valgrind sessions +- Add patch ksh93-uninitialized.dif to avoid sometimes random + errors on busy systems which may also related to bnc#844071 + ------------------------------------------------------------------- Thu Sep 19 08:43:37 UTC 2013 - werner@suse.de diff --git a/ksh.spec b/ksh.spec index 48b927d..a19b3fe 100644 --- a/ksh.spec +++ b/ksh.spec @@ -129,6 +129,10 @@ Patch32: ksh93-heredoclex.dif Patch33: ksh93-fdstatus.dif # PATCH-FIX-UPSTREAM ksh93-alias-k.dif [bnc#824187] Patch34: ksh93-alias-k.dif +# PATCH-FIX-SUSE Reduce warnings about uninitialized varaibles (most of them are handled correct) +Patch35: ksh93-uninitialized.dif +# PATCH-FIX-SUSE Do not use mount(2) system call instead of fs3d_mount(3ast) +Patch36: ksh93-fs3d.dif Patch42: ksh-locale.patch %description @@ -217,6 +221,8 @@ fi %patch32 %patch33 %patch34 +%patch35 +%patch36 %build # @@ -245,9 +251,6 @@ fi test -s $fd -a ! -c $fd && break || true done set -- $(readlink $fd) -grep pts /proc/mounts -ls -ld /dev/ptmx -ls -ld /dev/pts exec ./sigexec $SHELL ${1+"$@"} fi IGNORED=0x$(ps --no-headers -o ignored $$) @@ -466,7 +469,7 @@ ls -ld /dev/pts done nobuiltin=${PWD}/.nobuiltin nm -D ${root}/lib/libast.so | \ - grep -E 'T[[:blank:]](_ast_)?(str|mem|(get|put|set)env|(c|m|re|v)alloc)' | \ + grep -E 'T[[:blank:]](_ast_)?(str|mem|(get|put|set)env|free|(c|m|re|v|vm)alloc)' | \ sed -r 's/[[:xdigit:]]+[[:blank:]]+T[[:blank:]]+(_ast_)?([^[:blank:]]*)/-fno-builtin-\2/' | \ sort -u > $nobuiltin rm -rf $root @@ -481,7 +484,7 @@ ls -ld /dev/pts *) cflags @$nobuiltin RPM_OPT_FLAGS esac - export > .env + export | grep -vE 'PROFILEREAD|PWD|MAIL|HOME|HOST|HIST|LESS' > .env bin/package make CCFLAGS="$RPM_OPT_FLAGS -I${root}/include" HOSTTYPE="$HOSTTYPE" AR="$AR" CC="$CC" root=$(echo ${PWD}/arch/linux*) test -d $root || exit 1 @@ -704,7 +707,7 @@ ls -ld /dev/pts else cp %{S:3} EPL-1.0 cp %{S:4} CPL-1.0 - ln -sf EPL-v1.0 LICENSE + ln -sf EPL-1.0 LICENSE fi mv src/cmd/ksh93/OBSOLETE src/cmd/ksh93/OBSOLETE.mm echo '.VERBON 22' > grep.mm diff --git a/ksh93-dttree-crash.dif b/ksh93-dttree-crash.dif index 3af9865..b331d1b 100644 --- a/ksh93-dttree-crash.dif +++ b/ksh93-dttree-crash.dif @@ -510,6 +510,28 @@ + return 0; + else return (*dt->disc->eventf)(dt, DT_ANNOUNCE|DT_USER|flags, data, dt->disc); +} +--- src/lib/libast/cdt/cdtlib.h ++++ src/lib/libast/cdt/cdtlib.h 2013-10-09 10:14:11.000000000 +0000 +@@ -58,9 +58,9 @@ + /* This struct holds private method data created on DT_OPEN */ + struct _dtdata_s + { unsigned int lock; /* general dictionary lock */ +- Dtuser_t user; /* application's data */ + unsigned int type; /* method type, control flags */ + ssize_t size; /* number of objects */ ++ Dtuser_t user; /* application's data */ + Dt_t dict; /* when DT_INDATA is requested */ + }; + +@@ -123,7 +123,7 @@ typedef struct _dtlib_s + #endif /* _BLD_cdt */ + + /* these macros lock/unlock dictionaries. DTRETURN substitutes for "return" */ +-#define DTSETLOCK(dt) (((dt)->data->type&DT_SHARE) ? asolock(&(dt)->data->lock,1,ASO_SPINLOCK) : 0 ) ++#define DTSETLOCK(dt) (((dt)->data->type&DT_SHARE) ? asolock(&(dt)->data->lock,1,ASO_LOCK) : 0 ) + #define DTCLRLOCK(dt) (((dt)->data->type&DT_SHARE) ? asolock(&(dt)->data->lock,1,ASO_UNLOCK) : 0 ) + #define DTRETURN(ob,rv) do { (ob) = (rv); goto dt_return; } while(0) + #define DTERROR(dt, mesg) (!((dt)->disc && (dt)->disc->eventf) ? 0 : \ --- src/lib/libast/include/cdt.h +++ src/lib/libast/include/cdt.h 2012-12-20 10:29:45.000000000 +0000 @@ -164,6 +164,7 @@ struct _dtstat_s diff --git a/ksh93-fdstatus.dif b/ksh93-fdstatus.dif index 375452c..2a360f1 100644 --- a/ksh93-fdstatus.dif +++ b/ksh93-fdstatus.dif @@ -1,8 +1,15 @@ -| Fix for bnc#814135, bnc#808449, and bnc#835885 -| - crash in bestreclaim() after traversing a memory block with a very large size (ksh) -| - set -k does not work properly with ksh-93t-13.17 and higher -| - Problem after update of ksh from ksh-93u-0.14.1 to ksh-93u-0.22.1 -| This is a backport from the beta version ksh93v-2013-08-29 +--- src/cmd/ksh93/bltins/enum.c ++++ src/cmd/ksh93/bltins/enum.c 2013-10-18 08:23:28.000000000 +0000 +@@ -266,7 +266,9 @@ int b_enum(int argc, char** argv, Shblti + optdisc.opt.infof = enuminfo; + optdisc.np = tp; + nv_addtype(tp, enum_type, &optdisc.opt, sizeof(optdisc)); ++ nv_onattr(np,NV_LTOU|NV_UTOL); + } ++ nv_open(0,shp->var_tree,0); + return error_info.errors != 0; + } + --- src/cmd/ksh93/bltins/read.c +++ src/cmd/ksh93/bltins/read.c 2013-09-17 15:01:33.000000000 +0000 @@ -280,24 +280,25 @@ int sh_readline(register Shell_t *shp,ch @@ -178,15 +185,27 @@ /* copy the character as is */ --- src/cmd/ksh93/edit/history.c +++ src/cmd/ksh93/edit/history.c 2013-09-13 12:00:30.000000000 +0000 -@@ -153,7 +153,7 @@ static History_t *hist_ptr; +@@ -151,9 +151,9 @@ static History_t *hist_ptr; + (unsigned)acctfd < 10) + { int n; - if((n = fcntl(acctfd, F_DUPFD, 10)) >= 0) +- if((n = fcntl(acctfd, F_DUPFD, 10)) >= 0) ++ if((n = sh_fcntl(acctfd, F_DUPFD_CLOEXEC, 10)) >= 0) { - close(acctfd); + sh_close(acctfd); acctfd = n; } } +@@ -179,7 +179,7 @@ static int sh_checkaudit(History_t *hp, + { + char *cp, *last; + int id1, id2, r=0, n, fd; +- if((fd=open(name, O_RDONLY)) < 0) ++ if((fd=open(name, O_RDONLY|O_CLOEXEC)) < 0) + return(0); + if((n = read(fd, logbuf,len-1)) < 0) + goto done; @@ -203,7 +203,7 @@ static int sh_checkaudit(History_t *hp, } while(*cp==';' || *cp==' '); @@ -196,9 +215,20 @@ return(r); } -@@ -272,14 +272,14 @@ retry: +@@ -263,23 +263,23 @@ retry: + cp = path_relative(shp,histname); + if(!histinit) + histmode = S_IRUSR|S_IWUSR; +- if((fd=open(cp,O_BINARY|O_APPEND|O_RDWR|O_CREAT,histmode))>=0) ++ if((fd=open(cp,O_BINARY|O_APPEND|O_RDWR|O_CREAT|O_CLOEXEC,histmode))>=0) + { + hsize=lseek(fd,(off_t)0,SEEK_END); + } + if((unsigned)fd <=2) + { int n; - if((n=fcntl(fd,F_DUPFD,10))>=0) +- if((n=fcntl(fd,F_DUPFD,10))>=0) ++ if((n=sh_fcntl(fd,F_DUPFD_CLOEXEC,10))>=0) { - close(fd); + sh_close(fd); @@ -213,6 +243,15 @@ hsize = 0; if(unlink(cp)>=0) goto retry; +@@ -294,7 +294,7 @@ retry: + { + if(!(fname = pathtmp(NIL(char*),0,0,NIL(int*)))) + return(0); +- fd = open(fname,O_BINARY|O_APPEND|O_CREAT|O_RDWR,S_IRUSR|S_IWUSR); ++ fd = open(fname,O_BINARY|O_APPEND|O_CREAT|O_RDWR|O_CLOEXEC,S_IRUSR|S_IWUSR); + } + } + if(fd<0) @@ -308,7 +308,7 @@ retry: for(histmask=16;histmask <= maxlines; histmask <<=1 ); if(!(hp=new_of(History_t,(--histmask)*sizeof(off_t)))) @@ -222,6 +261,19 @@ return(0); } shgd->hist_ptr = hist_ptr = hp; +@@ -383,10 +383,10 @@ retry: + hp->auditfp = 0; + if(sh_isstate(SH_INTERACTIVE) && (hp->auditmask=sh_checkaudit(hp,SHOPT_AUDITFILE, buff, sizeof(buff)))) + { +- if((fd=sh_open(buff,O_BINARY|O_WRONLY|O_APPEND|O_CREAT,S_IRUSR|S_IWUSR))>=0 && fd < 10) ++ if((fd=sh_open(buff,O_BINARY|O_WRONLY|O_APPEND|O_CREAT|O_CLOEXEC,S_IRUSR|S_IWUSR))>=0 && fd < 10) + { + int n; +- if((n = sh_fcntl(fd,F_DUPFD, 10)) >= 0) ++ if((n = sh_fcntl(fd,F_DUPFD_CLOEXEC, 10)) >= 0) + { + sh_close(fd); + fd = n; @@ -425,7 +425,7 @@ void hist_close(register History_t *hp) #if SHOPT_ACCTFILE if(acctfd) @@ -240,7 +292,23 @@ tmpname = (char*)malloc(strlen(name)+14); if(last = strrchr(name,'/')) { -@@ -736,7 +736,7 @@ again: +@@ -485,7 +485,7 @@ static History_t* hist_trim(History_t *h + free(tmpname); + tmpname = name; + } +- fd = open(tmpname,O_RDONLY); ++ fd = open(tmpname,O_RDONLY|O_CLOEXEC); + sfsetfd(hist_old->histfp,fd); + if(tmpname==name) + tmpname = 0; +@@ -730,13 +730,13 @@ again: + if(last<0) + { + char buff[HIST_MARKSZ]; +- int fd = open(hp->histname,O_RDWR); ++ int fd = open(hp->histname,O_RDWR|O_CLOEXEC); + if(fd>=0) + { hist_marker(buff,hp->histind); write(fd,(char*)hist_stamp,2); write(fd,buff,HIST_MARKSZ); @@ -249,15 +317,20 @@ } } last = 0; -@@ -1195,7 +1195,7 @@ static int hist_exceptf(Sfio_t* fp, int +@@ -1195,10 +1195,10 @@ static int hist_exceptf(Sfio_t* fp, int if(errno==ENOSPC || hp->histwfail++ >= 10) return(0); /* write failure could be NFS problem, try to re-open */ - close(oldfd=sffileno(fp)); +- if((newfd=open(hp->histname,O_BINARY|O_APPEND|O_CREAT|O_RDWR,S_IRUSR|S_IWUSR)) >= 0) + sh_close(oldfd=sffileno(fp)); - if((newfd=open(hp->histname,O_BINARY|O_APPEND|O_CREAT|O_RDWR,S_IRUSR|S_IWUSR)) >= 0) ++ if((newfd=open(hp->histname,O_BINARY|O_APPEND|O_CREAT|O_RDWR|O_CLOEXEC,S_IRUSR|S_IWUSR)) >= 0) { - if(fcntl(newfd, F_DUPFD, oldfd) !=oldfd) +- if(fcntl(newfd, F_DUPFD, oldfd) !=oldfd) ++ if(sh_fcntl(newfd, F_DUPFD_CLOEXEC, oldfd) !=oldfd) + return(-1); + fcntl(oldfd,F_SETFD,FD_CLOEXEC); + close(newfd); --- src/cmd/ksh93/include/defs.h +++ src/cmd/ksh93/include/defs.h 2013-09-13 14:19:35.000000000 +0000 @@ -160,6 +160,7 @@ struct shared @@ -277,6 +350,15 @@ int topfd; \ int savesig; \ unsigned char *sigflag; /* pointer to signal states */ \ +@@ -243,7 +246,7 @@ struct shared + char *cur_line; \ + int offsets[10]; \ + Sfio_t **sftable; \ +- unsigned char *fdstatus; \ ++ unsigned int *fdstatus; \ + const char *pwd; \ + void *jmpbuffer; \ + void *mktype; \ @@ -423,10 +426,10 @@ extern void sh_printopts(Shopt_t,int,Sh extern int sh_readline(Shell_t*,char**,volatile int,int,ssize_t,long); extern Sfio_t *sh_sfeval(char*[]); @@ -510,7 +592,21 @@ if(nq = nv_search(sub, ap->table, NV_ADD)) { if(!nq->nvfun && nq->nvalue.cp && *nq->nvalue.cp==0) -@@ -485,6 +495,7 @@ static Namfun_t *array_clone(Namval_t *n +@@ -428,10 +438,13 @@ int nv_arraysettype(Namval_t *np, Namval + nv_offattr(nq,NV_RDONLY); + if(!nv_isattr(tp,NV_BINARY)) + { ++ char *prefix = shp->prefix; + if(xtrace) + sh_offoption(SH_XTRACE); + ap->nelem &= ~ARRAY_SCAN; ++ shp->prefix = 0; + sh_eval(sh_sfeval(av),0); ++ shp->prefix = prefix; + ap->nelem |= ARRAY_SCAN; + free((void*)av[0]); + if(xtrace) +@@ -485,6 +498,7 @@ static Namfun_t *array_clone(Namval_t *n if(ap->table) { ap->table = dtopen(&_Nvdisc,Dtoset); @@ -518,7 +614,27 @@ if(ap->scope && !(flags&NV_COMVAR)) { ap->scope = ap->table; -@@ -854,7 +865,9 @@ static struct index_array *array_grow(Na +@@ -762,7 +776,10 @@ static void array_putval(Namval_t *np, c + free((void*)aq->xp); + } + if((nfp = nv_disc(np,(Namfun_t*)ap,NV_POP)) && !(nfp->nofree&1)) ++ { ++ ap = 0; + free((void*)nfp); ++ } + if(!nv_isnull(np)) + { + if(!np->nvfun) +@@ -774,7 +791,7 @@ static void array_putval(Namval_t *np, c + if(np->nvalue.cp==Empty) + np->nvalue.cp = 0; + } +- if(!string && (flags&NV_TYPE)) ++ if(!string && (flags&NV_TYPE) && ap) + array_unscope(np,ap); + } + +@@ -854,7 +871,9 @@ static struct index_array *array_grow(Na np->nvalue.cp=0; if(nv_hasdisc(np,&array_disc) || (nv_type(np) && nv_isvtree(np))) { @@ -528,7 +644,7 @@ mp = nv_search("0", ap->header.table,NV_ADD); if(mp && nv_isnull(mp)) { -@@ -1169,6 +1182,7 @@ int nv_nextsub(Namval_t *np) +@@ -1169,6 +1188,7 @@ int nv_nextsub(Namval_t *np) */ Namval_t *nv_putsub(Namval_t *np,register char *sp,register long mode) { @@ -536,7 +652,7 @@ register struct index_array *ap = (struct index_array*)nv_arrayptr(np); register int size = (mode&ARRAY_MASK); #if SHOPT_FIXEDARRAY -@@ -1180,7 +1194,6 @@ Namval_t *nv_putsub(Namval_t *np,registe +@@ -1180,7 +1200,6 @@ Namval_t *nv_putsub(Namval_t *np,registe { if(sp) { @@ -544,7 +660,7 @@ if(ap && ap->xp && !strmatch(sp,"+([0-9])")) { Namval_t *mp = nv_namptr(ap->xp,0); -@@ -1258,7 +1271,10 @@ Namval_t *nv_putsub(Namval_t *np,registe +@@ -1258,7 +1277,10 @@ Namval_t *nv_putsub(Namval_t *np,registe char *cp; Namval_t *mp; if(!ap->header.table) @@ -555,7 +671,7 @@ sfprintf(sh.strbuf,"%d",ap->cur); cp = sfstruse(sh.strbuf); mp = nv_search(cp, ap->header.table, NV_ADD); -@@ -1666,6 +1682,7 @@ int nv_aimax(register Namval_t* np) +@@ -1666,6 +1688,7 @@ int nv_aimax(register Namval_t* np) */ void *nv_associative(register Namval_t *np,const char *sp,int mode) { @@ -563,7 +679,7 @@ register struct assoc_array *ap = (struct assoc_array*)nv_arrayptr(np); register int type; switch(mode) -@@ -1674,6 +1691,7 @@ void *nv_associative(register Namval_t * +@@ -1674,6 +1697,7 @@ void *nv_associative(register Namval_t * if(ap = (struct assoc_array*)calloc(1,sizeof(struct assoc_array))) { ap->header.table = dtopen(&_Nvdisc,Dtoset); @@ -571,7 +687,7 @@ ap->cur = 0; ap->pos = 0; ap->header.hdr.disc = &array_disc; -@@ -1742,7 +1760,6 @@ void *nv_associative(register Namval_t * +@@ -1742,7 +1766,6 @@ void *nv_associative(register Namval_t * case NV_ANAME: if(ap->cur) { @@ -615,7 +731,7 @@ for(tp=name_vals;*tp->sh_name;tp++,np++) { --- src/cmd/ksh93/sh/io.c -+++ src/cmd/ksh93/sh/io.c 2013-09-17 17:08:41.000000000 +0000 ++++ src/cmd/ksh93/sh/io.c 2013-10-18 09:48:17.000000000 +0000 @@ -39,6 +39,7 @@ #include "shnodes.h" #include "history.h" @@ -624,6 +740,24 @@ #include "timeout.h" #include "FEATURE/externs" #include "FEATURE/dynamic" +@@ -407,7 +408,7 @@ int sh_iovalidfd(Shell_t *shp, int fd) + { + Sfio_t **sftable = shp->sftable; + int max,n, **fdptrs = shp->fdptrs; +- unsigned char *fdstatus = shp->fdstatus; ++ unsigned int *fdstatus = shp->fdstatus; + if(fd<0) + return(0); + if(fd < shp->gd->lim.open_max) +@@ -422,7 +423,7 @@ int sh_iovalidfd(Shell_t *shp, int fd) + if(n > max) + n = max; + max = shp->gd->lim.open_max; +- shp->sftable = (Sfio_t**)calloc((n+1)*(sizeof(int*)+sizeof(Sfio_t*)+1),1); ++ shp->sftable = (Sfio_t**)calloc((n+1)*(sizeof(int*)+sizeof(Sfio_t*)+sizeof(*fdstatus)),1); + if(max) + memcpy(shp->sftable,sftable,max*sizeof(Sfio_t*)); + shp->fdptrs = (int**)(&shp->sftable[n]); @@ -453,6 +454,8 @@ void sh_ioinit(Shell_t *shp) sfnotify(sftrack); sh_iostream(shp,0); @@ -657,7 +791,47 @@ } else if(!(iop=sfnew((fd<=2?iop:0),bp,IOBSIZE,fd,flags))) return(NIL(Sfio_t*)); -@@ -964,7 +972,7 @@ int sh_pipe(register int pv[]) +@@ -686,7 +694,10 @@ int sh_close(register int fd) + register Sfio_t *sp; + register int r = 0; + if(fd<0) ++ { ++ errno = EBADF; + return(-1); ++ } + if(fd >= shp->gd->lim.open_max) + sh_iovalidfd(shp,fd); + if(!(sp=shp->sftable[fd]) || sfclose(sp) < 0) +@@ -699,13 +710,15 @@ int sh_close(register int fd) + } + if(fd>2) + shp->sftable[fd] = 0; ++ if(r = (shp->fdstatus[fd]>>8)) ++ close(r); + shp->fdstatus[fd] = IOCLOSE; + if(shp->fdptrs[fd]) + *shp->fdptrs[fd] = -1; + shp->fdptrs[fd] = 0; + if(fd < 10) + shp->inuse_bits &= ~(1<= shp->gd->lim.open_max) + sh_iovalidfd(shp,fdold); +- if(fdold<0 || fdold>2) ++ if(fdold<0 || fdold>9) + return(fdold); +- fdnew = sh_iomovefd(dup(fdold)); ++ fdnew = sh_iomovefd(sh_fcntl(fdold,F_DUPFD,10)); + shp->fdstatus[fdnew] = (shp->fdstatus[fdold]&~IOCLEX); + close(fdold); + shp->fdstatus[fdold] = IOCLOSE; +@@ -964,7 +977,7 @@ int sh_pipe(register int pv[]) while ((r=bind (pv[out], (struct sockaddr *) &sin, slen)) == -1 && errno==EADDRINUSE); if(r<0 || listen(pv[out],5) <0) { @@ -666,7 +840,7 @@ errormsg(SH_DICT,ERROR_system(1),e_pipe); } fcntl(pv[out],F_SETFD,FD_CLOEXEC); -@@ -1079,7 +1087,7 @@ static char *io_usename(char *name, int +@@ -1079,7 +1092,7 @@ static char *io_usename(char *name, int if((fd = sh_open(name,O_RDONLY,0)) >= 0) { r = fstat(fd,&statb); @@ -675,7 +849,7 @@ if(r) return(0); if(!S_ISREG(statb.st_mode)) -@@ -1144,6 +1152,7 @@ int sh_redirect(Shell_t *shp,struct iono +@@ -1144,6 +1157,7 @@ int sh_redirect(Shell_t *shp,struct iono char *tname=0, *after="", *trace = shp->st.trap[SH_DEBUGTRAP]; Namval_t *np=0; int isstring = shp->subshell?(sfset(sfstdout,0,0)&SF_STRING):0; @@ -683,7 +857,7 @@ if(flag==2) clexec = 1; -@@ -1245,16 +1254,35 @@ int sh_redirect(Shell_t *shp,struct iono +@@ -1245,16 +1259,35 @@ int sh_redirect(Shell_t *shp,struct iono { int dupfd,toclose= -1; io_op[2] = '&'; @@ -722,7 +896,7 @@ { message = e_file; goto fail; -@@ -1267,8 +1295,23 @@ int sh_redirect(Shell_t *shp,struct iono +@@ -1267,8 +1300,23 @@ int sh_redirect(Shell_t *shp,struct iono shp->subdup |= 1<subdup &= ~(1<fdstatus[fd] = (shp->fdstatus[dupfd]&~IOCLEX); if(toclose<0 && shp->fdstatus[fd]&IOREAD) shp->fdstatus[fd] |= IODUP; -@@ -1496,7 +1553,8 @@ int sh_redirect(Shell_t *shp,struct iono +@@ -1496,7 +1558,8 @@ int sh_redirect(Shell_t *shp,struct iono if(fn>9 || !(shp->inuse_bits&(1<sftable[fn],fn); } @@ -785,7 +959,7 @@ } if(flag==3) return(fd); -@@ -1531,7 +1589,24 @@ int sh_redirect(Shell_t *shp,struct iono +@@ -1531,7 +1594,24 @@ int sh_redirect(Shell_t *shp,struct iono shp->inuse_bits |= (1<fdstatus[fd] |= IOCLEX; -@@ -2059,9 +2134,11 @@ int sh_iocheckfd(Shell_t *shp, register +@@ -1619,12 +1699,12 @@ static int io_heredoc(Shell_t *shp,regis + sfclose(infile); + } + } ++ if(traceon && !(iop->iofile&IOSTRG)) ++ sfputr(sfstderr,iop->ioname,'\n'); + /* close stream outfile, but save file descriptor */ + fd = sffileno(outfile); + sfsetfd(outfile,-1); + sfclose(outfile); +- if(traceon && !(iop->iofile&IOSTRG)) +- sfputr(sfstderr,iop->ioname,'\n'); + lseek(fd,(off_t)0,SEEK_SET); + shp->fdstatus[fd] = IOREAD; + return(fd); +@@ -2059,9 +2139,11 @@ int sh_iocheckfd(Shell_t *shp, register if(!(n&(IOSEEK|IONOSEEK))) { struct stat statb; @@ -823,7 +1012,7 @@ if(null_ino==0 && stat(e_devnull,&statb) >=0) { null_ino = statb.st_ino; -@@ -2097,6 +2174,7 @@ int sh_iocheckfd(Shell_t *shp, register +@@ -2097,6 +2179,7 @@ int sh_iocheckfd(Shell_t *shp, register n |= IONOSEEK; else n |= IOSEEK; @@ -831,7 +1020,7 @@ } if(fd==0) n &= ~IOWRITE; -@@ -2143,6 +2221,7 @@ static int io_prompt(Shell_t *shp,Sfio_t +@@ -2143,6 +2226,7 @@ static int io_prompt(Shell_t *shp,Sfio_t } #endif /* TIOCLBIC */ cp = sh_mactry(shp,nv_getval(sh_scoped(shp,PS1NOD))); @@ -863,6 +1052,15 @@ else shp->trapnote |= SH_SIGTRAP; } +@@ -646,7 +653,7 @@ void job_init(Shell_t *shp, int lflag) + return; + while(close(JOBTTY)<0 && errno==EINTR) + errno = err; +- if((fd = open(ttynam,O_RDWR)) <0) ++ if((fd = sh_open(ttynam,O_RDWR)) <0) + return; + if(fd!=JOBTTY) + sh_iorenumber(shp,fd,JOBTTY); @@ -1313,6 +1320,7 @@ int job_post(Shell_t *shp,pid_t pid, pid return(0); } @@ -914,8 +1112,17 @@ return(c); lp->lexd.nest=1; lp->lastline = shp->inlineno; +@@ -2468,7 +2468,7 @@ static int alias_exceptf(Sfio_t *iop,int + if(dp!=handle) + sfdisc(iop,dp); + } +- else if(type==SF_FINAL) ++ else if(type==SF_DPOP || type==SF_FINAL) + free((void*)ap); + goto done; + } --- src/cmd/ksh93/sh/macro.c -+++ src/cmd/ksh93/sh/macro.c 2013-09-13 18:46:30.000000000 +0000 ++++ src/cmd/ksh93/sh/macro.c 2013-10-18 09:57:39.338735235 +0000 @@ -392,7 +392,7 @@ void sh_machere(Shell_t *shp,Sfio_t *inf break; } @@ -925,7 +1132,48 @@ break; case S_EOF: if((c=fcfill()) > 0) -@@ -1166,7 +1166,7 @@ retry1: +@@ -447,6 +447,7 @@ static void copyto(register Mac_t *mp,in + int ansi_c = 0; + int paren = 0; + int ere = 0; ++ int dotdot = 0; + int brace = 0; + Sfio_t *sp = mp->sp; + Stk_t *stkp = mp->shp->stk; +@@ -846,7 +847,7 @@ e_badsubscript,*cp); + { + sfwrite(stkp,first,c); + sfputc(stkp,0); +- mp->dotdot = stktell(stkp); ++ dotdot = stktell(stkp); + cp = first = fcseek(c+2); + } + break; +@@ -854,6 +855,7 @@ e_badsubscript,*cp); + } + done: + mp->sp = sp; ++ mp->dotdot = dotdot; + mp->quote = oldquote; + } + +@@ -1010,7 +1012,6 @@ static int subcopy(Mac_t *mp, int flag) + mp->pattern = flag?4:0; + mp->arrayok=1; + mp->subcopy++; +- mp->dotdot = 0; + copyto(mp,RBRACT,0); + mp->subcopy = 0; + mp->pattern = xpattern; +@@ -1099,6 +1100,7 @@ static int varsub(Mac_t *mp) + Stk_t *stkp = mp->shp->stk; + retry1: + mp->zeros = 0; ++ mp->dotdot = 0; + idbuff[0] = 0; + idbuff[1] = 0; + c = fcmbget(&LEN); +@@ -1166,7 +1168,7 @@ retry1: case S_PAR: if(type) goto nosub; @@ -934,7 +1182,7 @@ return(1); case S_DIG: var = 0; -@@ -1349,7 +1349,7 @@ retry1: +@@ -1349,7 +1351,7 @@ retry1: ap = nv_arrayptr(np=nq); if(ap) { @@ -943,7 +1191,7 @@ v = stkptr(stkp,mp->dotdot); dolmax =1; if(array_assoc(ap)) -@@ -2077,6 +2077,18 @@ static void comsubst(Mac_t *mp,register +@@ -2077,6 +2079,18 @@ static void comsubst(Mac_t *mp,register fcrestore(&save); return; } @@ -962,32 +1210,19 @@ } else { -@@ -2158,10 +2170,22 @@ static void comsubst(Mac_t *mp,register +@@ -2158,10 +2172,9 @@ static void comsubst(Mac_t *mp,register mp->ifsp = nv_getval(np); stkset(stkp,savptr,savtop); newlines = 0; - sfsetbuf(sp,(void*)sp,0); - bufsize = sfvalue(sp); -+ if(type==3 && mp->shp->spid) -+ { -+ c = mp->shp->exitval; -+ job_wait(mp->shp->spid); -+ if(mp->shp->exitval==ERROR_NOENT) -+ { -+ mp->shp->exitval = c; -+ mp->shp->savexit=mp->shp->exitval; -+ } -+ if(mp->shp->pipepid==mp->shp->spid) -+ mp->shp->spid = 0; -+ mp->shp->pipepid = 0; -+ } /* read command substitution output and put on stack or here-doc */ sfpool(sp, NIL(Sfio_t*), SF_WRITE); + sfset(sp, SF_WRITE|SF_PUBLIC|SF_SHARE,0); sh_offstate(SH_INTERACTIVE); if((foff = sfseek(sp,(Sfoff_t)0,SEEK_END)) > 0) { -@@ -2170,6 +2194,8 @@ static void comsubst(Mac_t *mp,register +@@ -2170,6 +2183,8 @@ static void comsubst(Mac_t *mp,register stkseek(stkp,soff+foff+64); stkseek(stkp,soff); } @@ -996,7 +1231,7 @@ while((str=(char*)sfreserve(sp,SF_UNBOUND,0)) && (c=bufsize=sfvalue(sp))>0) { #if SHOPT_CRNL -@@ -2291,6 +2317,13 @@ static void mac_copy(register Mac_t *mp, +@@ -2291,6 +2306,13 @@ static void mac_copy(register Mac_t *mp, Stk_t *stkp=mp->shp->stk; int oldpat = mp->pattern; nopat = (mp->quote||(mp->assign==1)||mp->arith); @@ -1010,7 +1245,7 @@ if(mp->zeros) { /* prevent leading 0's from becomming octal constants */ -@@ -2742,7 +2775,10 @@ static char *sh_tilde(Shell_t *shp,regis +@@ -2742,7 +2764,10 @@ static char *sh_tilde(Shell_t *shp,regis skip: #endif /* _WINIX */ if(!logins_tree) @@ -1428,8 +1663,18 @@ { if(token==RPAREN && (iof&IOLSEEK) && lexp->comsub) --- src/cmd/ksh93/sh/path.c -+++ src/cmd/ksh93/sh/path.c 2013-09-17 13:49:01.000000000 +0000 -@@ -592,7 +592,7 @@ static void funload(Shell_t *shp,int fno ++++ src/cmd/ksh93/sh/path.c 2013-10-18 09:58:16.134235592 +0000 +@@ -333,7 +333,8 @@ static char *path_lib(Shell_t *shp,Pathc + char save[8]; + for( ;pp; pp=pp->next) + { +- path_checkdup(shp,pp); ++ if(!pp->dev && !pp->ino) ++ path_checkdup(shp,pp); + if(pp->ino==statb.st_ino && pp->dev==statb.st_dev && pp->mtime==statb.st_mtime) + return(pp->lib); + } +@@ -592,7 +593,7 @@ static void funload(Shell_t *shp,int fno pname = path_fullname(shp,stakptr(PATH_OFFSET)); if(shp->fpathdict && (rp = dtmatch(shp->fpathdict,(void*)pname))) { @@ -1438,7 +1683,7 @@ while(1) { rpfirst = dtprev(shp->fpathdict,rp); -@@ -613,6 +613,7 @@ static void funload(Shell_t *shp,int fno +@@ -613,6 +614,7 @@ static void funload(Shell_t *shp,int fno } while((rp=dtnext(shp->fpathdict,rp)) && strcmp(pname,rp->fname)==0); sh_close(fno); @@ -1446,7 +1691,7 @@ return; } sh_onstate(SH_NOLOG); -@@ -868,15 +869,15 @@ Pathcomp_t *path_absolute(Shell_t *shp,r +@@ -868,15 +870,15 @@ Pathcomp_t *path_absolute(Shell_t *shp,r if(isfun && f>=0 && (cp = strrchr(name,'.'))) { *cp = 0; @@ -1465,7 +1710,7 @@ f = -1; return(0); } -@@ -1408,7 +1409,7 @@ static void exscript(Shell_t *shp,regist +@@ -1408,7 +1410,7 @@ static void exscript(Shell_t *shp,regist sabuf.ac_etime = compress( (time_t)(after-before)); fd = open( SHACCT , O_WRONLY | O_APPEND | O_CREAT,RW_ALL); write(fd, (const char*)&sabuf, sizeof( sabuf )); @@ -1493,7 +1738,7 @@ { arith_error(e_recursive,ep->expr,ep->emode); --- src/cmd/ksh93/sh/subshell.c -+++ src/cmd/ksh93/sh/subshell.c 2013-09-17 15:12:00.000000000 +0000 ++++ src/cmd/ksh93/sh/subshell.c 2013-10-18 10:00:20.914235855 +0000 @@ -122,23 +122,26 @@ void sh_subtmpfile(Shell_t *shp) register struct checkpt *pp = (struct checkpt*)shp->jmplist; register struct subshell *sp = subshell_data->pipe; @@ -1534,7 +1779,15 @@ pid_t pid; char *trap = shp->st.trapcom[0]; if(trap) -@@ -213,7 +216,7 @@ void sh_subfork(void) +@@ -204,6 +207,7 @@ void sh_subfork(void) + { + /* this is the child part of the fork */ + /* setting subpid to 1 causes subshell to exit when reached */ ++ shp->cpid = 0; + sh_onstate(SH_FORKED); + sh_onstate(SH_NOLOG); + sh_offoption(SH_MONITOR); +@@ -213,7 +217,7 @@ void sh_subfork(void) shp->comsub = 0; SH_SUBSHELLNOD->nvalue.s = 0; sp->subpid=0; @@ -1543,7 +1796,7 @@ shp->savesig = 0; } } -@@ -337,7 +340,7 @@ static void nv_restore(struct subshell * +@@ -337,7 +341,7 @@ static void nv_restore(struct subshell * } nv_setsize(mp,nv_size(np)); if(!(flags&NV_MINIMAL)) @@ -1552,7 +1805,7 @@ if(!nofree) mp->nvfun = np->nvfun; if(nv_isattr(np,NV_IDENT)) -@@ -379,7 +382,7 @@ static void nv_restore(struct subshell * +@@ -379,7 +383,7 @@ static void nv_restore(struct subshell * * return pointer to alias tree * create new one if in a subshell and one doesn't exist and create is non-zero */ @@ -1561,7 +1814,7 @@ { register struct subshell *sp = subshell_data; if(!sp || sp->shp->curenv==0) -@@ -387,6 +390,7 @@ Dt_t *sh_subaliastree(int create) +@@ -387,6 +391,7 @@ Dt_t *sh_subaliastree(int create) if(!sp->salias && create) { sp->salias = dtopen(&_Nvdisc,Dtoset); @@ -1569,7 +1822,7 @@ dtview(sp->salias,sp->shp->alias_tree); sp->shp->alias_tree = sp->salias; } -@@ -397,7 +401,7 @@ Dt_t *sh_subaliastree(int create) +@@ -397,7 +402,7 @@ Dt_t *sh_subaliastree(int create) * return pointer to function tree * create new one if in a subshell and one doesn't exist and create is non-zero */ @@ -1578,7 +1831,7 @@ { register struct subshell *sp = subshell_data; if(!sp || sp->shp->curenv==0) -@@ -405,6 +409,7 @@ Dt_t *sh_subfuntree(int create) +@@ -405,6 +410,7 @@ Dt_t *sh_subfuntree(int create) if(!sp->sfun && create) { sp->sfun = dtopen(&_Nvdisc,Dtoset); @@ -1586,7 +1839,7 @@ dtview(sp->sfun,sp->shp->fun_tree); sp->shp->fun_tree = sp->sfun; } -@@ -492,6 +497,8 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_ +@@ -492,6 +498,8 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_ subenv = 0; } shp->curenv = ++subenv; @@ -1595,7 +1848,7 @@ savst = shp->st; sh_pushcontext(shp,&buff,SH_JMPSUB); subshell = shp->subshell+1; -@@ -506,6 +513,7 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_ +@@ -506,6 +514,7 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_ sp->options = shp->options; sp->jobs = job_subsave(); sp->subdup = shp->subdup; @@ -1603,7 +1856,7 @@ #if SHOPT_COSHELL sp->coshell = shp->coshell; shp->coshell = 0; -@@ -528,7 +536,9 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_ +@@ -528,7 +537,9 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_ job.curpgid = 0; sp->subshare = shp->subshare; sp->comsub = shp->comsub; @@ -1614,7 +1867,7 @@ if(comsub) shp->comsub = comsub; if(!comsub || !shp->subshare) -@@ -602,7 +612,7 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_ +@@ -602,7 +613,7 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_ sp->tmpfd = -1; sp->pipefd = -1; /* use sftmp() file for standard output */ @@ -1623,7 +1876,35 @@ { sfswap(sp->saveout,sfstdout); errormsg(SH_DICT,ERROR_system(1),e_tmpcreate); -@@ -688,19 +698,27 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_ +@@ -637,6 +648,7 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_ + sh_popcontext(shp,&buff); + if(shp->subshell==0) /* must be child process */ + { ++ shp->st.trapcom[0] = 0; + subshell_data = sp->prev; + if(jmpval==SH_JMPSCRIPT) + siglongjmp(*shp->jmplist,jmpval); +@@ -662,6 +674,19 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_ + } + else + { ++ if(comsub!=1 && shp->spid) ++ { ++ int c = shp->exitval; ++ job_wait(shp->spid); ++ if(shp->exitval==ERROR_NOENT) ++ { ++ shp->exitval = c; ++ shp->savexit=shp->exitval; ++ } ++ if(shp->pipepid==shp->spid) ++ shp->spid = 0; ++ shp->pipepid = 0; ++ } + /* move tmp file to iop and restore sfstdout */ + iop = sfswap(sfstdout,NIL(Sfio_t*)); + if(!iop) +@@ -688,19 +713,27 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_ } sfset(iop,SF_READ,1); } @@ -1655,15 +1936,27 @@ job_subrestore(sp->jobs); shp->jobenv = savecurenv; job.curpgid = savejobpgid; -@@ -776,7 +794,6 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_ +@@ -762,8 +795,6 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_ + } + else + free((void*)sp->pwd); +- if(sp->pwdclose) +- close(sp->pwdfd); + if(sp->mask!=shp->mask) + umask(shp->mask=sp->mask); + if(shp->coutpipe!=sp->coutpipe) +@@ -775,8 +806,9 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_ + shp->cpipe[1] = sp->cpipe; shp->coutpipe = sp->coutpipe; } ++ if(sp->pwdclose) ++ close(sp->pwdfd); shp->subshare = sp->subshare; - shp->comsub = sp->comsub; shp->subdup = sp->subdup; #if SHOPT_COSHELL shp->coshell = sp->coshell; -@@ -806,7 +823,12 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_ +@@ -806,7 +838,12 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_ if(nsig>0) kill(getpid(),nsig); if(sp->subpid) @@ -1677,7 +1970,7 @@ sfseek(iop,(off_t)0,SEEK_SET); if(shp->trapnote) --- src/cmd/ksh93/sh/xec.c -+++ src/cmd/ksh93/sh/xec.c 2013-09-13 18:27:02.000000000 +0000 ++++ src/cmd/ksh93/sh/xec.c 2013-10-18 10:01:45.706235404 +0000 @@ -102,26 +102,30 @@ struct funenv * temp file. */ @@ -1870,8 +2163,15 @@ if(type&FPCL) sh_close(shp->inpipe[0]); if(type&(FCOOP|FAMP)) -@@ -1733,8 +1756,8 @@ int sh_exec(register const Shnode_t *t, +@@ -1730,11 +1753,15 @@ int sh_exec(register const Shnode_t *t, + if(shp->pipepid) + shp->pipepid = parent; + else ++ { job_wait(parent); ++ if(parent==shp->spid) ++ shp->spid = 0; ++ } if(shp->topfd > topfd) sh_iorestore(shp,topfd,0); - if(usepipe && tsetio && subdup && unpipe) @@ -1881,7 +2181,7 @@ if(!sh_isoption(SH_MONITOR)) { shp->trapnote &= ~SH_SIGIGNORE; -@@ -1906,8 +1929,8 @@ int sh_exec(register const Shnode_t *t, +@@ -1906,8 +1933,8 @@ int sh_exec(register const Shnode_t *t, { was_interactive = sh_isstate(SH_INTERACTIVE); sh_offstate(SH_INTERACTIVE); @@ -1891,7 +2191,7 @@ sh_iorenumber(shp,shp->inpipe[0],0); /* * if read end of pipe is a simple command -@@ -1924,7 +1947,7 @@ int sh_exec(register const Shnode_t *t, +@@ -1924,7 +1951,7 @@ int sh_exec(register const Shnode_t *t, jmpval = sigsetjmp(buffp->buff,0); if(jmpval==0) { @@ -1900,7 +2200,7 @@ tsetio = 1; sh_redirect(shp,t->fork.forkio,execflg); (t->fork.forktre)->tre.tretyp |= t->tre.tretyp&FSHOWME; -@@ -1953,8 +1976,8 @@ int sh_exec(register const Shnode_t *t, +@@ -1953,8 +1980,8 @@ int sh_exec(register const Shnode_t *t, if(type || !sh_isoption(SH_PIPEFAIL)) shp->exitval = type; } @@ -1911,7 +2211,7 @@ shp->pipepid = 0; shp->st.ioset = 0; if(simple && was_errexit) -@@ -2179,7 +2202,7 @@ int sh_exec(register const Shnode_t *t, +@@ -2179,7 +2206,7 @@ int sh_exec(register const Shnode_t *t, } shp->exitval = n; #ifdef SIGTSTP @@ -1920,7 +2220,7 @@ tcsetpgrp(JOBTTY,shp->gd->pid); #endif /*SIGTSTP */ job.curpgid = savepgid; -@@ -2320,7 +2343,10 @@ int sh_exec(register const Shnode_t *t, +@@ -2320,7 +2347,10 @@ int sh_exec(register const Shnode_t *t, nv_putsub(np,NIL(char*),0L); nv_putval(np,cp,0); if(nameref) @@ -1931,7 +2231,7 @@ if(trap=shp->st.trap[SH_DEBUGTRAP]) { av[0] = (t->tre.tretyp&COMSCAN)?"select":"for"; -@@ -2352,6 +2378,8 @@ int sh_exec(register const Shnode_t *t, +@@ -2352,6 +2382,8 @@ int sh_exec(register const Shnode_t *t, if(shp->st.breakcnt<0) shp->st.execbrk = (++shp->st.breakcnt !=0); } @@ -1940,7 +2240,7 @@ #if SHOPT_OPTIMIZE endfor: sh_popcontext(shp,buffp); -@@ -2466,8 +2494,10 @@ int sh_exec(register const Shnode_t *t, +@@ -2466,8 +2498,10 @@ int sh_exec(register const Shnode_t *t, #if SHOPT_FILESCAN if(iop) { @@ -1952,7 +2252,7 @@ dup(savein); shp->cur_line = 0; } -@@ -2688,6 +2718,7 @@ int sh_exec(register const Shnode_t *t, +@@ -2688,6 +2722,7 @@ int sh_exec(register const Shnode_t *t, else { root = dtopen(&_Nvdisc,Dtoset); @@ -1960,7 +2260,7 @@ nv_mount(np, (char*)0, root); np->nvalue.cp = Empty; dtview(root,shp->var_base); -@@ -2729,7 +2760,7 @@ int sh_exec(register const Shnode_t *t, +@@ -2729,7 +2764,7 @@ int sh_exec(register const Shnode_t *t, np = sh_fsearch(shp,fname,NV_ADD|HASH_NOSCOPE); if(!np) #endif /* SHOPT_NAMESPACE */ @@ -1969,7 +2269,7 @@ if(npv) { if(!shp->mktype) -@@ -2745,7 +2776,7 @@ int sh_exec(register const Shnode_t *t, +@@ -2745,7 +2780,7 @@ int sh_exec(register const Shnode_t *t, stakdelete(slp->slptr); if(rp->sdict) { @@ -1978,7 +2278,7 @@ shp->last_root = rp->sdict; for(mp=(Namval_t*)dtfirst(rp->sdict);mp;mp=nq) { -@@ -2799,7 +2830,8 @@ int sh_exec(register const Shnode_t *t, +@@ -2799,7 +2834,8 @@ int sh_exec(register const Shnode_t *t, rp->np = np; if(!shp->fpathdict) shp->fpathdict = dtopen(&_Rpdisc,Dtobag); @@ -1988,7 +2288,7 @@ dtuserdata(shp->fpathdict,shp,1); dtinsert(shp->fpathdict,rp); } -@@ -2909,6 +2941,15 @@ int sh_exec(register const Shnode_t *t, +@@ -2909,6 +2945,15 @@ int sh_exec(register const Shnode_t *t, break; } } @@ -2004,7 +2304,7 @@ if(shp->trapnote || (shp->exitval && sh_isstate(SH_ERREXIT)) && t && echeck) sh_chktrap(shp); -@@ -3165,7 +3206,7 @@ pid_t _sh_fork(Shell_t *shp,register pid +@@ -3165,7 +3210,7 @@ pid_t _sh_fork(Shell_t *shp,register pid { if(shp->topfd > restorefd) sh_iorestore(shp,restorefd,0); @@ -2013,7 +2313,7 @@ } } return(parent); -@@ -3477,8 +3518,7 @@ static void sh_funct(Shell_t *shp,Namval +@@ -3477,8 +3522,7 @@ static void sh_funct(Shell_t *shp,Namval struct funenv fun; char *fname = nv_getval(SH_FUNNAMENOD); struct Level *lp =(struct Level*)(SH_LEVELNOD->nvfun); @@ -2023,7 +2323,7 @@ shp->pipepid = 0; sh_stats(STAT_FUNCT); if(!lp->hdr.disc) -@@ -3521,7 +3561,6 @@ static void sh_funct(Shell_t *shp,Namval +@@ -3521,7 +3565,6 @@ static void sh_funct(Shell_t *shp,Namval lp->maxlevel = level; SH_LEVELNOD->nvalue.s = lp->maxlevel; shp->last_root = nv_dict(DOTSHNOD); @@ -2031,7 +2331,7 @@ #if 0 nv_putval(SH_FUNNAMENOD,shp->st.funname,NV_NOFREE); #else -@@ -3626,11 +3665,11 @@ static void coproc_init(Shell_t *shp, in +@@ -3626,11 +3669,11 @@ static void coproc_init(Shell_t *shp, in sh_pipe(shp->cpipe); if((outfd=shp->cpipe[1]) < 10) { @@ -2045,7 +2345,7 @@ shp->fdstatus[outfd] = IOCLOSE; shp->cpipe[1] = fd; } -@@ -3719,7 +3758,7 @@ static int run_subshell(Shell_t *shp,con +@@ -3719,7 +3762,7 @@ static int run_subshell(Shell_t *shp,con if(!shp->gd->shpath) shp->gd->shpath = pathshell(); pid = spawnveg(shp->shpath,arglist,envlist,grp); @@ -2054,7 +2354,7 @@ for(i=3; i < 10; i++) { if(shp->fdstatus[i]&IOCLEX && i!=pin && i!=pout) -@@ -4000,7 +4039,7 @@ static pid_t sh_ntfork(Shell_t *shp,cons +@@ -4000,7 +4043,7 @@ static pid_t sh_ntfork(Shell_t *shp,cons shp->gd->shpath = pathshell(); spawnpid = path_spawn(shp,shp->gd->shpath,&argv[-1],arge,pp,(grp<<1)|1); if(fd>=0) @@ -2063,3 +2363,108 @@ argv[0] = argv[-1]; } fail: +--- src/cmd/ksh93/tests/leaks.sh ++++ src/cmd/ksh93/tests/leaks.sh 2013-10-18 10:03:59.482236116 +0000 +@@ -67,6 +67,11 @@ done + + data="(v=;sid=;di=;hi=;ti='1328244300';lv='o';id='172.3.161.178';var=(k='conn_num._total';u=;fr=;l='Number of Connections';n='22';t='number';))" + read -C stat <<< "$data" ++for ((i=0; i < 1; i++)) ++do print -r -- "$data" ++done | while read -u$n -C stat ++ do : ++ done {n}<&0- + a=0$(vmstate --format='+%(size)u') + for ((i=0; i < 500; i++)) + do print -r -- "$data" +--- src/lib/libast/include/sfio_t.h ++++ src/lib/libast/include/sfio_t.h 2013-10-11 09:22:41.000000000 +0000 +@@ -34,7 +34,7 @@ + #define _SFIO_PRIVATE \ + Sfoff_t extent; /* current file size */ \ + Sfoff_t here; /* current physical location */ \ +- unsigned char unused_1;/* unused #1 */ \ ++ unsigned char ngetr; /* sfgetr count */ \ + unsigned char tiny[1];/* for unbuffered read stream */ \ + unsigned short bits; /* private flags */ \ + unsigned int mode; /* current io mode */ \ +@@ -82,7 +82,7 @@ + (ssize_t)(-1), /* val */ \ + (Sfoff_t)0, /* extent */ \ + (Sfoff_t)0, /* here */ \ +- 0, /* getr */ \ ++ 0, /* ngetr */ \ + {0}, /* tiny */ \ + 0, /* bits */ \ + (unsigned int)(((type)&(SF_RDWR))|SF_INIT), /* mode */ \ +@@ -93,7 +93,8 @@ + (mutex), /* mutex */ \ + (Void_t*)0, /* stdio */ \ + (Sfoff_t)0, /* lpos */ \ +- (size_t)0 /* iosz */ \ ++ (size_t)0, /* iosz */ \ ++ 0 /* getr */ \ + } + + /* function to clear an Sfio_t structure */ +@@ -110,7 +111,7 @@ + (f)->val = (ssize_t)(-1), /* val */ \ + (f)->extent = (Sfoff_t)(-1), /* extent */ \ + (f)->here = (Sfoff_t)0, /* here */ \ +- (f)->getr = 0, /* getr */ \ ++ (f)->ngetr = 0, /* ngetr */ \ + (f)->tiny[0] = 0, /* tiny */ \ + (f)->bits = 0, /* bits */ \ + (f)->mode = 0, /* mode */ \ +@@ -121,7 +122,8 @@ + (f)->mutex = (mtx), /* mutex */ \ + (f)->stdio = (Void_t*)0, /* stdio */ \ + (f)->lpos = (Sfoff_t)0, /* lpos */ \ +- (f)->iosz = (size_t)0 /* iosz */ \ ++ (f)->iosz = (size_t)0, /* iosz */ \ ++ (f)->getr = 0 /* getr */ \ + ) + + /* expose next stream inside discipline function; state saved in int f */ +--- src/lib/libast/sfio/sfmode.c ++++ src/lib/libast/sfio/sfmode.c 2013-10-11 09:26:43.000000000 +0000 +@@ -258,7 +258,7 @@ reg Sfio_t* f; /* stream to close */ + #endif + { + Sfproc_t* p; +- int pid, status; ++ int status; + + if(!(p = f->proc)) + return -1; +@@ -279,7 +279,7 @@ reg Sfio_t* f; /* stream to close */ + sigcritical(SIG_REG_EXEC|SIG_REG_PROC); + #endif + status = -1; +- while ((pid = waitpid(p->pid,&status,0)) == -1 && errno == EINTR) ++ while (waitpid(p->pid,&status,0) == -1 && errno == EINTR) + ; + #if _PACKAGE_ast + status = status == -1 ? +@@ -405,12 +405,16 @@ reg int local; /* a local call */ + if(f->mode&SF_GETR) + { f->mode &= ~SF_GETR; + #ifdef MAP_TYPE +- if((f->bits&SF_MMAP) && (f->tiny[0] += 1) >= (4*SF_NMAP) ) +- { /* turn off mmap to avoid page faulting */ +- sfsetbuf(f,(Void_t*)f->tiny,(size_t)SF_UNBOUND); +- f->tiny[0] = 0; ++ if(f->bits&SF_MMAP) ++ { ++ if (!++f->ngetr) ++ f->tiny[0]++; ++ if(((f->tiny[0]<<8)|f->ngetr) >= (4*SF_NMAP) ) ++ { /* turn off mmap to avoid page faulting */ ++ sfsetbuf(f,(Void_t*)f->tiny,(size_t)SF_UNBOUND); ++ f->ngetr = f->tiny[0] = 0; ++ } + } +- else + #endif + if(f->getr) + { f->next[-1] = f->getr; diff --git a/ksh93-fs3d.dif b/ksh93-fs3d.dif new file mode 100644 index 0000000..1fffe6b --- /dev/null +++ b/ksh93-fs3d.dif @@ -0,0 +1,65 @@ +2013-10-17 10:30:20 - werner@suse.de + +Found by debugging with valgrind and environment variable LD_LIBRARY_PATH that +the mount() system call function from the glibc is used instead of a fs3d_mount() +function. To avoid this make fs3d_mount() a weak symbol to be overloadable by +a shared library function and make the stub function return -1 for not configured +file system type. + +--- src/lib/libast/misc/fs3d.c ++++ src/lib/libast/misc/fs3d.c 2013-10-17 10:30:20.000000000 +0000 +@@ -28,6 +28,20 @@ + * only active for non-shared 3d library + */ + ++#if defined(__linux__) && defined(__GNUC__) ++# if defined __USE_ISOC99 ++# define _cat_pragma(exp) _Pragma(#exp) ++# define _weak_pragma(exp) _cat_pragma(weak name) ++# else ++# define _weak_pragma(exp) ++# endif ++# define _declare(name,sym) __extension__ extern __typeof__(sym) name ++# define weak_symbol(sym) _weak_pragma(name) _declare(sym,sym) __attribute__((__weak__)) ++# include ++#else ++# define weak_symbol(sym) ++#endif ++ + #define mount ______mount + + #include +@@ -35,6 +49,7 @@ + #undef mount + + #include ++weak_symbol(fs3d_mount); + + int + fs3d(register int op) +@@ -102,11 +117,18 @@ fs3d(register int op) + * user code that includes will have mount() mapped to fs3d_mount() + * this restricts the various "standard" mount prototype conflicts to this spot + * this means that code that includes cannot access the real mount +- * (at least without some additional macro hackery ++ * (at least without some additional macro hackery) + */ + + #undef mount +- ++#if defined(__linux__) && defined(__GNUC__) ++int __attribute__((__noinline__)) ++fs3d_mount(const char* source, char* target, int flags, void* data) ++{ ++ errno = ENODEV; ++ return -1; ++} ++#else + extern int mount(const char*, char*, int, void*); + + int +@@ -114,3 +136,4 @@ fs3d_mount(const char* source, char* tar + { + return mount(source, target, flags, data); + } ++#endif diff --git a/ksh93-uninitialized.dif b/ksh93-uninitialized.dif new file mode 100644 index 0000000..dc00de6 --- /dev/null +++ b/ksh93-uninitialized.dif @@ -0,0 +1,345 @@ +--- src/cmd/builtin/pty.c ++++ src/cmd/builtin/pty.c 2013-10-10 11:38:40.722736462 +0000 +@@ -503,7 +503,7 @@ masterline(Sfio_t* mp, Sfio_t* lp, char* + char* t; + ssize_t n; + ssize_t a; +- size_t promptlen; ++ size_t promptlen = 0; + ptrdiff_t d; + char promptbuf[64]; + +@@ -773,6 +773,8 @@ dialogue(Sfio_t* mp, Sfio_t* lp, int del + !(master->buf = vmnewof(vm, 0, char, 2 * SF_BUFSIZE, 0))) + { + error(ERROR_SYSTEM|2, "out of space"); ++ id = 0; ++ line = 0; + goto done; + } + master->vm = vm; +--- src/cmd/ksh93/sh/init.c ++++ src/cmd/ksh93/sh/init.c 2013-10-10 10:44:39.762735998 +0000 +@@ -1264,7 +1264,7 @@ Shell_t *sh_init(register int argc,regis + static int beenhere; + Shell_t *shp; + register int n; +- int type; ++ int type = 0; + static char *login_files[3]; + memfatal(); + n = strlen(e_version); +@@ -1943,7 +1943,7 @@ static Dt_t *inittree(Shell_t *shp,const + register const struct shtable2 *tp; + register unsigned n = 0; + register Dt_t *treep; +- Dt_t *base_treep, *dict; ++ Dt_t *base_treep, *dict = 0; + for(tp=name_vals;*tp->sh_name;tp++) + n++; + np = (Namval_t*)calloc(n,sizeof(Namval_t)); +--- src/cmd/ksh93/sh/macro.c ++++ src/cmd/ksh93/sh/macro.c 2013-10-18 09:26:43.677203216 +0200 +@@ -1794,7 +1794,7 @@ retry2: + register int d = (mode=='@'?' ':mp->ifs); + regoff_t match[2*(MATCH_MAX+1)]; + int nmatch, nmatch_prev, vsize_last; +- char *vlast; ++ char *vlast=NULL; + while(1) + { + if(!v) +--- src/cmd/ksh93/sh/name.c ++++ src/cmd/ksh93/sh/name.c 2013-10-10 12:41:07.278235928 +0000 +@@ -1354,7 +1354,7 @@ Namval_t *nv_open(const char *name, Dt_t + const char *msg = e_varname; + char *fname = 0; + int offset = staktell(); +- Dt_t *funroot; ++ Dt_t *funroot = NIL(Dt_t*); + #if NVCACHE + struct Cache_entry *xp; + #endif +@@ -1830,7 +1830,7 @@ void nv_putval(register Namval_t *np, co + else + { + const char *tofree=0; +- int offset,append; ++ int offset=0,append; + #if _lib_pathnative + char buff[PATH_MAX]; + #endif /* _lib_pathnative */ +--- src/cmd/ksh93/sh/nvdisc.c ++++ src/cmd/ksh93/sh/nvdisc.c 2013-10-10 10:28:44.682236529 +0000 +@@ -449,7 +449,7 @@ static Sfdouble_t lookupn(Namval_t *np, + char *nv_setdisc(register Namval_t* np,register const char *event,Namval_t *action,register Namfun_t *fp) + { + register struct vardisc *vp = (struct vardisc*)np->nvfun; +- register int type; ++ register int type = -1; + char *empty = ""; + while(vp) + { +@@ -505,6 +505,8 @@ char *nv_setdisc(register Namval_t* np,r + } + return(NIL(char*)); + } ++ if (type < 0) ++ return(NIL(char*)); + /* Handle GET/SET/APPEND/UNSET disc */ + if(vp && vp->fun.disc->putval!=assign) + vp = 0; +--- src/cmd/ksh93/sh/nvtree.c ++++ src/cmd/ksh93/sh/nvtree.c 2013-10-10 10:47:16.246316669 +0000 +@@ -146,7 +146,7 @@ void *nv_diropen(Namval_t *np,const char + { + const char *last; + char *next; +- size_t c,len=strlen(name); ++ size_t c=0,len=strlen(name); + struct nvdir *save, *dp = new_of(struct nvdir,len+1); + Namval_t *nq=0,fake; + Namfun_t *nfp=0; +@@ -586,7 +586,7 @@ void nv_outnode(Namval_t *np, Sfio_t* ou + char *fmtq,*ep,*xp; + Namval_t *mp; + Namarr_t *ap = nv_arrayptr(np); +- int scan,tabs=0,c,more,associative = 0; ++ int scan=0,tabs=0,c,more,associative = 0; + int saveI = Indent; + Indent = indent; + if(ap) +@@ -699,7 +699,7 @@ void nv_outnode(Namval_t *np, Sfio_t* ou + + static void outval(char *name, const char *vname, struct Walk *wp) + { +- register Namval_t *np, *nq, *last_table=wp->shp->last_table; ++ register Namval_t *np, *nq=0, *last_table=wp->shp->last_table; + register Namfun_t *fp; + int isarray=0, special=0,mode=0; + if(*name!='.' || vname[strlen(vname)-1]==']') +--- src/cmd/ksh93/sh/nvtype.c ++++ src/cmd/ksh93/sh/nvtype.c 2013-10-10 12:33:08.394735609 +0000 +@@ -854,9 +854,10 @@ void nv_newtype(Namval_t *mp) + Namval_t *nv_mktype(Namval_t **nodes, int numnodes) + { + Namval_t *mp=nodes[0], *bp=0, *np, *nq, **mnodes=nodes; +- int i,j,k,m,n,nd=0,nref=0,iref=0,inherit=0; ++ int i,j,k,nd=0,nref=0,iref=0,inherit=0; + int size=sizeof(NV_DATA), dsize=0, nnodes; +- size_t offset=0; ++ size_t offset=0,m; ++ ssize_t n; + char *name=0, *cp, *sp, **help; + Namtype_t *pp,*qp=0,*dp,*tp; + Dt_t *root = nv_dict(mp); +@@ -869,6 +870,7 @@ Namval_t *nv_mktype(Namval_t **nodes, in + _nv_unset(nodes[0],NV_RDONLY); + errormsg(SH_DICT,ERROR_exit(1),e_badtypedef,cp); + } ++ n=strlen(nodes[1]->nvname); + for(nnodes=1,i=1; i childfun.fun, NV_LAST); + if(tp = (Namtype_t*)nv_hasdisc(nq, &type_disc)) + tp->strsize = -tp->strsize; +-else sfprintf(sfstderr,"tp==NULL\n"); + for(r=0; r < dp->numnodes; r++) + { + Namval_t *nr = nv_namptr(dp->nodes,r); +--- src/cmd/ksh93/sh/parse.c ++++ src/cmd/ksh93/sh/parse.c 2013-10-10 12:48:37.786235751 +0000 +@@ -301,7 +301,7 @@ static Shnode_t *getanode(Lex_t *lp, str + */ + static Shnode_t *makelist(Lex_t *lexp, int type, Shnode_t *l, Shnode_t *r) + { +- register Shnode_t *t; ++ register Shnode_t *t = NIL(Shnode_t*); + if(!l || !r) + sh_syntax(lexp); + else +@@ -742,7 +742,7 @@ static Shnode_t *funct(Lex_t *lexp) + register Shnode_t *t; + register int flag; + struct slnod *volatile slp=0; +- Stak_t *savstak; ++ Stak_t *savstak = NIL(Stak_t*); + Sfoff_t first, last; + struct functnod *volatile fp; + Sfio_t *iop; +@@ -815,7 +815,7 @@ static Shnode_t *funct(Lex_t *lexp) + { + struct comnod *ac; + char *cp, **argv, **argv0; +- int c; ++ 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); +--- src/cmd/ksh93/sh/xec.c ++++ src/cmd/ksh93/sh/xec.c 2013-10-10 11:14:41.530735559 +0000 +@@ -1505,7 +1505,7 @@ int sh_exec(register const Shnode_t *t, + Namval_t node; + #endif /* SHOPT_NAMESPACE */ + struct Namref nr; +- long mode; ++ long mode = 0; + register struct slnod *slp; + if(!np->nvalue.ip) + { +@@ -1910,8 +1910,8 @@ int sh_exec(register const Shnode_t *t, + * don't create a new process, just + * save and restore io-streams + */ +- pid_t pid; +- int jmpval, waitall; ++ pid_t pid = 0; ++ int jmpval, waitall = 0; + int simple = (t->fork.forktre->tre.tretyp&COMMSK)==TCOM; + struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt)); + #if SHOPT_COSHELL +@@ -2403,7 +2403,7 @@ int sh_exec(register const Shnode_t *t, + Shnode_t *tt = t->wh.whtre; + #if SHOPT_FILESCAN + Sfio_t *iop=0; +- int savein; ++ int savein=-1; + #endif /*SHOPT_FILESCAN*/ + #if SHOPT_OPTIMIZE + int jmpval = ((struct checkpt*)shp->jmplist)->mode; +@@ -2872,7 +2872,7 @@ int sh_exec(register const Shnode_t *t, + else + { + register int traceon=0; +- register char *right; ++ register char *right = 0; + register char *trap; + char *argv[6]; + n = type>>TSHIFT; +@@ -2906,7 +2906,7 @@ int sh_exec(register const Shnode_t *t, + } + else if(type&TBINARY) + { +- char *op; ++ char *op = 0; + int pattern = 0; + if(trap || traceon) + op = (char*)(shtab_testops+(n&037)-1)->sh_name; +@@ -3371,7 +3371,7 @@ int sh_funscope(int argn, char *argv[],i + int jmpval; + volatile int r = 0; + int n; +- char *savstak; ++ char *savstak = 0; + struct funenv *fp = 0; + struct checkpt *buffp = (struct checkpt*)stkalloc(shp->stk,sizeof(struct checkpt)); + Namval_t *nspace = shp->namespace; +@@ -3487,10 +3487,10 @@ int sh_funscope(int argn, char *argv[],i + shp->st = *prevscope; + shp->topscope = (Shscope_t*)prevscope; + nv_getval(sh_scoped(shp,IFSNOD)); +- if(nsig) ++ if(nsig && savstak) + memcpy((char*)&shp->st.trapcom[0],savstak,nsig); + shp->trapnote=0; +- if(nsig) ++ if(nsig && savstak) + stakset(savstak,0); + shp->options = options; + shp->last_root = last_root; +@@ -3579,11 +3579,11 @@ static void sh_funct(Shell_t *shp,Namval + int sh_fun(Namval_t *np, Namval_t *nq, char *argv[]) + { + Shell_t *shp = sh_getinterp(); +- register int offset; ++ register int offset = 0; + register char *base; + Namval_t node; + struct Namref nr; +- long mode; ++ long mode = 0; + char *prefix = shp->prefix; + int n=0; + char *av[3]; +--- src/lib/libast/sfio/sfstrtof.h ++++ src/lib/libast/sfio/sfstrtof.h 2013-10-10 10:03:43.826235847 +0000 +@@ -211,8 +211,8 @@ S2F_function(str, end) char* str; char** + int decimal = 0; + int thousand = 0; + int part = 0; +- int back_part; +- S2F_batch back_n; ++ int back_part = 0; ++ S2F_batch back_n = 0; + S2F_number v; + S2F_number p; + S2F_part_t parts[16]; +--- src/lib/libast/sfio/sftable.c ++++ src/lib/libast/sfio/sftable.c 2013-10-10 10:08:26.026235628 +0000 +@@ -53,7 +53,7 @@ int type; /* >0: scanf, =0: printf, -1: + #endif + { + int base, fmt, flags, dot, width, precis; +- ssize_t n_str, size; ++ ssize_t n_str, size = 0; + char *t_str, *sp; + int v, n, skip, dollar, decimal, thousand; + Sffmt_t savft; +--- src/lib/libast/sfio/sfvprintf.c ++++ src/lib/libast/sfio/sfvprintf.c 2013-10-10 10:12:04.314277467 +0000 +@@ -101,7 +101,7 @@ char* form; /* format to use */ + va_list args; /* arg list if !argf */ + #endif + { +- int n, v, w, k, n_s, base, fmt, flags; ++ int n, v=0, w, k, n_s, base, fmt, flags; + Sflong_t lv; + char *sp, *ssp, *endsp, *ep, *endep; + int dot, width, precis, sign, decpt; +@@ -129,7 +129,7 @@ va_list args; /* arg list if !argf */ + int decimal = 0, thousand = 0; + + #if _has_multibyte +- wchar_t* wsp; ++ wchar_t* wsp = 0; + SFMBDCL(fmbs) /* state of format string */ + SFMBDCL(mbs) /* state of some string */ + #ifdef mbwidth +--- src/lib/libast/string/stropt.c ++++ src/lib/libast/string/stropt.c 2013-10-10 10:01:38.546735312 +0000 +@@ -60,13 +60,13 @@ stropt(const char* as, const void* tab, + register char* v; + register char* t; + char** p; +- char* u; ++ char* u = 0; + char* x; + char* e; + int n; + int ql; + int qr; +- int qc; ++ int qc = 0; + + if (!as) n = 0; + else if (!(x = s = strdup(as))) n = -1; +--- src/lib/libast/string/strtoi.h ++++ src/lib/libast/string/strtoi.h 2013-10-10 10:06:02.038735810 +0000 +@@ -230,13 +230,13 @@ S2I_function(a, e, base) const char* a; + #endif + register S2I_unumber n; + register S2I_unumber x; +- register int c; ++ register int c = 0; + register int shift; + register unsigned char* p; + register unsigned char* cv; + unsigned char* b; + unsigned char* k; +- S2I_unumber v; ++ S2I_unumber v = 0; + #if S2I_multiplier + register int base; + #endif