On Fri, Sep 7, 2012 at 3:14 PM, Irek Szczesniak <iszczesn...@gmail.com> wrote: > On Fri, Sep 7, 2012 at 2:53 PM, Irek Szczesniak <iszczesn...@gmail.com> wrote: >> On Fri, Sep 7, 2012 at 1:47 PM, Irek Szczesniak <iszczesn...@gmail.com> >> wrote: >>> David, I've tried the new ast-ksh.20120831 yesterday and hit these >>> errors when running the alias.sh tests on Solaris 11: >>> ./src/cmd/ksh93/tests/shtests: line 307: write to 1 failed [Bad file number] >>> ./src/cmd/ksh93/tests/shtests: line 307: open file limit exceeded [Bad >>> file number] >>> >>> truss reports that the fd 1 is closed immediately after the open() in >>> the shtests process (the process running alias.sh is not involved): >>> 23914: >>> open("/home/irek/work/ksh/astksh20120831/build/arch/sol11.i386-64/src/cmd/ksh93/.paths", >>> O_RDONLY) Err#2 ENOENT >>> 23914: open("/bin/.paths", O_RDONLY) Err#2 ENOENT >>> 23914: close(12) = 0 >>> 23914: close(1) = 0 >>> 23914: open("/tmp/test001/sf34.c85", O_RDWR|O_CREAT|O_EXCL, 0666) = 1 >>> 23914: close(1) = 0 >>> 23914: close(4) = 0 >>> 23914: close(1) = 0 >>> 23914: read(3, " 2 4\n", 8192) = 3 >>> 23914: read(3, 0xFFFFFD7FFFDFB490, 8192) = 0 >>> 23914: close(3) = 0 >>> 23914: open("/usr/lib/locale/en_US.UTF-8/LC_MESSAGES/SUNW_OST_OSLIB.mo", >>> O_RDONLY) Err#2 ENOENT >>> 23914: write(1, " 2 4\n", 3) Err#9 EBADF >>> 23914: write(2, " . / s r c / c m d / k s".., 77) = 77 >>> 23914: close(11) = 0 >>> >>> Any quick or dirty cure would be appreciated. >> >> I can't reproduce the problem with ast-ksh.20120824. > > This fails: > ./arch/sol11.i386\-64/bin/ksh -c 'x=$( /bin/true ; true ; )'' > ./arch/sol11.i386-64/bin/ksh: open file limit exceeded [Bad file number] > > This does not fail: > ./arch/sol11.i386\-64/bin/ksh -c 'x=${ /bin/true ; true ; }'' > > truss reports some suspicious syscalls: > fcntl(1, 4294967197, 0x0000000A) Err#22 EINVAL > fcntl(4294967295, F_SETFD, 0x00000001) Err#9 EBADF > close(1) = 0 > > My guess is that the new emulation for F_DUPFD_CLOEXEC is not > intercepted properly. > > OS is Opensolaris 2011.05 (an early version of Solaris 11), which > didn't have F_DUPFD_CLOEXEC
Patch below. src/lib/libast/misc/procopen.c still has an unresolved "if ((m->save = fcntl(arg2, F_dupfd_cloexec, 3)) < 0" and there are numerous cases of sh_fcntl(fd,F_dupfd_cloexec,...) followed by fcntl(fd,F_SETFD,FD_CLOEXEC) diff -r -u src/cmd/ksh93/edit/history.c src/cmd/ksh93/edit/history.c --- src/cmd/ksh93/edit/history.c Tue Aug 28 15:58:07 2012 +++ src/cmd/ksh93/edit/history.c Fri Sep 7 15:22:37 2012 @@ -151,7 +151,7 @@ (unsigned)acctfd < 10) { int n; - if((n = fcntl(acctfd, F_dupfd_cloexec, 10)) >= 0) + if((n = sh_fcntl(acctfd, F_dupfd_cloexec, 10)) >= 0) { sh_close(acctfd); acctfd = n; @@ -269,7 +269,7 @@ if((unsigned)fd <=2) { int n; - if((n=fcntl(fd,F_dupfd_cloexec,10))>=0) + if((n=sh_fcntl(fd,F_dupfd_cloexec,10))>=0) { sh_close(fd); fd=n; @@ -1194,7 +1194,7 @@ sh_close(oldfd=sffileno(fp)); 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_cloexec, oldfd) !=oldfd) + if(sh_fcntl(newfd, F_dupfd_cloexec, oldfd) !=oldfd) return(-1); fcntl(oldfd,F_SETFD,FD_CLOEXEC); close(newfd); diff -r -u src/cmd/ksh93/sh/path.c src/cmd/ksh93/sh/path.c --- src/cmd/ksh93/sh/path.c Tue Aug 28 16:09:27 2012 +++ src/cmd/ksh93/sh/path.c Fri Sep 7 15:21:40 2012 @@ -1296,7 +1296,7 @@ if(n!=10) { sh_close(10); - fcntl(n, F_dupfd_cloexec, 10); + sh_fcntl(n, F_dupfd_cloexec, 10); sh_close(n); n=10; } diff -r -u src/cmd/ksh93/sh/xec.c src/cmd/ksh93/sh/xec.c --- src/cmd/ksh93/sh/xec.c Tue Aug 28 16:23:11 2012 +++ src/cmd/ksh93/sh/xec.c Fri Sep 7 15:20:56 2012 @@ -122,7 +122,7 @@ return(0); usepipe++; fcntl(subpipe[0],F_SETFD,FD_CLOEXEC); - subpipe[2] = fcntl(1,F_dupfd_cloexec,10); + subpipe[2] = sh_fcntl(1,F_dupfd_cloexec,10); fcntl(subpipe[2],F_SETFD,FD_CLOEXEC); shp->fdstatus[subpipe[2]] = shp->fdstatus[1]; while(close(1)<0 && errno==EINTR) @@ -3392,7 +3392,7 @@ sh_pipe(shp->cpipe); if((outfd=shp->cpipe[1]) < 10) { - int fd=fcntl(shp->cpipe[1],F_dupfd_cloexec,10); + int fd=sh_fcntl(shp->cpipe[1],F_dupfd_cloexec,10); if(fd>=10) { shp->fdstatus[fd] = (shp->fdstatus[outfd]&~IOCLEX); Irek _______________________________________________ ast-developers mailing list ast-developers@research.att.com https://mailman.research.att.com/mailman/listinfo/ast-developers