Accepting request 74013 from shells

- Fix off by one error which should make timetype.sh work now
- Update the array fix as well as the pipe fix
- This also fixes bnc#677790

- Avoid redirection in subshell if an eval was used (bnc#697394)

- Extend Shift.JIS patch to avoid breakage of the parsers above
- Avoid mounting 3D file system as this does not exist on linux

OBS-URL: https://build.opensuse.org/request/show/74013
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/ksh?expand=0&rev=62
This commit is contained in:
Sascha Peilicke 2011-06-17 13:26:05 +00:00 committed by Git OBS Bridge
commit 5bf5bb85a9
8 changed files with 380 additions and 47 deletions

View File

@ -1,3 +1,21 @@
-------------------------------------------------------------------
Tue Jun 14 11:36:28 UTC 2011 - werner@suse.de
- Fix off by one error which should make timetype.sh work now
- Update the array fix as well as the pipe fix
- This also fixes bnc#677790
-------------------------------------------------------------------
Fri Jun 10 19:11:07 CEST 2011 - werner@suse.de
- Avoid redirection in subshell if an eval was used (bnc#697394)
-------------------------------------------------------------------
Wed Jun 8 15:14:46 CEST 2011 - werner@suse.de
- Extend Shift.JIS patch to avoid breakage of the parsers above
- Avoid mounting 3D file system as this does not exist on linux
-------------------------------------------------------------------
Wed Jun 1 11:23:03 CEST 2011 - werner@suse.de

View File

@ -75,6 +75,8 @@ Patch20: ksh93-argv0.dif
Patch21: ksh93-export.dif
Patch22: ksh93-eintr.dif
Patch23: ksh93-array.dif
Patch24: ksh93-pipe.dif
Patch25: ksh93-argv.dif
%global use_suid_exe 0
%global use_locale 1
%global debug_memleak 0
@ -149,11 +151,11 @@ find share/ -type d -a -empty | xargs -r rm -vrf
%patch21
%patch22
%patch23
%patch24
%patch25
%build
TMPDIR=$(mktemp -d /tmp/ksh-build.XXXXXX) || exit 1
mkdir ${TMPDIR}/bin || exit 1
PATH=${TMPDIR}/bin:$PATH
typeset -i IGNORED=0x$(ps --no-headers -o ignored $$)
typeset -i SIGPIPE=0x1000
if ((IGNORED & SIGPIPE)) ; then
@ -243,6 +245,7 @@ find share/ -type d -a -empty | xargs -r rm -vrf
feature=${TMPDIR:-/tmp}/feature.h
set -C
(cat > $feature)<<-'EOF'
#define SHOPT_FS_3D 0
#define SHOPT_SYSRC 1
#define SHOPT_REMOTE 1
#define SHOPT_CMDLIB_BLTIN 1
@ -257,32 +260,40 @@ find share/ -type d -a -empty | xargs -r rm -vrf
cat $feature
#
#
echo 'int main () { return !(sizeof(void*) >= 8); }' | $CC -x c -o test64 -
if ./test64 ; then
LARGEFILE=""
else
LARGEFILE="-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64"
fi
rm -f ./test64
case "$RPM_ARCH" in
ia64) RPM_OPT_FLAGS="${RPM_OPT_FLAGS//-O[s0-9]/-O}" ;;
s390*) RPM_OPT_FLAGS="${RPM_OPT_FLAGS//-O[s0-9]/-O}" ;;
ppc*|powerpc*)
RPM_OPT_FLAGS="${RPM_OPT_FLAGS//-O[s0-9]/-O}" ;;
esac
LARGEFILE="$(getconf LFS_CFLAGS)"
case "$RPM_ARCH" in
i[3456]86)
RPM_OPT_FLAGS="${RPM_OPT_FLAGS//-O[s0-9]/-O2} -m32"
HOSTTYPE=linux.i386
;;
x86_64)
RPM_OPT_FLAGS="${RPM_OPT_FLAGS//-O[s0-9]/-O2} -m64"
HOSTTYPE=linux.i386-64
;;
ia64)
RPM_OPT_FLAGS="${RPM_OPT_FLAGS//-O[s0-9]/-O}"
HOSTTYPE=linux.ia64
;;
s390)
RPM_OPT_FLAGS="${RPM_OPT_FLAGS//-O[s0-9]/-O} -m31"
HOSTTYPE=linux.s390
;;
s390*)
RPM_OPT_FLAGS="${RPM_OPT_FLAGS//-O[s0-9]/-O} -m64"
HOSTTYPE=linux.s390-64
;;
ppc|powerpc)
set -C
(cat > ${TMPDIR:-/tmp}/gcc)<<-EOF
#!/bin/sh
case "$@" in
*-dumpmachine*)
echo powerpc-suse-linux ;;
*) exec -a gcc gcc ${1+"$@"}
esac
EOF
set +C
chmod +x ${TMPDIR:-/tmp}/gcc
RPM_OPT_FLAGS="${RPM_OPT_FLAGS//-O[s0-9]/-O} -mno-powerpc64"
HOSTTYPE=linux.powerpc
;;
ppc64|powerpc64)
RPM_OPT_FLAGS="${RPM_OPT_FLAGS//-O[s0-9]/-O} -mpowerpc64"
HOSTTYPE=linux.powerpc64
;;
*)
RPM_OPT_FLAGS="${RPM_OPT_FLAGS//-O[s0-9]/-O}"
HOSTTYPE=linux.$RPM_ARCH
;;
esac
RPM_OPT_FLAGS=$(echo "${RPM_OPT_FLAGS}"|sed -r 's/[[:blank:]]+-g[0-9]?/ -g2/g')
UNIVERSE=att
@ -305,7 +316,6 @@ find share/ -type d -a -empty | xargs -r rm -vrf
cflags -Wl,-rpath,/%{_lib}/ast LDSOFLG
RPM_OPT_FLAGS="$RPM_OPT_FLAGS -D_GNU_SOURCE $LARGEFILE"
RPM_OPT_FLAGS="$RPM_OPT_FLAGS $IGNORE $FEATURE"
HOSTTYPE=linux.${RPM_ARCH}
mam_cc_L=use
mam_cc_OPTIMIZE=-pipe
export mam_cc_L mam_cc_OPTIMIZE HOSTTYPE LDFLAGS RPM_OPT_FLAGS UNIVERSE

