head 1.26; access; symbols netbsd-10-0-RELEASE:1.26 netbsd-10-0-RC6:1.26 netbsd-10-0-RC5:1.26 netbsd-10-0-RC4:1.26 netbsd-10-0-RC3:1.26 netbsd-10-0-RC2:1.26 netbsd-10-0-RC1:1.26 netbsd-10:1.26.0.2 netbsd-10-base:1.26 netbsd-9-3-RELEASE:1.24 cjep_sun2x-base1:1.25 cjep_sun2x:1.25.0.4 cjep_sun2x-base:1.25 cjep_staticlib_x-base1:1.25 netbsd-9-2-RELEASE:1.24 cjep_staticlib_x:1.25.0.2 cjep_staticlib_x-base:1.25 netbsd-9-1-RELEASE:1.24 phil-wifi-20200421:1.25 phil-wifi-20200411:1.25 is-mlppp:1.24.0.10 is-mlppp-base:1.24 phil-wifi-20200406:1.25 netbsd-8-2-RELEASE:1.23.2.1 netbsd-9-0-RELEASE:1.24 netbsd-9-0-RC2:1.24 netbsd-9-0-RC1:1.24 phil-wifi-20191119:1.24 netbsd-9:1.24.0.8 netbsd-9-base:1.24 phil-wifi-20190609:1.24 netbsd-8-1-RELEASE:1.23.2.1 netbsd-8-1-RC1:1.23.2.1 pgoyette-compat-merge-20190127:1.24 pgoyette-compat-20190127:1.24 pgoyette-compat-20190118:1.24 pgoyette-compat-1226:1.24 pgoyette-compat-1126:1.24 pgoyette-compat-1020:1.24 pgoyette-compat-0930:1.24 pgoyette-compat-0906:1.24 netbsd-7-2-RELEASE:1.16 pgoyette-compat-0728:1.24 netbsd-8-0-RELEASE:1.23.2.1 phil-wifi:1.24.0.6 phil-wifi-base:1.24 pgoyette-compat-0625:1.24 netbsd-8-0-RC2:1.23.2.1 pgoyette-compat-0521:1.24 pgoyette-compat-0502:1.24 pgoyette-compat-0422:1.24 netbsd-8-0-RC1:1.23.2.1 pgoyette-compat-0415:1.24 pgoyette-compat-0407:1.24 pgoyette-compat-0330:1.24 pgoyette-compat-0322:1.24 pgoyette-compat-0315:1.24 netbsd-7-1-2-RELEASE:1.16 pgoyette-compat:1.24.0.4 pgoyette-compat-base:1.24 netbsd-7-1-1-RELEASE:1.16 matt-nb8-mediatek:1.23.2.1.0.2 matt-nb8-mediatek-base:1.23.2.1 perseant-stdc-iso10646:1.24.0.2 perseant-stdc-iso10646-base:1.24 netbsd-8:1.23.0.2 netbsd-8-base:1.23 prg-localcount2-base3:1.23 prg-localcount2-base2:1.23 prg-localcount2-base1:1.23 prg-localcount2:1.22.0.2 prg-localcount2-base:1.22 pgoyette-localcount-20170426:1.22 bouyer-socketcan-base1:1.21 pgoyette-localcount-20170320:1.21 netbsd-7-1:1.16.0.30 netbsd-7-1-RELEASE:1.16 netbsd-7-1-RC2:1.16 netbsd-7-nhusb-base-20170116:1.16 bouyer-socketcan:1.21.0.4 bouyer-socketcan-base:1.21 pgoyette-localcount-20170107:1.21 netbsd-7-1-RC1:1.16 pgoyette-localcount-20161104:1.21 netbsd-7-0-2-RELEASE:1.16 localcount-20160914:1.21 netbsd-7-nhusb:1.16.0.28 netbsd-7-nhusb-base:1.16 pgoyette-localcount-20160806:1.21 pgoyette-localcount-20160726:1.21 pgoyette-localcount:1.21.0.2 pgoyette-localcount-base:1.21 netbsd-7-0-1-RELEASE:1.16 netbsd-7-0:1.16.0.26 netbsd-7-0-RELEASE:1.16 netbsd-7-0-RC3:1.16 netbsd-7-0-RC2:1.16 netbsd-7-0-RC1:1.16 netbsd-5-2-3-RELEASE:1.15 netbsd-5-1-5-RELEASE:1.15 netbsd-6-0-6-RELEASE:1.16 netbsd-6-1-5-RELEASE:1.16 netbsd-7:1.16.0.24 netbsd-7-base:1.16 yamt-pagecache-base9:1.16 yamt-pagecache-tag8:1.16 netbsd-6-1-4-RELEASE:1.16 netbsd-6-0-5-RELEASE:1.16 tls-earlyentropy:1.16.0.22 tls-earlyentropy-base:1.16 riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.16 riastradh-drm2-base3:1.16 netbsd-6-1-3-RELEASE:1.16 netbsd-6-0-4-RELEASE:1.16 netbsd-5-2-2-RELEASE:1.15 netbsd-5-1-4-RELEASE:1.15 netbsd-6-1-2-RELEASE:1.16 netbsd-6-0-3-RELEASE:1.16 netbsd-5-2-1-RELEASE:1.15 netbsd-5-1-3-RELEASE:1.15 netbsd-6-1-1-RELEASE:1.16 riastradh-drm2-base2:1.16 riastradh-drm2-base1:1.16 riastradh-drm2:1.16.0.14 riastradh-drm2-base:1.16 netbsd-6-1:1.16.0.20 netbsd-6-0-2-RELEASE:1.16 netbsd-6-1-RELEASE:1.16 khorben-n900:1.16.0.18 netbsd-6-1-RC4:1.16 netbsd-6-1-RC3:1.16 agc-symver:1.16.0.16 agc-symver-base:1.16 netbsd-6-1-RC2:1.16 netbsd-6-1-RC1:1.16 yamt-pagecache-base8:1.16 netbsd-5-2:1.15.0.52 netbsd-6-0-1-RELEASE:1.16 yamt-pagecache-base7:1.16 netbsd-5-2-RELEASE:1.15 netbsd-5-2-RC1:1.15 matt-nb6-plus-nbase:1.16 yamt-pagecache-base6:1.16 netbsd-6-0:1.16.0.12 netbsd-6-0-RELEASE:1.16 netbsd-6-0-RC2:1.16 tls-maxphys:1.16.0.10 tls-maxphys-base:1.16 matt-nb6-plus:1.16.0.8 matt-nb6-plus-base:1.16 netbsd-6-0-RC1:1.16 yamt-pagecache-base5:1.16 yamt-pagecache-base4:1.16 netbsd-6:1.16.0.6 netbsd-6-base:1.16 netbsd-5-1-2-RELEASE:1.15 netbsd-5-1-1-RELEASE:1.15 yamt-pagecache-base3:1.16 yamt-pagecache-base2:1.16 yamt-pagecache:1.16.0.4 yamt-pagecache-base:1.16 cherry-xenmp:1.16.0.2 cherry-xenmp-base:1.16 bouyer-quota2-nbase:1.16 bouyer-quota2:1.15.0.50 bouyer-quota2-base:1.15 matt-mips64-premerge-20101231:1.15 matt-nb5-mips64-premerge-20101231:1.15 matt-nb5-pq3:1.15.0.48 matt-nb5-pq3-base:1.15 netbsd-5-1:1.15.0.46 netbsd-5-1-RELEASE:1.15 netbsd-5-1-RC4:1.15 matt-nb5-mips64-k15:1.15 netbsd-5-1-RC3:1.15 netbsd-5-1-RC2:1.15 netbsd-5-1-RC1:1.15 netbsd-5-0-2-RELEASE:1.15 matt-nb5-mips64-premerge-20091211:1.15 matt-premerge-20091211:1.15 matt-nb5-mips64-u2-k2-k4-k7-k8-k9:1.15 matt-nb4-mips64-k7-u2a-k9b:1.15 matt-nb5-mips64-u1-k1-k5:1.15 matt-nb5-mips64:1.15.0.44 netbsd-5-0-1-RELEASE:1.15 jym-xensuspend-nbase:1.15 netbsd-5-0:1.15.0.42 netbsd-5-0-RELEASE:1.15 netbsd-5-0-RC4:1.15 netbsd-5-0-RC3:1.15 netbsd-5-0-RC2:1.15 jym-xensuspend:1.15.0.40 jym-xensuspend-base:1.15 netbsd-5-0-RC1:1.15 netbsd-5:1.15.0.38 netbsd-5-base:1.15 matt-mips64-base2:1.15 matt-mips64:1.15.0.36 mjf-devfs2:1.15.0.34 mjf-devfs2-base:1.15 netbsd-4-0-1-RELEASE:1.15 wrstuden-revivesa-base-3:1.15 wrstuden-revivesa-base-2:1.15 wrstuden-fixsa-newbase:1.15 wrstuden-revivesa-base-1:1.15 yamt-pf42-base4:1.15 yamt-pf42-base3:1.15 hpcarm-cleanup-nbase:1.15 yamt-pf42-baseX:1.15 yamt-pf42-base2:1.15 wrstuden-revivesa:1.15.0.32 wrstuden-revivesa-base:1.15 yamt-pf42:1.15.0.30 yamt-pf42-base:1.15 keiichi-mipv6:1.15.0.28 keiichi-mipv6-base:1.15 matt-armv6-nbase:1.15 matt-armv6-prevmlocking:1.15 wrstuden-fixsa-base-1:1.15 netbsd-4-0:1.15.0.26 netbsd-4-0-RELEASE:1.15 cube-autoconf:1.15.0.24 cube-autoconf-base:1.15 netbsd-4-0-RC5:1.15 netbsd-4-0-RC4:1.15 netbsd-4-0-RC3:1.15 netbsd-4-0-RC2:1.15 netbsd-4-0-RC1:1.15 matt-armv6:1.15.0.22 matt-armv6-base:1.15 matt-mips64-base:1.15 hpcarm-cleanup:1.15.0.20 hpcarm-cleanup-base:1.15 netbsd-3-1-1-RELEASE:1.15 netbsd-3-0-3-RELEASE:1.15 wrstuden-fixsa:1.15.0.18 wrstuden-fixsa-base:1.15 abandoned-netbsd-4-base:1.15 abandoned-netbsd-4:1.15.0.12 netbsd-3-1:1.15.0.14 netbsd-3-1-RELEASE:1.15 netbsd-3-0-2-RELEASE:1.15 netbsd-3-1-RC4:1.15 netbsd-3-1-RC3:1.15 netbsd-3-1-RC2:1.15 netbsd-3-1-RC1:1.15 netbsd-4:1.15.0.16 netbsd-4-base:1.15 netbsd-3-0-1-RELEASE:1.15 netbsd-3-0:1.15.0.10 netbsd-3-0-RELEASE:1.15 netbsd-3-0-RC6:1.15 netbsd-3-0-RC5:1.15 netbsd-3-0-RC4:1.15 netbsd-3-0-RC3:1.15 netbsd-3-0-RC2:1.15 netbsd-3-0-RC1:1.15 netbsd-2-0-3-RELEASE:1.15 netbsd-2-1:1.15.0.8 netbsd-2-1-RELEASE:1.15 netbsd-2-1-RC6:1.15 netbsd-2-1-RC5:1.15 netbsd-2-1-RC4:1.15 netbsd-2-1-RC3:1.15 netbsd-2-1-RC2:1.15 netbsd-2-1-RC1:1.15 netbsd-2-0-2-RELEASE:1.15 netbsd-3:1.15.0.6 netbsd-3-base:1.15 netbsd-2-0-1-RELEASE:1.15 netbsd-2:1.15.0.4 netbsd-2-base:1.15 netbsd-2-0-RELEASE:1.15 netbsd-2-0-RC5:1.15 netbsd-2-0-RC4:1.15 netbsd-2-0-RC3:1.15 netbsd-2-0-RC2:1.15 netbsd-2-0-RC1:1.15 netbsd-2-0:1.15.0.2 netbsd-2-0-base:1.15 netbsd-1-6-PATCH002-RELEASE:1.12 netbsd-1-6-PATCH002:1.12 netbsd-1-6-PATCH002-RC4:1.12 netbsd-1-6-PATCH002-RC3:1.12 netbsd-1-6-PATCH002-RC2:1.12 netbsd-1-6-PATCH002-RC1:1.12 netbsd-1-6-PATCH001:1.12 netbsd-1-6-PATCH001-RELEASE:1.12 netbsd-1-6-PATCH001-RC3:1.12 netbsd-1-6-PATCH001-RC2:1.12 netbsd-1-6-PATCH001-RC1:1.12 fvdl_fs64_base:1.14 netbsd-1-6-RELEASE:1.12 netbsd-1-6-RC3:1.12 netbsd-1-6-RC2:1.12 netbsd-1-6-RC1:1.12 netbsd-1-6:1.12.0.8 netbsd-1-6-base:1.12 netbsd-1-5-PATCH003:1.12 ELRICshvfork:1.12.0.6 ELRICshvfork-base:1.12 netbsd-1-5-PATCH002:1.12 netbsd-1-5-PATCH001:1.12 netbsd-1-5-RELEASE:1.12 netbsd-1-5-BETA2:1.12 netbsd-1-5-BETA:1.12 netbsd-1-4-PATCH003:1.10 netbsd-1-5-ALPHA2:1.12 netbsd-1-5:1.12.0.4 netbsd-1-5-base:1.12 minoura-xpg4dl:1.12.0.2 minoura-xpg4dl-base:1.12 netbsd-1-4-PATCH002:1.10 wrstuden-devbsize-19991221:1.10 wrstuden-devbsize:1.10.0.8 wrstuden-devbsize-base:1.10 comdex-fall-1999:1.10.0.6 comdex-fall-1999-base:1.10 netbsd-1-4-PATCH001:1.10 netbsd-1-4-RELEASE:1.10 netbsd-1-4:1.10.0.4 netbsd-1-4-base:1.10 netbsd-1-3-PATCH003:1.10 netbsd-1-3-PATCH003-CANDIDATE2:1.10 netbsd-1-3-PATCH003-CANDIDATE1:1.10 netbsd-1-3-PATCH003-CANDIDATE0:1.10 netbsd-1-3-PATCH002:1.10 netbsd-1-3-PATCH001:1.10 netbsd-1-3-RELEASE:1.10 netbsd-1-3-BETA:1.10 netbsd-1-3:1.10.0.2 netbsd-1-3-base:1.10 netbsd-1-2-PATCH001:1.9.6.1 netbsd-1-2-RELEASE:1.9 netbsd-1-2-BETA:1.9 netbsd-1-2-base:1.9 netbsd-1-2:1.9.0.6 netbsd-1-1-PATCH001:1.9 netbsd-1-1-RELEASE:1.9 netbsd-1-1:1.9.0.2 netbsd-1-1-base:1.9 netbsd-1-0-PATCH06:1.7 netbsd-1-0-PATCH05:1.7 netbsd-1-0-PATCH04:1.7 netbsd-1-0-PATCH03:1.7 netbsd-1-0-PATCH02:1.7 netbsd-1-0-PATCH1:1.7 netbsd-1-0-PATCH0:1.7 netbsd-1-0-RELEASE:1.7 netbsd-1-0:1.7.0.2 netbsd-1-0-base:1.7 lite-1:1.1.1.2 CSRG:1.1.1 netbsd-0-9-RELEASE:1.4 netbsd-0-9-BETA:1.4 netbsd-0-9-ALPHA2:1.4 netbsd-0-9-ALPHA:1.4 netbsd-0-9:1.4.0.2 netbsd-0-9-base:1.4 netbsd-0-8:1.3 netbsd-alpha-1:1.3 patchkit-0-2-2:1.1.1.1 WFJ-386bsd-01:1.1.1.1 WFJ-920714:1.1.1; locks; strict; comment @ * @; 1.26 date 2021.09.15.18.29.45; author kre; state Exp; branches; next 1.25; commitid SuhSRbaBbujN659D; 1.25 date 2020.04.03.16.22.23; author joerg; state Exp; branches; next 1.24; commitid BWQVwOlDsculrX2C; 1.24 date 2017.06.30.23.01.21; author kre; state Exp; branches 1.24.6.1; next 1.23; commitid 5ix3sf7rUwYV2sXz; 1.23 date 2017.04.29.15.14.28; author kre; state Exp; branches 1.23.2.1; next 1.22; commitid nnyWhTq1Q7knsrPz; 1.22 date 2017.04.22.16.02.39; author kre; state Exp; branches 1.22.2.1; next 1.21; commitid g3mgAp866NFPUxOz; 1.21 date 2016.05.12.13.31.37; author kre; state Exp; branches 1.21.2.1; next 1.20; commitid iu37RZX8UnWu7c6z; 1.20 date 2016.05.03.03.08.21; author kre; state Exp; branches; next 1.19; commitid rkkVpOUr02on2Z4z; 1.19 date 2016.05.02.01.46.31; author christos; state Exp; branches; next 1.18; commitid LoF0CYUx8JLoCQ4z; 1.18 date 2016.03.12.21.35.13; author christos; state Exp; branches; next 1.17; commitid 6UQydKTU47THOoYy; 1.17 date 2016.01.04.03.00.24; author christos; state Exp; branches; next 1.16; commitid CBd29bq5y6VfOyPy; 1.16 date 2011.02.17.15.13.49; author pooka; state Exp; branches; next 1.15; 1.15 date 2003.08.07.09.05.37; author agc; state Exp; branches 1.15.50.1; next 1.14; 1.14 date 2002.11.24.22.35.43; author christos; state Exp; branches; next 1.13; 1.13 date 2002.09.27.18.56.55; author christos; state Exp; branches; next 1.12; 1.12 date 2000.05.22.10.18.47; author elric; state Exp; branches 1.12.6.1; next 1.11; 1.11 date 2000.05.13.20.50.15; author elric; state Exp; branches; next 1.10; 1.10 date 96.10.16.15.45.18; author christos; state Exp; branches; next 1.9; 1.9 date 95.05.11.21.30.13; author christos; state Exp; branches 1.9.6.1; next 1.8; 1.8 date 95.03.21.09.10.07; author cgd; state Exp; branches; next 1.7; 1.7 date 94.06.11.16.12.31; author mycroft; state Exp; branches; next 1.6; 1.6 date 94.05.11.17.10.40; author jtc; state Exp; branches; next 1.5; 1.5 date 93.08.01.18.58.36; author mycroft; state Exp; branches; next 1.4; 1.4 date 93.05.02.01.28.45; author sef; state Exp; branches; next 1.3; 1.3 date 93.03.23.00.29.16; author cgd; state Exp; branches; next 1.2; 1.2 date 93.03.22.08.04.00; author cgd; state Exp; branches; next 1.1; 1.1 date 93.03.21.09.45.37; author cgd; state Exp; branches 1.1.1.1; next ; 1.24.6.1 date 2020.04.08.14.03.04; author martin; state Exp; branches; next 1.24.6.2; commitid Qli2aW9E74UFuA3C; 1.24.6.2 date 2020.04.21.18.41.06; author martin; state dead; branches; next 1.24.6.3; commitid 86tA4aEmdr3VCh5C; 1.24.6.3 date 2020.04.21.19.37.34; author martin; state Exp; branches; next ; commitid x6IB64bYH9UmWh5C; 1.23.2.1 date 2017.07.23.14.58.14; author snj; state Exp; branches; next ; commitid IcSSefq8ASq6Dm0A; 1.22.2.1 date 2017.05.02.03.19.14; author pgoyette; state Exp; branches; next ; commitid oFKELrgrBgUNoLPz; 1.21.2.1 date 2017.04.26.02.52.13; author pgoyette; state Exp; branches; next ; commitid ojV02aOSdzvBqZOz; 1.15.50.1 date 2011.03.05.15.08.31; author bouyer; state Exp; branches; next ; 1.12.6.1 date 2002.03.27.20.37.42; author elric; state Exp; branches; next ; 1.9.6.1 date 97.01.26.04.57.38; author rat; state Exp; branches; next ; 1.1.1.1 date 93.03.21.09.45.37; author cgd; state Exp; branches; next 1.1.1.2; 1.1.1.2 date 94.05.11.17.01.09; author jtc; state Exp; branches; next ; desc @@ 1.26 log @Improve the solution for the 2nd access to a fd which shouldn't be available ("13") issue reported by Jan Schaumann on netbsd-users. This fixes a bug in the earlier fix (a day or so ago) which could allow the shell's idea of which fd range was in use by the script to get wildly incorrect, but now also actually looks to see which fd's are in use as renamed other user fd's during the lifetime of a redirection which needs to be able to be undone (most redirections occur after a fork and are permanent in the child process). Attempting to access such a fd (as with attempts to access a fd in use by the shell for its own purposes) is treated as an attempt to access a closed fd (EBADF). Attempting to reuse the fd for some other purpose (which should be rare, even for scripts attempting to cause problems, since the shell generally knows which fds the script wants to use, and avoids them) will cause the renamed (renumbered) fd to be renamed again (moved aside to some other available fd), just as happens with the shell's private fds. Also, when a generic fd is required, don't give up because of EMFILE or similar unless there are no available fds at all (we might prefer >10 or bigger, but if there are none there, use anything). This avoids redirection errors when ulimit -n has been set small, and all the fds >10 that are available have been used, but we need somewhere to park the old user of a fd while we reuse that fd for the redirection. @ text @/* $NetBSD: redir.h,v 1.25 2020/04/03 16:22:23 joerg Exp $ */ /*- * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by * Kenneth Almquist. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * @@(#)redir.h 8.2 (Berkeley) 5/4/95 */ /* flags passed to redirect */ #define REDIR_PUSH 0x01 /* save previous values of file descriptors */ #define REDIR_BACKQ 0x02 /* save the command output in memory */ #define REDIR_VFORK 0x04 /* running under vfork(2), be careful */ #define REDIR_KEEP 0x08 /* don't close-on-exec */ union node; void redirect(union node *, int); void popredir(void); int fd0_redirected_p(void); void clearredir(int); int movefd(int, int); int to_upper_fd(int); void register_sh_fd(int, void (*)(int, int)); void sh_close(int); struct output; int outredir(struct output *, union node *, int); extern int max_user_fd; /* highest fd used by user */ extern long user_fd_limit; /* highest possible user fd */ @ 1.25 log @Don't define max_user_fd in the header. @ text @d1 1 a1 1 /* $NetBSD: redir.h,v 1.24 2017/06/30 23:01:21 kre Exp $ */ d56 1 @ 1.24 log @ Include redirections in trace output from "set -x" @ text @d1 1 a1 1 /* $NetBSD: redir.h,v 1.23 2017/04/29 15:14:28 kre Exp $ */ d55 1 a55 1 int max_user_fd; /* highest fd used by user */ @ 1.24.6.1 log @Merge changes from current as of 20200406 @ text @d1 1 a1 1 /* $NetBSD$ */ d55 1 a55 1 extern int max_user_fd; /* highest fd used by user */ @ 1.24.6.2 log @Sync with HEAD @ text @d1 1 a1 1 /* $NetBSD: redir.h,v 1.24.6.1 2020/04/08 14:03:04 martin Exp $ */ @ 1.24.6.3 log @Ooops, restore accidently removed files from merge mishap @ text @d1 1 a1 1 /* $NetBSD: redir.h,v 1.25 2020/04/03 16:22:23 joerg Exp $ */ @ 1.23 log @ Keep track of which file descriptors the shell is using for its own purposes, and move them elsewhere whenever a user redirection happens to pick the same number. With this we can move the shell file descriptors back to lower values (be slightly kinder to the kernel) since we can no longer clash. (Also get rid of a little old unneeded code.) This also completes the fdflags command, which no longer permits access to (by way or either obtaining, or changing) the shell's internal fds. @ text @d1 1 a1 1 /* $NetBSD: redir.h,v 1.22 2017/04/22 16:02:39 kre Exp $ */ d52 2 @ 1.23.2.1 log @Pull up following revision(s) (requested by kre in ticket #103): bin/kill/kill.c: 1.28 bin/sh/Makefile: 1.111-1.113 bin/sh/arith_token.c: 1.5 bin/sh/arith_tokens.h: 1.2 bin/sh/arithmetic.c: 1.3 bin/sh/arithmetic.h: 1.2 bin/sh/bltin/bltin.h: 1.15 bin/sh/cd.c: 1.49-1.50 bin/sh/error.c: 1.40 bin/sh/eval.c: 1.142-1.151 bin/sh/exec.c: 1.49-1.51 bin/sh/exec.h: 1.26 bin/sh/expand.c: 1.113-1.119 bin/sh/expand.h: 1.23 bin/sh/histedit.c: 1.49-1.52 bin/sh/input.c: 1.57-1.60 bin/sh/input.h: 1.19-1.20 bin/sh/jobs.c: 1.86-1.87 bin/sh/main.c: 1.71-1.72 bin/sh/memalloc.c: 1.30 bin/sh/memalloc.h: 1.17 bin/sh/mknodenames.sh: 1.4 bin/sh/mkoptions.sh: 1.3-1.4 bin/sh/myhistedit.h: 1.12-1.13 bin/sh/nodetypes: 1.16-1.18 bin/sh/option.list: 1.3-1.5 bin/sh/parser.c: 1.133-1.141 bin/sh/parser.h: 1.22-1.23 bin/sh/redir.c: 1.58 bin/sh/redir.h: 1.24 bin/sh/sh.1: 1.149-1.159 bin/sh/shell.h: 1.24 bin/sh/show.c: 1.43-1.47 bin/sh/show.h: 1.11 bin/sh/syntax.c: 1.4 bin/sh/syntax.h: 1.8 bin/sh/trap.c: 1.41 bin/sh/var.c: 1.56-1.65 bin/sh/var.h: 1.29-1.35 An initial attempt at implementing LINENO to meet the specs. Aside from one problem (not too hard to fix if it was ever needed) this version does about as well as most other shell implementations when expanding $((LINENO)) and better for ${LINENO} as it retains the "LINENO hack" for the latter, and that is very accurate. Unfortunately that means that ${LINENO} and $((LINENO)) do not always produce the same value when used on the same line (a defect that other shells do not share - aside from the FreeBSD sh as it is today, where only the LINENO hack exists and so (like for us before this commit) $((LINENO)) is always either 0, or at least whatever value was last set, perhaps by LINENO=${LINENO} which does actually work ... for that one line...) This could be corrected by simply removing the LINENO hack (look for the string LINENO in parser.c) in which case ${LINENO} and $((LINENO)) would give the same (not perfectly accurate) values, as do most other shells. POSIX requires that LINENO be set before each command, and this implementation does that fairly literally - except that we only bother before the commands which actually expand words (for, case and simple commands). Unfortunately this forgot that expansions also occur in redirects, and the other compound commands can also have redirects, so if a redirect on one of the other compound commands wants to use the value of $((LINENO)) as a part of a generated file name, then it will get an incorrect value. This is the "one problem" above. (Because the LINENO hack is still enabled, using ${LINENO} works.) This could be fixed, but as this version of the LINENO implementation is just for reference purposes (it will be superseded within minutes by a better one) I won't bother. However should anyone else decide that this is a better choice (it is probably a smaller implementation, in terms of code & data space then the replacement, but also I would expect, slower, and definitely less accurate) this defect is something to bear in mind, and fix. This version retains the *BSD historical practice that line numbers in functions (all functions) count from 1 from the start of the function, and elsewhere, start from 1 from where the shell started reading the input file/stream in question. In an "eval" expression the line number starts at the line of the "eval" (and then increases if the input is a multi-line string). Note: this version is not documented (beyond as much as LINENO was before) hence this slightly longer than usual commit message. A better LINENO implementation. This version deletes (well, #if 0's out) the LINENO hack, and uses the LINENO var for both ${LINENO} and $((LINENO)). (Code to invert the LINENO hack when required, like when de-compiling the execution tree to provide the "jobs" command strings, is still included, that can be deleted when the LINENO hack is completely removed - look for refs to VSLINENO throughout the code. The var funclinno in parser.c can also be removed, it is used only for the LINENO hack.) This version produces accurate results: $((LINENO)) was made as accurate as the LINENO hack made ${LINENO} which is very good. That's why the LINENO hack is not yet completely removed, so it can be easily re-enabled. If you can tell the difference when it is in use, or not in use, then something has broken (or I managed to miss a case somewhere.) The way that LINENO works is documented in its own (new) section in the man page, so nothing more about that, or the new options, etc, here. This version introduces the possibility of having a "reference" function associated with a variable, which gets called whenever the value of the variable is required (that's what implements LINENO). There is just one function pointer however, so any particular variable gets at most one of the set function (as used for PATH, etc) or the reference function. The VFUNCREF bit in the var flags indicates which func the variable in question uses (if any - the func ptr, as before, can be NULL). I would not call the results of this perfect yet, but it is close. Unbreak (at least) i386 build .... I have no idea why this built for me on amd64 (problem was missing prototype for snprintf witout ) While here, add some (DEBUG mode only) tracing that proved useful in solving another problem. Set the line number before expanding args, not after. As the line_number would have usually been set earlier, this change is mostly an effective no-op, but it is better this way (just in case) - not observed to have caused any problems. Undo some over agressive fixes for a (pre-commit) bug that did not need these changes to be fixed - and these cause problems in another absurd use case. Either of these issues is unlikely to be seen by anyone who isn't an idiot masochist... PR bin/52280 removescapes_nl in expari() even when not quoted, CRTNONL's appear regardless of quoting (unlike CTLESC). New sentence, new line. Whitespace. Improve the (new) LINENO section, markup changes (with thanks to wiz@@ for assistace) and some better wording in a few placed. I am an idiot... revert the previous unintended commit. Remove some left over baggage from the LINENO v1 implementation that didn't get removed with v2, and should have. This would have had (I think, without having tested it) one very minor effect on the way LINENO worked in the v2 implementation, but my guess is it would have taken a long time before anyone noticed... Correct spelling in comments of DEBUG only code... (Perhaps) temporary fix to pkgtools (cwrappers) build (configure). Expanding `` containing \ \n sequences looks to have been giving problems. I don't think this is the correct fix, but it will do no worse harm than (perhaps) incorrectly calculating LINENO in this kind of (rare) circumstance. I'll look and see if there should be a better fix later. s/volatile/const/ -- wonderful how opposites attract like this. NFC (normal use) - DEBUG only change, when showing empty arg list don't omit terminating \n. Free stack memory in a couple of obscure cases where it wasn't being done (one in probably dead code that is never compiled, the other in a very rare error case.) Since it is stack memory it wasn't lost in any case, just held longer than needed. Many internal memory management type fixes. PR bin/52302 (core dump with interactive shell, here doc and error on same line) is fixed. (An old bug.) echo "$( echo x; for a in $( seq 1000 ); do printf '%s\n'; done; echo y )" consistently prints 1002 lines (x, 1000 empty ones, then y) as it should (And you don't want to know what it did before, or why.) (Another old one.) (Recently added) Problems with ~ expansion fixed (mem management related). Proper fix for the cwrappers configure problem (which includes the quick fix that was done earlier, but extends upon that to be correct). (This was another newly added problem.) And the really devious (and rare) old bug - if STACKSTRNUL() needs to allocate a new buffer in which to store the \0, calculate the size of the string space remaining correctly, unlike when SPUTC() grows the buffer, there is no actual data being stored in the STACKSTRNUL() case - the string space remaining was calculated as one byte too few. That would be harmless, unless the next buffer also filled, in which case it was assumed that it was really full, not one byte less, meaning one junk char (a nul, or anything) was being copied into the next (even bigger buffer) corrupting the data. Consistent use of stalloc() to allocate a new block of (stack) memory, and grabstackstr() to claim a block of (stack) memory that had already been occupied but not claimed as in use. Since grabstackstr is implemented as just a call to stalloc() this is a no-op change in practice, but makes it much easier to comprehend what is really happening. Previous code sometimes used stalloc() when the use case was really for grabstackstr(). Change grabstackstr() to actually use the arg passed to it, instead of (not much better than) guessing how much space to claim, More care when using unstalloc()/ungrabstackstr() to return space, and in particular when the stack must be returned to its previous state, rather than just returning no-longer needed space, neither of those work. They also don't work properly if there have been (really, even might have been) any stack mem allocations since the last stalloc()/grabstackstr(). (If we know there cannot have been then the alloc/release sequence is kind of pointless.) To work correctly in general we must use setstackmark()/popstackmark() so do that when needed. Have those also save/restore the top of stack string space remaining. [Aside: for those reading this, the "stack" mentioned is not in any way related to the thing used for maintaining the C function call state, ie: the "stack segment" of the program, but the shell's internal memory management strategy.] More comments to better explain what is happening in some cases. Also cleaned up some hopelessly broken DEBUG mode data that were recently added (no effect on anyone but the poor semi-human attempting to make sense of it...). User visible changes: Proper counting of line numbers when a here document is delimited by a multi-line end-delimiter, as in cat << 'REALLY END' here doc line 1 here doc line 2 REALLY END (which is an obscure case, but nothing says should not work.) The \n in the end-delimiter of the here doc (the last one) was not incrementing the line number, which from that point on in the script would be 1 too low (or more, for end-delimiters with more than one \n in them.) With tilde expansion: unset HOME; echo ~ changed to return getpwuid(getuid())->pw_home instead of failing (returning ~) POSIX says this is unspecified, which makes it difficult for a script to compensate for being run without HOME set (as in env -i sh script), so while not able to be used portably, this seems like a useful extension (and is implemented the same way by some other shells). Further, with HOME=; printf %s ~ we now write nothing (which is required by POSIX - which requires ~ to expand to the value of $HOME if it is set) previously if $HOME (in this case) or a user's directory in the passwd file (for ~user) were a null STRING, We failed the ~ expansion and left behind '~' or '~user'. Changed the long name for the -L option from lineno_fn_relative to local_lineno as the latter seemed to be marginally more popular, and perhaps more importantly, is the same length as the peviously existing quietprofile option, which means the man page indentation for the list of options can return to (about) what it was before... (That is, less indented, which means more data/line, which means less lines of man page - a good thing!) Cosmetic changes to variable flags - make their values more suited to my delicate sensibilities... (NFC). Arrange not to barf (ever) if some turkey makes _ readonly. Do this by adding a VNOERROR flag that causes errors in var setting to be ignored (intended use is only for internal shell var setting, like of "_"). (nb: invalid var name errors ignore this flag, but those should never occur on a var set by the shell itself.) From FreeBSD: don't simply discard memory if a variable is not set for any reason (including because it is readonly) if the var's value had been malloc'd. Free it instead... NFC - DEBUG changes, update this to new TRACE method. KNF - white space and comment formatting. NFC - DEBUG mode only change - convert this to the new TRACE() format. NFC - DEBUG mode only change - complete a change made earlier (marking the line number when included in the trace line tag to show whether it comes from the parser, or the elsewhere as they tend to be quite different). Initially only one case was changed, while I pondered whether I liked it or not. Now it is all done... Also when there is a line tag at all, always include the root/sub-shell indicator character, not only when the pid is included. NFC: DEBUG related comment change - catch up with reality. NFC: DEBUG mode only change. Fix botched cleanup of one TRACE(). "b" more forgiving when sorting options to allow reasonable (and intended) flexibility in option.list format. Changes nothing for current option.list. Now that excessive use of STACKSTRNUL has served its purpose (well, accidental purpose) in exposing the bug in its implementation, go back to not using it when not needed for DEBUG TRACE purposes. This change should have no practical effect on either a DEBUG shell (where the STACKSTRNUL() calls remain) or a non DEBUG shell where they are not needed. Correct the initial line number used for processing -c arg strings. (It was inheriting the value from end of profile file processing) - I didn't notice before as I usually test with empty or no profile files to avoid complications. Trivial change which should have very limited impact. Fix from FreeBSD (applied there in July 2008...) Don't dump core with input like sh -c 'x=; echo >&$x' - that is where the word after a >& or <& redirect expands to nothing at all. Another fix from FreeBSD (this one from April 2009). When processing a string (as in eval, trap, or sh -c) don't allow trailing \n's to destroy the exit status of the last command executed. That is: sh -c 'false ' echo $? should produce 1, not 0. It is amazing what nonsense appears to work sometimes... (all my nonsense too!) Two bugs here, one benign because of the way the script is used. The other hidden by NetBSD's sort being stable, and the data not really requiring sorting at all... So as it happens these fixes change nothing, but they are needed anyway. (The contents of the generated file are only used in DEBUG shells, so this is really even less important than it seems.) Another ancient (highly improbable) bug bites the dust. This one caused by incorrect macro usage (ie: using the wrong one) which has been in the sources since version 1.1 (ie: forever). Like the previous (STACKSTRNUL) bug, the probability of this one actually occurring has been infinitesimal but the LINENO code increases that to infinitesimal and a smidgen... (or a few, depending upon usage). Still, apparently that was enough, Kamil Rytarowski discovered that the zsh configure script (damn competition!) managed to trigger this problem. source .editrc after we initialize so that commands persist! Make arg parsing in kill POSIX compatible with POSIX (XBD 2.12) by parsing the way getopt(3) would, if only it could handle the (required) -signumber and -signame options. This adds two "features" to kill, -ssigname and -lstatus now work (ie: one word with all of the '-', the option letter, and its value) and "--" also now works (kill -- -pid1 pid2 will not attempt to send the pid1 signal to pid2, but rather SIGTERM to the pid1 process group and pid2). It is still the case that (apart from --) at most 1 option is permitted (-l, -s, -signame, or -signumber.) Note that we now have an ambiguity, -sname might mean "-s name" or send the signal "sname" - if one of those turns out to be valid, that will be accepted, otherwise the error message will indicate that "sname" is not a valid signal name, not that "name" is not. Keeping the "-s" and signal name as separate words avoids this issue. Also caution: should someone be weird enough to define a new signal name (as in the part after SIG) which is almost the same name as an existing name that starts with 'S' by adding an extra 'S' prepended (eg: adding a SIGSSYS) then the ambiguity problem becomes much worse. In that case "kill -ssys" will be resolved in favour of the "-s" flag being used (the more modern syntax) and would send a SIGSYS, rather that a SIGSSYS. So don't do that. While here, switch to using signalname(3) (bye bye NSIG, et. al.), add some constipation, and show a little pride in formatting the signal names for "kill -l" (and in the usage when appropriate -- same routine.) Respect COLUMNS (POSIX XBD 8.3) as primary specification of the width (terminal width, not number of columns to print) for kill -l, a very small value for COLUMNS will cause kill -l output to list signals one per line, a very large value will cause them all to be listed on one line.) (eg: "COLUMNS=1 kill -l") TODO: the signal printing for "trap -l" and that for "kill -l" should be switched to use a common routine (for the sh builtin versions.) All changes of relevance here are to bin/kill - the (minor) changes to bin/sh are only to properly expose the builtin version of getenv(3) so the builtin version of kill can use it (ie: make its prototype available.) Properly support EDITRC - use it as (naming) the file when setting up libedit, and re-do the config whenever EDITRC is set. Get rid of workarounds for ancient groff html backend. Simplify macro usage. Make one example more like a real world possibility (it still isn't, but is closer) - though the actual content is irrelevant to the point being made. Add literal prompt support this allows one to do: CA="$(printf '\1')" PS1="${CA}$(tput bold)${CA}\$${CA}$(tput sgr0)${CA} " Now libedit supports embedded mode switch sequence, improve sh support for them (adds PSlit variable to set the magic character). NFC: DEBUG only change - provide an externally visible (to the DEBUG sh internals) interface to one of the internal (private to trace code) functions Include redirections in trace output from "set -x" Implement PS1, PS2 and PS4 expansions (variable expansions, arithmetic expansions, and if enabled by the promptcmds option, command substitutions.) Implement a bunch of new shell environment variables. many mostly useful in prompts when expanded at prompt time, but all available for general use. Many of the new ones are not available in SMALL shells (they work as normal if assigned, but the shell does not set or use them - and there is no magic in a SMALL shell (usually for install media.)) Omnibus manual update for prompt expansions and new variables. Throw in some random cleanups as a bonus. Correct a markup typo (why did I not see this before the prev commit??) Sort options (our default is 0..9AaBbZz). Fix markup problems and a typo. Make $- list flags in the same order they appear in sh(1) Do a better job of detecting the error in pkgsrc/devel/libbson-1.6.3's configure script, ie: $(( which is intended to be a sub-shell in a command substitution, but is an arith subst instead, it needs to be written $( ( to do as intended. Instead of just blindly carrying on to find the missing )) somewhere, anywhere, give up as soon as we have seen an unbalanced ')' that isn't immediately followed by another ')' which in a valid arith subst it always would be. While here, there has been a comment in the code for quite a while noting a difference in the standard between the text descr & grammar when it comes to the syntax of case statements. Add more comments to explain why parsing it as we do is in fact definitely the correct way (ie: the grammar wins arguments like this...). DEBUG and white space changes only. Convert TRACE() calls for DEBUg mode to the new style. NFC (when not debugging sh). Mostly DEBUG and white space changes. Convert DEEBUG TRACE() calls to the new format. Also #if 0 a function definition that is used nowhere. While here, change the function of pushfile() slightly - it now sets the buf pointer in the top (new) input descriptor to NULL, instead of simply leaving it - code that needs a buffer always (before and after) must malloc() one and assign it after the call. But code which does not (which will be reading from a string or similar) now does not have to explicitly set it to NULL (cleaner interface.) NFC intended (or observed.) DEBUG changes: convert DEBUG TRACE() calls to new format. ALso, cause exec failures to always cause the shell to exit with status 126 or 127, whatever the cause. 127 is intended for lookup failures (and is used that way), 126 is used for anything else that goes wrong (as in several other shells.) We no longer use 2 (more easily confused with an exit status of the command exec'd) for shell exec failures. DEBUG only changes. Convert the TRACE() calls in the remaining files that still used it to the new format. NFC. Fix a reference after free (and consequent nonsense diagnostic for attempts to set readonly variables) I added in 1.60 by incompletely copying the FreeBSD fix for the lost memory issue. @ text @d1 1 a1 1 /* $NetBSD: redir.h,v 1.23 2017/04/29 15:14:28 kre Exp $ */ a51 2 struct output; int outredir(struct output *, union node *, int); @ 1.22 log @ Keep track of the biggest fd used by, or available to, the user/script and use that to control which fd's are examined by a (bare) fdflags (with no fd args). Usually this will mean that fdflags will no longer show the shell's internal use fds, only user fds. This is only a partial fix however, a user can easily discover the shell's fd usage (eg: using fstat) and can then still use fdflags to manipulate those fds (or even send output to them). The shell needs to monitor its own fd usage better, and keep out of the way of user fds - coming sometime later... @ text @d1 1 a1 1 /* $NetBSD: redir.h,v 1.21 2016/05/12 13:31:37 kre Exp $ */ d50 2 @ 1.22.2.1 log @Sync with HEAD - tag prg-localcount2-base1 @ text @d1 1 a1 1 /* $NetBSD: redir.h,v 1.23 2017/04/29 15:14:28 kre Exp $ */ a49 2 void register_sh_fd(int, void (*)(int, int)); void sh_close(int); @ 1.21 log @ More work on file descriptors... This is the copyfd() cleanup. copyfd() duplicates file descriptors - it used to be widely used, but these days has seen its popularity dwindle. Strip it of an option that ceased to be variable (simplifying code) and cause all its users to check its result, so it does not need to handle errors itself (simplifying code further), and make it become a private inernal routine in redir.c (all callers from other places have switched to a more modern interface.) Make sure we error() if N>&N fails (if N is closed.) @ text @d1 1 a1 1 /* $NetBSD: redir.h,v 1.20 2016/05/03 03:08:21 kre Exp $ */ d50 2 @ 1.21.2.1 log @Sync with HEAD @ text @d1 1 a1 1 /* $NetBSD: redir.h,v 1.22 2017/04/22 16:02:39 kre Exp $ */ a49 2 int max_user_fd; /* highest fd used by user */ @ 1.20 log @ Remove unnecessary extern var declaration that was a remnant of an earlier version of the previous (fd>10) fixes. ok christos@@ @ text @d1 1 a1 1 /* $NetBSD: redir.h,v 1.19 2016/05/02 01:46:31 christos Exp $ */ a47 1 int copyfd(int, int, int, int); @ 1.19 log @Fix handing of user file descriptors outside the 0..9 range. Also, move (most of) the shell's internal use fd's to much higher values (depending upon what ulimit -n allows) so they are less likely to clash with user supplied fd numbers. A future patch will (hopefully) avoid this problem completely by dynamically moving the shell's internal fds around as needed. (From kre@@) @ text @d1 1 a1 1 /* $NetBSD: redir.h,v 1.18 2016/03/12 21:35:13 christos Exp $ */ a50 2 extern int big_sh_fd; @ 1.18 log @Don't close-on-exec redirections created explicitly for the command being ran; i.e. we want this to work: $ cat succ1 #!/bin/sh ./succ2 6>out $ cat succ2 #!/bin/sh echo succ2 >&6 $ ./succ1 And this to fail: $ cat fail1 #!/bin/sh exec 6> out echo "fail1" >&6 ./fail2 exec 6>&- $ cat fail2 #!obj.amd64/sh echo "fail2" >&6 $ ./fail1 ./fail2: 6: Bad file descriptor XXX: Do we want a -k (keep flag on exec to make redirections not close-on-exec? @ text @d1 1 a1 1 /* $NetBSD: redir.h,v 1.17 2016/01/04 03:00:24 christos Exp $ */ d49 2 d52 1 @ 1.17 log @Don't leak redirected rescriptors to exec'ed processes. This is what ksh does, but bash does not. For example: $ cat test1 #!/bin/sh exec 6> out echo "test" >&6 sh ./test2 exec 6>&- $ cat test2 echo "test2" >&6 $ ./test1 ./test2: 6: Bad file descriptor This fixes by side effect the problem of the rc system leaking file descriptors 7 and 8 to all starting daemons: $ fstat -p 1359 USER CMD PID FD MOUNT INUM MODE SZ|DV R/W root powerd 1359 wd / 2 drwxr-xr-x 512 r root powerd 1359 0 / 63029 crw-rw-rw- null rw root powerd 1359 1 / 63029 crw-rw-rw- null rw root powerd 1359 2 / 63029 crw-rw-rw- null rw root powerd 1359 3* kqueue pending 0 root powerd 1359 4 / 64463 crw-r----- power r root powerd 1359 7 flags 0x80034 root powerd 1359 8 flags 0x80034 root powerd 1359 9* pipe 0xfffffe815d7bfdc0 -> 0x0 w Note fd=7,8 pointing to the revoked pty from the parent rc process. @ text @d1 1 a1 1 /* $NetBSD: redir.h,v 1.16 2011/02/17 15:13:49 pooka Exp $ */ d38 4 a41 3 #define REDIR_PUSH 01 /* save previous values of file descriptors */ #define REDIR_BACKQ 02 /* save the command output in memory */ #define REDIR_VFORK 04 /* running under vfork(2), be careful */ @ 1.16 log @Tell copyfd if the caller wants the exact tofd to just fd >= tofd. Fixes "echo foo > /rump/bar" in a rump hijacked shell. reviewed by christos @ text @d1 1 a1 1 /* $NetBSD: redir.h,v 1.15 2003/08/07 09:05:37 agc Exp $ */ d47 1 a47 1 int copyfd(int, int, int); @ 1.15 log @Move UCB-licensed code from 4-clause to 3-clause licence. Patches provided by Joel Baker in PR 22249, verified by myself. @ text @d1 1 a1 1 /* $NetBSD: redir.h,v 1.14 2002/11/24 22:35:43 christos Exp $ */ d47 1 a47 1 int copyfd(int, int); @ 1.15.50.1 log @Sync with HEAD @ text @d1 1 a1 1 /* $NetBSD$ */ d47 1 a47 1 int copyfd(int, int, int); @ 1.14 log @Fixes from David Laight: - ansification - format of output of jobs command (etc) - job identiers %+, %- etc - $? and $(...) - correct quoting of output of set, export -p and readonly -p - differentiation between nornal and 'posix special' builtins - correct behaviour (posix) for errors on builtins and special builtins - builtin printf and kill - set -o debug (if compiled with DEBUG) - cd src obj (as ksh - too useful to do without) - unset -e name, remove non-readonly variable from export list. (so I could unset -e PS1 before running the test shell...) @ text @d1 1 a1 1 /* $NetBSD: redir.h,v 1.13 2002/09/27 18:56:55 christos Exp $ */ d18 1 a18 5 * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by the University of * California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors @ 1.13 log @VFork()ing shell: From elric@@netbsd.org: Plus my changes: - walking process group fix in foregrounding a job. - reset of process group in parent shell if interrupted before the wait. - move INTON lower in the dowait so that the job structure is consistent. - error check all setpgid(), tcsetpgrp() calls. - eliminate unneeded strpgid() call. - check that we don't belong in the process group before we try to set it. @ text @d1 1 a1 1 /* $NetBSD: redir.h,v 1.12.6.1 2002/03/27 20:37:42 elric Exp $ */ d47 5 a51 5 void redirect __P((union node *, int)); void popredir __P((void)); int fd0_redirected_p __P((void)); void clearredir __P((int)); int copyfd __P((int, int)); @ 1.12 log @Back out previous vfork changes. @ text @d1 1 a1 1 /* $NetBSD: redir.h,v 1.10 1996/10/16 15:45:18 christos Exp $ */ d44 1 d50 1 a50 1 void clearredir __P((void)); @ 1.12.6.1 log @Doing the vfork work on ash on a branch to try to shake out the problems before I expose everyone to them. This checkin represents a merge of the prior work, which I backed out a while ago, to the HEAD only and does not incorporate any additional bugfixes. The additional bugfixes and code-cleanup will occur in later checkins. For reference the patches that were used are: cvs diff -kk -r1.51 -r1.55 eval.c | patch cvs diff -kk -r1.27 -r1.28 exec.c | patch cvs diff -kk -r1.15 -r1.16 exec.h | patch cvs diff -kk -r1.32 -r1.33 input.c | patch cvs diff -kk -r1.10 -r1.11 input.h | patch cvs diff -kk -r1.32 -r1.35 jobs.c | patch cvs diff -kk -r1.9 -r1.11 jobs.h | patch cvs diff -kk -r1.36 -r1.37 main.c | patch cvs diff -kk -r1.20 -r1.21 redir.c | patch cvs diff -kk -r1.10 -r1.11 redir.h | patch cvs diff -kk -r1.10 -r1.12 shell.h | patch cvs diff -kk -r1.22 -r1.23 trap.c | patch cvs diff -kk -r1.12 -r1.13 trap.h | patch cvs diff -kk -r1.23 -r1.24 var.c | patch cvs diff -kk -r1.16 -r1.17 var.h | patch All other changes were simply the resolution of the resulting conflicts, which occured only in the merge of jobs.c. Begins to address PR: bin/5475 @ text @d1 1 a1 1 /* $NetBSD: redir.h,v 1.12 2000/05/22 10:18:47 elric Exp $ */ a43 1 #define REDIR_VFORK 04 /* running under vfork(2), be careful */ d49 1 a49 1 void clearredir __P((int)); @ 1.11 log @Now we use vfork(2) instead of fork(2) when we can. @ text @a43 1 #define REDIR_VFORK 04 /* running under vfork(2), be careful */ d49 1 a49 1 void clearredir __P((int)); @ 1.10 log @PR/2808: Remove trailing whitespace (from FreeBSD) @ text @d1 1 a1 1 /* $NetBSD: redir.h,v 1.9 1995/05/11 21:30:13 christos Exp $ */ d44 1 d50 1 a50 1 void clearredir __P((void)); @ 1.9 log @Merge in my changes from vangogh, and fix the x=`false`; echo $? == 0 bug. @ text @d1 1 a1 1 /* $NetBSD$ */ d49 1 a49 1 void clearredir __P((void)); @ 1.9.6.1 log @Update /bin/sh from trunk per request of Christos Zoulas. Fixes many bugs. @ text @d1 1 a1 1 /* $NetBSD: redir.h,v 1.10 1996/10/16 15:45:18 christos Exp $ */ d49 1 a49 1 void clearredir __P((void)); @ 1.8 log @convert to new RCS id conventions. @ text @d38 1 a38 1 * @@(#)redir.h 8.1 (Berkeley) 5/31/93 a44 1 #ifdef __STDC__ d46 6 a51 12 void redirect(union node *, int); void popredir(void); void clearredir(void); int copyfd(int, int); int fd0_redirected_p(void); #else void redirect(); void popredir(); void clearredir(); int copyfd(); int fd0_redirected_p(); #endif @ 1.7 log @Add RCS ids. @ text @d1 2 d38 1 a38 2 * from: @@(#)redir.h 8.1 (Berkeley) 5/31/93 * $Id: $ @ 1.6 log @sync with 4.4lite @ text @d36 2 a37 1 * @@(#)redir.h 8.1 (Berkeley) 5/31/93 @ 1.5 log @Add RCS identifiers. @ text @d2 2 a3 2 * Copyright (c) 1991 The Regents of the University of California. * All rights reserved. d36 1 a36 2 * from: @@(#)redir.h 5.1 (Berkeley) 3/7/91 * $Id: $ @ 1.4 log @Jim "wilson@@moria.cygnus.com" Wilson's patches to make C News (and other things) work. @ text @d36 2 a37 3 * @@(#)redir.h 5.1 (Berkeley) 3/7/91 * * $Header: /b/source/CVS/src/bin/sh/redir.h,v 1.3 1993/03/23 00:29:16 cgd Exp $ @ 1.3 log @changed "Id" to "Header" for rcsids @ text @d38 1 a38 1 * $Header: redir.h,v 1.2 93/03/22 08:12:46 cgd Exp $ d51 1 d57 1 @ 1.2 log @added rcs ids to all files @ text @d38 1 a38 1 * $Id: redir.h,v 1.2 93/03/21 22:15:57 cgd Exp $ @ 1.1 log @Initial revision @ text @d37 2 @ 1.1.1.1 log @initial import of 386bsd-0.1 sources @ text @@ 1.1.1.2 log @44lite code @ text @d2 2 a3 2 * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. d36 1 a36 1 * @@(#)redir.h 8.1 (Berkeley) 5/31/93 a48 1 int fd0_redirected_p(void); a53 1 int fd0_redirected_p(); @