20
ksh93-argv.dif Normal file
View File

@ -0,0 +1,20 @@
--- src/cmd/ksh93/sh/xec.c
+++ src/cmd/ksh93/sh/xec.c 2011-06-14 13:31:32.471925963 +0200
@@ -2914,7 +2914,7 @@ int sh_fun(Namval_t *np, Namval_t *nq, c
long mode;
char *prefix = shp->prefix;
int n=0;
- char *av[2];
+ char *av[3];
Fcin_t save;
fcsave(&save);
if((offset=staktell())>0)
@@ -2922,7 +2922,7 @@ int sh_fun(Namval_t *np, Namval_t *nq, c
shp->prefix = 0;
if(!argv)
{
- argv = av;
+ argv = av+1;
argv[1]=0;
}
argv[0] = nv_name(np);

View File

@ -49,3 +49,14 @@
{
if((ap->header.nelem&ARRAY_NOCHILD) && nv_isattr(ap->cur,NV_CHILD))
continue;
--- src/cmd/ksh93/sh/xec.c
+++ src/cmd/ksh93/sh/xec.c 2011-06-14 13:31:32.471925963 +0200
@@ -680,7 +680,7 @@ static int set_instance(Shell_t *shp,Nam
char *sp=0,*cp;
Namarr_t *ap;
Namval_t *np;
- if(!nv_isattr(nq,NV_MINIMAL|NV_EXPORT) && (np=(Namval_t*)nq->nvenv) && nv_isarray(np))
+ if(!nv_isattr(nq,NV_MINIMAL|NV_EXPORT|NV_ARRAY) && (np=(Namval_t*)nq->nvenv) && nv_isarray(np))
nq = np;
cp = nv_name(nq);
memset(nr,0,sizeof(*nr));

View File

@ -47,17 +47,6 @@
}
/*
--- src/cmd/ksh93/sh/subshell.c
+++ src/cmd/ksh93/sh/subshell.c 2011-04-29 15:34:13.747926082 +0200
@@ -235,7 +235,7 @@
if(!sp->shpwd || np==SH_LEVELNOD || np==L_ARGNOD || np==SH_SUBSCRNOD || np==SH_NAMENOD)
return(np);
/* don't bother to save if in newer scope */
- if(sp->var!=shp->var_tree && sp->var!=shp->var_base && shp->last_root==shp->var_tree)
+ if(sp->var!=shp->var_tree && shp->last_root==shp->var_tree)
return(np);
if((ap=nv_arrayptr(np)) && (mp=nv_opensub(np)))
{
--- src/cmd/ksh93/sh/xec.c
+++ src/cmd/ksh93/sh/xec.c 2011-05-03 15:02:23.411926136 +0200
@@ -53,6 +53,7 @@

188
ksh93-pipe.dif Normal file
View File

@ -0,0 +1,188 @@
--- src/cmd/ksh93/include/defs.h
+++ src/cmd/ksh93/include/defs.h 2011-06-10 17:37:22.852426230 +0200
@@ -154,7 +154,7 @@ struct limits
pid_t bckpid; /* background process id */ \
pid_t cpid; \
pid_t pipepid; \
- int32_t ppid; /* parent process id of shell */ \
+ pid_t ppid; /* parent process id of shell */ \
int topfd; \
int sigmax; /* maximum number of signals */ \
int savesig; \
--- src/cmd/ksh93/sh/io.c
+++ src/cmd/ksh93/sh/io.c 2011-06-10 18:13:02.511926423 +0200
@@ -1076,15 +1076,18 @@ int sh_redirect(Shell_t *shp,struct iono
message = e_file;
goto fail;
}
- if(shp->subshell && dupfd==1 && (sfset(sfstdout,0,0)&SF_STRING))
+ if(shp->subshell && dupfd==1)
{
if(sfset(sfstdout,0,0)&SF_STRING)
sh_subtmpfile(shp);
- shp->subdup |= 1<< fn;
+ if(shp->comsub==1)
+ shp->subdup |= 1<< fn;
dupfd = sffileno(sfstdout);
}
else if(shp->sftable[dupfd])
sfsync(shp->sftable[dupfd]);
+ if(dupfd!=1 && fn < 10)
+ shp->subdup &= ~(1<<fn);
}
else if(fd=='-' && fname[1]==0)
{
--- src/cmd/ksh93/sh/xec.c
+++ src/cmd/ksh93/sh/xec.c 2011-06-10 18:09:32.396425650 +0200
@@ -86,10 +86,11 @@ struct funenv
* temp file.
*/
static int subpipe[3] = {-1};
-static int subdup;
+static int subdup,tsetio,usepipe;
static void iousepipe(Shell_t *shp)
{
int i;
+ usepipe++;
fcntl(subpipe[0],F_SETFD,FD_CLOEXEC);
subpipe[2] = fcntl(1,F_DUPFD,10);
shp->fdstatus[subpipe[2]] = shp->fdstatus[1];
@@ -112,6 +113,7 @@ static void iounpipe(Shell_t *shp)
{
int n;
char buff[SF_BUFSIZE];
+ usepipe = 0;
close(1);
fcntl(subpipe[2], F_DUPFD, 1);
shp->fdstatus[1] = shp->fdstatus[subpipe[2]];
@@ -135,6 +137,7 @@ static void iounpipe(Shell_t *shp)
}
sh_close(subpipe[0]);
subpipe[0] = -1;
+ tsetio = 0;
}
/*
@@ -533,8 +536,10 @@ int sh_eval(register Sfio_t *iop, int mo
static Sfio_t *io_save;
volatile int traceon=0, lineno=0;
int binscript=shp->binscript;
+ char comsub = shp->comsub;
io_save = iop; /* preserve correct value across longjmp */
shp->binscript = 0;
+ shp->comsub = 0;
#define SH_TOPFUN 0x8000 /* this is a temporary tksh hack */
if (mode & SH_TOPFUN)
{
@@ -573,6 +578,7 @@ int sh_eval(register Sfio_t *iop, int mo
break;
}
sh_popcontext(&buff);
+ shp->comsub = comsub;
shp->binscript = binscript;
if(traceon)
sh_onoption(SH_XTRACE);
@@ -1245,13 +1251,16 @@ int sh_exec(register const Shnode_t *t,
{
register pid_t parent;
int no_fork,jobid;
- int pipes[2];
+ int pipes[3];
if(shp->subshell)
{
sh_subtmpfile(shp);
- subpipe[0] = -1;
- if(shp->comsub==1 && !(shp->fdstatus[1]&IONOSEEK) && sh_pipe(subpipe)>=0)
- iousepipe(shp);
+ if(!usepipe)
+ {
+ subpipe[0] = -1;
+ if(shp->comsub==1 && !(shp->fdstatus[1]&IONOSEEK) && sh_pipe(subpipe)>=0)
+ iousepipe(shp);
+ }
if((type&(FAMP|TFORK))==(FAMP|TFORK))
sh_subfork();
}
@@ -1291,7 +1300,10 @@ int sh_exec(register const Shnode_t *t,
#endif /* SHOPT_BGX */
nv_getval(RANDNOD);
if(type&FCOOP)
+ {
+ pipes[2] = 0;
coproc_init(shp,pipes);
+ }
#if SHOPT_AMP
if((type&(FAMP|FINT)) == (FAMP|FINT))
parent = sh_ntfork(shp,t,com,&jobid,ntflag);
@@ -1353,6 +1365,8 @@ int sh_exec(register const Shnode_t *t,
shp->pipepid = parent;
else
job_wait(parent);
+ if(usepipe && tsetio && subdup)
+ iounpipe(shp);
if(!sh_isoption(SH_MONITOR))
{
shp->trapnote &= ~SH_SIGIGNORE;
@@ -1496,6 +1510,8 @@ int sh_exec(register const Shnode_t *t,
jmpval = sigsetjmp(buff.buff,0);
if(jmpval==0)
{
+ if(shp->comsub==1)
+ tsetio = 1;
sh_redirect(shp,t->fork.forkio,execflg);
(t->fork.forktre)->tre.tretyp |= t->tre.tretyp&FSHOWME;
sh_exec(t->fork.forktre,flags&~simple);
@@ -1523,6 +1539,8 @@ int sh_exec(register const Shnode_t *t,
if(type || !sh_isoption(SH_PIPEFAIL))
shp->exitval = type;
}
+ if(shp->comsub==1 && subpipe[0]>=0)
+ iounpipe(shp);
shp->pipepid = 0;
shp->st.ioset = 0;
if(simple && was_errexit)
@@ -1580,14 +1598,22 @@ int sh_exec(register const Shnode_t *t,
* All elements of the pipe are started by the parent.
* The last element executes in current environment
*/
- int pvo[2]; /* old pipe for multi-stage */
- int pvn[2]; /* current set up pipe */
+ int pvo[3]; /* old pipe for multi-stage */
+ int pvn[3]; /* current set up pipe */
int savepipe = pipejob;
int showme = t->tre.tretyp&FSHOWME;
pid_t savepgid = job.curpgid;
job.curpgid = 0;
if(shp->subshell)
+ {
sh_subtmpfile(shp);
+ if(!usepipe)
+ {
+ subpipe[0] = -1;
+ if(shp->comsub==1 && !(shp->fdstatus[1]&IONOSEEK) && sh_pipe(subpipe)>=0)
+ iousepipe(shp);
+ }
+ }
shp->inpipe = pvo;
shp->outpipe = pvn;
pvo[1] = -1;
@@ -2543,7 +2569,10 @@ pid_t _sh_fork(register pid_t parent,int
if(jobid)
*jobid = myjob;
if(shp->comsub==1 && subpipe[0]>=0)
- iounpipe(shp);
+ {
+ if(!tsetio || !subdup)
+ iounpipe(shp);
+ }
return(parent);
}
#if !_std_malloc
@@ -2602,6 +2631,7 @@ pid_t _sh_fork(register pid_t parent,int
if(sig>0)
sh_fault(sig);
sh_sigcheck();
+ usepipe=0;
return(0);
}

View File

@ -116,17 +116,110 @@
else
{
--- src/cmd/ksh93/sh/macro.c
+++ src/cmd/ksh93/sh/macro.c 2007-12-20 17:50:28.000000000 +0000
@@ -2079,7 +2079,7 @@
+++ src/cmd/ksh93/sh/macro.c 2011-06-10 08:20:29.451926367 +0000
@@ -51,6 +51,8 @@
#if !SHOPT_MULTIBYTE
#define mbchar(p) (*(unsigned char*)p++)
+#else
+#define mb2wc(w,p,n) (*ast.mb_towc)(&w,(char*)p,n)
#endif
static int _c_;
@@ -494,7 +496,7 @@ static void copyto(register Mac_t *mp,in
int i;
unsigned char mb[8];
- n = wctomb((char*)mb, c);
+ n = mbconv((char*)mb, c);
for(i=0;i<n;i++)
sfputc(stkp,mb[i]);
}
@@ -1908,6 +1910,9 @@ static void comsubst(Mac_t *mp,register
struct _mac_ savemac;
int savtop = stktell(stkp);
char lastc, *savptr = stkfreeze(stkp,0);
+#if SHOPT_MULTIBYTE
+ wchar_t lastw;
+#endif
int was_history = sh_isstate(SH_HISTORY);
int was_verbose = sh_isstate(SH_VERBOSE);
int was_interactive = sh_isstate(SH_INTERACTIVE);
@@ -2025,6 +2030,9 @@ static void comsubst(Mac_t *mp,register
stkset(stkp,savptr,savtop);
newlines = 0;
lastc = 0;
+#if SHOPT_MULTIBYTE
+ lastw = 0;
+#endif
sfsetbuf(sp,(void*)sp,0);
bufsize = sfvalue(sp);
/* read command substitution output and put on stack or here-doc */
@@ -2075,6 +2083,17 @@ static void comsubst(Mac_t *mp,register
}
else if(lastc)
{
+#if SHOPT_MULTIBYTE
+ if(lastw)
+ {
+ int n;
+ char mb[8];
+ n = mbconv(mb, lastw);
+ mac_copy(mp,mb,n);
+ lastw = 0;
+ }
+ else
+#endif
mac_copy(mp,&lastc,1);
lastc = 0;
}
newlines = nextnewlines;
- if(++c < bufsize)
+ if(c++ < bufsize)
@@ -2083,8 +2102,22 @@ static void comsubst(Mac_t *mp,register
str[c] = 0;
else
{
@@ -2167,13 +2167,13 @@ static void mac_copy(register Mac_t *mp,
+ ssize_t len = 1;
+
/* can't write past buffer so save last character */
- lastc = str[--c];
+#if SHOPT_MULTIBYTE
+ if ((len = mbsize(str))>1)
+ {
+ len = mb2wc(lastw,str,len);
+ if (len < 0)
+ {
+ lastw = 0;
+ len = 1;
+ }
+ }
+#endif
+ c -= len;
+ lastc = str[c];
str[c] = 0;
}
mac_copy(mp,str,c);
@@ -2102,7 +2135,21 @@ static void comsubst(Mac_t *mp,register
sfnputc(stkp,'\n',newlines);
}
if(lastc)
+ {
+#if SHOPT_MULTIBYTE
+ if(lastw)
+ {
+ int n;
+ char mb[8];
+ n = mbconv(mb, lastw);
+ mac_copy(mp,mb,n);
+ lastw = 0;
+ }
+ else
+#endif
mac_copy(mp,&lastc,1);
+ lastc = 0;
+ }
sfclose(sp);
return;
}
@@ -2173,13 +2220,13 @@ static void mac_copy(register Mac_t *mp,
if(mp->pattern)
{
char *sp = "&|()";
@ -163,8 +256,8 @@
#if SHOPT_MULTIBYTE
int len;
--- src/cmd/ksh93/tests/sjis.sh
+++ src/cmd/ksh93/tests/sjis.sh 2007-12-20 17:50:28.000000000 +0000
@@ -0,0 +1,63 @@
+++ src/cmd/ksh93/tests/sjis.sh 2011-05-20 17:11:28.623926368 +0200
@@ -0,0 +1,67 @@
+########################################################################
+# #
+# Copyright (c) 2007 SuSE Linux Products GmbH, Nuernberg, Germany #
@ -207,11 +300,15 @@
+ mbchar="$(printf "\x81\x${second}")"
+ if test -z "${mbchar}" ; then
+ let err++ # ERROR in builtin printf
+ echo ' builtin printf with \\x81\\x'${second} failed as result is empty
+ continue
+ fi
+ if test -x "${printf}" ; then
+ if test $(${printf} "\x81\x${second}") != ${mbchar} ; then
+ let err++ # ERROR in builtin printf
+ echo -n ' \\x81\\x'${second} 'failed with '
+ echo -n $(${printf} "\x81\x${second}") '!= '
+ echo ${mbchar}
+ continue
+ fi
+ fi

View File

@ -239,7 +239,7 @@
foo() { return 0; }
trap foo EXIT
- { sleep 2; kill -$exp \$\$; sleep 3; kill -0 \$\$ && kill -KILL \$\$; } &
+ { sleep 2; kill -$exp \$\$; sleep 4; kill -0 \$\$ && kill -KILL \$\$; } &
+ { sleep 2; kill -$exp \$\$; sleep 6; kill -0 \$\$ && kill -KILL \$\$; } &
$yes | while read yes; do
- (/bin/date; sleep .1)
+ (/bin/date; sleep .05)