- fix segfault in variable substitution [bsc#1129288]

- fix untrusted environment execution [bsc#1160796] [CVE-2019-14868]

OBS-URL: https://build.opensuse.org/package/show/shells/ksh?expand=0&rev=240
This commit is contained in:
Michael Schröder 2024-08-01 12:13:15 +00:00 committed by Git OBS Bridge
commit 54ca44b456
78 changed files with 12352 additions and 0 deletions

23
.gitattributes vendored Normal file
View File

@ -0,0 +1,23 @@
## Default LFS
*.7z filter=lfs diff=lfs merge=lfs -text
*.bsp filter=lfs diff=lfs merge=lfs -text
*.bz2 filter=lfs diff=lfs merge=lfs -text
*.gem filter=lfs diff=lfs merge=lfs -text
*.gz filter=lfs diff=lfs merge=lfs -text
*.jar filter=lfs diff=lfs merge=lfs -text
*.lz filter=lfs diff=lfs merge=lfs -text
*.lzma filter=lfs diff=lfs merge=lfs -text
*.obscpio filter=lfs diff=lfs merge=lfs -text
*.oxt filter=lfs diff=lfs merge=lfs -text
*.pdf filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.rpm filter=lfs diff=lfs merge=lfs -text
*.tbz filter=lfs diff=lfs merge=lfs -text
*.tbz2 filter=lfs diff=lfs merge=lfs -text
*.tgz filter=lfs diff=lfs merge=lfs -text
*.ttf filter=lfs diff=lfs merge=lfs -text
*.txz filter=lfs diff=lfs merge=lfs -text
*.whl filter=lfs diff=lfs merge=lfs -text
*.xz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zst filter=lfs diff=lfs merge=lfs -text

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.osc

14
Agreement Normal file
View File

@ -0,0 +1,14 @@
http://www.research.att.com/sw/download/
http://www.research.att.com/sw/download/beta/
User: `I accept www.opensource.org/licenses/cpl'
Password: `.'
#user='I accept www.opensource.org/licenses/eclipse'
user='I accept www.opensource.org/licenses/cpl'
#subdir=beta
subdir=tgz
version=2012-02-29
wget --user="${user}" --password='.' \
http://www2.research.att.com/sw/download/${subdir}/ast-ksh.${version}.tgz \
http://www2.research.att.com/sw/download/${subdir}/INIT.${version}.tgz \
http://www2.research.att.com/sw/download/${subdir}/ast-base.${version}.tgz

245
CPL Normal file
View File

@ -0,0 +1,245 @@
+------------------------------------------------------------------------------+
| This license covers all software that refers to the URL |
| http://www.opensource.org/licenses/cpl1.0.txt |
+------------------------------------------------------------------------------+
Common Public License Version 1.0
THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS COMMON
PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF
THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
1. DEFINITIONS
"Contribution" means:
a) in the case of the initial Contributor, the initial code and
documentation distributed under this Agreement, and
b) in the case of each subsequent Contributor:
i) changes to the Program, and
ii) additions to the Program;
where such changes and/or additions to the Program originate from
and are distributed by that particular Contributor. A Contribution
'originates' from a Contributor if it was added to the Program by
such Contributor itself or anyone acting on such Contributor's
behalf. Contributions do not include additions to the Program
which: (i) are separate modules of software distributed in
conjunction with the Program under their own license agreement, and
(ii) are not derivative works of the Program.
"Contributor" means any person or entity that distributes the Program.
"Licensed Patents " mean patent claims licensable by a Contributor
which are necessarily infringed by the use or sale of its Contribution
alone or when combined with the Program.
"Program" means the Contributions distributed in accordance with this
Agreement.
"Recipient" means anyone who receives the Program under this
Agreement, including all Contributors.
2. GRANT OF RIGHTS
a) Subject to the terms of this Agreement, each Contributor hereby
grants Recipient a non-exclusive, worldwide, royalty-free copyright
license to reproduce, prepare derivative works of, publicly
display, publicly perform, distribute and sublicense the
Contribution of such Contributor, if any, and such derivative
works, in source code and object code form.
b) Subject to the terms of this Agreement, each Contributor hereby
grants Recipient a non-exclusive, worldwide, royalty-free patent
license under Licensed Patents to make, use, sell, offer to sell,
import and otherwise transfer the Contribution of such Contributor,
if any, in source code and object code form. This patent license
shall apply to the combination of the Contribution and the Program
if, at the time the Contribution is added by the Contributor, such
addition of the Contribution causes such combination to be covered
by the Licensed Patents. The patent license shall not apply to any
other combinations which include the Contribution. No hardware per
se is licensed hereunder.
c) Recipient understands that although each Contributor grants the
licenses to its Contributions set forth herein, no assurances are
provided by any Contributor that the Program does not infringe the
patent or other intellectual property rights of any other entity.
Each Contributor disclaims any liability to Recipient for claims
brought by any other entity based on infringement of intellectual
property rights or otherwise. As a condition to exercising the
rights and licenses granted hereunder, each Recipient hereby
assumes sole responsibility to secure any other intellectual
property rights needed, if any. For example, if a third party
patent license is required to allow Recipient to distribute the
Program, it is Recipient's responsibility to acquire that license
before distributing the Program.
d) Each Contributor represents that to its knowledge it has
sufficient copyright rights in its Contribution, if any, to grant
the copyright license set forth in this Agreement.
3. REQUIREMENTS
A Contributor may choose to distribute the Program in object code form
under its own license agreement, provided that:
a) it complies with the terms and conditions of this Agreement; and
b) its license agreement:
i) effectively disclaims on behalf of all Contributors all
warranties and conditions, express and implied, including
warranties or conditions of title and non-infringement, and implied
warranties or conditions of merchantability and fitness for a
particular purpose;
ii) effectively excludes on behalf of all Contributors all
liability for damages, including direct, indirect, special,
incidental and consequential damages, such as lost profits;
iii) states that any provisions which differ from this Agreement
are offered by that Contributor alone and not by any other party;
and
iv) states that source code for the Program is available from such
Contributor, and informs licensees how to obtain it in a reasonable
manner on or through a medium customarily used for software
exchange.
When the Program is made available in source code form:
a) it must be made available under this Agreement; and
b) a copy of this Agreement must be included with each copy of the
Program.
Contributors may not remove or alter any copyright notices contained
within the Program.
Each Contributor must identify itself as the originator of its
Contribution, if any, in a manner that reasonably allows subsequent
Recipients to identify the originator of the Contribution.
4. COMMERCIAL DISTRIBUTION
Commercial distributors of software may accept certain
responsibilities with respect to end users, business partners and the
like. While this license is intended to facilitate the commercial use
of the Program, the Contributor who includes the Program in a
commercial product offering should do so in a manner which does not
create potential liability for other Contributors. Therefore, if a
Contributor includes the Program in a commercial product offering,
such Contributor ("Commercial Contributor") hereby agrees to defend
and indemnify every other Contributor ("Indemnified Contributor")
against any losses, damages and costs (collectively "Losses") arising
from claims, lawsuits and other legal actions brought by a third party
against the Indemnified Contributor to the extent caused by the acts
or omissions of such Commercial Contributor in connection with its
distribution of the Program in a commercial product offering. The
obligations in this section do not apply to any claims or Losses
relating to any actual or alleged intellectual property infringement.
In order to qualify, an Indemnified Contributor must: a) promptly
notify the Commercial Contributor in writing of such claim, and b)
allow the Commercial Contributor to control, and cooperate with the
Commercial Contributor in, the defense and any related settlement
negotiations. The Indemnified Contributor may participate in any such
claim at its own expense.
For example, a Contributor might include the Program in a commercial
product offering, Product X. That Contributor is then a Commercial
Contributor. If that Commercial Contributor then makes performance
claims, or offers warranties related to Product X, those performance
claims and warranties are such Commercial Contributor's responsibility
alone. Under this section, the Commercial Contributor would have to
defend claims against the other Contributors related to those
performance claims and warranties, and if a court requires any other
Contributor to pay any damages as a result, the Commercial Contributor
must pay those damages.
5. NO WARRANTY
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS
PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY
OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely
responsible for determining the appropriateness of using and
distributing the Program and assumes all risks associated with its
exercise of rights under this Agreement, including but not limited to
the risks and costs of program errors, compliance with applicable
laws, damage to or loss of data, programs or equipment, and
unavailability or interruption of operations.
6. DISCLAIMER OF LIABILITY
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR
ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING
WITHOUT LIMITATION LOST PROFITS), 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 OR
DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
7. GENERAL
If any provision of this Agreement is invalid or unenforceable under
applicable law, it shall not affect the validity or enforceability of
the remainder of the terms of this Agreement, and without further
action by the parties hereto, such provision shall be reformed to the
minimum extent necessary to make such provision valid and enforceable.
If Recipient institutes patent litigation against a Contributor with
respect to a patent applicable to software (including a cross-claim or
counterclaim in a lawsuit), then any patent licenses granted by that
Contributor to such Recipient under this Agreement shall terminate as
of the date such litigation is filed. In addition, if Recipient
institutes patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Program
itself (excluding combinations of the Program with other software or
hardware) infringes such Recipient's patent(s), then such Recipient's
rights granted under Section 2(b) shall terminate as of the date such
litigation is filed.
All Recipient's rights under this Agreement shall terminate if it
fails to comply with any of the material terms or conditions of this
Agreement and does not cure such failure in a reasonable period of
time after becoming aware of such noncompliance. If all Recipient's
rights under this Agreement terminate, Recipient agrees to cease use
and distribution of the Program as soon as reasonably practicable.
However, Recipient's obligations under this Agreement and any licenses
granted by Recipient relating to the Program shall continue and
survive.
Everyone is permitted to copy and distribute copies of this Agreement,
but in order to avoid inconsistency the Agreement is copyrighted and
may only be modified in the following manner. The Agreement Steward
reserves the right to publish new versions (including revisions) of
this Agreement from time to time. No one other than the Agreement
Steward has the right to modify this Agreement. IBM is the initial
Agreement Steward. IBM may assign the responsibility to serve as the
Agreement Steward to a suitable separate entity. Each new version of
the Agreement will be given a distinguishing version number. The
Program (including Contributions) may always be distributed subject to
the version of the Agreement under which it was received. In addition,
after a new version of the Agreement is published, Contributor may
elect to distribute the Program (including its Contributions) under
the new version. Except as expressly stated in Sections 2(a) and 2(b)
above, Recipient receives no rights or licenses to the intellectual
property of any Contributor under this Agreement, whether expressly,
by implication, estoppel or otherwise. All rights in the Program not
expressly granted under this Agreement are reserved.
This Agreement is governed by the laws of the State of New York and
the intellectual property laws of the United States of America. No
party to this Agreement will bring a legal action under this Agreement
more than one year after the cause of action arose. Each party waives
its rights to a jury trial in any resulting litigation.
Copyright (c) 2004 by the Open Source Initiative
This is a copy of the license posted on 2004-10-06 at:
http://www.opensource.org/licenses/cpl

221
EPL Normal file
View File

@ -0,0 +1,221 @@
+------------------------------------------------------------------------------+
| This license covers all software that refers to the URL |
| http://www.eclipse.org/org/documents/epl-v10.html |
+------------------------------------------------------------------------------+
Eclipse Public License - v 1.0
THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC
LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM
CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
1. DEFINITIONS
"Contribution" means:
a) in the case of the initial Contributor, the initial code and
documentation distributed under this Agreement, and
b) in the case of each subsequent Contributor:
i) changes to the Program, and
ii) additions to the Program;
where such changes and/or additions to the Program originate from and are
distributed by that particular Contributor. A Contribution 'originates' from
a Contributor if it was added to the Program by such Contributor itself or
anyone acting on such Contributor's behalf. Contributions do not include
additions to the Program which: (i) are separate modules of software
distributed in conjunction with the Program under their own license
agreement, and (ii) are not derivative works of the Program.
"Contributor" means any person or entity that distributes the Program.
"Licensed Patents" mean patent claims licensable by a Contributor which are
necessarily infringed by the use or sale of its Contribution alone or when
combined with the Program.
"Program" means the Contributions distributed in accordance with this
Agreement.
"Recipient" means anyone who receives the Program under this Agreement,
including all Contributors.
2. GRANT OF RIGHTS
a) Subject to the terms of this Agreement, each Contributor hereby grants
Recipient a non-exclusive, worldwide, royalty-free copyright license to
reproduce, prepare derivative works of, publicly display, publicly perform,
distribute and sublicense the Contribution of such Contributor, if any, and
such derivative works, in source code and object code form.
b) Subject to the terms of this Agreement, each Contributor hereby grants
Recipient a non-exclusive, worldwide, royalty-free patent license under
Licensed Patents to make, use, sell, offer to sell, import and otherwise
transfer the Contribution of such Contributor, if any, in source code and
object code form. This patent license shall apply to the combination of the
Contribution and the Program if, at the time the Contribution is added by
the Contributor, such addition of the Contribution causes such combination
to be covered by the Licensed Patents. The patent license shall not apply to
any other combinations which include the Contribution. No hardware per se is
licensed hereunder.
c) Recipient understands that although each Contributor grants the licenses
to its Contributions set forth herein, no assurances are provided by any
Contributor that the Program does not infringe the patent or other
intellectual property rights of any other entity. Each Contributor disclaims
any liability to Recipient for claims brought by any other entity based on
infringement of intellectual property rights or otherwise. As a condition to
exercising the rights and licenses granted hereunder, each Recipient hereby
assumes sole responsibility to secure any other intellectual property rights
needed, if any. For example, if a third party patent license is required to
allow Recipient to distribute the Program, it is Recipient's responsibility
to acquire that license before distributing the Program.
d) Each Contributor represents that to its knowledge it has sufficient
copyright rights in its Contribution, if any, to grant the copyright license
set forth in this Agreement.
3. REQUIREMENTS
A Contributor may choose to distribute the Program in object code form under
its own license agreement, provided that:
a) it complies with the terms and conditions of this Agreement; and
b) its license agreement:
i) effectively disclaims on behalf of all Contributors all warranties and
conditions, express and implied, including warranties or conditions of title
and non-infringement, and implied warranties or conditions of
merchantability and fitness for a particular purpose;
ii) effectively excludes on behalf of all Contributors all liability for
damages, including direct, indirect, special, incidental and consequential
damages, such as lost profits;
iii) states that any provisions which differ from this Agreement are offered
by that Contributor alone and not by any other party; and
iv) states that source code for the Program is available from such
Contributor, and informs licensees how to obtain it in a reasonable manner
on or through a medium customarily used for software exchange.
When the Program is made available in source code form:
a) it must be made available under this Agreement; and
b) a copy of this Agreement must be included with each copy of the Program.
Contributors may not remove or alter any copyright notices contained within
the Program.
Each Contributor must identify itself as the originator of its Contribution,
if any, in a manner that reasonably allows subsequent Recipients to identify
the originator of the Contribution.
4. COMMERCIAL DISTRIBUTION
Commercial distributors of software may accept certain responsibilities with
respect to end users, business partners and the like. While this license is
intended to facilitate the commercial use of the Program, the Contributor
who includes the Program in a commercial product offering should do so in a
manner which does not create potential liability for other Contributors.
Therefore, if a Contributor includes the Program in a commercial product
offering, such Contributor ("Commercial Contributor") hereby agrees to
defend and indemnify every other Contributor ("Indemnified Contributor")
against any losses, damages and costs (collectively "Losses") arising from
claims, lawsuits and other legal actions brought by a third party against
the Indemnified Contributor to the extent caused by the acts or omissions of
such Commercial Contributor in connection with its distribution of the
Program in a commercial product offering. The obligations in this section do
not apply to any claims or Losses relating to any actual or alleged
intellectual property infringement. In order to qualify, an Indemnified
Contributor must: a) promptly notify the Commercial Contributor in writing
of such claim, and b) allow the Commercial Contributor to control, and
cooperate with the Commercial Contributor in, the defense and any related
settlement negotiations. The Indemnified Contributor may participate in any
such claim at its own expense.
For example, a Contributor might include the Program in a commercial product
offering, Product X. That Contributor is then a Commercial Contributor. If
that Commercial Contributor then makes performance claims, or offers
warranties related to Product X, those performance claims and warranties are
such Commercial Contributor's responsibility alone. Under this section, the
Commercial Contributor would have to defend claims against the other
Contributors related to those performance claims and warranties, and if a
court requires any other Contributor to pay any damages as a result, the
Commercial Contributor must pay those damages.
5. NO WARRANTY
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON
AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR
CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A
PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the
appropriateness of using and distributing the Program and assumes all risks
associated with its exercise of rights under this Agreement , including but
not limited to the risks and costs of program errors, compliance with
applicable laws, damage to or loss of data, programs or equipment, and
unavailability or interruption of operations.
6. DISCLAIMER OF LIABILITY
EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY
CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION
LOST PROFITS), 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 OR DISTRIBUTION OF THE PROGRAM OR THE
EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY
OF SUCH DAMAGES.
7. GENERAL
If any provision of this Agreement is invalid or unenforceable under
applicable law, it shall not affect the validity or enforceability of the
remainder of the terms of this Agreement, and without further action by the
parties hereto, such provision shall be reformed to the minimum extent
necessary to make such provision valid and enforceable.
If Recipient institutes patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Program itself
(excluding combinations of the Program with other software or hardware)
infringes such Recipient's patent(s), then such Recipient's rights granted
under Section 2(b) shall terminate as of the date such litigation is filed.
All Recipient's rights under this Agreement shall terminate if it fails to
comply with any of the material terms or conditions of this Agreement and
does not cure such failure in a reasonable period of time after becoming
aware of such noncompliance. If all Recipient's rights under this Agreement
terminate, Recipient agrees to cease use and distribution of the Program as
soon as reasonably practicable. However, Recipient's obligations under this
Agreement and any licenses granted by Recipient relating to the Program
shall continue and survive.
Everyone is permitted to copy and distribute copies of this Agreement, but
in order to avoid inconsistency the Agreement is copyrighted and may only be
modified in the following manner. The Agreement Steward reserves the right
to publish new versions (including revisions) of this Agreement from time to
time. No one other than the Agreement Steward has the right to modify this
Agreement. The Eclipse Foundation is the initial Agreement Steward. The
Eclipse Foundation may assign the responsibility to serve as the Agreement
Steward to a suitable separate entity. Each new version of the Agreement
will be given a distinguishing version number. The Program (including
Contributions) may always be distributed subject to the version of the
Agreement under which it was received. In addition, after a new version of
the Agreement is published, Contributor may elect to distribute the Program
(including its Contributions) under the new version. Except as expressly
stated in Sections 2(a) and 2(b) above, Recipient receives no rights or
licenses to the intellectual property of any Contributor under this
Agreement, whether expressly, by implication, estoppel or otherwise. All
rights in the Program not expressly granted under this Agreement are
reserved.
This Agreement is governed by the laws of the State of New York and the
intellectual property laws of the United States of America. No party to this
Agreement will bring a legal action under this Agreement more than one year
after the cause of action arose. Each party waives its rights to a jury
trial in any resulting litigation.

3
INIT.2012-08-01.tar.bz2 Normal file
View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:0b854435757829f9fbc9d24242192e2056069862d9c463bf8dcfb76b1f094c8b
size 295820

26
Warning Normal file
View File

@ -0,0 +1,26 @@
GPL 1.0/2.0 versus CPL1.0 as well as versus EPL1.0
==================================================
According to http://www.gnu.org/licenses/license-list.html
the current CPL-1.0 as well as EPL-1.0 is incompatible with
the GPL.
Therefore no developer should use the libraries provided
by the ksh in any project under the GPL.
For compiling use
-I/usr/include/ast
on the gcc compiler command line. For linking please
add the line
-L/usr/lib/ast
or
-L/usr/lib64/ast
on 64bit architectures to the command line of the
linker or gcc.

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:81f4007679dad9a93b2a4ed241cbe2e86d1422ee3b74c4f905aaae1345070af2
size 8035476

View File

@ -0,0 +1,887 @@
--- src/cmd/ksh93/Makefile
+++ src/cmd/ksh93/Makefile 2012-08-06 21:25:47.000000000 +0000
@@ -161,6 +161,7 @@ DATAFILES = limits.c msg.c strdata.c tes
shell$(RELEASE) $(VERSION) id=shell :LIBRARY: shell.3 nval.3 alarm.c cd_pwd.c cflow.c deparse.c \
enum.c getopts.c hist.c misc.c print.c read.c sleep.c trap.c test.c \
+ poll.c \
typeset.c ulimit.c umask.c whence.c main.c nvdisc.c nvtype.c \
arith.c args.c array.c completion.c defs.c edit.c expand.c regress.c \
fault.c fcin.c history.c init.c io.c jobs.c lex.c macro.c name.c \
--- src/cmd/ksh93/Mamfile
+++ src/cmd/ksh93/Mamfile 2012-08-06 21:25:47.000000000 +0000
@@ -548,6 +548,22 @@ meta test.o %.c>%.o bltins/test.c test
prev bltins/test.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -Iinclude -I${PACKAGE_ast_INCLUDE} -D_API_ast=20100309 -D_PACKAGE_ast -D_BLD_shell -DSHOPT_DYNAMIC -DSHOPT_MULTIBYTE -DSHOPT_PFSH -DSHOPT_STATS -DSHOPT_NAMESPACE -DSHOPT_COSHELL -DSHOPT_HISTEXPAND -DERROR_CONTEXT_T=Error_context_t -DSHOPT_FIXEDARRAY -DSHOPT_ESH -DKSHELL -c bltins/test.c
done test.o generated
+
+make poll.o
+make bltins/poll.c
+prev ${PACKAGE_ast_INCLUDE}/tmx.h implicit
+prev FEATURE/poll implicit
+prev FEATURE/externs implicit
+prev include/builtins.h implicit
+prev include/io.h implicit
+prev ${PACKAGE_ast_INCLUDE}/error.h implicit
+prev include/defs.h implicit
+done bltins/poll.c
+meta poll.o %.c>%.o bltins/poll.c test
+prev bltins/poll.c
+exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -Iinclude -I${PACKAGE_ast_INCLUDE} -D_API_ast=20100309 -D_PACKAGE_ast -D_BLD_shell -DSHOPT_DYNAMIC -DSHOPT_MULTIBYTE -DSHOPT_PFSH -DSHOPT_STATS -DSHOPT_NAMESPACE -DSHOPT_COSHELL -DSHOPT_DYNAMIC -DSHOPT_HISTEXPAND -DERROR_CONTEXT_T=Error_context_t -DSHOPT_FIXEDARRAY -DSHOPT_ESH -DKSHELL -c bltins/poll.c
+done poll.o generated
+
make typeset.o
make bltins/typeset.c
prev FEATURE/dynamic implicit
@@ -1328,7 +1344,7 @@ meta hexpand.o %.c>%.o edit/hexpand.c he
prev edit/hexpand.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -Iinclude -I${PACKAGE_ast_INCLUDE} -DSHOPT_HISTEXPAND -DSHOPT_EDPREDICT -DSHOPT_MULTIBYTE -DKSHELL -DSHOPT_ESH -DSHOPT_VSH -D_PACKAGE_ast -DSHOPT_PFSH -DSHOPT_STATS -DSHOPT_NAMESPACE -DSHOPT_COSHELL -D_BLD_shell -D_API_ast=20100309 -DERROR_CONTEXT_T=Error_context_t -DSHOPT_FIXEDARRAY -c edit/hexpand.c
done hexpand.o generated
-exec - ${AR} rc libshell.a alarm.o cd_pwd.o cflow.o deparse.o enum.o getopts.o hist.o misc.o print.o read.o sleep.o trap.o test.o typeset.o ulimit.o umask.o whence.o main.o nvdisc.o nvtype.o arith.o args.o array.o completion.o defs.o edit.o expand.o regress.o fault.o fcin.o
+exec - ${AR} rc libshell.a alarm.o cd_pwd.o cflow.o deparse.o enum.o getopts.o hist.o misc.o poll.o print.o read.o sleep.o trap.o test.o typeset.o ulimit.o umask.o whence.o main.o nvdisc.o nvtype.o arith.o args.o array.o completion.o defs.o edit.o expand.o regress.o fault.o fcin.o
exec - ${AR} rc libshell.a history.o init.o io.o jobs.o lex.o macro.o name.o nvtree.o parse.o path.o string.o streval.o subshell.o tdump.o timers.o trestore.o waitevent.o xec.o env.o limits.o msg.o strdata.o testops.o keywords.o options.o signals.o aliases.o builtins.o variables.o lexstates.o emacs.o vi.o hexpand.o
exec - (ranlib libshell.a) >/dev/null 2>&1 || true
done libshell.a generated
--- src/cmd/ksh93/bltins/poll.c
+++ src/cmd/ksh93/bltins/poll.c 2012-08-07 03:13:40.000000000 +0000
@@ -0,0 +1,717 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 2007-2012 AT&T Intellectual Property *
+* and is licensed under the *
+* Eclipse Public License, Version 1.0 *
+* by AT&T Intellectual Property *
+* *
+* A copy of the License is available at *
+* http://www.eclipse.org/org/documents/epl-v10.html *
+* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* Roland Mainz <roland.mainz@nrubsig.org> *
+* *
+***********************************************************************/
+#pragma prototyped
+
+#include "defs.h"
+#include "variables.h"
+#include "lexstates.h"
+#include "io.h"
+#include "name.h"
+#include "builtins.h"
+#include "history.h"
+#include "terminal.h"
+#include <stdio.h>
+#include <stdbool.h>
+#include <poll.h>
+#include <tmx.h>
+#include <stk.h>
+
+#ifndef SH_DICT
+# define SH_DICT "libshell"
+#endif
+
+#define sh_contexttoshell(context) ((context)?((context)->shp):(NULL))
+
+static
+const char sh_optpoll[] =
+"[-?\n@(#)$Id: poll (AT&T Labs Research) 2012-08-01 $\n]"
+"[-author?Roland Mainz <roland.mainz@nrubsig.org>]"
+"[-license?http://www.eclipse.org/org/documents/epl-v10.html]"
+"[+NAME? poll - input/output multiplexing]"
+"[+DESCRIPTION?The poll command provides applications with a "
+ "mechanism for multiplexing input/output over a set of "
+ "file descriptors. "
+ "For each member of the (optionally sparse) indexed or "
+ "associative compound or type (see \btypeset -T\b) array "
+ "variable \bvar\b, poll examines the given file descriptor "
+ "in the subscript \b.fd\b for the event(s) specified in "
+ "the subscript \b.events\b. "
+ "The poll command identifies those file descriptors on "
+ "which an application can read or write data, or on which "
+ "certain events have occurred.]"
+"[+?The \bvar\b argument specifies an array of file descriptors to "
+ "be examined and the events of interest for each file "
+ "descriptor. "
+ "It is a array of compound variables (or user-defined type) "
+ "with one member for each open file descriptor of interest. "
+ "The array's compound or type variable members contain the "
+ "following subscripts:]{"
+ "[+?\b.fd\b # file descriptor]"
+ "[+?\b.events\b # compound variable of requested event(s)]"
+ "[+?\b.revents\b # compound variable of returned event(s)]"
+ "}"
+"[+?The \bfd\b variable specifies an open file descriptor and the "
+ "\bevents\b and \brevents\b members are compound variables "
+ "constructed from the following boolean member variables:]"
+ "{ "
+ "[+.pollin?('true'|'false') Data other than high priority "
+ "data may be read without blocking. For STREAMS, this "
+ "flag is set in \brevents\b even if the message "
+ "is of zero length.]"
+ "[+.pollrdnorm?('true'|'false') Normal data (priority band "
+ "equals 0) may be read without blocking. For STREAMS, "
+ "this flag is set in \brevents\b even if the message "
+ "is of zero length.]"
+ "[+.pollrdband?('true'|'false') Data from a non-zero "
+ "priority band may be read without blocking. For "
+ "STREAMS, this flag is set in \brevents\b even if the "
+ "message is of zero length.]"
+ "[+.pollpri?('true'|'false') High priority data may be "
+ "received without blocking. For STREAMS, this flag is "
+ "set in \brevents\b even if the message is of zero "
+ "length.]"
+ "[+.pollout?('true'|'false') Normal data (priority band "
+ "equals 0) may be written without blocking.]"
+ "[+.pollwrnorm?('true'|'false') The same as \bpollout\b.]"
+ "[+.pollwrband?('true'|'false') Priority data (priority band "
+ "> 0) may be written. This event only examines bands "
+ "that have been written to at least once.]"
+ "[+.pollerr?('true'|'false') An error has occurred on the "
+ "device or stream. This flag is only valid in the "
+ "\brevents\b compound variable; it is not used in the "
+ "\bevents\b compound variable.]"
+ "[+.pollhup?('true'|'false') A hangup has occurred on the "
+ "stream. This event and \bpollout\b are mutually "
+ "exclusive; a stream can never be writable if a "
+ "hangup has occurred. "
+ "However, this event and \bpollin\b, "
+ "\bpollrdband\b, or \bpollpri\b are not "
+ "mutually exclusive. This flag is only valid "
+ "in the \brevents\b compound variable; it is not "
+ "used in the \bevents\b compound variable.]"
+ "[+.pollnval?('true'|'false') The specified fd value does "
+ "not belong to an open file. "
+ "This flag is only valid in the \brevents\b compound "
+ "variable; it is not used in the \bevents\b "
+ "compound variable.]"
+ "}"
+"]"
+
+"[+?If the value fd is less than 0, events is ignored and "
+ "revents is set to 0 in that entry on return from poll.]"
+
+"[+?The results of the poll query are stored in the \brevents\b "
+ "compound variable members in the \bvar\b structure. "
+ "\bpoll*\b-variables are set in the \brevents\b compound "
+ "variable to indicate which of the requested events are true. "
+ "If none are true, the matching member in the \brevents\b "
+ "compound variable will have the value of 'false' when the "
+ "poll command returns. "
+ "The \brevents\b compound variable members \bpollhup\b, "
+ "\bpollerr\b, and \bpollnval\b are always set to 'true' in "
+ "\brevents\b if the conditions they indicate are true; this "
+ "occurs even though these flags were not present and/or set "
+ "to 'true' in the \bevents\b compound variable.]"
+
+"[+?If none of the defined events have occurred on any selected "
+ "file descriptor, poll waits at least timeout milliseconds "
+ "for an event to occur on any of the selected file "
+ "descriptors. "
+ "On a computer where millisecond timing accuracy is not "
+ "available, timeout is rounded up to the nearest legal value "
+ "available on that system. If the value timeout is 0, poll "
+ "returns immediately. If the value of timeout is -1, poll "
+ "blocks until a requested event occurs or until the call is "
+ "interrupted.]"
+
+"[+?The poll utility supports regular files, terminal and "
+ "pseudo-terminal devices, STREAMS-based files, FIFOs, and "
+ "pipes. The behavior of poll on elements of fds that refer "
+ "to other types of file is unspecified.]"
+
+"[+?The poll utility supports sockets.]"
+#ifdef __SunOS
+"[+?The poll utility may be used on Solaris on directory fds of "
+ "/proc/$pid/ to get a \bpollhup='true'\b when the process quits.]"
+#endif
+"[+?A file descriptor for a socket that is listening for connections "
+ "will indicate that it is ready for reading, once connections "
+ "are available. A file descriptor for a socket that "
+ "is connecting asynchronously will indicate that it is ready "
+ "for writing, once a connection has been established.]"
+
+"[+?Regular files always poll TRUE for reading and writing.]"
+
+"[e:eventarray]:[fdcount?Upon successful completion, an indexed array "
+ "of strings is returned which contains a list of array "
+ "subscripts in the poll array which received events.]"
+"[S!:pollsfio?Look into sfio streams for buffered information and set "
+ "pollin/pollout to reflect sfio stream state.]"
+"[R:pollttyraw?Put tty connections into raw mode when polling. The "
+ "fd is returned to tty cooked mode before poll(1) exits.]"
+"[t:timeout]:[seconds?Timeout in seconds. If the value timeout is 0, "
+ "poll returns immediately. If the value of timeout is -1, "
+ "poll blocks until a requested event occurs or until the "
+ "call is interrupted.]"
+"\n"
+"\nvar\n"
+"\n"
+"[+EXIT STATUS?]{"
+ "[+0?Success.]"
+ "[+>0?An error occurred.]"
+"}"
+"[+NOTES?]{"
+ "[+?poll*-variables defined in \bevents\b will always appear "
+ "in \brevents\b. This gives the script author control over "
+ "which poll*-variables he can expect in \brevents\b.]"
+
+ "[+?The \bpollinhup\b, \bpollnval\b and \bpollerr\b variables "
+ "may appear in the \brevents\b compound variable even if "
+ "they were not requested in \bevents\b.]"
+
+ "[+?Using the value of variables in \brevents\b which are "
+ "not set in \bevents\b can be done by putting a '-' suffix "
+ "after the variable name, e.g. use "
+ "\b${ar[x]].revents.pollhup-}\b to get the value of "
+ "\bar[x]].revents.pollhup\b or an empty string if the variable "
+ "was not set.]"
+
+ "[+?Like \bpoll\b(2) it is legal to poll on the same fd in "
+ "multiple entries, for exanple to listen for different events "
+ "or to allow multiple callers to pool their poll lists "
+ "together into one \bpoll\b(1) call.]"
+"}"
+
+/* quoting: ']' must be quoted as "]]" and '?' must be quoted as "//" */
+"[+EXAMPLES?]{"
+ "[+?The following example will wait for 10 seconds for input "
+ "on fd 0, variable \bp[fd0]].revents.pollin\b will be 'true' "
+ "or 'false' depening on whether the stream 0 is ready for "
+ "reading:]{"
+ "[+?compound -A p=( [fd0]]=( fd=0 events=( pollin='true' ) ) ) ; poll -t10 p ; print -v p]"
+ "}"
+
+ "[+?The following example will wait for 2 seconds for input "
+ "on fd 0, and variables \bp[0]].revents.pollin\b and "
+ "\bp[0]].revents.pollhup\b will be 'true' after polling ends "
+ "because there is both input data available and the end of "
+ "the stream was reached:]{"
+ "[+?printf '\\n' | ksh -c 'compound -a p=( ( fd=0 events=( pollin=\"true\" pollhup=\"true\" ) ) ) ; poll -t2 p ; print -v p']"
+ "}"
+"}"
+
+"[+SEE ALSO?\bopen\b(1),\btmpfile\b(1),\bdup\b(1),\bclose\b(1),\bpoll\b(2)]"
+;
+
+
+/* Like |nv_open()| but constructs variable name on the fly using |sprintf()| format */
+static
+Namval_t *nv_open_fmt(Dt_t *dict, int flags, const char *namefmt, ...)
+{
+ char varnamebuff[PATH_MAX];
+ va_list ap;
+
+ va_start(ap, namefmt);
+ vsnprintf(varnamebuff, sizeof(varnamebuff), namefmt, ap);
+ va_end(ap);
+
+ return nv_open(varnamebuff, dict, flags);
+}
+
+/* Name/value mapping table for POLL*-flags */
+struct pollflagnamemap
+{
+ const int flag;
+ const char *name;
+};
+
+const
+struct pollflagnamemap pfnm[]=
+{
+ { POLLIN, "pollin" },
+#ifdef POLLPRI
+ { POLLPRI, "pollpri" },
+#endif
+ { POLLOUT, "pollout" },
+#ifdef POLLRDNORM
+ { POLLRDNORM, "pollrdnorm" },
+#endif
+#ifdef POLLWRNORM
+ { POLLWRNORM, "pollwrnorm" },
+#endif
+#ifdef POLLRDBAND
+ { POLLRDBAND, "pollrdband" },
+#endif
+#ifdef POLLWRBAND
+ { POLLWRBAND, "pollwrband" },
+#endif
+#ifdef POLLMSG
+ { POLLMSG, "pollmsg" },
+#endif
+#ifdef POLLREMOVE
+ { POLLREMOVE, "pollremove" },
+#endif
+#ifdef POLLRDHUP
+ { POLLRDHUP, "pollrdhup" },
+#endif
+ { POLLERR, "pollerr" },
+ { POLLHUP, "pollhup" },
+ { POLLNVAL, "pollnval" },
+ { 0, NULL },
+};
+
+/* structure to keep track of per array entry data */
+struct pollstat
+{
+ /* name of array subscript */
+ const char *array_subscript;
+
+ /* |sfio| keeps track of sfio information */
+ struct
+ {
+ Sfio_t *sfd;
+ ssize_t flags;
+ } sfio;
+
+ /*
+ * Bits in |eventvar_found| are POLL*-bits, set if matching
+ * ar[i].events.poll* var was found. We use this later to
+ * set the same ar[i].revents.poll* variable, regardless
+ * whether it was polled or not. This was done so the script
+ * author can control which poll* variables in the "revents"
+ * compound appear and which not.
+ */
+ int eventvar_found;
+};
+
+/* poll on given |fds| data and retry after EINTR/EAGAIN while adjusting timeout */
+static
+int poll_loop(Shbltin_t* context, struct pollfd *fds, nfds_t nfds, int timeout)
+{
+/* nanoseconds to milliseconds */
+#define TIME_NS2MS(t) ((t)/(1000UL*1000UL))
+/* milliseconds to nanoseconds */
+#define TIME_MS2NS(t) (((Time_t)(t))*(1000UL*1000UL))
+
+ int n;
+
+ /* We need two codepaths here:
+ * 1. timeout > 0: we have to wait for |timeout| or events.
+ * 2. timeout <= 0: we have to wait forever (-1), return
+ * immediately (0) or an event occurs.
+ */
+ if (timeout > 0)
+ {
+ const Time_t starttime = tmxgettime();
+ Time_t timeout_ns = TIME_MS2NS(timeout);
+
+ do
+ {
+ while(((n = poll(fds, nfds, timeout)) < 0) &&
+ ((errno == EINTR) || (errno == EAGAIN)) &&
+ (!context->sigset))
+ errno=0;
+
+ timeout_ns=timeout_ns-(tmxgettime()-starttime);
+ timeout=TIME_NS2MS(timeout_ns);
+ } while((timeout > 0) && (!context->sigset));
+ }
+ else
+ {
+ while(((n = poll(fds, nfds, timeout)) < 0) &&
+ ((errno == EINTR) || (errno == EAGAIN)) &&
+ (!context->sigset))
+ errno=0;
+ }
+ return n;
+}
+
+/* set ".poll*"-variables in "ar[i].revents" per data in |currpollfd| and |currps| */
+static
+void set_compound_revents(Shell_t *shp, const char *parrayname, struct pollstat *currps, struct pollfd *currpollfd)
+{
+ const char *subname=currps->array_subscript;
+ Namval_t *np;
+ int pi;
+
+ np = nv_open_fmt(shp->var_tree, NV_VARNAME|NV_NOFAIL|NV_COMVAR, "%s[%s].revents", parrayname, subname);
+ if (!np)
+ {
+ errormsg(SH_DICT, ERROR_ERROR, "could not create pollfd %s[%s].revents", parrayname, subname);
+ return;
+ }
+ nv_setvtree(np); /* make "revents" really a compound variable */
+ nv_close(np);
+
+ for (pi=0 ; pfnm[pi].name != NULL ; pi++)
+ {
+ /*
+ * POLLHUP|POLLNVAL|POLLERR can always appear in |currpollfd->revents|
+ * even if we did not request them in |currpollfd->events|
+ */
+ if ((currps->eventvar_found & pfnm[pi].flag) ||
+ ((currpollfd->revents & (POLLHUP|POLLNVAL|POLLERR)) & pfnm[pi].flag))
+ {
+ np = nv_open_fmt(shp->var_tree, NV_VARNAME|NV_NOFAIL, "%s[%s].revents.%s", parrayname, subname, pfnm[pi].name);
+ if (!np)
+ continue;
+
+ nv_putval(np, ((currpollfd->revents & pfnm[pi].flag)?"true":"false"), 0);
+ nv_close(np);
+ }
+ }
+}
+
+/* |main()| for poll(1) builtin */
+extern
+int b_poll(int argc, char *argv[], Shbltin_t* context)
+{
+ Shell_t *shp = sh_contexttoshell(context);
+ Namval_t *np,
+ *array_np,
+ *array_np_sub;
+ Sfio_t *strstk = NULL; /* stk object for memory allocations */
+ const char *parrayname, /* name of array with poll data */
+ *eventarrayname = NULL, /* name of array with indexes to results */
+ *subname, /* current subscript */
+ *s;
+ int n;
+ int fd;
+ nfds_t numpollfd = 0; /* number of entries to poll */
+ int i,
+ j;
+ double timeout = -1.;
+ char buff[PATH_MAX*2+1]; /* fixme: theoretically enough to hold two variable names */
+ bool ttyraw = false;
+ bool pollsfio = true;
+ int pi; /* index for |pfnm| */
+ struct pollfd *pollfd = NULL, /* data for poll(2) */
+ *currpollfd; /* current |pollfd| we are working on */
+ struct pollstat *pollstat = NULL, /* context data from shell array */
+ *currps; /* current |pollstat| we are working on */
+ int retval = 0; /* return value of builtin */
+
+ while (n = optget(argv, sh_optpoll)) switch (n)
+ {
+ case 't':
+ errno = 0;
+ timeout = strtod(opt_info.arg, (char **)NULL);
+ if (errno != 0)
+ errormsg(SH_DICT, ERROR_system(1), "%s: invalid timeout", opt_info.arg);
+
+ /* -t uses seconds */
+ if (timeout >=0)
+ timeout *= 1000.;
+ break;
+ case 'e':
+ eventarrayname = opt_info.arg;
+ break;
+ case 'S':
+ pollsfio=opt_info.num?true:false;
+ break;
+ case 'R':
+ ttyraw=opt_info.num?true:false;
+ break;
+ case ':':
+ errormsg(SH_DICT, ERROR_ERROR, "%s", opt_info.arg);
+ break;
+ case '?':
+ errormsg(SH_DICT, ERROR_usage(2), "%s", opt_info.arg);
+ break;
+ }
+ argc -= opt_info.index;
+ argv += opt_info.index;
+ if(argc!=1)
+ errormsg(SH_DICT, ERROR_usage(2), optusage((char*)0));
+
+ parrayname = argv[0];
+
+ strstk = stkopen(0);
+ if (!strstk)
+ errormsg(SH_DICT, ERROR_system(1), e_nospace);
+
+ array_np = nv_open(parrayname, shp->var_tree, NV_VARNAME|NV_NOFAIL|NV_NOADD);
+ if (!array_np)
+ {
+ stkclose(strstk);
+ errormsg(SH_DICT, ERROR_system(1), "cannot find array variable %s", parrayname);
+ }
+ if (!nv_isattr(array_np, NV_ARRAY))
+ {
+ nv_close(array_np);
+ stkclose(strstk);
+ errormsg(SH_DICT, ERROR_system(1), "variable %s is not an array", parrayname);
+ }
+
+ /*
+ * Count number of array elememts. We need to do it "manually"
+ * to handle sparse indexed and associative arrays
+ */
+ nv_putsub(array_np, NULL, ARRAY_SCAN);
+ array_np_sub = array_np;
+ do
+ {
+ if (!(subname=nv_getsub(array_np_sub)))
+ break;
+ numpollfd++;
+ } while(array_np_sub && nv_nextsub(array_np_sub));
+
+ /*
+ * Done with counting, now we need to allocate a work area big enough
+ */
+ pollfd = (struct pollfd *)stkalloc(strstk, (sizeof(struct pollfd) * numpollfd));
+ pollstat = (struct pollstat *)stkalloc(strstk, (sizeof(struct pollstat) * numpollfd));
+ if (!pollfd || !pollstat)
+ {
+ errormsg(SH_DICT, ERROR_ERROR, e_nospace);
+ goto done_error;
+ }
+
+ /*
+ * Walk the array again and fetch the data we need...
+ */
+ nv_putsub(array_np, NULL, ARRAY_SCAN);
+ array_np_sub = array_np;
+ i = 0;
+ do
+ {
+ currps=&pollstat[i];
+ currpollfd=&pollfd[i];
+
+ if (!(subname=nv_getsub(array_np_sub)))
+ break;
+
+ currps->array_subscript=subname=stkcopy(strstk, subname);
+ if (!subname)
+ {
+ errormsg(SH_DICT, ERROR_ERROR, e_nospace);
+ goto done_error;
+ }
+
+ np = nv_open_fmt(shp->var_tree, NV_VARNAME|NV_NOFAIL|NV_NOADD, "%s[%s].fd", parrayname, subname);
+ if (!np)
+ {
+ errormsg(SH_DICT, ERROR_ERROR, "missing pollfd %s[%s].fd", parrayname, subname);
+ goto done_error;
+ }
+ fd = (int)nv_getnum(np);
+ nv_close(np);
+ if ((fd < -1) || (fd > OPEN_MAX))
+ {
+ errormsg(SH_DICT, ERROR_ERROR, "invalid pollfd %s[%s].fd %d", parrayname, subname, fd);
+ goto done_error;
+ }
+ currpollfd->fd = fd;
+
+ np = nv_open_fmt(shp->var_tree, NV_VARNAME|NV_NOFAIL|NV_COMVAR|NV_NOADD, "%s[%s].events", parrayname, subname);
+ if (!np)
+ {
+ errormsg(SH_DICT, ERROR_ERROR, "missing pollfd %s[%s].events", parrayname, subname);
+ goto done_error;
+ }
+ nv_close(np);
+
+ currpollfd->events=0;
+ currpollfd->revents=0;
+ currps->eventvar_found=0;
+ for (pi=0 ; pfnm[pi].name != NULL ; pi++)
+ {
+ const char *s;
+
+ np = nv_open_fmt(shp->var_tree, NV_VARNAME|NV_NOFAIL|NV_NOADD, "%s[%s].events.%s", parrayname, subname, pfnm[pi].name);
+ if (!np)
+ continue;
+
+ currps->eventvar_found |= pfnm[pi].flag;
+ s=nv_getval(np);
+ if ((s != NULL) && (!strcmp(s, "true")))
+ currpollfd->events |= pfnm[pi].flag;
+ nv_close(np);
+ }
+
+ i++;
+ } while(array_np_sub && nv_nextsub(array_np_sub));
+
+ nv_close(array_np);
+ array_np=NULL;
+
+ /*
+ * If sfio handles fds we need to check whether there are
+ * any data in the sfio buffers and remember this information
+ * so we can set { POLLIN, POLLOUT } on demand to reflect
+ * this information.
+ */
+ if (pollsfio)
+ {
+ Sfio_t **sfd;
+ int num_sfd=0,
+ active_sfd=0;
+
+ sfd = (Sfio_t **)stkalloc(strstk, (sizeof(Sfio_t *) * (numpollfd+1)));
+ if (!sfd)
+ {
+ errormsg(SH_DICT, ERROR_ERROR, e_nospace);
+ goto done_error;
+ }
+
+ for (i=0 ; i < numpollfd ; i++)
+ {
+ currps=&pollstat[i];
+ fd=pollfd[i].fd;
+
+ currps->sfio.sfd=(fd>=0)?sh_fd2sfio(fd):NULL;
+ currps->sfio.flags=0;
+ if (currps->sfio.sfd!=NULL)
+ {
+ /* Only add |currps->sfio.sfd| to the
+ * |sfd| array (list of |Sfio_t*|
+ * passed to |sfpoll()|) if it is not
+ * in that list yet. This prevents
+ * that we call |sfpoll()| on the same
+ * sfio stream multiple times (which
+ * can happen if pollfd contains the
+ * same fd multiple times (which is
+ * valid usage, for example if multiple
+ * consumers pool their pool lists in
+ * one poll call or listen to different
+ * sets of poll event flags)).
+ */
+ for (j=0 ; j < num_sfd ; j++)
+ {
+ if (sfd[j]==currps->sfio.sfd)
+ break;
+ }
+ if (j == num_sfd)
+ sfd[num_sfd++]=currps->sfio.sfd;
+ }
+ }
+
+ active_sfd = sfpoll(&sfd[0], num_sfd, 0);
+ if (active_sfd > 0)
+ {
+ ssize_t sfpoll_flags;
+
+ for (i=0 ; i < active_sfd ; i++)
+ {
+ sfpoll_flags=sfvalue(sfd[i]);
+
+ /*
+ * We have to loop over all entries
+ * because single fd may be polled
+ * multiple times in different pollfd
+ * entries
+ */
+ for (j=0 ; j < numpollfd ; j++)
+ {
+ if (pollstat[j].sfio.sfd == sfd[i])
+ pollstat[j].sfio.flags=sfpoll_flags;
+ }
+ }
+ }
+ }
+
+ /*
+ * Create --eventarray array on demand
+ */
+ if (eventarrayname)
+ {
+ np = nv_open_fmt(shp->var_tree, NV_VARNAME|NV_ARRAY|NV_NOFAIL, "%s", eventarrayname);
+ if (!np)
+ {
+ errormsg(SH_DICT, ERROR_ERROR, "could not create eventarray variable %s", eventarrayname);
+ goto done_error;
+ }
+
+ nv_close(np);
+ }
+
+ /*
+ * Make sure we poll on "raw" tty to catch _every_ keystroke...
+ */
+ if (ttyraw)
+ {
+ for (i=0 ; i < numpollfd ; i++)
+ {
+ fd=pollfd[i].fd;
+ if ((fd >=0) && (shp->fdstatus[fd]&IOTTY))
+ tty_raw(fd, 1);
+ }
+ }
+
+ /*
+ * ... then poll for events...
+ */
+ n = poll_loop(context, pollfd, numpollfd, timeout);
+
+ /*
+ * ... and restore the tty's to "cooked" mode
+ */
+ if (ttyraw)
+ {
+ for (i=0 ; i < numpollfd ; i++)
+ {
+ fd=pollfd[i].fd;
+ if ((fd >=0) && (shp->fdstatus[fd]&IOTTY))
+ tty_cooked(fd);
+ }
+ }
+
+ if (n < 0)
+ {
+ /* |ERROR_system(0)| won't quit the builtin */
+ errormsg(SH_DICT, ERROR_system(0), "poll(2) failure");
+ retval=1;
+ }
+
+ /*
+ * Write results back into the array
+ */
+ for (i=0 ; i < numpollfd ; i++)
+ {
+ /* Adjust data in |pollfd[i]| to reflect sfio stream status (if requested) */
+ if (pollsfio)
+ {
+ if ((pollfd[i].events & POLLIN) && (pollstat[i].sfio.flags & SF_READ))
+ pollfd[i].revents |= POLLIN;
+ if ((pollfd[i].events & POLLOUT) && (pollstat[i].sfio.flags & SF_WRITE))
+ pollfd[i].revents |= POLLOUT;
+ }
+
+ set_compound_revents(shp, parrayname, &pollstat[i], &pollfd[i]);
+
+ if (eventarrayname && pollfd[i].revents)
+ {
+ sprintf(buff, "%s+=( '%s' )", eventarrayname, pollstat[i].array_subscript);
+ sh_trap(buff, 0);
+ }
+ }
+
+ goto done;
+
+done_error:
+ retval=1;
+done:
+ if (array_np)
+ nv_close(array_np);
+ if (strstk)
+ stkclose(strstk);
+
+ return(retval);
+}
--- src/cmd/ksh93/data/builtins.c
+++ src/cmd/ksh93/data/builtins.c 2012-08-06 21:25:47.000000000 +0000
@@ -109,6 +109,7 @@ const struct shtable3 shtab_builtins[] =
#endif /* JOBS */
"false", NV_BLTIN|BLT_ENV, bltin(false),
"getopts", NV_BLTIN|BLT_ENV, bltin(getopts),
+ "poll", NV_BLTIN, bltin(poll),
"print", NV_BLTIN|BLT_ENV, bltin(print),
"printf", NV_BLTIN|BLT_ENV, bltin(printf),
"pwd", NV_BLTIN, bltin(pwd),
--- src/cmd/ksh93/include/builtins.h
+++ src/cmd/ksh93/include/builtins.h 2012-08-06 21:25:47.000000000 +0000
@@ -100,6 +100,7 @@ extern int b_wait(int, char*[],Shbltin_t
extern int b_whence(int, char*[],Shbltin_t*);
extern int b_alarm(int, char*[],Shbltin_t*);
+extern int b_poll(int, char*[],Shbltin_t*);
extern int b_print(int, char*[],Shbltin_t*);
extern int b_printf(int, char*[],Shbltin_t*);
extern int b_pwd(int, char*[],Shbltin_t*);
--- src/cmd/ksh93/tests/builtin_poll.sh
+++ src/cmd/ksh93/tests/builtin_poll.sh 2012-08-07 01:22:35.000000000 +0000
@@ -0,0 +1,100 @@
+########################################################################
+# #
+# This software is part of the ast package #
+# Copyright (c) 2009-2012 Roland Mainz #
+# and is licensed under the #
+# Eclipse Public License, Version 1.0 #
+# by AT&T Intellectual Property #
+# #
+# A copy of the License is available at #
+# http://www.eclipse.org/org/documents/epl-v10.html #
+# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
+# #
+# #
+# Roland Mainz <roland.mainz@nrubsig.org> #
+# #
+########################################################################
+
+#
+# Copyright (c) 2009, 2012, Roland Mainz. All rights reserved.
+#
+
+#
+# Test module to check the ksh93 "poll" builtin
+#
+
+# test setup
+function err_exit
+{
+ print -u2 -n '\t'
+ print -u2 -r ${Command}[$1]: "${@:2}"
+ (( Errors++ ))
+}
+alias err_exit='err_exit $LINENO'
+
+set -o nounset
+Command=${0##*/}
+integer Errors=0
+
+typeset ocwd
+typeset tmpdir
+
+# create temporary test directory
+ocwd="${PWD}"
+tmpdir="${ mktemp -t -d 'test_builtin_poll.XXXXXXXX' ; }" || err_exit 'Cannot create temporary directory.'
+
+cd "${tmpdir}" || { err_exit "cd ${tmpdir} failed." ; exit $((Errors<125?Errors:125)) ; }
+
+
+# basic tests
+function test1
+{
+ compound d1=(
+ compound -A u=(
+ [y]=( integer fd=5 ; compound events=( pollin='true' ) revents=() )
+ [x]=( integer fd=5 ; compound events=( pollin='true' ) revents=() )
+ )
+ )
+
+ # test 1:
+ print -C d1 >'testdata.cpv'
+ cat '/dev/zero' | $SHELL -o errexit -c 'builtin poll ; read -C <"testdata.cpv" d1 ; redirect 5<&0 ; poll -e d1.res -t 5. d1.u ; print -C d1 >"testdata.cpv"' >'log.txt' 2>&1 || err_exit "poll returned non-zero exit code $?"
+ unset d1 ; read -C d1 <'testdata.cpv' || err_exit 'Cannot read test data.'
+ [[ "$(< 'log.txt')" == '' ]] || err_exit "Excepted empty stdout/stderr, got $(printf '%q\n' "$(< 'log.txt')")"
+ [[ "${d1.u[x].revents.pollin-}" == 'true' ]] || err_exit "d1.u[x].revents contains '${d1.u[x].revents-}', not 'POLLIN'"
+ [[ "${d1.u[y].revents.pollin-}" == 'true' ]] || err_exit "d1.u[y].revents contains '${d1.u[y].revents-}', not 'POLLIN'"
+ [[ "${d1.res[*]-}" == 'x y' ]] || err_exit "d1.res contains '${d1.res[*]-}', not 'x y'"
+
+ rm 'testdata.cpv' 'log.txt'
+
+ # test 2:
+ unset d1.res
+ d1.u[z]=( integer fd=5 ; compound events=( pollout='true' ) revents=() )
+
+ print -C d1 >'testdata.cpv'
+ $SHELL -o errexit -c 'builtin poll ; read -C <"testdata.cpv" d1 ; { poll -e d1.res -t 5. d1.u ; } 5<"/dev/null" 5>"/dev/null" ; print -C d1 >"testdata.cpv"' >'log.txt' 2>&1 || err_exit "poll returned non-zero exit code $?"
+ unset d1 ; read -C d1 <'testdata.cpv' || err_exit 'Cannot read test data.'
+
+ [[ "$(< 'log.txt')" == '' ]] || err_exit "Excepted empty stdout/stderr, got $(printf '%q\n' "$(< 'log.txt')")"
+ [[ "${d1.u[x].revents.pollin-}" == 'true' ]] || err_exit "d1.u[x].revents contains '${d1.u[x].revents-}', not 'POLLIN'"
+ [[ "${d1.u[y].revents.pollin-}" == 'true' ]] || err_exit "d1.u[y].revents contains '${d1.u[y].revents-}', not 'POLLIN'"
+ [[ "${d1.u[z].revents.pollout-}" == 'true' ]] || err_exit "d1.u[z].revents contains '${d1.u[z].revents-}', not 'POLLOUT,'"
+ [[ "${d1.res[*]-}" == 'x y z' ]] || err_exit "d1.res contains '${d1.res[*]-}', not 'x y z'"
+
+ rm 'testdata.cpv' 'log.txt'
+
+ return 0
+}
+
+# run tests
+builtin 'poll' || err_exit 'poll builtin not found.'
+
+test1
+
+# cleanup
+cd "${ocwd}"
+rmdir "${tmpdir}" || err_exit "Cannot remove temporary directory ${tmpdir}."
+
+
+# tests done
+exit $((Errors<125?Errors:125))

24
cpp.patch Normal file
View File

@ -0,0 +1,24 @@
iffe depends on cc -E not inserting newlines between tokens
Index: ksh93/src/cmd/INIT/iffe.sh
===================================================================
--- ksh93.orig/src/cmd/INIT/iffe.sh
+++ ksh93/src/cmd/INIT/iffe.sh
@@ -3427,7 +3427,7 @@ $src
(eval "$src") <&$nullin || e=1
;;
mac*|nomac*)
- if compile $cc -E $tmp.c <&$nullin >$tmp.i
+ if compile $cc -E -P $tmp.c <&$nullin >$tmp.i
then sed -e '/<<[ ]*".*"[ ]*>>/!d' -e 's/<<[ ]*"//g' -e 's/"[ ]*>>//g' $tmp.i
else e=1
fi
@@ -3718,7 +3718,7 @@ $inc
<<\"#define $v\">> $v <<\"/* native $v */\">>
<<\"#endif\">>
#endif" > $tmp.c
- if compile $cc -E $tmp.c <&$nullin >$tmp.i
+ if compile $cc -E -P $tmp.c <&$nullin >$tmp.i
then sed -e '/<<[ ]*".*"[ ]*>>/!d' -e 's/<<[ ]*"//g' -e 's/"[ ]*>>//g' $tmp.i > $tmp.t
if test -s $tmp.t
then success

56
ifs-crash.sh Normal file
View File

@ -0,0 +1,56 @@
#!/bin/ksh
typeset -lui count=${1:-4}
function g
{
IFS=
}
function f
{
typeset IFS
(g)
: $V
}
while ((count-- > 0))
do
f
done
function crash
{
typeset L_FILE
typeset L_VALIDATION
typeset L_VARIABLE
typeset L_MOD IFS
OS=$(uname)
}
crash
function crash2
{
typeset IFS
IFS='\t'
true
unset IFS
echo a b c | while read x y z; do
echo $x
echo $y
echo $z
done
}
crash2
echo a b c | while read x y z; do
echo $x
echo $y
echo $z
done
echo "[${0##*/}: success]"
# end here

8
ksh-locale.patch Normal file
View File

@ -0,0 +1,8 @@
--- lib/package/ast-ksh.pkg
+++ lib/package/ast-ksh.pkg 2011-07-05 16:29:57.891926052 +0000
@@ -1,4 +1,4 @@
-ast-ksh :PACKAGE: ksh93 libast libcmd libcoshell libsum libdll
+ast-ksh :PACKAGE: msgcc ksh93 libpp libast libcmd libcoshell libsum libdll
:COVERS: ksh

14
ksh-rpmlintrc Normal file
View File

@ -0,0 +1,14 @@
addFilter(".*binary-or-shlib-defines-rpath.*/lib/ast/.*\.so.*")
addFilter(".*binary-or-shlib-defines-rpath.*/lib/ast/bin/shcomp.*")
addFilter(".*binary-or-shlib-defines-rpath.*/lib/ast/bin/ksh.*")
addFilter(".*binary-or-shlib-defines-rpath.*/lib64/ast/.*\.so.*")
addFilter(".*binary-or-shlib-defines-rpath.*/lib64/ast/bin/shcomp.*")
addFilter(".*binary-or-shlib-defines-rpath.*/lib64/ast/bin/ksh.*")
addFilter(".*suse-filelist-forbidden-devel-in-lib.*/lib/ast/.*\.so.*")
addFilter(".*suse-filelist-forbidden-devel-in-lib.*/lib64/ast/.*\.so.*")
addFilter(".*devel-file-in-non-devel-package.*/lib/ast/.*\.so")
addFilter(".*devel-file-in-non-devel-package.*/lib64/ast/.*\.so")
addFilter(".*script-without-shebang.*/usr/share/ksh/fun/.*")
addFilter(".*no-rpm-opt-flags.*ldtest.c.*")
addFilter(".*invalid-suse-version-check.*")
addFilter(".*obsolete-suse-version-check.*")

2843
ksh.changes Normal file

File diff suppressed because it is too large Load Diff

904
ksh.spec Normal file
View File

@ -0,0 +1,904 @@
#
# spec file for package ksh
#
# Copyright (c) 2024 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
# Please submit bugfixes or comments via https://bugs.opensuse.org/
#
Name: ksh
%global date 2012-08-01
%global use_suid_exe 0
%global use_opt_bins 1
%if !0%{?qemu_user_space_build:1}
%global do_tests 1
%else
%global do_tests 0
%endif
%global use_locale 0
%if 0%{?suse_version} >= 1550
%define libdir %{_libdir}
%define bindir %{_bindir}
%else
%define libdir /%{_lib}
%define bindir /bin
%endif
BuildRequires: bind-utils
BuildRequires: bison
BuildRequires: flex
BuildRequires: gdbm-devel
BuildRequires: glibc-devel
BuildRequires: groff
BuildRequires: libbz2-devel
BuildRequires: ncurses-devel
BuildRequires: procps
BuildRequires: psmisc
BuildRequires: update-alternatives
BuildRequires: zlib-devel
# /bin/ex and /bin/ed required for build
BuildRequires: awk
BuildRequires: ed
BuildRequires: strace
BuildRequires: vim
URL: http://www.research.att.com/~gsf/download/
Requires(post): /bin/ln /bin/rm /etc/bash.bashrc /bin/true
Requires(postun):/bin/ln /bin/rm /etc/bash.bashrc /bin/true
Requires(post): update-alternatives
Requires(preun):update-alternatives
%if %use_suid_exe
PreReq: permissions
%endif
Version: 93vu
Release: 0
Summary: Korn Shell
License: CPL-1.0 AND EPL-1.0
Group: System/Shells
BuildRoot: %{_tmppath}/%{name}-%{version}-build
Source: INIT.%{date}.tar.bz2
Source1: ast-base.%{date}.tar.bz2
Source3: EPL
Source4: CPL
Source10: leak1.sh
Source11: leak2.sh
Source12: ifs-crash.sh
Source13: ulimit.sh
Source14: leak3.sh
Source20: Agreement
Source21: Warning
Source30: ksh-rpmlintrc
Source31: vmbalance
Source42: sigexec.c
Patch0: ksh93.dif
Patch1: workaround-stupid-build-system.diff
Patch2: ksh93-no-posix_spawn.dif
Patch3: ksh93-shift_ijs.dif
Patch4: ksh93-gmt2utc.dif
Patch5: ksh93-uname.dif
Patch6: ksh93-vi.dif
Patch7: ksh93-profile.dif
Patch8: ksh93-test.dif
Patch9: ksh93-compat.dif
Patch10: ksh93-suid_exec.dif
Patch11: ksh93-signals.dif
Patch12: ksh93-limits.dif
Patch13: ksh93-unset-f.dif
Patch14: ksh93-ia64.dif
Patch15: ksh93-s390.dif
Patch16: ksh93-gcc.dif
Patch17: ksh93-heredoc.dif
Patch18: ksh93-jobs.dif
Patch19: ksh93-reg.dif
Patch20: ksh93-aso.dif
Patch21: ksh93-vm.dif
Patch22: ksh93-limit-name-len.dif
Patch23: ksh93-foreground-prgrp.dif
Patch24: ksh93-builtin.dif
# PATCH-FIX-UPSTREAM ksh93-read-dont-ignore-esc.dif [bnc#765171]
# is part of ksh93u+ 2012-06-28
# PATCH-EXTEND-UPSTREAM astksh_builtin_poll20120806_001.diff [bnc#779888]
Patch27: astksh_builtin_poll20120806_001.diff
# PATCH-FIX-UPSTREAM ksh93-env.dif [bnc#785266, bnc#803613]
Patch28: ksh93-env.dif
# PATCH-FIX-UPSTREAM ksh93-typedef.dif
Patch29: ksh93-typedef.dif
# PATCH-EXTEND-UPSTREAM ksh93-pathtemp.dif [bnc#786134]
# the fix is part of ksh93u+ 2012-06-28
# nevertheless the /dev/shm extension is useful
Patch30: ksh93-pathtemp.dif
# PATCH-FIX-UPSTREAM ksh93-dttree-crash.dif [bnc#795324]
Patch31: ksh93-dttree-crash.dif
# PATCH-FIX-UPSTREAM ksh93-heredoclex.dif [bnc#804998]
Patch32: ksh93-heredoclex.dif
# PATCH-FIX-UPSTREAM ksh93-fdstatus.dif [bnc#808449, bnc#814135]
# this is a backport from the alpha version ksh93v-2013-04-22
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-UPSTREAM Ouch ... use memmove instead of memcopy on overlapping areas
Patch36: ksh93-sfio.dif
# [bnc#899014]
Patch37: ksh93-path-skip.dif
Patch38: ksh93-fs3d.dif
# [bnc#852160]
Patch39: ksh93-subshellpwd.dif
# [bnc#867401]
Patch40: ksh93-cdpwd.dif
# [bnc#893031]
Patch41: ksh93-longenv.dif
Patch42: ksh93-malloc-hook.dif
Patch43: ksh93-disable-vfork.dif
Patch44: ksh93-joblock.dif
Patch45: ksh93-stkfreeze.dif
Patch46: ksh93-stkset-abort.dif
Patch47: ksh93-stkalias.dif
Patch48: ksh93-backtick.dif
Patch49: ksh93-nvtree-free.dif
Patch50: ksh93-int16double.dif
Patch51: ksh93-jpold.dif
Patch52: ksh93-redirectleak.dif
Patch53: ksh93-optimizeleak.dif
Patch54: ksh93-edpredict.dif
Patch55: ksh93-spawnlock.dif
Patch56: ksh93-filedefined.dif
Patch57: ksh93-no-sysctl.dif
Patch58: ksh93-putval.dif
Patch59: ksh93-untrustedenv.dif
Patch62: ksh-locale.patch
Patch63: cpp.patch
%description
The original Korn Shell. The ksh is an sh-compatible command
interpreter that executes commands read from standard input or from a
file.
Authors:
--------
David Korn <dgk@research.att.com>
Glenn Fowler <gsf@research.att.com>
Phong Vo <kpv@research.att.com>
%package -n ksh-devel
Summary: Korn Shell development environment
License: CPL-1.0
Group: Development/Libraries/C and C++
Requires: ksh = %{version}-%{release}
%description -n ksh-devel
The package includes C header files and the static libraries together
with the shared libraries for linking with other projects. Please be
aware that the CPL licensed code can not be used within GPL licensed
project.
Authors:
--------
David Korn <dgk@research.att.com>
Glenn Fowler <gsf@research.att.com>
Phong Vo <kpv@research.att.com>
%prep
chmod +x %{S:31}
%setup -q -n ksh93 -T -c -a 0
tar --use-compress-program=bzcat -xf %{S:1} \
lib/package/ \
src/cmd/ksh93/ src/lib/libast/ src/lib/libcmd/ src/lib/libcoshell/ src/lib/libdll/ src/lib/libsum/ \
src/cmd/builtin/ src/cmd/msgcc/ src/lib/libpp/ src/lib/libuu/
if test -d share ; then
find share/ \( -name chef -o -name fudd -o -name piglatin -o -name valley \) -a -type d |\
xargs -r rm -vrf
find share/ ! \( -name libast -o -name libcmd -o -name libdll -o -name libshell \) -a -type f |\
xargs -r rm -vf
find share/ -type d -a -empty | xargs -r rm -vrf
find share/ -type d -a -empty | xargs -r rm -vrf
fi
%patch -P 0
%patch -P 62
%patch -P 1
%patch -P 2
%patch -P 3
%patch -P 4
%patch -P 5
%patch -P 6
%patch -P 7
%patch -P 8
%patch -P 9
%patch -P 10
%patch -P 11
%patch -P 12
%patch -P 13
%ifarch ia64
%patch -P 14
%endif
%patch -P 15
%patch -P 16
%patch -P 17
%patch -P 18
%patch -P 19
%patch -P 20
%patch -P 21
%patch -P 22
%patch -P 23
%patch -P 24
%patch -P 27
%patch -P 28
%patch -P 29
%patch -P 30
%patch -P 31
%patch -P 32
%patch -P 33
%patch -P 34
%patch -P 35
%patch -P 36
%patch -P 37
%patch -P 38
%patch -P 39
%patch -P 40
%patch -P 41
%patch -P 42
%if 0%{?ksh_no_vfork}
%patch -P 43
%endif
%patch -P 44
%patch -P 45
%patch -P 46
%patch -P 47
%patch -P 48
%patch -P 49
%patch -P 50
%patch -P 51
%patch -P 52
%patch -P 53
%patch -P 54
%patch -P 55
%patch -P 56
%patch -P 57
%patch -P 58
%patch -P 59
%patch -P 63 -p 1
%build
%global _lto_cflags %{_lto_cflags} -ffat-lto-objects
#
# Check for a clean signal environment for runtime tests
#
typeset -i IGNORED=0x$(ps --no-headers -o ignored $$)
typeset -i SIGMASK=0x0
typeset -i usesigexec=0
let "SIGMASK|=(1<<($(kill -l PIPE)-1))"
let "SIGMASK|=(1<<($(kill -l URG) -1))"
let "SIGMASK|=(1<<($(kill -l XFSZ)-1))"
((IGNORED & SIGMASK)) && let ++usesigexec || true
test -t 0 || let ++usesigexec
%if 0%{?qemu_user_space_build:1}
# agraf: In a qemu user space build, ps can not find the actual sigmask
# of processes, so we run into an endless loop. Disable sigexec.
usesigexec=0
%endif
if ((usesigexec > 0)) ; then
${CC:-gcc} ${RPM_OPT_FLAGS} -o sigexec %{S:42} -lutil
for fd in /proc/$$/fd/*; do
test -s $fd -a ! -c $fd && break || true
done
set -- $(readlink $fd)
exec ./sigexec $SHELL ${1+"$@"}
fi
IGNORED=0x$(ps --no-headers -o ignored $$)
AR="ar"
CC=gcc
PATH=${PWD}:$PATH
LANG=POSIX
TMPDIR=$(mktemp -d /tmp/ksh-build.XXXXXX) || exit 1
SUSE_ASNEEDED=0
export AR CC PATH LANG TMPDIR SUSE_ASNEEDED
#
# Remove optimizer which cause runtime leaks in ksh
#
RPM_OPT_FLAGS="${RPM_OPT_FLAGS//-funwind-tables/}"
RPM_OPT_FLAGS="${RPM_OPT_FLAGS//-fasynchronous-unwind-tables/}"
# This package failed when testing with -Wl,-as-needed being default.
# So we disable it here, if you want to retest, just delete this
# comment and the line below.
RPM_OPT_FLAGS="${RPM_OPT_FLAGS//-as-needed/-no-as-needed/}"
# Use POSIX as environment
test -n "${!LC_*}" && unset "${!LC_*}"
# ksh currently does not build with -Werror=return-type
RPM_OPT_FLAGS="${RPM_OPT_FLAGS//-Werror=return-type/}"
cflags ()
{
set +x
local flag=$1; shift
local var=$1; shift
test -n "${flag}" -a -n "${var}" || return
case "${!var}" in
*${flag}*) return
esac
set -o noclobber
case "$flag" in
-Wl,*)
if echo 'int main () { return 0; }' | \
${CC:-gcc} -Werror $flag -o /dev/null -xc - > /dev/null 2>&1 ; then
eval $var=\${$var:+\$$var\ }$flag
fi
;;
*)
if ${CC:-gcc} -Werror $flag -S -o /dev/null -xc /dev/null > /dev/null 2>&1 ; then
eval $var=\${$var:+\$$var\ }$flag
fi
esac
set +o noclobber
set -x
}
relink ()
{
set +x
local search=$1; shift
local target=$1; shift
test -n "${search}" -a -n "${target}" || exit 1
local object=$(find ${root:-/tmp}/src/cmd/ -name ${search}.o)
local cmd=$(
grep -e "-o $search" ${log:-/dev/null} | tail -n 1 | \
sed -r -e "s@\+ g?cc@${CC:-gcc}@" \
-e "s@-o $search@-o ${root:-/tmp}$target@" \
-e "s@[[:blank:]]${search}.o[[:blank:]]@ $object @" \
-e "s@[[:blank:]](/[^[:blank:]]*)?lib([[:alnum:]]+)\.a@ -l\2@g" \
-e "s@'@@g")
set -x
$cmd ${1+"$@"}
}
#
# If _you_ are knowing how to fix this in the autogenerated
# sources of ksh/ast without breaking them, then let me know.
#
cflags -Wno-missing-braces IGNORE
cflags -Wno-unknown-pragmas IGNORE
cflags -Wno-parentheses IGNORE
cflags -Wno-char-subscripts IGNORE
cflags -Wno-uninitialized IGNORE
cflags -Wno-implicit IGNORE
cflags -Wno-unused-value IGNORE
cflags -Wno-type-limits IGNORE
cflags -Wclobbered RPM_OPT_FLAGS
#
# Do not use -DSHOPT_SPAWN=1 and/or -DSHOPT_AMP=1 this would cause
# errors due race conditions while executing the test suite.
#
feature=${PWD}/.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
#define SHOPT_CMDLIB_HDR <cmdlist.h>
#define SHOPT_CMDLIB_DIR "%{libdir}/ast/bin"
#define SH_CMDLIB_DIR "%{libdir}/ast/bin"
#define THISPROG "%{libdir}/ast/bin/suid_exec"
#define _AST_std_malloc 0
#define _map_malloc 1
EOF
set +C
FEATURE="-include $feature"
cat $feature
#
#
LARGEFILE="$(getconf LFS_CFLAGS)"
case "$RPM_ARCH" in
i[3456]86)
RPM_OPT_FLAGS="${RPM_OPT_FLAGS//-O[s0-9]/-O2}"
cflags -m32 RPM_OPT_FLAGS
HOSTTYPE=linux.i386
;;
x86_64)
RPM_OPT_FLAGS="${RPM_OPT_FLAGS//-O[s0-9]/-O2}"
cflags -m64 RPM_OPT_FLAGS
HOSTTYPE=linux.i386-64
;;
ia64)
RPM_OPT_FLAGS="${RPM_OPT_FLAGS//-O[s0-9]/-O}"
cflags -mlp64 RPM_OPT_FLAGS
cflags -mno-volatile-asm-stop RPM_OPT_FLAGS
HOSTTYPE=linux.ia64
;;
s390)
RPM_OPT_FLAGS="${RPM_OPT_FLAGS//-O[s0-9]/-O}"
cflags -m31 RPM_OPT_FLAGS
HOSTTYPE=linux.s390
;;
s390*)
RPM_OPT_FLAGS="${RPM_OPT_FLAGS//-O[s0-9]/-O}"
cflags -m64 RPM_OPT_FLAGS
HOSTTYPE=linux.s390-64
;;
ppc|powerpc)
RPM_OPT_FLAGS="${RPM_OPT_FLAGS//-O[s0-9]/-O}"
cflags -mno-powerpc64 RPM_OPT_FLAGS
HOSTTYPE=linux.powerpc
_PACKAGE_HOSTTYPE_=linux.powerpc
export _PACKAGE_HOSTTYPE_
;;
ppc64le|powerpc64le)
RPM_OPT_FLAGS="${RPM_OPT_FLAGS//-O[s0-9]/-O}"
# -mpowerpc64 is correct, the compiler defaults to
# little endian anyway
cflags -mpowerpc64 RPM_OPT_FLAGS
HOSTTYPE=linux.powerpc64le
;;
ppc64|powerpc64)
RPM_OPT_FLAGS="${RPM_OPT_FLAGS//-O[s0-9]/-O}"
cflags -mpowerpc64 RPM_OPT_FLAGS
HOSTTYPE=linux.powerpc64
;;
*)
RPM_OPT_FLAGS="${RPM_OPT_FLAGS//-O[s0-9]/-O}"
HOSTTYPE=linux.$RPM_ARCH
;;
esac
MEMORY=execve
for mm in mmap mmap2 mmap64 munmap munmap2 munmap64 ; do
if strace -e $mm /bin/true > /dev/null 2>&1 ; then
MEMORY="${MEMORY:+${MEMORY},}$mm"
fi
done
MEMORY="-s 128 ${MEMORY:+-e ${MEMORY}}"
RPM_OPT_FLAGS=$(echo "${RPM_OPT_FLAGS}"|sed -r 's/([[:blank:]]+)-g[[:digit:]]+/\1-g2/g;s/([[:blank:]]+)-g([[:blank:]]+|$)/\1-g2\2/g')
UNIVERSE=att
LDFLAGS="-lm"
LDSOFLG=""
cflags -std=gnu99 RPM_OPT_FLAGS
cflags -fPIC RPM_OPT_FLAGS
cflags -fno-strict-aliasing RPM_OPT_FLAGS
cflags -fno-zero-initialized-in-bss RPM_OPT_FLAGS
cflags -fno-delete-null-pointer-checks RPM_OPT_FLAGS
cflags -fno-unsafe-loop-optimizations RPM_OPT_FLAGS
cflags -fsigned-bitfields RPM_OPT_FLAGS
cflags -fsigned-chars RPM_OPT_FLAGS
cflags -fsigned-zeros RPM_OPT_FLAGS
case "$(gcc --version | head -n 1)" in
*4.[012345].*)
cflags -fno-tree-sink RPM_OPT_FLAGS ;;
*) cflags -ftree-loop-linear RPM_OPT_FLAGS ;;
esac
cflags -g2 RPM_OPT_FLAGS
cflags -pipe RPM_OPT_FLAGS
cflags -Wl,-O2 LDFLAGS
cflags -Wl,--hash-size=16699 LDFLAGS
cflags -Wl,-O2 LDSOFLG
cflags -Wl,-warn-common LDSOFLG
cflags -Wl,--as-needed LDSOFLG
cflags -Wl,--hash-size=8599 LDSOFLG
cflags -Wl,-Bsymbolic-functions LDSOFLG
cflags -Wl,-rpath,%{libdir}/ast LDSOFLG
RPM_OPT_FLAGS="$RPM_OPT_FLAGS -D_GNU_SOURCE $LARGEFILE"
RPM_OPT_FLAGS="$RPM_OPT_FLAGS $IGNORE $FEATURE"
mam_cc_L=use
mam_cc_OPTIMIZE=-pipe
export mam_cc_L mam_cc_OPTIMIZE HOSTTYPE LDFLAGS RPM_OPT_FLAGS UNIVERSE
printenv
getconf PAGESIZE
#
# Build libast first and then determine the library functions used
# by this library simply to avoid that gcc will overwrites those with
# its own builtin functions.
#
bin/package view
root=$(echo ${PWD}/arch/linux*)
bin/package make ast-ast CCFLAGS="$RPM_OPT_FLAGS -fno-builtin -I${root}/include" HOSTTYPE="$HOSTTYPE" AR="$AR" CC="$CC"
test -d $root || exit 1
log=${root}/lib/package/gen/make.out
test -s $log || exit 1
for lib in libast ; do
test -s ${root}/lib/${lib}.a || exit 1
obj=$(ar t ${root}/lib/${lib}.a)
test $? -eq 0 || exit 1
case "$lib" in
libast)
base=src/lib/$lib
vers=$(grep :LIBRARY: ${base}/Makefile | sed "s@.*\([0-9]\+\.[0-9]\+\).*@\1@")
link="-L${root}/lib/ -Wl,-rpath-link,${root}/lib -Wl,-rpath,%{libdir}/ast $LDSOFLG"
;;
esac
soname="-Wl,-soname,${lib}.so.${vers%.*},-stats"
pushd ${root}/${base}
$CC -shared $soname -o ${root}/lib/${lib}.so.${vers} ${obj} $link
ln -sf ${lib}.so.${vers} ${root}/lib/${lib}.so.${vers%.*}
ln -sf ${lib}.so.${vers} ${root}/lib/${lib}.so
popd
done
nobuiltin=${PWD}/.nobuiltin
nm -D ${root}/lib/libast.so | \
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
case "$(gcc --version | head -n 1)" in
*4.[01].*)
set +x
for opt in $(cat $nobuiltin) ; do
cflags $opt RPM_OPT_FLAGS
done
set -x
;;
*) cflags @$nobuiltin RPM_OPT_FLAGS
esac
export | grep -vE 'PROFILEREAD|PWD|MAIL|HOME|HOST|HIST|LESS|TMP' > .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
log=${root}/lib/package/gen/make.out
test -s $log || exit 1
for lib in libast libcmd libdll libshell ; do
test -s ${root}/lib/${lib}.a || exit 1
obj=$(ar t ${root}/lib/${lib}.a)
test $? -eq 0 || exit 1
case "$lib" in
libshell)
base=src/cmd/ksh93
vers=$(grep ^VERSION ${base}/Makefile | sed "s@.*\([0-9]\+\.[0-9]\+\).*@\1@")
link="-L${root}/lib/ -Wl,-rpath-link,${root}/lib -Wl,-rpath,%{libdir}/ast $LDSOFLG $LDFLAGS -ldll -lcmd -last -lm -ldl"
;;
libdll)
base=src/lib/$lib
vers=$(grep :LIBRARY: ${base}/Makefile | sed "s@.*\([0-9]\+\.[0-9]\+\).*@\1@")
link="-L${root}/lib/ -Wl,-rpath-link,${root}/lib -Wl,-rpath,%{libdir}/ast $LDSOFLG -ldl -last"
;;
libcmd)
base=src/lib/$lib
vers=$(grep :LIBRARY: ${base}/Makefile | sed "s@.*\([0-9]\+\.[0-9]\+\).*@\1@")
link="-L${root}/lib/ -Wl,-rpath-link,${root}/lib -Wl,-rpath,%{libdir}/ast $LDSOFLG -last"
;;
libast)
base=src/lib/$lib
vers=$(grep :LIBRARY: ${base}/Makefile | sed "s@.*\([0-9]\+\.[0-9]\+\).*@\1@")
link="-L${root}/lib/ -Wl,-rpath-link,${root}/lib -Wl,-rpath,%{libdir}/ast $LDSOFLG"
;;
esac
soname="-Wl,-soname,${lib}.so.${vers%.*},-stats"
pushd ${root}/${base}
$CC -shared $soname -o ${root}/lib/${lib}.so.${vers} ${obj} $link
ln -sf ${lib}.so.${vers} ${root}/lib/${lib}.so.${vers%.*}
ln -sf ${lib}.so.${vers} ${root}/lib/${lib}.so
popd
done
base=src/cmd/ksh93
test=${PWD}/${base}/tests
OPATH=$PATH
OSHELL=$SHELL
PATH=$PATH:${root}/bin
SHELL=${root}/bin/ksh
SHCOMP=${root}/bin/shcomp
export PATH SHCOMP SHELL
%if %do_tests
pushd ${test}
typeset -i failed=0
ln -sf ${root}/lib ${test}/../
sed -ri '/^L[[:blank:]]/a \t 8000' pty.sh
sed -ri 's/(SECONDS[[:blank:]]*>[[:blank:]]*)([[:digit:]]+)/\18/' signal.sh
unset ${!LESS*}
printf '\033[1m'
grep -E '^(model name|flags)[[:blank:]]*:' /proc/cpuinfo | sort -ur | fold -s
printf '\033(B\033[m'
${SHELL} shtests
result=$(${SHELL} -k -c 'd=`/bin/echo x y=z`; echo $d x y=z')
test "$result" = 'x x' || exit 1
result=$(${SHELL} -c 'echo | echo "x`/bin/echo y`"')
test "$result" = xy || exit 1
result=$(${SHELL} -c 'echo | echo "x$(/bin/echo y)"')
test "$result" = xy || exit 1
exec 3> ${TMPDIR:-/tmp}/log
LANG=POSIX
strace $MEMORY -o '!%{S:31}' ${SHELL} %{S:10} 400
strace $MEMORY -o '!%{S:31}' ${SHELL} %{S:10} 4000
strace $MEMORY -o '!%{S:31}' ${SHELL} %{S:11} 400
strace $MEMORY -o '!%{S:31}' ${SHELL} %{S:11} 4000
strace $MEMORY -o '!%{S:31}' ${SHELL} %{S:12} 4
strace $MEMORY -o '!%{S:31}' ${SHELL} %{S:12} 40
strace $MEMORY -o '!%{S:31}' ${SHELL} %{S:13} 400
strace $MEMORY -o '!%{S:31}' ${SHELL} %{S:13} 4000
strace $MEMORY -o '!%{S:31}' ${SHELL} %{S:14} 400
strace $MEMORY -o '!%{S:31}' ${SHELL} %{S:14} 4000
if test $((IGNORED & SIGPIPE)) -eq 0 ; then
${SHELL} -c 'g="false"; trap "print -u2 PIPED; \$g && exit 0 ; g=true" PIPE ; while true ; do echo hello ; done' | head -n 10
fi
LANG=en_US.UTF-8
strace $MEMORY -o '!%{S:31}' ${SHELL} %{S:10} 400
strace $MEMORY -o '!%{S:31}' ${SHELL} %{S:10} 4000
strace $MEMORY -o '!%{S:31}' ${SHELL} %{S:11} 400
strace $MEMORY -o '!%{S:31}' ${SHELL} %{S:11} 4000
strace $MEMORY -o '!%{S:31}' ${SHELL} %{S:12} 4
strace $MEMORY -o '!%{S:31}' ${SHELL} %{S:12} 40
strace $MEMORY -o '!%{S:31}' ${SHELL} %{S:13} 400
strace $MEMORY -o '!%{S:31}' ${SHELL} %{S:13} 4000
strace $MEMORY -o '!%{S:31}' ${SHELL} %{S:14} 400
strace $MEMORY -o '!%{S:31}' ${SHELL} %{S:14} 4000
if test $((IGNORED & SIGPIPE)) -eq 0 ; then
${SHELL} -c 'g="false"; trap "print -u2 PIPED; \$g && exit 0 ; g=true" PIPE ; while true ; do echo hello ; done' | head -n 10
fi
LANG=POSIX
exec 3>&-
printf '\033[1m'
uniq -c ${TMPDIR:-/tmp}/log
printf '\033(B\033[m'
killall -q -s 9 ${SHELL} || true
popd
%endif
pushd ${root}/${base}
rm -f libshell.a
rm -f ${root}/bin/ksh
rm -f ${root}/bin/shcomp
for bin in ksh shcomp pty what mime asa dlls suid_exec ; do
relink $bin /bin/$bin -Wl,-rpath-link,${root}/lib -Wl,-rpath,%{libdir}/ast
done
popd
LD_LIBRARY_PATH=${root}/lib
export LD_LIBRARY_PATH
mkdir -p share/locale/C/LC_MESSAGES
includes="-I$(cpp -print-search-dirs | sed -rn 's@^install:[[:blank:]]@@p')include"
includes="$includes $(find $root -name FEATURE -printf ' -I%h')"
includes="$includes -I/usr/include/linux"
sed -rn "\@mamake -C cmd/ksh93@,\@mamake -C@ {
s@^\+ g?cc@$SHELL msgcc -M-set=ast $includes@
s@[[:blank:]]-c[[:blank:]]([^[:blank:]\.]+/([^[:blank:]\.\/]+))\.c@ -c \1\.c -o msgs/\2\.mso@p
}" ${root}/lib/package/gen/make.out > src/cmd/ksh93/doit
pushd src/cmd/ksh93
mkdir msgs
${root}/lib/probe/C/pp/probe $(type -p gcc) > pp_default.h
$SHELL ./doit
$SHELL msgcc -o libshell.msg msgs/*.mso
rm -rf msgs/
popd
msggen share/locale/C/LC_MESSAGES/libshell src/cmd/ksh93/libshell.msg
pushd ${root}/bin
PATH=$PATH:.
set -- $(shcomp --version 2>&1)
eval version=\${$#}
for bin in shcomp pty what mime asa dlls ; do
$bin --nroff 2>&1 | sed 's/\(\.TH .*\)/\1 "%{date}" "" "Korn shell utilities"/' > ../man/man1/$bin.1ast
done
popd
test -d /tmp -a /tmp -ef ${TMPDIR} || rm -rf ${TMPDIR}
SHELL=$OSHELL
PATH=$OPATH
%install
root=$(echo ${PWD}/arch/linux*)
test -d $root || exit 1
pushd $root || exit 1
mkdir -p %{buildroot}%{bindir}
mkdir -p %{buildroot}%{_bindir}
mkdir -p %{buildroot}%{libdir}/ast/bin
mkdir -p %{buildroot}%{_includedir}/ast
mkdir -p %{buildroot}%{_libdir}/ast
mkdir -p %{buildroot}%{_mandir}
mkdir %{buildroot}%{_mandir}/man1
mkdir %{buildroot}%{_mandir}/man3
%if %use_locale
mkdir -p %{buildroot}%{_datadir}/locale
%endif
mkdir -p %{buildroot}%{_datadir}/ksh/fun
mkdir -p %{buildroot}%{_sysconfdir}/permissions.d
install bin/ksh %{buildroot}%{bindir}/ksh93
install bin/shcomp %{buildroot}%{_bindir}/shcomp
%if %use_opt_bins
for bin in pty what mime asa dlls ; do
install bin/$bin %{buildroot}/%{_bindir}/$bin
done
%endif
%if %use_suid_exe
install bin/suid_exec %{buildroot}%{libdir}/ast/bin/
%endif
# create update-alternatives symlinks
mkdir -p %{buildroot}%{_sysconfdir}/alternatives/
touch %{buildroot}/%{_sysconfdir}/alternatives/ksh
%if 0%{?suse_version} < 1550
touch %{buildroot}/%{_sysconfdir}/alternatives/usr-bin-ksh
ln -sf %{_sysconfdir}/alternatives/usr-bin-ksh %{buildroot}%{_bindir}/ksh
%endif
touch %{buildroot}/%{_sysconfdir}/alternatives/ksh.1.gz
touch %{buildroot}/%{_sysconfdir}/alternatives/rksh.1.gz
ln -sf %{_sysconfdir}/alternatives/ksh %{buildroot}%{bindir}/ksh
ln -sf %{_sysconfdir}/alternatives/ksh.1.gz %{buildroot}/%{_mandir}/man1/ksh.1.gz
ln -sf %{_sysconfdir}/alternatives/rksh.1.gz %{buildroot}/%{_mandir}/man1/rksh.1.gz
ln -sf %{bindir}/ksh93 %{buildroot}%{_bindir}/rksh
ln -sf ../../bin/ksh93 %{buildroot}%{libdir}/ast/ksh
ln -sf ast %{buildroot}%{libdir}/ksh
cp -a lib/*.so* %{buildroot}%{libdir}/ast/
cp -a fun/* %{buildroot}%{_datadir}/ksh/fun/
if cmp -s %{buildroot}%{_datadir}/ksh/fun/pushd %{buildroot}%{_datadir}/ksh/fun/popd ; then
ln -sf pushd %{buildroot}%{_datadir}/ksh/fun/popd
fi
%if 0%{?suse_version} < 1550
for so in %{buildroot}%{libdir}/ast/*.so.*.* ; do
so=${so##*/}
ln -sf %{libdir}/ast/$so %{buildroot}%{_libdir}/ast/${so%%%%.*}.so
done
rm -f %{buildroot}%{_libdir}/ast/*.so.*
%endif
sed -rn '/^\.de Af/,/^\.\./p;/^\.de aF/,/^\.\./p' man/man3/int.3 > af.man
for man in $(grep -l '\.}S' man/man[138]/*.[138]); do
sed -ri '1r af.man' $man
done
for man in man/man[138]/*.[138] ; do
sed -ri 's/\\f5/\\fB/g;s/^\.H/\.P\n\.H/g;s/\.}S/\.aF/;s/^\.LI/\.LR/;s/\\\(le/\\\(<=/' $man
done
install -m 0644 lib/*.a %{buildroot}%{_libdir}/ast/
install -m 0644 man/man1/sh.1 %{buildroot}%{_mandir}/man1/ksh93.1
install -m 0644 man/man1/shcomp.1ast %{buildroot}%{_mandir}/man1/shcomp.1ast
%if %use_opt_bins
for bin in pty what mime asa dlls ; do
install -m 0644 man/man1/$bin.1ast %{buildroot}%{_mandir}/man1/$bin.1ast
done
%endif
for man in man/man3/*.3 ; do
man=${man##*/}
ast=${man}ast
install -m 0644 man/man3/${man} %{buildroot}%{_mandir}/man3/${ast}
done
install -m 0644 include/ast/* %{buildroot}%{_includedir}/ast/
if cmp -s %{buildroot}%{_includedir}/ast/namval.h %{buildroot}%{_includedir}/ast/ast_namval.h ; then
ln -sf ast_namval.h %{buildroot}%{_includedir}/ast/namval.h
fi
popd
%if %use_locale
for msg in share/locale/* ; do
test -d $msg || continue
mkdir -p %{buildroot}%{_datadir}/locale/${msg##*/}/LC_MESSAGES
cp -vp ${msg}/LC_MESSAGES/* %{buildroot}%{_datadir}/locale/${msg##*/}/LC_MESSAGES/
done
echo %%dir %{_datadir}/locale/C > ksh.lang
echo %%dir %{_datadir}/locale/C/LC_MESSAGES >> ksh.lang
%endif
find %{buildroot}/ -type f -o -type l | sed -r '
s:%{buildroot}::
s:(%{_datadir}/locale/)([^/_]+)(.*$):%%lang\(\2\) \1\2\3:
s:^([^%%].*)::
s:%%lang\(C\) ::
/^ *$/d' >> ksh.lang
if test -s lib/package/LICENSES/ast ; then
cp lib/package/LICENSES/ast LICENSE
else
cp %{S:3} EPL-1.0
cp %{S:4} CPL-1.0
ln -sf EPL-1.0 LICENSE
fi
mv src/cmd/ksh93/OBSOLETE src/cmd/ksh93/OBSOLETE.mm
echo '.VERBON 22' > grep.mm
sed -rn '/function grep/,/^}/p' src/cmd/ksh93/tests/grep.sh >> grep.mm
echo '.VERBOFF' >> grep.mm
tdevice=ascii8
troff -Tascii8 < /dev/null > /dev/null 2>&1 || tdevice=utf8
cat src/cmd/ksh93/builtins.mm | sed 's/\\f5/\\fB/g;s/^\.H/\.P\n\.H/g' | troff -T$tdevice -t -mm | grotty -bou > Builtins
cat src/cmd/ksh93/PROMO.mm | sed 's/\\f5/\\fB/g;s/^\.H/\.P\n\.H/g' | troff -T$tdevice -t -mm | grotty -bou > PROMO
cat src/cmd/ksh93/OBSOLETE.mm | sed 's/\\f5/\\fB/g;s/^\.H/\.P\n\.H/g' | troff -T$tdevice -t -mm | grotty -bou > OBSOLETE
cat src/cmd/ksh93/sh.memo | sed 's/\\f5/\\fB/g;s/^\.H/\.P\n\.H/g' | troff -T$tdevice -t -mm | grotty -bou > MEMORANDUM
cp %{S:21} .
%if %use_suid_exe
set -C
(cat > %{buildroot}%{_sysconfdir}/permissions.d/ksh) <<-EOF
%{libdir}/ast/bin/suid_exec root:root 4755
EOF
(cat > %{buildroot}%{_sysconfdir}/permissions.d/ksh.paranoid) <<-EOF
%{libdir}/ast/bin/suid_exec root:root 0755
EOF
set +C
%endif
%if %use_suid_exe
%if %{defined verify_permissions}
%verifyscript
%verify_permissions -e %{libdir}/ast/bin/suid_exec
%endif
%endif
%post
test -e etc/bash.bashrc && ln -sf bash.bashrc etc/ksh.kshrc || true
%if %use_suid_exe
%if %{defined set_permissions}
%set_permissions %{libdir}/ast/bin/suid_exec
%endif
%endif
if test -x %{libdir}/ast/bin/ksh ; then
%{_sbindir}/update-alternatives \
--quiet \
--force \
--remove ksh %{libdir}/ast/bin/ksh
rm -f %{libdir}/ast/bin/ksh
rm -f %{libdir}/ast/bin/shcomp
fi
%{_sbindir}/update-alternatives \
--install %{bindir}/ksh ksh %{bindir}/ksh93 20 \
%if 0%{?suse_version} < 1550
--slave %{_bindir}/ksh usr-bin-ksh /bin/ksh93 \
%endif
--slave %{_mandir}/man1/ksh.1.gz ksh.1.gz %{_mandir}/man1/ksh93.1.gz \
--slave %{_mandir}/man1/rksh.1.gz rksh.1.gz %{_mandir}/man1/ksh93.1.gz
%postun
if test $1 -eq 0 -a ! -x bin/ksh ; then
if test ! -x bin/pdksh ; then
rm -f etc/ksh.kshrc
fi
fi
if [ ! -f %{bindir}/ksh93 ] ; then
%{_sbindir}/update-alternatives --quiet --remove ksh %{bindir}/ksh93
fi
%posttrans
if test -x bin/ksh -o -x bin/pdksh ; then
test -e etc/bash.bashrc && ln -sf bash.bashrc etc/ksh.kshrc || true
fi
%files -f ksh.lang
%defattr(-,root,root)
%if %use_suid_exe
%config %attr(0644,root,root) %{_sysconfdir}/permissions.d/ksh
%config %attr(0644,root,root) %{_sysconfdir}/permissions.d/ksh.paranoid
%endif
%doc LICENSE EPL-1.0 CPL-1.0 src/cmd/ksh93/COMPATIBILITY src/cmd/ksh93/RELEASE*
%doc Builtins PROMO OBSOLETE MEMORANDUM
%{_bindir}/ksh
%doc %{_mandir}/man1/ksh.1.gz
%doc %{_mandir}/man1/rksh.1.gz
%doc %{_mandir}/man1/ksh93.1.gz
%ghost %{_sysconfdir}/alternatives/ksh
%if 0%{?suse_version} < 1550
/bin/ksh93
/bin/ksh
%ghost %{_sysconfdir}/alternatives/usr-bin-ksh
%endif
%ghost %{_sysconfdir}/alternatives/ksh.1.gz
%ghost %{_sysconfdir}/alternatives/rksh.1.gz
%doc %{_mandir}/man1/shcomp.1ast.gz
%if %use_opt_bins
%doc %{_mandir}/man1/pty.1ast.gz
%doc %{_mandir}/man1/what.1ast.gz
%doc %{_mandir}/man1/mime.1ast.gz
%doc %{_mandir}/man1/asa.1ast.gz
%doc %{_mandir}/man1/dlls.1ast.gz
%endif
%{_bindir}/*
%dir %{libdir}/ast
%dir %{libdir}/ast/bin
%if %use_suid_exe
%attr(4755,root,root) %{libdir}/ast/bin/suid_exec
%endif
%{libdir}/ast/*.so*
%{libdir}/ast/ksh
%{libdir}/ksh
%dir %{_datadir}/ksh
%dir %{_datadir}/ksh/fun
%{_datadir}/ksh/fun/*
%files -n ksh-devel
%defattr(-,root,root)
%doc LICENSE Warning
%dir %{_libdir}/ast/
%{_libdir}/ast/*.so
%{_libdir}/ast/*.a
%doc %{_mandir}/man3/*
%{_includedir}/ast/
%changelog

13
ksh93-alias-k.dif Normal file
View File

@ -0,0 +1,13 @@
--- src/cmd/ksh93/data/builtins.c
+++ src/cmd/ksh93/data/builtins.c 2013-06-11 16:24:46.269439322 +0000
@@ -78,8 +78,8 @@ const struct shtable3 shtab_builtins[] =
#if _bin_newgrp || _usr_bin_newgrp
"newgrp", NV_BLTIN|BLT_ENV|BLT_SPC, Bltin(login),
#endif /* _bin_newgrp || _usr_bin_newgrp */
- "alias", NV_BLTIN|BLT_SPC, bltin(alias),
- "hash", NV_BLTIN|BLT_SPC, bltin(alias),
+ "alias", NV_BLTIN|BLT_SPC|BLT_DCL, bltin(alias),
+ "hash", NV_BLTIN|BLT_SPC|BLT_DCL, bltin(alias),
"enum", NV_BLTIN|BLT_ENV|BLT_SPC|BLT_DCL,bltin(enum),
"eval", NV_BLTIN|BLT_ENV|BLT_SPC|BLT_EXIT,bltin(eval),
"exit", NV_BLTIN|BLT_ENV|BLT_SPC, bltin(return),

25
ksh93-aso.dif Normal file
View File

@ -0,0 +1,25 @@
--- src/lib/libast/features/aso
+++ src/lib/libast/features/aso 2012-02-20 12:09:41.065934089 +0100
@@ -5,7 +5,10 @@ if aso note{ gcc 4.1+ 64 bit memory atom
int main()
{
uint64_t i = 0;
- return __sync_fetch_and_add(&i,7);
+ uint32_t j = 0;
+ uint16_t l = 0;
+ uint8_t m = 0;
+ return __sync_fetch_and_add(&i,7)+__sync_fetch_and_add(&j,7)+__sync_fetch_and_add(&l,7)+__sync_fetch_and_add(&m,7);
}
}end && {
#define _aso_cas8(p,o,n) __sync_val_compare_and_swap(p,o,n)
@@ -31,7 +34,9 @@ elif aso note{ gcc 4.1+ 32 bit memory at
int main()
{
uint32_t i = 0;
- return __sync_fetch_and_add(&i,7);
+ uint16_t j = 0;
+ uint8_t l = 0;
+ return __sync_fetch_and_add(&i,7)+__sync_fetch_and_add(&j,7)+__sync_fetch_and_add(&l,7);
}
}end && {
#define _aso_cas8(p,o,n) __sync_val_compare_and_swap(p,o,n)

151
ksh93-backtick.dif Normal file
View File

@ -0,0 +1,151 @@
--- ./src/cmd/ksh93/sh/io.c.orig 2015-12-09 11:17:56.993309654 +0000
+++ ./src/cmd/ksh93/sh/io.c 2015-12-09 11:20:10.671805470 +0000
@@ -692,7 +692,7 @@ int sh_close(register int fd)
}
if(fd >= shp->gd->lim.open_max)
sh_iovalidfd(shp,fd);
- if(!(sp=shp->sftable[fd]) || sfclose(sp) < 0)
+ if(!(sp=shp->sftable[fd]) || sffileno(sp) != fd || sfclose(sp) < 0)
{
int err=errno;
if(fdnotify)
--- ./src/cmd/ksh93/sh/jobs.c.orig 2015-11-27 12:18:44.168204649 +0000
+++ ./src/cmd/ksh93/sh/jobs.c 2015-11-27 14:49:54.255529119 +0000
@@ -1630,6 +1630,8 @@ int job_wait(register pid_t pid)
}
sfsync(sfstderr);
job.waitsafe = 0;
+ if (pw && !job.savesig && shp->subshell)
+ sh_readpipedata();
nochild = job_reap(job.savesig);
if(job.waitsafe)
continue;
--- ./src/cmd/ksh93/sh/macro.c.orig 2015-08-11 12:00:52.454212675 +0000
+++ ./src/cmd/ksh93/sh/macro.c 2015-11-27 14:02:27.493074974 +0000
@@ -2183,7 +2183,7 @@ static void comsubst(Mac_t *mp,register
stkseek(stkp,soff+foff+64);
stkseek(stkp,soff);
}
- if(foff > IOBSIZE)
+ if(sffileno(sp)>=0 && foff>(Sfoff_t)IOBSIZE)
sfsetbuf(sp,NULL,SF_UNBOUND);
while((str=(char*)sfreserve(sp,SF_UNBOUND,0)) && (c=bufsize=sfvalue(sp))>0)
{
--- ./src/cmd/ksh93/sh/subshell.c.orig 2015-08-11 11:59:29.030528394 +0000
+++ ./src/cmd/ksh93/sh/subshell.c 2015-12-09 11:20:38.614700038 +0000
@@ -105,11 +105,23 @@ static struct subshell
#if SHOPT_COSHELL
void *coshell;
#endif /* SHOPT_COSHELL */
+ char *pipedata;
+ size_t pipedatalen;
} *subshell_data;
static long subenv;
+static void sh_addtopipedata(struct subshell *sp, void *buf, size_t len)
+{
+ if (!sp->pipedata)
+ sp->pipedata = malloc(len);
+ else
+ sp->pipedata = realloc(sp->pipedata, sp->pipedatalen + len);
+ memcpy(sp->pipedata + sp->pipedatalen, buf, len);
+ sp->pipedatalen += len;
+}
+
/*
* This routine will turn the sftmp() file into a real /tmp file or pipe
* if the /tmp file create fails
@@ -146,7 +158,7 @@ void sh_subtmpfile(Shell_t *shp)
sh_fcntl(sp->pipefd,F_SETFD,FD_CLOEXEC);
/* write the data to the pipe */
if(off = sftell(sfstdout))
- write(fds[1],sfsetbuf(sfstdout,(Void_t*)sfstdout,0),(size_t)off);
+ sh_addtopipedata(sp, sfsetbuf(sfstdout,(Void_t*)sfstdout,0),(size_t)off);
sfclose(sfstdout);
if((sh_fcntl(fds[1],F_DUPFD, 1)) != 1)
errormsg(SH_DICT,ERROR_system(1),e_file+4);
@@ -173,6 +185,50 @@ void sh_subtmpfile(Shell_t *shp)
}
}
+void sh_readpipedata()
+{
+ register struct subshell *sp = subshell_data;
+ fd_set rfd;
+ if (sp)
+ sp = sp->pipe;
+ if (!sp || sp->pipefd < 0 || sp->pipefd >= FD_SETSIZE)
+ return;
+ sigset_t sigsaved, sigchld;
+ sigemptyset(&sigchld);
+ sigaddset(&sigchld, SIGCHLD);
+ /* block sigchild */
+ sigprocmask(SIG_BLOCK, &sigchld, &sigsaved);
+ FD_ZERO(&rfd);
+ FD_SET(sp->pipefd, &rfd);
+ while (!job.savesig) {
+ int i = pselect(sp->pipefd + 1, &rfd, 0, 0, 0, &sigsaved);
+ if (i > 0) {
+ char buf[4096];
+ i = read(sp->pipefd, buf, 4096);
+ if (i == 0 || (i < 0 && errno != EINTR))
+ break;
+ sh_addtopipedata(sp, buf, i);
+ }
+ }
+ sigprocmask(SIG_SETMASK, &sigsaved, 0);
+}
+
+void sh_emptypipe(struct subshell *sp, int pipefd)
+{
+ int i;
+ char buf[4096];
+ if (!sp || pipefd < 0)
+ return;
+ for (;;) {
+ i = read(pipefd, buf, 4096);
+ if (i < 0 && errno == EINTR)
+ continue;
+ if (i <= 0)
+ break;
+ sh_addtopipedata(sp, buf, i);
+ }
+}
+
/*
* This routine creates a temp file if necessary and creates a subshell.
@@ -614,7 +670,7 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_
sp->tmpfd = -1;
sp->pipefd = -1;
/* use sftmp() file for standard output */
- if(!(iop = sftmp(comsub==1?PIPE_BUF:IOBSIZE)))
+ if(!(iop = sftmp(comsub==1?SF_UNBOUND:IOBSIZE)))
{
sfswap(sp->saveout,sfstdout);
errormsg(SH_DICT,ERROR_system(1),e_tmpcreate);
@@ -822,6 +878,22 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_
sh_argfree(shp,argsav,0);
if(shp->topfd != buff.topfd)
sh_iorestore(shp,buff.topfd|IOSUBSHELL,jmpval);
+
+ /* empty the pipe and move all data into iop */
+ if (comsub && sp->pipefd>=0)
+ {
+ sh_emptypipe(sp, sffileno(iop));
+ sfclose(iop);
+ sp->pipefd = -1;
+ iop = sftmp(SF_UNBOUND);
+ if (sp->pipedatalen)
+ sfwrite(iop, sp->pipedata, sp->pipedatalen);
+ if (sp->pipedata)
+ free(sp->pipedata);
+ sp->pipedata = 0;
+ sp->pipedatalen = 0;
+ }
+
if(sp->sig)
{
if(sp->prev)

187
ksh93-builtin.dif Normal file
View File

@ -0,0 +1,187 @@
--- src/cmd/builtin/pty.c
+++ src/cmd/builtin/pty.c 2013-02-01 15:59:52.697952156 +0000
@@ -216,27 +216,64 @@ mkpty(int* master, int* slave)
#if !_lib_openpty
char* sname;
#endif
+#ifdef __linux__
+ sigset_t blckttou, oldset;
+ (void)sigemptyset(&blckttou);
+ (void)sigaddset(&blckttou, SIGTTOU);
+ sigprocmask(SIG_BLOCK, &blckttou, &oldset);
+#endif
/*
* some systems hang hard during the handshake
* if you know why then please let us know
*/
- alarm(4);
- if (tcgetattr(STDERR_FILENO, &tty) >= 0)
- ttyp = &tty;
- else
+ alarm(6);
+ if (tcgetattr(sffileno(sfstderr), &tty) < 0)
{
+ if (errno != ENOTTY)
+ error(-1, "unable to get standard error terminal attributes");
+ cfmakeraw(&tty);
ttyp = 0;
- error(-1, "unable to get standard error terminal attributes");
}
+ tty.c_lflag |= ICANON | IEXTEN | ISIG | ECHO|ECHOE|ECHOK|ECHOKE;
+ tty.c_oflag |= (ONLCR | OPOST);
+ tty.c_oflag &= ~(OCRNL | ONLRET);
+ tty.c_iflag |= BRKINT;
+ tty.c_iflag &= ~IGNBRK;
+ tty.c_lflag |= ISIG;
+ tty.c_cc[VTIME] = 0;
+ tty.c_cc[VMIN] = CMIN;
+#ifdef B115200
+ cfsetispeed(&tty, B115200);
+ cfsetospeed(&tty, B115200);
+#elif defined(B57600)
+ cfsetispeed(&tty, B57600);
+ cfsetospeed(&tty, B57600);
+#elif defined(B38400)
+ cfsetispeed(&tty, B38400);
+ cfsetospeed(&tty, B38400);
+#endif
+ ttyp = &tty;
#ifdef TIOCGWINSZ
- if (ioctl(STDERR_FILENO, TIOCGWINSZ, &win) >= 0)
- winp = &win;
- else
+ if (ioctl(sffileno(sfstderr), TIOCGWINSZ, &win) < 0)
{
+ if (errno != ENOTTY)
+ error(-1, "unable to get standard error window size");
+ win.ws_row = 0;
+ win.ws_col = 0;
winp = 0;
- error(-1, "unable to get standard error window size");
}
+ if (win.ws_row < 24)
+ win.ws_row = 24;
+ if (win.ws_col < 80)
+ win.ws_col = 80;
+ winp = &win;
+#endif
+#ifdef __linux__
+# if !_lib_openpty
+# undef _lib_openpty
+# define _lib_openpty 1
+# endif
#endif
#if _lib_openpty
if (openpty(master, slave, NULL, ttyp, winp) < 0)
@@ -279,6 +316,9 @@ mkpty(int* master, int* slave)
#if !O_cloexec
fcntl(*slave, F_SETFD, FD_CLOEXEC);
#endif
+#ifdef __linux__
+ sigprocmask(SIG_SETMASK, &oldset, NULL);
+#endif
alarm(0);
return 0;
}
@@ -317,9 +357,13 @@ process(Sfio_t* mp, Sfio_t* lp, int dela
char* s;
Sfio_t* ip;
Sfio_t* sps[2];
+ struct stat dst;
+ struct stat fst;
ip = sfstdin;
- for (;;)
+ if (!fstat(sffileno(ip), &dst) && !stat("/dev/null", &fst) && dst.st_dev == fst.st_dev && dst.st_ino == fst.st_ino)
+ ip = 0;
+ do
{
i = 0;
t = timeout;
@@ -336,39 +380,39 @@ process(Sfio_t* mp, Sfio_t* lp, int dela
{
if (n < 0)
error(ERROR_SYSTEM|2, "poll failed");
- if (t < 0)
- break;
+ break;
}
- else
- for (i = 0; i < n; i++)
+ for (i = t = 0; i < n; i++)
+ {
+ if (!(sfvalue(sps[i]) & SF_READ))
+ /*skip*/;
+ else if (sps[i] == mp)
{
- if (!(sfvalue(sps[i]) & SF_READ))
- /*skip*/;
- else if (sps[i] == mp)
+ t++;
+ if (!(s = (char*)sfreserve(mp, SF_UNBOUND, -1)))
{
- if (!(s = (char*)sfreserve(mp, SF_UNBOUND, -1)))
- {
- sfclose(mp);
- mp = 0;
- }
- else if ((r = sfvalue(mp)) > 0 && (sfwrite(sfstdout, s, r) != r || sfsync(sfstdout)))
- {
- error(ERROR_SYSTEM|2, "output write failed");
- goto done;
- }
+ sfclose(mp);
+ mp = 0;
}
- else
+ else if ((r = sfvalue(mp)) > 0 && (sfwrite(sfstdout, s, r) != r || sfsync(sfstdout)))
{
- if (!(s = sfgetr(ip, '\n', 1)))
- ip = 0;
- else if (sfputr(mp, s, '\r') < 0 || sfsync(mp))
- {
- error(ERROR_SYSTEM|2, "write failed");
- goto done;
- }
+ error(ERROR_SYSTEM|2, "output write failed");
+ goto done;
}
}
- }
+ else
+ {
+ t++;
+ if (!(s = sfgetr(ip, '\n', 1)))
+ ip = 0;
+ else if (sfputr(mp, s, '\r') < 0 || sfsync(mp))
+ {
+ error(ERROR_SYSTEM|2, "write failed");
+ goto done;
+ }
+ }
+ }
+ } while (t);
done:
if (mp)
sfclose(mp);
--- src/cmd/builtin/what.c
+++ src/cmd/builtin/what.c 2012-02-13 11:02:18.645933606 +0000
@@ -68,7 +68,7 @@ static struct
int match;
int single;
size_t skip[UCHAR_MAX+1];
- unsigned char prev[3];
+ unsigned char prev[4];
} state;
static void
@@ -99,7 +99,7 @@ what(const char* file, Sfio_t* ip, Sfio_
{
next:
s = state.prev;
- s[0] = s[1] = s[2] = 0;
+ s[0] = s[1] = s[2] = s[3] = 0;
switch (mid)
{
default:

19
ksh93-cdpwd.dif Normal file
View File

@ -0,0 +1,19 @@
--- ./src/cmd/ksh93/bltins/cd_pwd.c.orig 2014-11-13 16:07:38.336318883 +0000
+++ ./src/cmd/ksh93/bltins/cd_pwd.c 2014-11-13 16:24:53.323415375 +0000
@@ -116,9 +116,14 @@ int b_cd(int argc, char *argv[],Shbltin_
char *sp;
for(dp=dir; *dp=='.'; dp++)
{
- if(*++dp=='.' && (*++dp=='/' || *dp==0))
+ if (dp[1]=='.' && (dp[2]=='/' || dp[2]==0))
+ {
n++;
- else if(*dp && *dp!='/')
+ dp += 2;
+ }
+ else if (dp[1]=='/' || dp[1]==0)
+ dp++;
+ else
break;
if(*dp==0)
break;

83
ksh93-compat.dif Normal file
View File

@ -0,0 +1,83 @@
--- src/lib/libast/astsa/ast.h
+++ src/lib/libast/astsa/ast.h 2012-02-21 12:03:33.000000000 +0000
@@ -93,6 +93,12 @@ typedef struct
#define pointerof(x) ((void*)((char*)0+(x)))
#define roundof(x,y) (((x)+(y)-1)&~((y)-1))
+#ifdef __GNUC__
+#if (__GNUC__ >= 4) && !defined(offsetof)
+#define offsetof(type,member) __builtin_offsetof(type,member)
+#endif
+#endif
+
#ifndef offsetof
#define offsetof(type,member) ((unsigned long)&(((type*)0)->member))
#endif
--- src/lib/libast/features/libpath.sh
+++ src/lib/libast/features/libpath.sh 2007-03-30 16:45:55.000000000 +0000
@@ -21,7 +21,7 @@
########################################################################
ok=0
for i in \
- -x /lib/ld.so /lib/ld-*.so /usr/lib/ld.so /lib/rld \
+ -x /lib64/ld.so /lib/ld.so /lib64/ld-*.so /lib/ld-*.so /usr/lib/ld.so /lib/rld \
-f /usr/shlib/libc.so /shlib/libc.so /usr/lib/libc.so \
-r /usr/shlib/libc.so /shlib/libc.so
do case $i in
--- src/lib/libast/features/map.c
+++ src/lib/libast/features/map.c 2009-12-09 11:13:24.000000000 +0000
@@ -67,10 +67,14 @@ main()
#define _map_malloc 1
printf("\n");
printf("#define _map_libc 1\n");
+#endif
+#if _map_libc || defined(__linux__)
printf("#undef basename\n");
printf("#define basename _ast_basename\n");
printf("#undef dirname\n");
printf("#define dirname _ast_dirname\n");
+#endif
+#if _map_libc
#if !_lib_eaccess
printf("#undef eaccess\n");
printf("#define eaccess _ast_eaccess\n");
--- src/lib/libast/features/sys
+++ src/lib/libast/features/sys 2012-02-21 12:04:43.000000000 +0000
@@ -134,7 +134,7 @@ tst typ_signed_size_t output{
}
}end
-define offsetof (type,member) ((size_t)&(((type*)0)->member))
+define offsetof (type,member) __builtin_offsetof(type,member)
define EXIT_FAILURE 1
define EXIT_SUCCESS 0
define MB_CUR_MAX 1
--- src/lib/libdll/features/dll
+++ src/lib/libdll/features/dll 2007-03-30 16:40:59.000000000 +0000
@@ -15,7 +15,7 @@ tst dll_DYNAMIC link{
}end
tst run{
lib=
- for d in /shlib /usr/shlib /lib /usr/lib
+ for d in /lib64 /usr/lib64 /lib /usr/lib
do if test -d $d
then for s in "*.*" "*[!a]*"
do for b in libc
@@ -52,7 +52,7 @@ tst run{
"") lib=/lib/libc.so.1 ;;
esac
case $lib in
- /usr/lib/*)
+ /usr/lib64/*|/usr/lib/*)
case `package` in
sgi.mips3)
abi=/lib32
@@ -65,7 +65,7 @@ tst run{
esac
case $abi in
?*) if test -d $abi
- then lib=`echo $lib | sed 's,/usr/lib/,,'`
+ then lib=`echo $lib | sed 's,/usr/lib\(64\)\?/,,'`
lib=$abi/$lib
fi
;;

11
ksh93-disable-vfork.dif Normal file
View File

@ -0,0 +1,11 @@
--- src/lib/libast/features/lib.orig 2014-11-19 13:03:58.009305098 +0000
+++ src/lib/libast/features/lib 2014-11-19 13:23:05.010183379 +0000
@@ -221,7 +221,7 @@ tst lib_vfork unistd.h stdlib.h vfork.h
_exit(2);
}
status = 1;
- _exit(wait(&status) < 0 || status != 0);
+ _exit(wait(&status) < 0 || status != 0 || 1);
}
}end

960
ksh93-dttree-crash.dif Normal file
View File

@ -0,0 +1,960 @@
--- src/cmd/ksh93/bltins/typeset.c
+++ src/cmd/ksh93/bltins/typeset.c 2013-10-25 13:20:42.799733785 +0000
@@ -579,7 +579,7 @@ static int setall(char **argv,regist
np = sh_fsearch(shp,name,NV_ADD|HASH_NOSCOPE);
else
#endif /* SHOPT_NAMESPACE */
- np = nv_open(name,sh_subfuntree(1),NV_NOARRAY|NV_IDENT|NV_NOSCOPE);
+ np = nv_open(name,sh_subfuntree(shp,1),NV_NOARRAY|NV_IDENT|NV_NOSCOPE);
}
else
{
@@ -1168,14 +1168,14 @@ static int unall(int argc, char **argv,
{
name = sh_optunalias;
if(shp->subshell)
- troot = sh_subaliastree(0);
+ troot = sh_subaliastree(shp,0);
}
else
name = sh_optunset;
while(r = optget(argv,name)) switch(r)
{
case 'f':
- troot = sh_subfuntree(1);
+ troot = sh_subfuntree(shp,1);
break;
case 'a':
all=1;
--- src/cmd/ksh93/include/defs.h
+++ src/cmd/ksh93/include/defs.h 2013-10-25 13:20:42.799733785 +0000
@@ -423,10 +423,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*[]);
extern void sh_setmatch(Shell_t*,const char*,int,int,int[],int);
-extern Dt_t *sh_subaliastree(int);
+extern Dt_t *sh_subaliastree(Shell_t*,int);
extern void sh_scope(Shell_t*, struct argnod*, int);
extern Namval_t *sh_scoped(Shell_t*, Namval_t*);
-extern Dt_t *sh_subfuntree(int);
+extern Dt_t *sh_subfuntree(Shell_t*,int);
extern void sh_subjobcheck(pid_t);
extern int sh_subsavefd(int);
extern void sh_subtmpfile(Shell_t*);
--- src/cmd/ksh93/sh/arith.c
+++ src/cmd/ksh93/sh/arith.c 2013-10-25 13:20:42.799733785 +0000
@@ -180,7 +180,10 @@ static Namval_t *scope(register Namval_t
{
ap = nv_arrayptr(np);
if(ap && !ap->table)
+ {
ap->table = dtopen(&_Nvdisc,Dtoset);
+ dtuserdata(ap->table,shp,1);
+ }
if(ap && ap->table && (nq=nv_search(nv_getsub(np),ap->table,NV_ADD)))
nq->nvenv = (char*)np;
if(nq && nv_isnull(nq))
--- src/cmd/ksh93/sh/array.c
+++ src/cmd/ksh93/sh/array.c 2013-10-25 13:20:42.800733693 +0000
@@ -79,6 +79,7 @@ struct assoc_array
static Namarr_t *array_scope(Namval_t *np, Namarr_t *ap, int flags)
{
+ Shell_t *shp = sh_getinterp();
Namarr_t *aq;
#if SHOPT_FIXEDARRAY
struct fixed_array *fp;
@@ -95,6 +96,7 @@ static Namarr_t *array_scope(Namval_t *n
if(is_associative(aq))
{
aq->scope = (void*)dtopen(&_Nvdisc,Dtoset);
+ dtuserdata(aq->scope,shp,1);
dtview((Dt_t*)aq->scope,aq->table);
aq->table = (Dt_t*)aq->scope;
return(aq);
@@ -271,6 +273,7 @@ int nv_arrayisset(Namval_t *np, Namarr_t
*/
static Namval_t *array_find(Namval_t *np,Namarr_t *arp, int flag)
{
+ Shell_t *shp=sh_getinterp();
register struct index_array *ap = (struct index_array*)arp;
register union Value *up;
Namval_t *mp;
@@ -373,7 +376,10 @@ static Namval_t *array_find(Namval_t *np
{
char *cp;
if(!ap->header.table)
+ {
ap->header.table = dtopen(&_Nvdisc,Dtoset);
+ dtuserdata(ap->header.table,shp,1);
+ }
sfprintf(sh.strbuf,"%d",ap->cur);
cp = sfstruse(sh.strbuf);
mp = nv_search(cp, ap->header.table, NV_ADD);
@@ -402,6 +408,7 @@ static Namval_t *array_find(Namval_t *np
#if SHOPT_TYPEDEF
int nv_arraysettype(Namval_t *np, Namval_t *tp, const char *sub, int flags)
{
+ Shell_t *shp = sh_getinterp();
Namval_t *nq;
char *av[2];
int rdonly = nv_isattr(np,NV_RDONLY);
@@ -410,7 +417,10 @@ int nv_arraysettype(Namval_t *np, Namval
av[1] = 0;
sh.last_table = 0;
if(!ap->table)
+ {
ap->table = dtopen(&_Nvdisc,Dtoset);
+ dtuserdata(ap->table,shp,1);
+ }
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
if(ap->table)
{
ap->table = dtopen(&_Nvdisc,Dtoset);
+ dtuserdata(ap->table,shp,1);
if(ap->scope && !(flags&NV_COMVAR))
{
ap->scope = ap->table;
@@ -854,7 +865,9 @@ static struct index_array *array_grow(Na
np->nvalue.cp=0;
if(nv_hasdisc(np,&array_disc) || (nv_type(np) && nv_isvtree(np)))
{
+ Shell_t *shp = sh_getinterp();
ap->header.table = dtopen(&_Nvdisc,Dtoset);
+ dtuserdata(ap->header.table,shp,1);
mp = nv_search("0", ap->header.table,NV_ADD);
if(mp && nv_isnull(mp))
{
@@ -1169,6 +1182,7 @@ int nv_nextsub(Namval_t *np)
*/
Namval_t *nv_putsub(Namval_t *np,register char *sp,register long mode)
{
+ Shell_t *shp = sh_getinterp();
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
{
if(sp)
{
- Shell_t *shp = sh_getinterp();
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
char *cp;
Namval_t *mp;
if(!ap->header.table)
+ {
ap->header.table = dtopen(&_Nvdisc,Dtoset);
+ dtuserdata(ap->header.table,shp,1);
+ }
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)
*/
void *nv_associative(register Namval_t *np,const char *sp,int mode)
{
+ Shell_t *shp = sh_getinterp();
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 *
if(ap = (struct assoc_array*)calloc(1,sizeof(struct assoc_array)))
{
ap->header.table = dtopen(&_Nvdisc,Dtoset);
+ dtuserdata(ap->header.table,shp,1);
ap->cur = 0;
ap->pos = 0;
ap->header.hdr.disc = &array_disc;
@@ -1742,7 +1760,6 @@ void *nv_associative(register Namval_t *
case NV_ANAME:
if(ap->cur)
{
- Shell_t *shp = sh_getinterp();
if(!shp->instance && nv_isnull(ap->cur))
return(NIL(void*));
return((void*)ap->cur->nvname);
--- src/cmd/ksh93/sh/init.c
+++ src/cmd/ksh93/sh/init.c 2013-10-25 13:20:42.800733693 +0000
@@ -1909,9 +1909,13 @@ static Init_t *nv_init(Shell_t *shp)
(OPTINDNOD)->nvalue.lp = (&shp->st.optindex);
/* set up the seconds clock */
shp->alias_tree = inittree(shp,shtab_aliases);
+ dtuserdata(shp->alias_tree,shp,1);
shp->track_tree = dtopen(&_Nvdisc,Dtset);
+ dtuserdata(shp->track_tree,shp,1);
shp->bltin_tree = inittree(shp,(const struct shtable2*)shtab_builtins);
+ dtuserdata(shp->bltin_tree,shp,1);
shp->fun_tree = dtopen(&_Nvdisc,Dtoset);
+ dtuserdata(shp->fun_tree,shp,1);
dtview(shp->fun_tree,shp->bltin_tree);
nv_mount(DOTSHNOD, "type", shp->typedict=dtopen(&_Nvdisc,Dtoset));
nv_adddisc(DOTSHNOD, shdiscnames, (Namval_t**)0);
@@ -1954,6 +1958,7 @@ static Dt_t *inittree(Shell_t *shp,const
nbltins = n;
}
base_treep = treep = dtopen(&_Nvdisc,Dtoset);
+ dtuserdata(treep,shp,1);
treep->user = (void*)shp;
for(tp=name_vals;*tp->sh_name;tp++,np++)
{
--- src/cmd/ksh93/sh/macro.c
+++ src/cmd/ksh93/sh/macro.c 2013-10-25 13:20:42.801733601 +0000
@@ -2742,7 +2742,10 @@ static char *sh_tilde(Shell_t *shp,regis
skip:
#endif /* _WINIX */
if(!logins_tree)
+ {
logins_tree = dtopen(&_Nvdisc,Dtbag);
+ dtuserdata(logins_tree,shp,1);
+ }
if(np=nv_search(string,logins_tree,NV_ADD))
{
c = shp->subshell;
--- src/cmd/ksh93/sh/name.c
+++ src/cmd/ksh93/sh/name.c 2013-10-25 13:20:42.802733508 +0000
@@ -821,6 +821,7 @@ Namval_t *nv_create(const char *name, D
{
Dt_t *dp = dtview(shp->var_tree,(Dt_t*)0);
rp->sdict = dtopen(&_Nvdisc,Dtoset);
+ dtuserdata(rp->sdict,shp,1);
dtview(rp->sdict,dp);
dtview(shp->var_tree,rp->sdict);
}
@@ -1170,7 +1171,10 @@ Namval_t *nv_create(const char *name, D
ap = nv_arrayptr(np);
}
if(n && ap && !ap->table)
+ {
ap->table = dtopen(&_Nvdisc,Dtoset);
+ dtuserdata(ap->table,shp,1);
+ }
if(ap && ap->table && (nq=nv_search(sub,ap->table,n)))
nq->nvenv = (char*)np;
if(nq && nv_isnull(nq))
@@ -1391,7 +1395,7 @@ Namval_t *nv_open(const char *name, Dt_t
while((c= *(unsigned char*)cp++) && (c!='=') && (c!='/') &&
(c>=0x200 || !(c=sh_lexstates[ST_NORM][c]) || c==S_EPAT || c==S_COLON));
if(shp->subshell && c=='=')
- root = sh_subaliastree(1);
+ root = sh_subaliastree(shp,1);
if(c= *--cp)
*cp = 0;
np = nv_search(name, root, (flags&NV_NOADD)?0:NV_ADD);
@@ -2350,6 +2354,7 @@ void sh_scope(Shell_t *shp, struct argno
newroot = nv_dict(shp->namespace);
#endif /* SHOPT_NAMESPACE */
newscope = dtopen(&_Nvdisc,Dtoset);
+ dtuserdata(newscope,shp,1);
if(envlist)
{
dtview(newscope,(Dt_t*)shp->var_tree);
@@ -3334,7 +3339,10 @@ int nv_rename(register Namval_t *np, int
if(ap=nv_arrayptr(np))
{
if(!ap->table)
+ {
ap->table = dtopen(&_Nvdisc,Dtoset);
+ dtuserdata(ap->table,shp,1);
+ }
if(ap->table)
mp = nv_search(nv_getsub(np),ap->table,NV_ADD);
nv_arraychild(np,mp,0);
--- src/cmd/ksh93/sh/nvdisc.c
+++ src/cmd/ksh93/sh/nvdisc.c 2013-10-25 13:20:42.802733508 +0000
@@ -246,6 +246,7 @@ static void chktfree(register Namval_t *
*/
static void assign(Namval_t *np,const char* val,int flags,Namfun_t *handle)
{
+ Shell_t *shp = sh_getinterp();
int type = (flags&NV_APPEND)?APPEND:ASSIGN;
register struct vardisc *vp = (struct vardisc*)handle;
register Namval_t *nq = vp->disc[type];
@@ -330,7 +331,7 @@ static void assign(Namval_t *np,const ch
}
else if(!nq || !isblocked(bp,type))
{
- Dt_t *root = sh_subfuntree(1);
+ Dt_t *root = sh_subfuntree(shp,1);
int n;
Namarr_t *ap;
block(bp,type);
@@ -1296,6 +1297,7 @@ static Namfun_t *clone_table(Namval_t* n
Dt_t *oroot=tp->dict,*nroot=dtopen(&_Nvdisc,Dtoset);
if(!nroot)
return(0);
+ dtuserdata(nroot,dtuserdata(oroot,0,0),1);
memcpy((void*)ntp,(void*)fp,sizeof(struct table));
ntp->dict = nroot;
ntp->parent = nv_lastdict();
@@ -1493,6 +1495,6 @@ Namval_t *sh_fsearch(Shell_t *shp, const
sfputr(stkp,nv_name(shp->namespace),'.');
sfputr(stkp,fname,0);
fname = stkptr(stkp,offset);
- return(nv_search(fname,sh_subfuntree(add&NV_ADD),add));
+ return(nv_search(fname,sh_subfuntree(shp,add&NV_ADD),add));
}
#endif /* SHOPT_NAMESPACE */
--- src/cmd/ksh93/sh/path.c
+++ src/cmd/ksh93/sh/path.c 2013-10-25 13:20:42.803733416 +0000
@@ -592,7 +592,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)))
{
- Dt_t *funtree = sh_subfuntree(1);
+ Dt_t *funtree = sh_subfuntree(shp,1);
while(1)
{
rpfirst = dtprev(shp->fpathdict,rp);
@@ -868,13 +868,13 @@ Pathcomp_t *path_absolute(Shell_t *shp,r
if(isfun && f>=0 && (cp = strrchr(name,'.')))
{
*cp = 0;
- if(nv_open(name,sh_subfuntree(1),NV_NOARRAY|NV_IDENT|NV_NOSCOPE))
+ if(nv_open(name,sh_subfuntree(shp,1),NV_NOARRAY|NV_IDENT|NV_NOSCOPE))
f = -1;
*cp = '.';
}
if(isfun && f>=0)
{
- nv_onattr(nv_open(name,sh_subfuntree(1),NV_NOARRAY|NV_IDENT|NV_NOSCOPE),NV_LTOU|NV_FUNCTION);
+ nv_onattr(nv_open(name,sh_subfuntree(shp,1),NV_NOARRAY|NV_IDENT|NV_NOSCOPE),NV_LTOU|NV_FUNCTION);
funload(shp,f,name);
close(f);
f = -1;
--- src/cmd/ksh93/sh/subshell.c
+++ src/cmd/ksh93/sh/subshell.c 2013-10-25 13:20:42.803733416 +0000
@@ -379,7 +379,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
*/
-Dt_t *sh_subaliastree(int create)
+Dt_t *sh_subaliastree(Shell_t *shp,int create)
{
register struct subshell *sp = subshell_data;
if(!sp || sp->shp->curenv==0)
@@ -387,6 +387,7 @@ Dt_t *sh_subaliastree(int create)
if(!sp->salias && create)
{
sp->salias = dtopen(&_Nvdisc,Dtoset);
+ dtuserdata(sp->salias,shp,1);
dtview(sp->salias,sp->shp->alias_tree);
sp->shp->alias_tree = sp->salias;
}
@@ -397,7 +398,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
*/
-Dt_t *sh_subfuntree(int create)
+Dt_t *sh_subfuntree(Shell_t *shp,int create)
{
register struct subshell *sp = subshell_data;
if(!sp || sp->shp->curenv==0)
@@ -405,6 +406,7 @@ Dt_t *sh_subfuntree(int create)
if(!sp->sfun && create)
{
sp->sfun = dtopen(&_Nvdisc,Dtoset);
+ dtuserdata(sp->sfun,shp,1);
dtview(sp->sfun,sp->shp->fun_tree);
sp->shp->fun_tree = sp->sfun;
}
--- src/cmd/ksh93/sh/xec.c
+++ src/cmd/ksh93/sh/xec.c 2013-10-25 13:20:42.804733324 +0000
@@ -2688,6 +2688,7 @@ int sh_exec(register const Shnode_t *t,
else
{
root = dtopen(&_Nvdisc,Dtoset);
+ dtuserdata(root,shp,1);
nv_mount(np, (char*)0, root);
np->nvalue.cp = Empty;
dtview(root,shp->var_base);
@@ -2729,7 +2730,7 @@ int sh_exec(register const Shnode_t *t,
np = sh_fsearch(shp,fname,NV_ADD|HASH_NOSCOPE);
if(!np)
#endif /* SHOPT_NAMESPACE */
- np = nv_open(fname,sh_subfuntree(1),NV_NOASSIGN|NV_NOARRAY|NV_VARNAME|NV_NOSCOPE);
+ np = nv_open(fname,sh_subfuntree(shp,1),NV_NOASSIGN|NV_NOARRAY|NV_VARNAME|NV_NOSCOPE);
if(npv)
{
if(!shp->mktype)
@@ -2743,11 +2744,6 @@ int sh_exec(register const Shnode_t *t,
slp = (struct slnod*)np->nvenv;
sh_funstaks(slp->slchild,-1);
stakdelete(slp->slptr);
- if(shp->funload)
- {
- free((void*)np->nvalue.rp);
- np->nvalue.rp = 0;
- }
if(rp->sdict)
{
Namval_t *mp, *nq;
@@ -2761,6 +2757,12 @@ int sh_exec(register const Shnode_t *t,
dtclose(rp->sdict);
rp->sdict = 0;
}
+ if(shp->funload)
+ {
+ if(!shp->fpathdict)
+ free((void*)np->nvalue.rp);
+ np->nvalue.rp = 0;
+ }
}
if(!np->nvalue.rp)
{
@@ -2799,7 +2801,10 @@ int sh_exec(register const Shnode_t *t,
if(!shp->fpathdict)
shp->fpathdict = dtopen(&_Rpdisc,Dtobag);
if(shp->fpathdict)
+ {
+ dtuserdata(shp->fpathdict,shp,1);
dtinsert(shp->fpathdict,rp);
+ }
}
}
else
--- src/lib/libast/Mamfile
+++ src/lib/libast/Mamfile 2013-10-25 13:20:42.806733139 +0000
@@ -3969,6 +3969,14 @@ meta dtopen.o %.c>%.o cdt/dtopen.c dtope
prev cdt/dtopen.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -Icdt -Icomp -Iinclude -Istd -I${INSTALLROOT}/include/ast -D_PACKAGE_ast -c cdt/dtopen.c
done dtopen.o generated
+make dtstat.o
+make cdt/dtstat.c
+prev cdt/dthdr.h implicit
+done cdt/dtstat.c
+meta dtstat.o %.c>%.o cdt/dtstat.c dtstat
+prev cdt/dtstat.c
+exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -Icdt -Icomp -Iinclude -Istd -I${INSTALLROOT}/include/ast -D_PACKAGE_ast -c cdt/dtstat.c
+done dtstat.o generated
make dtstrhash.o
make cdt/dtstrhash.c
prev cdt/dthdr.h implicit
@@ -3985,6 +3993,14 @@ meta dttree.o %.c>%.o cdt/dttree.c dttre
prev cdt/dttree.c
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -Icdt -Icomp -Iinclude -Istd -I${INSTALLROOT}/include/ast -D_PACKAGE_ast -c cdt/dttree.c
done dttree.o generated
+make dtuser.o
+make cdt/dtuser.c
+prev cdt/dthdr.h implicit
+done cdt/dtuser.c
+meta dtuser.o %.c>%.o cdt/dtuser.c dtuser
+prev cdt/dtuser.c
+exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -Icdt -Icomp -Iinclude -Istd -I${INSTALLROOT}/include/ast -D_PACKAGE_ast -c cdt/dtuser.c
+done dtuser.o generated
make dtview.o
make cdt/dtview.c
prev cdt/dthdr.h implicit
@@ -6101,7 +6117,7 @@ exec - ${AR} rc libast.a state.o transit
exec - ${AR} rc libast.a streval.o strexpr.o strmatch.o strcopy.o modei.o modex.o strmode.o strlcat.o strlcpy.o strlook.o strncopy.o strsearch.o strpsearch.o stresc.o stropt.o strtape.o strpcmp.o strnpcmp.o strvcmp.o strnvcmp.o tok.o tokline.o tokscan.o pathaccess.o pathcat.o pathcanon.o pathcheck.o pathpath.o pathexists.o pathfind.o pathkey.o pathprobe.o pathrepl.o pathnative.o pathposix.o pathtemp.o pathtmp.o pathstat.o pathgetlink.o pathsetlink.o pathbin.o pathshell.o pathcd.o pathprog.o fs3d.o ftwalk.o ftwflags.o fts.o astintercept.o conformance.o getenv.o setenviron.o optget.o optjoin.o optesc.o optctx.o strsort.o struniq.o magic.o mime.o mimetype.o signal.o sigflag.o systrace.o error.o errorf.o errormsg.o errorx.o localeconv.o setlocale.o translate.o catopen.o iconv.o lc.o lctab.o mc.o base64.o recfmt.o recstr.o reclen.o fmtrec.o fmtbase.o fmtbuf.o fmtclock.o fmtdev.o fmtelapsed.o fmterror.o fmtesc.o fmtfmt.o fmtfs.o fmtident.o fmtint.o fmtip4.o fmtip6.o fmtls.o fmtmatch.o fmtmode.o fmtnum.o fmtperm.o fmtre.o fmttime.o
exec - ${AR} rc libast.a fmtuid.o fmtgid.o fmtsignal.o fmtscale.o fmttmx.o fmttv.o fmtversion.o strelapsed.o strperm.o struid.o strgid.o strtoip4.o strtoip6.o stack.o stk.o swapget.o swapmem.o swapop.o swapput.o sigdata.o sigcrit.o sigunblock.o procopen.o procclose.o procrun.o procfree.o tmdate.o tmequiv.o tmfix.o tmfmt.o tmform.o tmgoff.o tminit.o tmleap.o tmlex.o tmlocale.o tmmake.o tmpoff.o tmscan.o tmsleep.o tmtime.o tmtype.o tmweek.o tmword.o tmzone.o tmxdate.o tmxduration.o tmxfmt.o tmxgettime.o tmxleap.o tmxmake.o tmxscan.o tmxsettime.o tmxsleep.o tmxtime.o tmxtouch.o tvcmp.o tvgettime.o tvsettime.o tvsleep.o tvtouch.o cmdarg.o vecargs.o vecfile.o vecfree.o vecload.o vecstring.o univdata.o touch.o mnt.o debug.o memccpy.o memchr.o memcmp.o memcpy.o memdup.o memmove.o memset.o mkdir.o mkfifo.o mknod.o rmdir.o remove.o rename.o link.o unlink.o strdup.o strchr.o strrchr.o strstr.o strtod.o strtold.o strtol.o strtoll.o strtoul.o strtoull.o strton.o strtonll.o strntod.o strntold.o strnton.o
exec - ${AR} rc libast.a strntonll.o strntol.o strntoll.o strntoul.o strntoull.o strcasecmp.o strncasecmp.o strerror.o mktemp.o tmpnam.o fsync.o execlp.o execve.o execvp.o execvpe.o spawnveg.o vfork.o killpg.o hsearch.o tsearch.o getlogin.o putenv.o setenv.o unsetenv.o lstat.o statvfs.o eaccess.o gross.o omitted.o readlink.o symlink.o getpgrp.o setpgid.o setsid.o waitpid.o creat64.o fcntl.o open.o atexit.o getdents.o getwd.o dup2.o errno.o getpreroot.o ispreroot.o realopen.o setpreroot.o getgroups.o mount.o system.o iblocks.o modedata.o tmdata.o memfatal.o sfkeyprintf.o sfdcdio.o sfdcdos.o sfdcfilter.o sfdcseekable.o sfdcslow.o sfdcsubstr.o sfdctee.o sfdcunion.o sfdcmore.o sfdcprefix.o wc.o wc2utf8.o basename.o closelog.o dirname.o fmtmsglib.o fnmatch.o ftw.o getdate.o getsubopt.o glob.o nftw.o openlog.o re_comp.o resolvepath.o realpath.o regcmp.o regexp.o setlogmask.o strftime.o strptime.o swab.o syslog.o tempnam.o wordexp.o mktime.o regalloc.o regclass.o regcoll.o regcomp.o regcache.o regdecomp.o regerror.o regexec.o regfatal.o reginit.o
-exec - ${AR} rc libast.a regnexec.o regsubcomp.o regsubexec.o regsub.o regrecord.o regrexec.o regstat.o dtclose.o dtdisc.o dthash.o dtlist.o dtmethod.o dtopen.o dtstrhash.o dttree.o dtview.o dtwalk.o dtnew.o dtcomp.o sfclose.o sfclrlock.o sfdisc.o sfdlen.o sfexcept.o sfgetl.o sfgetu.o sfcvt.o sfecvt.o sffcvt.o sfextern.o sffilbuf.o sfflsbuf.o sfprints.o sfgetd.o sfgetr.o sfllen.o sfmode.o sfmove.o sfnew.o sfpkrd.o sfnotify.o sfnputc.o sfopen.o sfpeek.o sfpoll.o sfpool.o sfpopen.o sfprintf.o sfputd.o sfputl.o sfputr.o sfputu.o sfrd.o sfread.o sfreserve.o sfscanf.o sfseek.o sfset.o sfsetbuf.o sfsetfd.o sfsize.o sfsk.o sfstack.o sfstrtod.o sfsync.o sfswap.o sftable.o sftell.o sftmp.o sfungetc.o sfvprintf.o sfvscanf.o sfwr.o sfwrite.o sfpurge.o sfraise.o sfwalk.o sfgetm.o sfmutex.o sfputm.o sfresize.o _sfclrerr.o _sfeof.o _sferror.o _sffileno.o _sfopen.o _sfstacked.o _sfvalue.o _sfgetc.o _sfgetl.o _sfgetl2.o _sfgetu.o _sfgetu2.o _sfdlen.o _sfllen.o _sfslen.o _sfulen.o _sfputc.o _sfputd.o _sfputl.o _sfputm.o
+exec - ${AR} rc libast.a regnexec.o regsubcomp.o regsubexec.o regsub.o regrecord.o regrexec.o regstat.o dtclose.o dtdisc.o dthash.o dtlist.o dtmethod.o dtopen.o dtstat.o dtstrhash.o dttree.o dtuser.o dtview.o dtwalk.o dtnew.o dtcomp.o sfclose.o sfclrlock.o sfdisc.o sfdlen.o sfexcept.o sfgetl.o sfgetu.o sfcvt.o sfecvt.o sffcvt.o sfextern.o sffilbuf.o sfflsbuf.o sfprints.o sfgetd.o sfgetr.o sfllen.o sfmode.o sfmove.o sfnew.o sfpkrd.o sfnotify.o sfnputc.o sfopen.o sfpeek.o sfpoll.o sfpool.o sfpopen.o sfprintf.o sfputd.o sfputl.o sfputr.o sfputu.o sfrd.o sfread.o sfreserve.o sfscanf.o sfseek.o sfset.o sfsetbuf.o sfsetfd.o sfsize.o sfsk.o sfstack.o sfstrtod.o sfsync.o sfswap.o sftable.o sftell.o sftmp.o sfungetc.o sfvprintf.o sfvscanf.o sfwr.o sfwrite.o sfpurge.o sfraise.o sfwalk.o sfgetm.o sfmutex.o sfputm.o sfresize.o _sfclrerr.o _sfeof.o _sferror.o _sffileno.o _sfopen.o _sfstacked.o _sfvalue.o _sfgetc.o _sfgetl.o _sfgetl2.o _sfgetu.o _sfgetu2.o _sfdlen.o _sfllen.o _sfslen.o _sfulen.o _sfputc.o _sfputd.o _sfputl.o _sfputm.o
exec - ${AR} rc libast.a _sfputu.o clearerr.o fclose.o fdopen.o feof.o ferror.o fflush.o fgetc.o fgetpos.o fgets.o fileno.o fopen.o fprintf.o fpurge.o fputc.o fputs.o fread.o freopen.o fscanf.o fseek.o fseeko.o fsetpos.o ftell.o ftello.o fwrite.o flockfile.o ftrylockfile.o funlockfile.o getc.o getchar.o getw.o pclose.o popen.o printf.o putc.o putchar.o puts.o putw.o rewind.o scanf.o setbuf.o setbuffer.o setlinebuf.o setvbuf.o snprintf.o sprintf.o sscanf.o asprintf.o vasprintf.o tmpfile.o ungetc.o vfprintf.o vfscanf.o vprintf.o vscanf.o vsnprintf.o vsprintf.o vsscanf.o _doprnt.o _doscan.o _filbuf.o _flsbuf.o _stdfun.o _stdopen.o _stdprintf.o _stdscanf.o _stdsprnt.o _stdvbuf.o _stdvsnprnt.o _stdvsprnt.o _stdvsscn.o fgetwc.o fwprintf.o putwchar.o vfwscanf.o wprintf.o fgetws.o fwscanf.o swprintf.o vswprintf.o wscanf.o fputwc.o getwc.o swscanf.o vswscanf.o fputws.o getwchar.o ungetwc.o vwprintf.o fwide.o putwc.o vfwprintf.o vwscanf.o stdio_c99.o fcloseall.o fmemopen.o getdelim.o getline.o frexp.o frexpl.o astcopy.o
exec - ${AR} rc libast.a astconf.o astdynamic.o astlicense.o astquery.o astwinsize.o conftab.o aststatic.o getopt.o getoptl.o aso.o asolock.o asometh.o asorelax.o aso-sem.o aso-fcntl.o vmbest.o vmclear.o vmclose.o vmdcheap.o vmdebug.o vmdisc.o vmexit.o vmlast.o vmopen.o vmpool.o vmprivate.o vmprofile.o vmregion.o vmsegment.o vmset.o vmstat.o vmstrdup.o vmtrace.o vmwalk.o vmmopen.o malloc.o vmgetmem.o a64l.o acosh.o asinh.o atanh.o cbrt.o crypt.o erf.o err.o exp.o exp__E.o expm1.o gamma.o getpass.o lgamma.o log.o log1p.o log__L.o rand48.o random.o rcmd.o rint.o support.o sfstrtmp.o spawn.o
exec - (ranlib libast.a) >/dev/null 2>&1 || true
--- src/lib/libast/cdt/cdtlib.h
+++ src/lib/libast/cdt/cdtlib.h 2013-10-25 13:20:42.807733047 +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/cdt/dtcomp.c
+++ src/lib/libast/cdt/dtcomp.c 2013-10-25 13:20:42.807733047 +0000
@@ -52,9 +52,3 @@ extern ssize_t dtsize(Dt_t* d)
{
return (ssize_t)(*(_DT(d)->searchf))((d),(Void_t*)(0),DT_STAT);
}
-
-#undef dtstat
-extern ssize_t dtstat(Dt_t* d)
-{
- return (ssize_t)(*(_DT(d)->searchf))((d),(Void_t*)(0),DT_STAT);
-}
--- src/lib/libast/cdt/dthash.c
+++ src/lib/libast/cdt/dthash.c 2013-10-25 13:20:42.807733047 +0000
@@ -52,11 +52,13 @@ static int htable(Dt_t* dt)
if((n = hash->tblz) > 0 && (hash->type&H_FIXED) )
return 0; /* fixed size table */
- if(n == 0 && disc && disc->eventf) /* let user have input */
+ if(disc && disc->eventf) /* let user have input */
{ if((*disc->eventf)(dt, DT_HASHSIZE, &n, disc) > 0 )
{ if(n < 0) /* fix table size */
{ hash->type |= H_FIXED;
- n = -n;
+ n = -n; /* desired table size */
+ if(hash->tblz >= n ) /* table size is fixed now */
+ return 0;
}
}
}
@@ -234,12 +236,13 @@ static Void_t* hstat(Dt_t* dt, Dtstat_t*
for(endt = (t = hash->htbl) + hash->tblz; t < endt; ++t)
{ for(n = 0, l = *t; l; l = l->_rght)
+ { if(n < DT_MAXSIZE)
+ st->lsize[n] += 1;
n += 1;
+ }
st->mlev = n > st->mlev ? n : st->mlev;
if(n < DT_MAXSIZE) /* if chain length is small */
- { st->msize = n > st->msize ? n : st->msize;
- st->lsize[n] += n;
- }
+ st->msize = n > st->msize ? n : st->msize;
}
}
@@ -310,7 +313,7 @@ int type;
hsh = _DTHSH(dt,key,disc);
tbl = hash->htbl + (hsh & (hash->tblz-1));
- pp = ll = NIL(Dtlink_t*);
+ pp = ll = NIL(Dtlink_t*); /* pp is the before, ll is the here */
for(p = NIL(Dtlink_t*), l = *tbl; l; p = l, l = l->_rght)
{ if(hsh == l->_hash)
{ o = _DTOBJ(disc,l); k = _DTKEY(disc,o);
@@ -342,20 +345,41 @@ int type;
_dtfree(dt, ll, type);
DTRETURN(obj, _DTOBJ(disc,ll));
}
+ else if(type & DT_INSTALL )
+ { if(dt->meth->type&DT_BAG)
+ goto do_insert;
+ else if(!(lnk = _dtmake(dt, obj, type)) )
+ DTRETURN(obj, NIL(Void_t*) );
+ else /* replace old object with new one */
+ { if(pp) /* remove old object */
+ pp->_rght = ll->_rght;
+ else *tbl = ll->_rght;
+ o = _DTOBJ(disc,ll);
+ _dtfree(dt, ll, DT_DELETE);
+ DTANNOUNCE(dt, o, DT_DELETE);
+
+ goto do_insert;
+ }
+ }
else
{ /**/DEBUG_ASSERT(type&(DT_INSERT|DT_ATTACH|DT_APPEND|DT_RELINK));
- if(!(dt->meth->type&DT_BAG) )
+ if((dt->meth->type&DT_BAG) )
+ goto do_insert;
+ else
{ if(type&(DT_INSERT|DT_APPEND|DT_ATTACH) )
- type |= DT_SEARCH; /* for announcement */
+ type |= DT_MATCH; /* for announcement */
else if(lnk && (type&DT_RELINK) )
+ { /* remove a duplicate */
+ o = _DTOBJ(disc, lnk);
_dtfree(dt, lnk, DT_DELETE);
+ DTANNOUNCE(dt, o, DT_DELETE);
+ }
DTRETURN(obj, _DTOBJ(disc,ll));
}
- else goto do_insert;
}
}
else /* no matching object */
- { if(!(type&(DT_INSERT|DT_APPEND|DT_ATTACH|DT_RELINK)) )
+ { if(!(type&(DT_INSERT|DT_INSTALL|DT_APPEND|DT_ATTACH|DT_RELINK)) )
DTRETURN(obj, NIL(Void_t*));
do_insert: /* inserting a new object */
--- src/lib/libast/cdt/dtlist.c
+++ src/lib/libast/cdt/dtlist.c 2013-10-25 13:20:42.807733047 +0000
@@ -142,9 +142,9 @@ int type;
}
#if __STD_C
-static Void_t* liststat(Dt_t* dt, Dtstat_t* st)
+static Void_t* listat(Dt_t* dt, Dtstat_t* st)
#else
-static Void_t* liststat(dt, st)
+static Void_t* listat(dt, st)
Dt_t* dt;
Dtstat_t* st;
#endif
@@ -186,7 +186,7 @@ int type;
else if(type&DT_CLEAR)
DTRETURN(obj, lclear(dt));
else if(type&DT_STAT )
- DTRETURN(obj, liststat(dt, (Dtstat_t*)obj));
+ DTRETURN(obj, listat(dt, (Dtstat_t*)obj));
h = list->here; /* save finger to last search object */
list->here = NIL(Dtlink_t*);
@@ -202,8 +202,9 @@ int type;
{ r = (Dtlink_t*)obj;
goto do_insert;
}
- else if(type&(DT_INSERT|DT_APPEND|DT_ATTACH))
- { if(!(r = _dtmake(dt, obj, type)) )
+ else if(type&(DT_INSERT|DT_INSTALL|DT_APPEND|DT_ATTACH))
+ { dt_insert:
+ if(!(r = _dtmake(dt, obj, type)) )
DTRETURN(obj, NIL(Void_t*));
dt->data->size += 1;
@@ -290,7 +291,7 @@ int type;
}
r = h ? h : r;
}
- if(!r)
+ if(!r) /* not found */
DTRETURN(obj, NIL(Void_t*));
if(type&(DT_DELETE|DT_DETACH|DT_REMOVE))
--- src/lib/libast/cdt/dtopen.c
+++ src/lib/libast/cdt/dtopen.c 2013-10-25 13:20:42.808732955 +0000
@@ -153,25 +153,3 @@ void _dtfree(Dt_t* dt, Dtlink_t* l, int
if(disc->link < 0) /* free holder */
(void)(*dt->memoryf)(dt, (Void_t*)l, 0, disc);
}
-
-int dtuserlock(Dt_t* dt, unsigned int key, int type)
-{
- if(type > 0)
- return asolock(&dt->data->user.lock, key, ASO_LOCK);
- else if(type < 0)
- return asolock(&dt->data->user.lock, key, ASO_UNLOCK);
- else return asolock(&dt->data->user.lock, key, ASO_TRYLOCK);
-}
-
-Void_t* dtuserdata(Dt_t* dt, Void_t* data, unsigned int key)
-{
- if(key == 0)
- return dt->data->user.data;
- else if(dtuserlock(dt, key, 1) < 0 )
- return NIL(Void_t*);
- else
- { dt->data->user.data = data;
- dtuserlock(dt, key, -1);
- return data;
- }
-}
--- src/lib/libast/cdt/dtstat.c
+++ src/lib/libast/cdt/dtstat.c 2013-10-25 13:20:42.808732955 +0000
@@ -0,0 +1,54 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1985-2012 AT&T Intellectual Property *
+* and is licensed under the *
+* Eclipse Public License, Version 1.0 *
+* by AT&T Intellectual Property *
+* *
+* A copy of the License is available at *
+* http://www.eclipse.org/org/documents/epl-v10.html *
+* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* Glenn Fowler <gsf@research.att.com> *
+* David Korn <dgk@research.att.com> *
+* Phong Vo <kpv@research.att.com> *
+* *
+***********************************************************************/
+#include "dthdr.h"
+
+/* Get statistics for a dictionary
+**
+** Written by Kiem-Phong Vo
+*/
+
+ssize_t dtstat(Dt_t* dt, Dtstat_t* dtst)
+{
+ ssize_t sz, k, maxk;
+ char *str;
+ char *end;
+
+ sz = (ssize_t)(*dt->meth->searchf)(dt, (Void_t*)dtst, DT_STAT);
+
+ str = dtst->mesg;
+ end = &dtst->mesg[sizeof(dtst->mesg)] - 1;
+ str += sfsprintf(str, end - str, "Objects=%d Levels=%d(Largest:", dtst->size, dtst->mlev+1);
+
+ /* print top 3 levels */
+ for(k = maxk = 0; k <= dtst->mlev; ++k)
+ if(dtst->lsize[k] > dtst->lsize[maxk])
+ maxk = k;
+ if(maxk > 0)
+ maxk -= 1;
+ for(k = 0; k < 3 && maxk <= dtst->mlev; ++k, ++maxk)
+ str += sfsprintf(str, end - str, " lev[%d]=%d", maxk, dtst->lsize[maxk] );
+ if (str < end)
+ *str++ = ')';
+ *str = 0;
+
+ return sz;
+}
--- src/lib/libast/cdt/dtstrhash.c
+++ src/lib/libast/cdt/dtstrhash.c 2013-10-25 13:20:42.808732955 +0000
@@ -22,40 +22,38 @@
#include "dthdr.h"
/* Hashing a string into an unsigned integer.
-** The basic method is to continuingly accumulate bytes and multiply
-** with some given prime. The length n of the string is added last.
-** The recurrent equation is like this:
-** h[k] = (h[k-1] + bytes)*prime for 0 <= k < n
-** h[n] = (h[n-1] + n)*prime
-** The prime is chosen to have a good distribution of 1-bits so that
-** the multiplication will distribute the bits in the accumulator well.
-** The below code accumulates 2 bytes at a time for speed.
-**
-** Written by Kiem-Phong Vo (02/28/03)
+** This is the FNV (Fowler-Noll-Vo) hash function.
+** Written by Kiem-Phong Vo (01/10/2012)
*/
#if __STD_C
uint dtstrhash(uint h, Void_t* args, ssize_t n)
#else
uint dtstrhash(h,args,n)
-reg uint h;
+uint h;
Void_t* args;
ssize_t n;
#endif
{
unsigned char *s = (unsigned char*)args;
- if(n <= 0)
- { for(; *s != 0; s += s[1] ? 2 : 1)
- h = (h + (s[0]<<8) + s[1])*DT_PRIME;
- n = s - (unsigned char*)args;
+#if _ast_sizeof_int == 8 /* 64-bit hash */
+#define FNV_PRIME ((1<<40) + (1<<8) + 0xb3)
+#define FNV_OFFSET 14695981039346656037
+#else /* 32-bit hash */
+#define FNV_PRIME ((1<<24) + (1<<8) + 0x93)
+#define FNV_OFFSET 2166136261
+#endif
+ h = (h == 0 || h == ~0) ? FNV_OFFSET : h;
+ if(n <= 0) /* see discipline key definition for == 0 */
+ { for(; *s != 0; ++s )
+ h = (h ^ s[0]) * FNV_PRIME;
}
else
{ unsigned char* ends;
- for(ends = s+n-1; s < ends; s += 2)
- h = (h + (s[0]<<8) + s[1])*DT_PRIME;
- if(s <= ends)
- h = (h + (s[0]<<8))*DT_PRIME;
+ for(ends = s+n; s < ends; ++s)
+ h = (h ^ s[0]) * FNV_PRIME;
}
- return (h+n)*DT_PRIME;
+
+ return h;
}
--- src/lib/libast/cdt/dttree.c
+++ src/lib/libast/cdt/dttree.c 2013-10-25 13:20:42.808732955 +0000
@@ -545,7 +545,14 @@ int type;
}
else goto no_root;
}
- else if(type&DT_REMOVE) /* remove a particular element in the tree */
+ else if(type&(DT_DELETE|DT_DETACH))
+ { dt_delete: /* remove an object from the dictionary */
+ obj = _DTOBJ(disc,root);
+ _dtfree(dt, root, type);
+ dt->data->size -= 1;
+ goto no_root;
+ }
+ else if(type&DT_REMOVE) /* remove a particular object */
{ if(_DTOBJ(disc,root) == obj)
goto dt_delete;
else
@@ -555,28 +562,32 @@ int type;
DTRETURN(obj, NIL(Void_t*));
}
}
- else if(type&(DT_DELETE|DT_DETACH))
- { dt_delete: /* remove an object from the dictionary */
- obj = _DTOBJ(disc,root);
- _dtfree(dt, root, type);
- dt->data->size -= 1;
- goto no_root;
- }
else if(type&(DT_INSERT|DT_APPEND|DT_ATTACH))
{ if(dt->meth->type&DT_OSET)
- { type |= DT_SEARCH; /* for announcement */
+ { type |= DT_MATCH; /* for announcement */
goto has_root;
}
- else
+ else /* if(dt->meth->type&DT_OBAG) */
{ root->_left = NIL(Dtlink_t*);
root->_rght = link._left;
link._left = root;
goto dt_insert;
}
}
+ else if(type&DT_INSTALL)
+ { /* remove old object before insert new one */
+ o = _DTOBJ(disc, root);
+ _dtfree(dt, root, DT_DELETE);
+ DTANNOUNCE(dt, o, DT_DELETE);
+ goto dt_insert;
+ }
else if(type&DT_RELINK) /* a duplicate */
{ if(dt->meth->type&DT_OSET)
+ { /* remove object */
+ o = _DTOBJ(disc, me);
_dtfree(dt, me, DT_DELETE);
+ DTANNOUNCE(dt, o, DT_DELETE);
+ }
else
{ me->_left = NIL(Dtlink_t*);
me->_rght = link._left;
@@ -612,7 +623,7 @@ int type;
{ obj = NIL(Void_t*);
goto no_root;
}
- else if(type&(DT_INSERT|DT_APPEND|DT_ATTACH))
+ else if(type&(DT_INSERT|DT_APPEND|DT_ATTACH|DT_INSTALL))
{ dt_insert:
if(!(root = _dtmake(dt, obj, type)) )
{ obj = NIL(Void_t*);
--- src/lib/libast/cdt/dtuser.c
+++ src/lib/libast/cdt/dtuser.c 2013-10-25 13:20:42.808732955 +0000
@@ -0,0 +1,59 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1985-2012 AT&T Intellectual Property *
+* and is licensed under the *
+* Eclipse Public License, Version 1.0 *
+* by AT&T Intellectual Property *
+* *
+* A copy of the License is available at *
+* http://www.eclipse.org/org/documents/epl-v10.html *
+* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
+* *
+* Information and Software Systems Research *
+* AT&T Research *
+* Florham Park NJ *
+* *
+* Glenn Fowler <gsf@research.att.com> *
+* David Korn <dgk@research.att.com> *
+* Phong Vo <kpv@research.att.com> *
+* *
+***********************************************************************/
+#include "dthdr.h"
+
+/* Perform various functions on the user's behalf.
+**
+** Written by Kiem-Phong Vo (01/05/2012)
+*/
+
+/* managing the lock dt->data->user.lock */
+int dtuserlock(Dt_t* dt, unsigned int key, int type)
+{
+ if(key == 0)
+ return -1;
+ else if(type > 0)
+ return asolock(&dt->data->user.lock, key, ASO_LOCK);
+ else if(type < 0)
+ return asolock(&dt->data->user.lock, key, ASO_UNLOCK);
+ else return asolock(&dt->data->user.lock, key, ASO_TRYLOCK);
+}
+
+/* managing the user data slot dt->data->user.data */
+Void_t* dtuserdata(Dt_t* dt, Void_t* data, int set)
+{
+ if(set == 0) /* just return current value */
+ return asogetptr(&dt->data->user.data);
+ else while(1)
+ { Void_t *current = dt->data->user.data;
+ if(asocasptr(&dt->data->user.data, current, data) == current)
+ return current;
+ }
+}
+
+/* announcing an event on the user's behalf */
+int dtuserevent(Dt_t* dt, int flags, Void_t* data)
+{
+ if(!dt->disc->eventf)
+ return 0;
+ else return (*dt->disc->eventf)(dt, DT_ANNOUNCE|DT_USER|flags, data, dt->disc);
+}
--- src/lib/libast/include/cdt.h
+++ src/lib/libast/include/cdt.h 2013-10-25 13:20:42.809732863 +0000
@@ -164,6 +164,7 @@ struct _dtstat_s
ssize_t msize; /* max #defined elts in below arrays */
ssize_t lsize[DT_MAXSIZE]; /* #objects by level */
ssize_t tsize[DT_MAXSIZE]; /* #tables by level */
+ char mesg[256]; /* digest of top level statistics */
};
/* supported storage methods */
@@ -199,7 +200,8 @@ struct _dtstat_s
#define DT_ATLEAST 0000040000 /* find the least elt >= object */
#define DT_ATMOST 0000100000 /* find the biggest elt <= object */
#define DT_REMOVE 0002000000 /* remove a specific object */
-#define DT_TOANNOUNCE (DT_INSERT|DT_DELETE|DT_SEARCH|DT_NEXT|DT_PREV|DT_FIRST|DT_LAST|DT_MATCH|DT_ATTACH|DT_DETACH|DT_APPEND|DT_ATLEAST|DT_ATMOST|DT_REMOVE)
+#define DT_INSTALL 0004000000 /* install a new object */
+#define DT_TOANNOUNCE (DT_INSERT|DT_DELETE|DT_SEARCH|DT_NEXT|DT_PREV|DT_FIRST|DT_LAST|DT_MATCH|DT_ATTACH|DT_DETACH|DT_APPEND|DT_ATLEAST|DT_ATMOST|DT_REMOVE|DT_INSTALL)
#define DT_RELINK 0000002000 /* re-inserting (dtdisc,dtmethod...) */
#define DT_FLATTEN 0000000040 /* flatten objects into a list */
@@ -216,6 +218,7 @@ struct _dtstat_s
/* the actual event will be this bit */
/* combined with the operation bit */
#define DT_OPTIMIZE 0100000000 /* optimizing data structure */
+#define DT_USER 0200000000 /* an announcement on user's behalf */
/* events for discipline and method event-handling functions */
#define DT_OPEN 1 /* a dictionary is being opened */
@@ -277,7 +280,8 @@ extern int dtwalk _ARG_((Dt_t*, int(*)(
extern int dtcustomize _ARG_((Dt_t*, int, int));
extern unsigned int dtstrhash _ARG_((unsigned int, Void_t*, ssize_t));
extern int dtuserlock _ARG_((Dt_t*, unsigned int, int));
-extern Void_t* dtuserdata _ARG_((Dt_t*, Void_t*, unsigned int));
+extern Void_t* dtuserdata _ARG_((Dt_t*, Void_t*, int));
+extern int dtuserevent _ARG_((Dt_t*, int, Void_t*));
/* deal with upward binary compatibility (operation bit translation, etc.) */
extern Dt_t* _dtopen _ARG_((Dtdisc_t*, Dtmethod_t*, unsigned long));
@@ -334,6 +338,7 @@ _END_EXTERNS_
#define dtsearch(d,o) (*(_DT(d)->searchf))((d),(Void_t*)(o),DT_SEARCH)
#define dtmatch(d,o) (*(_DT(d)->searchf))((d),(Void_t*)(o),DT_MATCH)
#define dtinsert(d,o) (*(_DT(d)->searchf))((d),(Void_t*)(o),DT_INSERT)
+#define dtinstall(d,o) (*(_DT(d)->searchf))((d),(Void_t*)(o),DT_INSTALL)
#define dtappend(d,o) (*(_DT(d)->searchf))((d),(Void_t*)(o),DT_APPEND)
#define dtdelete(d,o) (*(_DT(d)->searchf))((d),(Void_t*)(o),DT_DELETE)
#define dtremove(d,o) (*(_DT(d)->searchf))((d),(Void_t*)(o),DT_REMOVE)
@@ -345,7 +350,6 @@ _END_EXTERNS_
#define dtextract(d) (Dtlink_t*)(*(_DT(d)->searchf))((d),(Void_t*)(0),DT_EXTRACT)
#define dtrestore(d,l) (Dtlink_t*)(*(_DT(d)->searchf))((d),(Void_t*)(l),DT_RESTORE)
-#define dtstat(d,s) (ssize_t)(*(_DT(d)->searchf))((d),(Void_t*)(s),DT_STAT)
#define dtsize(d) (ssize_t)(*(_DT(d)->searchf))((d),(Void_t*)(0),DT_STAT)
#define DT_PRIME 17109811 /* 2#00000001 00000101 00010011 00110011 */

40
ksh93-edpredict.dif Normal file
View File

@ -0,0 +1,40 @@
--- src/cmd/ksh93/edit/edit.c.orig 2016-02-18 10:33:20.604776826 +0000
+++ src/cmd/ksh93/edit/edit.c 2016-02-18 10:34:02.019627077 +0000
@@ -628,8 +628,8 @@ void ed_setup(register Edit_t *ep, int f
ep->hoff = 0;
#endif /* SHOPT_EDPREDICT */
#if KSHELL
- ep->e_stkptr = stakptr(0);
ep->e_stkoff = staktell();
+ ep->e_stkptr = stakfreeze(0);
if(!(last = shp->prompt))
last = "";
shp->prompt = 0;
--- src/cmd/ksh93/edit/emacs.c.orig 2016-02-18 10:33:27.144753171 +0000
+++ src/cmd/ksh93/edit/emacs.c 2016-02-18 10:34:33.289514039 +0000
@@ -721,10 +721,8 @@ process:
draw(ep,FINAL);
tty_cooked(ERRIO);
if(ed->e_nlist)
- {
ed->e_nlist = 0;
- stakset(ed->e_stkptr,ed->e_stkoff);
- }
+ stakset(ed->e_stkptr,ed->e_stkoff);
if(c == '\n')
{
out[eol++] = '\n';
--- src/cmd/ksh93/edit/vi.c.orig 2016-02-18 10:33:35.772722001 +0000
+++ src/cmd/ksh93/edit/vi.c 2016-02-18 10:36:15.506143712 +0000
@@ -608,10 +608,8 @@ int ed_viread(void *context, int fd, reg
/* to cause the shell to process the line */
tty_cooked(ERRIO);
if(ed->e_nlist)
- {
ed->e_nlist = 0;
- stakset(ed->e_stkptr,ed->e_stkoff);
- }
+ stakset(ed->e_stkptr,ed->e_stkoff);
if( vp->addnl )
{
virtual[++last_virt] = '\n';

22
ksh93-env.dif Normal file
View File

@ -0,0 +1,22 @@
--- src/cmd/ksh93/sh/init.c
+++ src/cmd/ksh93/sh/init.c 2013-02-15 13:29:57.129444048 +0000
@@ -336,6 +336,8 @@ static void put_restricted(register Namv
int path_scoped = 0, fpath_scoped=0;
Pathcomp_t *pp;
char *name = nv_name(np);
+ if (!shp)
+ shp = sh_getinterp();
if(!(flags&NV_RDONLY) && sh_isoption(SH_RESTRICTED))
errormsg(SH_DICT,ERROR_exit(1),e_restricted,nv_name(np));
if(np==PATHNOD || (path_scoped=(strcmp(name,PATHNOD->nvname)==0)))
--- src/cmd/ksh93/sh/name.c
+++ src/cmd/ksh93/sh/name.c 2012-10-16 12:12:43.000000000 +0000
@@ -2162,7 +2162,7 @@ static void attstore(register Namval_t *
if((flag&(NV_UTOL|NV_LTOU|NV_INTEGER)) == (NV_UTOL|NV_LTOU))
{
data = (void*)nv_mapchar(np,0);
- if(strcmp(data,e_tolower) && strcmp(data,e_toupper))
+ if(data && strcmp(data,e_tolower) && strcmp(data,e_toupper))
return;
}
flag &= (NV_RDONLY|NV_UTOL|NV_LTOU|NV_RJUST|NV_LJUST|NV_ZFILL|NV_INTEGER);

1631
ksh93-fdstatus.dif Normal file

File diff suppressed because it is too large Load Diff

35
ksh93-filedefined.dif Normal file
View File

@ -0,0 +1,35 @@
--- ./src/lib/libast/features/stdio.orig 2017-12-20 12:15:45.571650029 +0000
+++ ./src/lib/libast/features/stdio 2017-12-20 12:16:26.250531883 +0000
@@ -6,6 +6,8 @@ cat{
#define _FILE_DEFINED 1
#define _FILE_defined 1
#define _FILEDEFED 1
+ #define __FILE_defined 1
+ #define ____FILE_defined 1
#ifndef __FILE_TAG
#define __FILE_TAG _sfio_s
--- ./src/lib/libast/include/ast.h.orig 2017-12-20 12:16:37.212500201 +0000
+++ ./src/lib/libast/include/ast.h 2017-12-20 12:17:25.635360669 +0000
@@ -58,9 +58,21 @@ struct _sfio_s;
#ifndef __FILE_typedef
#define __FILE_typedef 1
#endif
+#ifndef _FILE_DEFINED
+#define _FILE_DEFINED 1
+#endif
+#ifndef _FILE_defined
+#define _FILE_defined 1
+#endif
#ifndef _FILEDEFED
#define _FILEDEFED 1
#endif
+#ifndef __FILE_defined
+#define __FILE_defined 1
+#endif
+#ifndef ____FILE_defined
+#define ____FILE_defined 1
+#endif
#endif
/*

View File

@ -0,0 +1,13 @@
--- src/cmd/ksh93/sh/jobs.c
+++ src/cmd/ksh93/sh/jobs.c 2012-02-08 10:52:14.000000000 +0000
@@ -845,7 +845,9 @@ static void job_reset(register struct pr
{
/* save the terminal state for current job */
#ifdef SIGTSTP
- job_fgrp(pw,tcgetpgrp(job.fd));
+ pid_t tgrp;
+ if((tgrp=tcgetpgrp(job.fd))!=job.mypid)
+ job_fgrp(pw,tgrp);
if(tcsetpgrp(job.fd,job.mypid) !=0)
return;
#endif /* SIGTSTP */

62
ksh93-fs3d.dif Normal file
View File

@ -0,0 +1,62 @@
--- ./src/lib/libast/misc/fs3d.c.orig 2014-11-11 12:09:50.142397030 +0000
+++ ./src/lib/libast/misc/fs3d.c 2014-11-11 12:11:19.667992242 +0000
@@ -39,6 +39,7 @@
int
fs3d(register int op)
{
+#if SHOPT_FS_3D
register int cur;
register char* v;
char val[sizeof(FS3D_off) + 8];
@@ -95,6 +96,7 @@ fs3d(register int op)
return cur;
nope:
fsview = -1;
+#endif
return 0;
}
@@ -107,6 +109,7 @@ fs3d(register int op)
#undef mount
+#if SHOPT_FS_3D
extern int mount(const char*, char*, int, void*);
int
@@ -114,3 +117,4 @@ fs3d_mount(const char* source, char* tar
{
return mount(source, target, flags, data);
}
+#endif
--- ./src/lib/libast/path/pathkey.c.orig 2014-11-11 12:11:29.333948438 +0000
+++ ./src/lib/libast/path/pathkey.c 2014-11-11 12:11:47.067868209 +0000
@@ -109,8 +109,10 @@ pathkey_20100601(const char* lang, const
* 3D
*/
+#if SHOPT_FS_3D
if (!flags && fs3d(FS3D_TEST) && (c = mount(path, tmp, FS3D_GET|FS3D_ALL|FS3D_SIZE(PATH_MAX), NiL)) > 1 && c < PATH_MAX)
path = tmp;
+#endif
/*
* preroot
--- ./src/lib/libcoshell/coinit.c.orig 2014-11-11 12:08:49.438671153 +0000
+++ ./src/lib/libcoshell/coinit.c 2014-11-11 12:09:25.956506292 +0000
@@ -355,6 +355,7 @@ coinitialize(Coshell_t* co, int flags)
p = (int)sfstrtell(sp);
sfprintf(sp, "vpath ");
n = PATH_MAX;
+#if SHOPT_FS_3D
if (fs3d(FS3D_TEST))
for (;;)
{
@@ -370,6 +371,7 @@ coinitialize(Coshell_t* co, int flags)
}
}
else
+#endif
{
m = 0;
sfprintf(sp, "- /#option/2d");

65
ksh93-gcc.dif Normal file
View File

@ -0,0 +1,65 @@
--- src/lib/libast/misc/optget.c
+++ src/lib/libast/misc/optget.c 2013-01-28 14:52:53.000000000 +0000
@@ -4367,9 +4367,9 @@ optget(register char** argv, const char*
*/
opt_info.assignment = 0;
- num = 1;
- w = v = 0;
- x = 0;
+ nov = no = num = 1;
+ e = w = v = 0;
+ n = x = 0;
for (;;)
{
if (!opt_info.offset)
@@ -5214,7 +5214,7 @@ optget(register char** argv, const char*
if (opt_info.num != LONG_MIN)
opt_info.num = (long)(opt_info.number = num);
- if ((n = *++s == '#') || *s == ':' || w && !nov && v && (optnumber(v, &e, NiL), n = !*e))
+ if ((n = (*++s == '#')) || *s == ':' || w && !nov && v && (optnumber(v, &e, NiL), n = !*e))
{
if (w)
{
--- src/lib/libpp/ppsearch.c
+++ src/lib/libpp/ppsearch.c 2012-03-14 11:40:11.000000000 +0000
@@ -107,6 +107,14 @@ ppmultiple(register struct ppfile* fp, r
* search for file using directories in dp
*/
+#define stupidgcc(flag) \
+({ \
+ char *name = NiL; \
+ if (!(fp->flags & INC_MEMBER(flag)) && (xp = fp->bound[flag])) \
+ name = xp->name; \
+ name; \
+})
+
static int
search(register struct ppfile* fp, register struct ppdirs* dp, int type, int flags)
{
@@ -146,10 +154,10 @@ search(register struct ppfile* fp, regis
(fp->flags & INC_BOUND(INC_STANDARD)) ? "STANDARD|" : "",
dp ? (dp->index == INC_PREFIX ? "pre" : dp->index == INC_LOCAL ? "lcl" : dp->index == INC_VENDOR ? "vnd" : "std") : NiL,
dp ? dp->name : NiL,
- !(fp->flags & INC_MEMBER(INC_PREFIX)) && fp->bound[INC_PREFIX] ? fp->bound[INC_PREFIX]->name : NiL,
- !(fp->flags & INC_MEMBER(INC_LOCAL)) && fp->bound[INC_LOCAL] ? fp->bound[INC_LOCAL]->name : NiL,
- !(fp->flags & INC_MEMBER(INC_VENDOR)) && fp->bound[INC_VENDOR] ? fp->bound[INC_VENDOR]->name : NiL,
- !(fp->flags & INC_MEMBER(INC_STANDARD)) && (xp = fp->bound[INC_STANDARD]) ? xp->name : NiL,
+ stupidgcc(INC_PREFIX),
+ stupidgcc(INC_LOCAL),
+ stupidgcc(INC_VENDOR),
+ stupidgcc(INC_STANDARD),
error_info.file
));
if (flags & SEARCH_HOSTED)
@@ -578,6 +586,8 @@ if (pp.test & 0x0010) error(1, "SEARCH#%
return -1;
}
+#undef stupidgcc
+
/*
* search for an include file
* if (flags&SEARCH_INCLUDE) then

70
ksh93-gmt2utc.dif Normal file
View File

@ -0,0 +1,70 @@
--- src/lib/libast/man/tm.3
+++ src/lib/libast/man/tm.3 2006-04-19 15:55:42.000000000 +0000
@@ -70,7 +70,7 @@ are used to determine local time zone an
.PP
.L time_t
values are the number of seconds since the epoch,
-.BR "Jan 1 00:00:00 GMT 1970" ,
+.BR "Jan 1 00:00:00 UTC 1970" ,
with leap seconds omitted.
.PP
The global variable
@@ -433,7 +433,7 @@ that includes the hours and minutes.
.B z
Time zone
.I SHHMM
-west of GMT offset where
+west of UTC offset where
.I S
is
.B +
@@ -614,7 +614,7 @@ Meridian names: AM, PM.
.TP
.B 43-46
.B UTC
-time zone names: GMT, UTC, UCT, CUT.
+time zone names: UTC, GMT, UCT, CUT.
.TP
.B 47-50
Daylight savings time suffix names: DST.
--- src/lib/libast/man/tmx.3
+++ src/lib/libast/man/tmx.3 2006-04-19 15:54:55.000000000 +0000
@@ -59,7 +59,7 @@ are used to determine local time zone in
.PP
.L time_t
values are the number of seconds since the epoch,
-.BR "Jan 1 00:00:00 GMT 1970" ,
+.BR "Jan 1 00:00:00 UTC 1970" ,
with leap seconds omitted.
.PP
The global variable
@@ -492,7 +492,7 @@ Meridian names: AM, PM.
.TP
.B 43-46
.B UTC
-time zone names: GMT, UTC, UCT, CUT.
+time zone names: UTC, GMT, UCT, CUT.
.TP
.B 47-50
Daylight savings time suffix names: DST.
--- src/lib/libast/tm/tmdata.c
+++ src/lib/libast/tm/tmdata.c 2006-04-19 15:52:53.000000000 +0000
@@ -54,7 +54,7 @@ static char* format[] =
"AM", "PM",
- "GMT", "UTC", "UCT", "CUT",
+ "UTC", "GMT", "UCT", "CUT",
"DST", "", "", "",
@@ -230,8 +230,8 @@ static Tm_leap_t leap[] =
static Tm_zone_t zone[] =
{
- 0, "GMT", 0, ( 0 * 60), 0, /* UTC */
0, "UCT", 0, ( 0 * 60), 0, /* UTC */
+ 0, "GMT", 0, ( 0 * 60), 0, /* UTC */
0, "UTC", 0, ( 0 * 60), 0, /* UTC */
0, "CUT", 0, ( 0 * 60), 0, /* UTC */
0, "Z", 0, ( 0 * 60), 0, /* UTC */

11
ksh93-heredoc.dif Normal file
View File

@ -0,0 +1,11 @@
--- src/cmd/ksh93/sh/lex.c
+++ src/cmd/ksh93/sh/lex.c 2012-01-16 15:09:38.000000000 +0000
@@ -1893,6 +1893,8 @@ static int here_copy(Lex_t *lp,register
sfputc(sp,'\\');
}
}
+ if (LEN < 1)
+ LEN = 1;
bufp = fcseek(-LEN);
}
else

19
ksh93-heredoclex.dif Normal file
View File

@ -0,0 +1,19 @@
--- src/cmd/ksh93/sh/lex.c
+++ src/cmd/ksh93/sh/lex.c 2013-02-26 12:21:11.618820739 +0100
@@ -1559,6 +1559,7 @@ static int comsub(register Lex_t *lp, in
register int line=lp->sh->inlineno;
char *first,*cp=fcseek(0),word[5];
int off, messages=0, assignok=lp->assignok, csub;
+ struct ionod *inheredoc = lp->heredoc;
struct lexstate save;
save = lp->lex;
csub = lp->comsub;
@@ -1683,7 +1684,7 @@ done:
lp->lexd.dolparen--;
lp->lex = save;
lp->assignok = (endchar(lp)==RBRACT?assignok:0);
- if(lp->heredoc)
+ if(lp->heredoc && !inheredoc)
errormsg(SH_DICT,ERROR_exit(SYNBAD),e_lexsyntax5,lp->sh->inlineno,lp->heredoc->ioname);
return(messages);
}

40
ksh93-ia64.dif Normal file
View File

@ -0,0 +1,40 @@
--- src/cmd/ksh93/features/math.sh
+++ src/cmd/ksh93/features/math.sh 2012-01-20 14:23:38.000000000 +0000
@@ -130,6 +130,18 @@ echo "#include <math.h>"
case $_hdr_ieeefp in
1) echo "#include <ieeefp.h>" ;;
esac
+cat <<!
+#if defined(__ia64__) && defined(signbit)
+# if defined __GNUC__ && __GNUC__ >= 4
+# define __signbitl(f) __builtin_signbitl(f)
+# else
+# include <ast_float.h>
+# if _lib_copysignl
+# define __signbitl(f) (int)(copysignl(1.0,(f))<0.0)
+# endif
+# endif
+#endif
+!
echo
: generate the intercept functions and table entries
--- src/lib/libast/sfio/sfcvt.c
+++ src/lib/libast/sfio/sfcvt.c 2013-02-01 17:13:48.305452072 +0000
@@ -54,6 +54,16 @@ static char *Zero = "0";
#endif
#endif
+#if defined(__ia64__) && defined(signbit)
+# if defined __GNUC__ && __GNUC__ >= 4
+# define __signbitl(f) __builtin_signbitl(f)
+# else
+# if _lib_copysignl
+# define __signbitl(f) (int)(copysignl(1.0,(f))<0.0)
+# endif
+# endif
+#endif
+
#if !_lib_signbit
#if !_ast_fltmax_double
static int neg0ld(Sfdouble_t f)

22
ksh93-int16double.dif Normal file
View File

@ -0,0 +1,22 @@
--- src/cmd/ksh93/sh/array.c.orig 2015-04-01 11:26:36.544797902 +0000
+++ src/cmd/ksh93/sh/array.c 2015-04-01 11:27:01.414692760 +0000
@@ -592,7 +592,7 @@ static char *array_getval(Namval_t *np,
return(cp);
}
#if SHOPT_FIXEDARRAY
- if(ap->fixed && nv_isattr(np,NV_INT16P) == NV_INT16)
+ if(ap->fixed && nv_isattr(np,NV_INT16P|NV_DOUBLE) == NV_INT16)
np->nvalue.s = *np->nvalue.sp;
#endif /* SHOPT_FIXEDARRAY */
return(nv_getv(np,&ap->hdr));
--- src/cmd/ksh93/sh/name.c.orig 2015-04-01 11:25:38.049045236 +0000
+++ src/cmd/ksh93/sh/name.c 2015-04-01 11:25:55.169972879 +0000
@@ -1647,7 +1647,7 @@ void nv_putval(register Namval_t *np, co
return;
}
up= &np->nvalue;
- if(nv_isattr(np,NV_INT16P) == NV_INT16)
+ if(nv_isattr(np,NV_INT16P|NV_DOUBLE) == NV_INT16)
{
if(!np->nvalue.up || !nv_isarray(np))
{

31
ksh93-joblock.dif Normal file
View File

@ -0,0 +1,31 @@
--- ./src/cmd/ksh93/include/jobs.h.orig 2014-11-19 14:14:36.055335722 +0000
+++ ./src/cmd/ksh93/include/jobs.h 2014-11-19 14:16:12.275918218 +0000
@@ -33,6 +33,7 @@
# include <signal.h>
#endif /* !SIGINT */
#include "FEATURE/options"
+#include <aso.h>
#if SHOPT_COSHELL
# include <coshell.h>
@@ -150,16 +151,13 @@ extern struct jobs job;
#define vmbusy() 0
#endif
-#define job_lock() (job.in_critical++)
+#define job_lock() asoincint(&job.in_critical)
#define job_unlock() \
do { \
int _sig; \
- if (!--job.in_critical && (_sig = job.savesig)) \
- { \
- if (!job.in_critical++ && !vmbusy()) \
- job_reap(_sig); \
- job.in_critical--; \
- } \
+ if (asogetint(&job.in_critical) == 1 && (_sig = job.savesig) && !vmbusy()) \
+ job_reap(_sig); \
+ asodecint(&job.in_critical); \
} while(0)
extern const char e_jobusage[];

35
ksh93-jobs.dif Normal file
View File

@ -0,0 +1,35 @@
--- src/cmd/ksh93/sh/jobs.c
+++ src/cmd/ksh93/sh/jobs.c 2012-12-20 13:33:28.000000000 +0000
@@ -638,12 +638,14 @@ void job_init(Shell_t *shp, int lflag)
/* This should have already been done by rlogin */
register int fd;
register char *ttynam;
+ int err = errno;
#ifndef SIGTSTP
setpgid(0,shp->gd->pid);
#endif /*SIGTSTP */
if(job.mypgid<0 || !(ttynam=ttyname(JOBTTY)))
return;
- close(JOBTTY);
+ while(close(JOBTTY)<0 && errno==EINTR)
+ errno = err;
if((fd = open(ttynam,O_RDWR)) <0)
return;
if(fd!=JOBTTY)
@@ -1110,7 +1112,7 @@ static struct process *job_bystring(regi
int job_kill(register struct process *pw,register int sig)
{
- Shell_t *shp = pw->p_shp;
+ Shell_t *shp;
register pid_t pid;
register int r;
const char *msg;
@@ -1123,6 +1125,7 @@ int job_kill(register struct process *pw
errno = ECHILD;
if(pw==0)
goto error;
+ shp = pw->p_shp;
pid = pw->p_pid;
#if SHOPT_COSHELL
if(pw->p_cojob)

10
ksh93-jpold.dif Normal file
View File

@ -0,0 +1,10 @@
--- src/cmd/ksh93/sh/jobs.c.orig 2015-09-15 15:56:08.902265877 +0000
+++ src/cmd/ksh93/sh/jobs.c 2015-09-15 15:57:00.866122451 +0000
@@ -1981,6 +1981,7 @@ again:
{
count = bp->count;
jp = bp->list;
+ jpold = 0;
goto again;
}
if(jp)

31
ksh93-limit-name-len.dif Normal file
View File

@ -0,0 +1,31 @@
--- src/cmd/ksh93/include/ulimit.h
+++ src/cmd/ksh93/include/ulimit.h 2012-02-02 11:30:00.242435132 +0000
@@ -157,7 +157,7 @@
typedef struct Limit_s
{
- const char name[16];
+ const char* name;
const char* description;
int index;
const char* conf;
--- src/cmd/ksh93/sh/init.c
+++ src/cmd/ksh93/sh/init.c 2013-02-01 15:53:58.733952540 +0000
@@ -170,7 +170,7 @@ struct match
char *val;
char *rval[2];
regoff_t *match;
- char node[NV_MINSZ+sizeof(char*)];
+ char node[NV_MINSZ+sizeof(char*)+sizeof(Dtlink_t)];
regoff_t first;
int vsize;
int nmatch;
@@ -766,7 +766,7 @@ static int hasgetdisc(register Namfun_t
void sh_setmatch(Shell_t *shp,const char *v, int vsize, int nmatch, regoff_t match[],int index)
{
struct match *mp = &ip->SH_MATCH_init;
- Namval_t *np = nv_namptr(mp->node,0);
+ Namval_t *np = (Namval_t*)(&(mp->node[0]));
register int i,n,x, savesub=shp->subshell;
Namarr_t *ap = nv_arrayptr(SH_MATCHNOD);
shp->subshell = 0;

122
ksh93-limits.dif Normal file
View File

@ -0,0 +1,122 @@
--- src/lib/libast/comp/conf.sh
+++ src/lib/libast/comp/conf.sh 2010-08-17 15:45:16.000000000 +0000
@@ -143,7 +143,7 @@ main()
return 1;
#else
_ast_intmax_t s = 0x7fffffffffffffffLL;
- unsigned _ast_intmax_t u = 0xffffffffffffffffLL;
+ unsigned _ast_intmax_t u = 0xffffffffffffffffULL;
return 0;
#endif
@@ -801,7 +801,11 @@ defined() # list-file
cat <<!
${head}
#include <sys/types.h>
+#include <sys/uio.h>
#include <limits.h>
+#if defined(__linux__)
+#include <linux/limits.h>
+#endif
#include <unistd.h>$systeminfo$headers
${tail}
#undef conf
@@ -829,7 +833,11 @@ unsigned int conf[] = {
cat <<!
${head}
#include <sys/types.h>
+#include <sys/uio.h>
#include <limits.h>
+#if defined(__linux__)
+#include <linux/limits.h>
+#endif
#include <unistd.h>$systeminfo$headers
${tail}
#undef conf
@@ -870,7 +878,11 @@ done
cat <<!
${head}
#include <sys/types.h>
+#include <sys/uio.h>
#include <limits.h>
+#if defined(__linux__)
+#include <linux/limits.h>
+#endif
#include <unistd.h>$systeminfo$headers
${tail}
#undef conf
@@ -1048,7 +1060,7 @@ do eval name=\"'$'CONF_name_$key\"
case $flags in
*[Ll]*) d=
case ${conf_name} in
- LONG_MAX|SSIZE_MAX)
+ LONG_MAX|UINT_MAX|INT_MAX|SHRT_MAX|SSIZE_MAX|WORD_BIT|LONG_BIT|PTHREAD_*)
x=
;;
*) eval x='$'CONF_const_${conf_name}
@@ -1108,7 +1120,11 @@ do eval name=\"'$'CONF_name_$key\"
${head}
#include <stdio.h>
#include <sys/types.h>
+#include <sys/uio.h>
#include <limits.h>
+#if defined(__linux__)
+#include <linux/limits.h>
+#endif
#include <unistd.h>$systeminfo$headers
${tail}
int
@@ -1123,7 +1139,11 @@ main()
${head}
#include <stdio.h>
#include <sys/types.h>
+#include <sys/uio.h>
#include <limits.h>
+#if defined(__linux__)
+#include <linux/limits.h>
+#endif
#include <unistd.h>$systeminfo$headers
${tail}
${script}
@@ -1270,7 +1290,11 @@ printf("#endif\n");
*) cat > $tmp.c <<!
${head}
#include <sys/types.h>
+#include <sys/uio.h>
#include <limits.h>
+#if defined(__linux__)
+#include <linux/limits.h>
+#endif
#include <unistd.h>$systeminfo$headers
${tail}
${script}
@@ -1349,7 +1373,7 @@ ${script}
*[lLuU])
case $LL_suffix in
??) case $conf_limit in
- *[!lL][lL]|*[!lL][lL][uU])
+ *[0-9a-fA-F][lL]|*[0-9a-fA-F][uU][lL])
conf_limit=${conf_limit}L
;;
esac
@@ -1384,7 +1408,7 @@ ${script}
*[lLuU])
case $LL_suffix in
??) case $conf_minmax in
- *[!lL][lL]|*[!lL][lL][uU])
+ *[0-9a-fA-F][lL]|*[0-9a-fA-F][uU][lL])
conf_minmax=${conf_minmax}L
;;
esac
@@ -1561,7 +1585,11 @@ esac
cat <<!
${head}
#include <sys/types.h>
+#include <sys/uio.h>
#include <limits.h>
+#if defined(__linux__)
+#include <linux/limits.h>
+#endif
#include <unistd.h>$systeminfo$headers
${tail}
#include "${base}.h"

65
ksh93-longenv.dif Normal file
View File

@ -0,0 +1,65 @@
--- ./src/cmd/ksh93/include/defs.h.orig 2014-11-13 16:34:43.395195739 +0000
+++ ./src/cmd/ksh93/include/defs.h 2014-11-13 16:38:37.944297333 +0000
@@ -162,8 +162,8 @@ struct shared
Namval_t *prev_table; /* previous table used in nv_open */ \
Sfio_t *outpool; /* ouput stream pool */ \
long timeout; /* read timeout */ \
- short curenv; /* current subshell number */ \
- short jobenv; /* subshell number for jobs */ \
+ long curenv; /* current subshell number */ \
+ long jobenv; /* subshell number for jobs */ \
int infd; /* input file descriptor */ \
short nextprompt; /* next prompt is PS<nextprompt> */ \
short poolfiles; \
--- ./src/cmd/ksh93/include/jobs.h.orig 2014-11-13 16:35:10.331086826 +0000
+++ ./src/cmd/ksh93/include/jobs.h 2014-11-13 16:38:53.856235814 +0000
@@ -87,7 +87,7 @@ struct process
unsigned short p_exit; /* exit value or signal number */
unsigned short p_exitmin; /* minimum exit value for xargs */
unsigned short p_flag; /* flags - see below */
- int p_env; /* subshell environment number */
+ long p_env; /* subshell environment number */
#ifdef JOBS
off_t p_name; /* history file offset for command */
struct termios p_stty; /* terminal state for job */
--- ./src/cmd/ksh93/sh/jobs.c.orig 2014-11-13 16:36:02.050894977 +0000
+++ ./src/cmd/ksh93/sh/jobs.c 2014-11-13 16:37:09.568636499 +0000
@@ -1815,7 +1815,7 @@ static struct process *job_unpost(regist
register struct process *pw;
/* make sure all processes are done */
#ifdef DEBUG
- sfprintf(sfstderr,"ksh: job line %4d: drop pid=%d critical=%d pid=%d env=%d\n",__LINE__,getpid(),job.in_critical,pwtop->p_pid,pwtop->p_env);
+ sfprintf(sfstderr,"ksh: job line %4d: drop pid=%d critical=%d pid=%d env=%ld\n",__LINE__,getpid(),job.in_critical,pwtop->p_pid,pwtop->p_env);
sfsync(sfstderr);
#endif /* DEBUG */
pwtop = pw = job_byjid((int)pwtop->p_job);
--- ./src/cmd/ksh93/sh/subshell.c.orig 2014-11-13 16:34:53.259157199 +0000
+++ ./src/cmd/ksh93/sh/subshell.c 2014-11-13 16:38:11.440395221 +0000
@@ -107,7 +107,7 @@ static struct subshell
#endif /* SHOPT_COSHELL */
} *subshell_data;
-static int subenv;
+static long subenv;
/*
@@ -183,7 +183,8 @@ void sh_subfork(void)
{
register struct subshell *sp = subshell_data;
Shell_t *shp = sp->shp;
- int curenv = shp->curenv, comsub=shp->comsub;
+ long curenv = shp->curenv;
+ int comsub=shp->comsub;
pid_t pid;
char *trap = shp->st.trapcom[0];
if(trap)
@@ -476,7 +477,7 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_
struct subshell sub_data;
register struct subshell *sp = &sub_data;
int jmpval,nsig=0,duped=0;
- int savecurenv = shp->curenv;
+ long savecurenv = shp->curenv;
int savejobpgid = job.curpgid;
int *saveexitval = job.exitval;
int16_t subshell;

15
ksh93-malloc-hook.dif Normal file
View File

@ -0,0 +1,15 @@
--- ./src/lib/libast/vmalloc/malloc.c.orig 2014-11-19 11:51:06.992595039 +0000
+++ ./src/lib/libast/vmalloc/malloc.c 2014-11-19 12:00:22.713076989 +0000
@@ -1070,12 +1070,8 @@ extern Void_t* F1(_ast_valloc, size_t,n)
#if !_UWIN
-#if !_malloc_hook
-
#include <malloc.h>
-#endif
-
typedef struct mallinfo Mallinfo_t;
typedef struct mstats Mstats_t;

11
ksh93-no-posix_spawn.dif Normal file
View File

@ -0,0 +1,11 @@
--- src/lib/libast/features/lib.orig 2024-05-13 14:35:41.921554657 +0000
+++ src/lib/libast/features/lib 2024-05-13 14:36:15.401506572 +0000
@@ -266,6 +266,8 @@ tst lib_posix_spawn unistd.h stdlib.h sp
int status;
char* cmd[3];
char tmp[1024];
+ NOTE("posix_spawn() DISABLED");
+ _exit(0);
if (argv[1])
_exit(signal(SIGHUP, SIG_DFL) != SIG_IGN);
signal(SIGHUP, SIG_IGN);

13
ksh93-no-sysctl.dif Normal file
View File

@ -0,0 +1,13 @@
--- ./src/lib/libcmd/uname.c.orig 2020-11-13 13:08:48.136513672 +0000
+++ ./src/lib/libcmd/uname.c 2020-11-13 13:09:03.356469649 +0000
@@ -90,10 +90,6 @@ __STDPP__directive pragma pp:hide getdom
# include <sys/utsname.h>
#endif
-#ifdef __linux__
-# include <sys/sysctl.h>
-#endif
-
#if defined(__STDPP__directive) && defined(__STDPP__hide)
__STDPP__directive pragma pp:nohide getdomainname gethostid gethostname sethostname
#else

11
ksh93-nvtree-free.dif Normal file
View File

@ -0,0 +1,11 @@
--- src/cmd/ksh93/sh/nvtree.c.orig 2015-03-17 16:00:01.111718083 +0000
+++ src/cmd/ksh93/sh/nvtree.c 2015-03-17 16:00:31.560586300 +0000
@@ -1152,6 +1152,8 @@ static void put_tree(register Namval_t *
nv_putv(np, val, flags,fp);
if(val && nv_isattr(np,(NV_INTEGER|NV_BINARY)))
return;
+ if (!val && !np->nvfun)
+ return;
if(ap= nv_arrayptr(np))
nleft = array_elem(ap);
if(nleft==0)

15
ksh93-optimizeleak.dif Normal file
View File

@ -0,0 +1,15 @@
--- ./src/cmd/ksh93/sh/name.c.orig 2016-06-01 13:09:29.754690694 +0000
+++ ./src/cmd/ksh93/sh/name.c 2016-06-01 13:09:53.348690652 +0000
@@ -2726,6 +2726,12 @@ void nv_optimize(Namval_t *np)
}
if((xp= (struct optimize*)fp) && xp->ptr==shp->argaddr)
return;
+ if (xp && xp->next) {
+ register struct optimize *xpn;
+ for (xpn = xp->next; xpn; xpn = xpn->next)
+ if (xpn->ptr == shp->argaddr && xpn->np == np)
+ return;
+ }
if(op = opt_free)
opt_free = op->next;
else

13
ksh93-path-skip.dif Normal file
View File

@ -0,0 +1,13 @@
--- ./src/cmd/ksh93/sh/path.c.orig 2014-10-09 15:50:51.198269322 +0000
+++ ./src/cmd/ksh93/sh/path.c 2014-10-09 15:51:16.351159405 +0000
@@ -517,8 +517,8 @@ static int path_opentype(Shell_t *shp,co
do
{
pp = path_nextcomp(shp,oldpp=pp,name,0);
- while(oldpp && (oldpp->flags&PATH_SKIP))
- oldpp = oldpp->next;
+ if (oldpp && (oldpp->flags&PATH_SKIP))
+ continue;
if(fun && (!oldpp || !(oldpp->flags&PATH_FPATH)))
continue;
if((fd = sh_open(path_relative(shp,stakptr(PATH_OFFSET)),O_RDONLY,0)) >= 0)

114
ksh93-pathtemp.dif Normal file
View File

@ -0,0 +1,114 @@
--- src/lib/libast/path/pathtemp.c
+++ src/lib/libast/path/pathtemp.c 2012-10-25 10:35:14.510345073 +0000
@@ -73,15 +73,49 @@
#include <ls.h>
#include <tv.h>
#include <tm.h>
+#include <error.h>
#define ATTEMPT 10
#define TMP_ENV "TMPDIR"
#define TMP_PATH_ENV "TMPPATH"
#define TMP1 "/tmp"
-#define TMP2 "/usr/tmp"
+#define TMP2 "/var/tmp"
-#define VALID(d) (*(d)&&!eaccess(d,W_OK|X_OK))
+static inline int xaccess(const char *path, int mode)
+{
+ static size_t pgsz;
+ struct statvfs vfs;
+ int ret;
+
+ if (!pgsz)
+ pgsz = strtoul(astconf("PAGESIZE",NiL,NiL),NiL,0);
+
+ if (!path || !*path)
+ {
+ errno = EFAULT;
+ goto err;
+ }
+
+ do
+ ret = statvfs(path, &vfs);
+ while (ret < 0 && errno == EINTR);
+
+ if (ret < 0)
+ goto err;
+
+ if (vfs.f_frsize*vfs.f_bavail < pgsz)
+ {
+ errno = ENOSPC;
+ goto err;
+ }
+
+ return eaccess(path, mode);
+err:
+ return -1;
+}
+
+#define VALID(d) (*(d)&&!xaccess(d,W_OK|X_OK))
static struct
{
@@ -182,7 +216,7 @@ pathtemp(char* buf, size_t len, const ch
tv.tv_nsec = 0;
else
tvgettime(&tv);
- if (!(d = (char*)dir) || *d && eaccess(d, W_OK|X_OK))
+ if (!(d = (char*)dir) || (*d && xaccess(d, W_OK|X_OK)))
{
if (!tmp.vec)
{
@@ -227,7 +261,7 @@ pathtemp(char* buf, size_t len, const ch
tmp.dir = tmp.vec;
d = *tmp.dir++;
}
- if (!d && (!*(d = astconf("TMP", NiL, NiL)) || eaccess(d, W_OK|X_OK)) && eaccess(d = TMP1, W_OK|X_OK) && eaccess(d = TMP2, W_OK|X_OK))
+ if (!d && (!*(d = astconf("TMP", NiL, NiL)) || xaccess(d, W_OK|X_OK)) && xaccess(d = TMP1, W_OK|X_OK) && xaccess(d = TMP2, W_OK|X_OK))
return 0;
}
if (!len)
--- src/lib/libast/sfio/sftmp.c
+++ src/lib/libast/sfio/sftmp.c 2012-10-25 12:09:18.026344912 +0000
@@ -20,6 +20,14 @@
* *
***********************************************************************/
#include "sfhdr.h"
+#if _PACKAGE_ast
+# if defined(__linux__) && _lib_statfs
+# include <sys/statfs.h>
+# ifndef TMPFS_MAGIC
+# define TMPFS_MAGIC 0x01021994
+# endif
+# endif
+#endif
/* Create a temporary stream for read/write.
** The stream is originally created as a memory-resident stream.
@@ -207,7 +215,24 @@ Sfio_t* f;
int fd;
#if _PACKAGE_ast
+# if defined(__linux__) && _lib_statfs
+ /*
+ * Use the area of POSIX shared memory objects for the new temporary file descriptor
+ * that is do not access HD or SSD but only the memory based tmpfs of the POSIX SHM
+ */
+ static int doshm;
+ static char *shm = "/dev/shm";
+ if (!doshm)
+ {
+ struct statfs fs;
+ if (statfs(shm, &fs) < 0 || fs.f_type != TMPFS_MAGIC || eaccess(shm, W_OK|X_OK))
+ shm = NiL;
+ doshm++;
+ }
+ if(!(file = pathtemp(NiL,PATH_MAX,shm,"sf",&fd)))
+# else
if(!(file = pathtemp(NiL,PATH_MAX,NiL,"sf",&fd)))
+# endif
return -1;
_rmtmp(f, file);
free(file);

64
ksh93-profile.dif Normal file
View File

@ -0,0 +1,64 @@
--- src/cmd/ksh93/sh/main.c
+++ src/cmd/ksh93/sh/main.c 2010-08-17 15:35:18.000000000 +0000
@@ -200,14 +200,38 @@ int sh_main(int ac, char *av[], Shinit_f
{
/* system profile */
sh_source(shp, iop, e_sysprofile);
+ }
+ /* make sure PWD is set up correctly */
+ path_pwd(shp,1);
+#if SHOPT_SYSRC
+ if(!sh_isoption(SH_NOEXEC))
+ {
+ if(!sh_isoption(SH_NOUSRPROFILE) && !sh_isoption(SH_PRIVILEGED) && sh_isoption(SH_RC))
+ {
+#if SHOPT_BASH
+ if(sh_isoption(SH_BASH) && !sh_isoption(SH_POSIX))
+ sh_source(shp, iop, e_bash_sysrc);
+ else
+#endif
+ {
+ if(name = sh_mactry(shp,nv_getval(ENVNOD)))
+ name = *name ? strdup(name) : (char*)0;
+ if(!name || !strmatch(name, "?(.)/./*"))
+ sh_source(shp, iop, e_sysrc);
+ if(name)
+ free(name);
+ }
+ }
+ }
+#endif
+ if(sh_isoption(SH_LOGIN_SHELL) && !sh_isoption(SH_NOPROFILE))
+ {
if(!sh_isoption(SH_NOUSRPROFILE) && !sh_isoption(SH_PRIVILEGED))
{
char **files = shp->gd->login_files;
while ((name = *files++) && !sh_source(shp, iop, sh_mactry(shp,name)));
}
}
- /* make sure PWD is set up correctly */
- path_pwd(shp,1);
if(!sh_isoption(SH_NOEXEC))
{
if(!sh_isoption(SH_NOUSRPROFILE) && !sh_isoption(SH_PRIVILEGED) && sh_isoption(SH_RC))
@@ -215,9 +239,6 @@ int sh_main(int ac, char *av[], Shinit_f
#if SHOPT_BASH
if(sh_isoption(SH_BASH) && !sh_isoption(SH_POSIX))
{
-#if SHOPT_SYSRC
- sh_source(shp, iop, e_bash_sysrc);
-#endif
sh_source(shp, iop, shp->gd->rcfile ? shp->gd->rcfile : sh_mactry(shp,(char*)e_bash_rc));
}
else
@@ -225,10 +246,6 @@ int sh_main(int ac, char *av[], Shinit_f
{
if(name = sh_mactry(shp,nv_getval(ENVNOD)))
name = *name ? strdup(name) : (char*)0;
-#if SHOPT_SYSRC
- if(!strmatch(name, "?(.)/./*"))
- sh_source(shp, iop, e_sysrc);
-#endif
if(name)
{
sh_source(shp, iop, name);

15
ksh93-putval.dif Normal file
View File

@ -0,0 +1,15 @@
--- ./src/cmd/ksh93/sh/name.c.orig 2019-04-04 14:28:17.044667686 +0000
+++ ./src/cmd/ksh93/sh/name.c 2019-04-04 14:28:32.472629455 +0000
@@ -1986,8 +1986,11 @@ void nv_putval(register Namval_t *np, co
up->cp = cp;
if(sp)
{
+ size_t splen = strlen(sp);
int c = cp[dot+append];
- memmove(cp+append,sp,dot);
+ memmove(cp+append,sp,dot>splen?splen:dot);
+ if (dot>splen)
+ memset(cp+append+splen,0,dot-splen);
cp[dot+append] = c;
if(nv_isattr(np, NV_RJUST) && nv_isattr(np, NV_ZFILL))
rightjust(cp,size,'0');

20
ksh93-redirectleak.dif Normal file
View File

@ -0,0 +1,20 @@
--- src/cmd/ksh93/sh/io.c.orig 2015-12-09 11:18:00.657295950 +0000
+++ src/cmd/ksh93/sh/io.c 2015-12-09 11:18:57.719080685 +0000
@@ -1541,7 +1541,17 @@ int sh_redirect(Shell_t *shp,struct iono
sh_iosave(shp,fn,indx,tname?fname:(trunc?Empty:0));
}
else if(sh_subsavefd(fn))
+ {
+ if(fd==fn)
+ {
+ if((r=sh_fcntl(fd,F_DUPFD,10)) > 0)
+ {
+ fd = r;
+ sh_close(fn);
+ }
+ }
sh_iosave(shp,fn,indx|IOSUBSHELL,tname?fname:0);
+ }
}
if(fd<0)
{

18
ksh93-reg.dif Normal file
View File

@ -0,0 +1,18 @@
--- src/cmd/ksh93/edit/edit.c
+++ src/cmd/ksh93/edit/edit.c 2013-02-01 17:18:31.405454238 +0000
@@ -1769,8 +1769,13 @@ int ed_histgen(Edit_t *ep,const char *pa
mplast->next = mp;
mplast->next = 0;
}
- ep->hlist = (Histmatch_t**)argv;
- ep->hfirst = ep->hlist?ep->hlist[0]:0;
+ if (argv)
+ {
+ ep->hlist = (Histmatch_t**)argv;
+ ep->hfirst = ep->hlist?ep->hlist[0]:0;
+ }
+ else
+ ep->hfirst = 0;
return(ep->hmax=ac);
}

22
ksh93-s390.dif Normal file
View File

@ -0,0 +1,22 @@
--- src/cmd/ksh93/bltins/read.c
+++ src/cmd/ksh93/bltins/read.c 2013-02-01 15:29:39.393452098 +0000
@@ -288,6 +288,19 @@ int sh_readline(register Shell_t *shp,ch
ep->e_nttyparm.c_lflag |= ISIG;
tty_set(fd,TCSADRAIN,&ep->e_nttyparm);
}
+#if defined(__linux__)
+ else if ((shp->fdstatus[fd]&(IOTTY|IONOSEEK))==0)
+ {
+ struct stat st;
+ if ((fstat(fd, &st) == 0) && S_ISFIFO(st.st_mode))
+ {
+ int fdflg;
+ if (((fdflg = fcntl(fd, F_GETFL)) != -1) && !(fdflg & O_NONBLOCK))
+ fcntl(fd, F_SETFL, fdflg|O_NONBLOCK);
+ shp->fdstatus[fd] |= IONOSEEK;
+ }
+ }
+#endif
}
binary = nv_isattr(np,NV_BINARY);
if(!binary && !(flags&(N_FLAG|NN_FLAG)))

263
ksh93-sfio.dif Normal file
View File

@ -0,0 +1,263 @@
--- 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/sfflsbuf.c
+++ src/lib/libast/sfio/sfflsbuf.c 2013-10-18 11:50:01.866235555 +0000
@@ -96,7 +96,7 @@ int c; /* if c>=0, c is also written out
isall = SFISALL(f,isall);
if((w = SFWR(f,data,n,f->disc)) > 0)
{ if((n -= w) > 0) /* save unwritten data, then resume */
- memcpy((char*)f->data,(char*)data+w,n);
+ memmove((char*)f->data,(char*)data+w,n);
written += w;
f->next = f->data+n;
if(c < 0 && (!isall || n == 0))
--- 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;
--- src/lib/libast/sfio/sfmove.c
+++ src/lib/libast/sfio/sfmove.c 2013-10-18 12:04:03.194735625 +0000
@@ -113,7 +113,11 @@ reg int rc; /* record separator */
/* try reading a block of data */
direct = 0;
- if((r = fr->endb - (next = fr->next)) <= 0)
+ if(fr->rsrv && (r = -fr->rsrv->slen) > 0)
+ { fr->rsrv->slen = 0;
+ next = fr->rsrv->data;
+ }
+ else if((r = fr->endb - (next = fr->next)) <= 0)
{ /* amount of data remained to be read */
if((w = n > MAX_SSIZE ? MAX_SSIZE : (ssize_t)n) < 0)
{ if(fr->extent < 0)
--- src/lib/libast/sfio/sfpoll.c
+++ src/lib/libast/sfio/sfpoll.c 2013-10-18 11:59:50.778735232 +0000
@@ -138,7 +138,7 @@ int tm; /* time in millisecs for select
while((np = SFPOLL(fds,m,tm)) < 0 )
{ if(errno == eintr || errno == EAGAIN)
errno = 0;
- else break;
+ else goto report;
}
if(np > 0) /* poll succeeded */
np = c;
@@ -147,14 +147,14 @@ int tm; /* time in millisecs for select
{ f = fa[check[r]];
if((f->flags&SF_WRITE) && !WRREADY(f) )
- { if(fds[m].revents&POLLOUT)
+ { if(fds[m].revents&(POLLOUT|POLLHUP|POLLERR))
status[check[r]] |= SF_WRITE;
}
if((f->flags&SF_READ) && !RDREADY(f))
{ if((f->mode&SF_WRITE) && HASAUXFD(f))
m += 1;
- if(fds[m].revents&POLLIN)
+ if(fds[m].revents&(POLLIN|POLLHUP|POLLERR))
status[check[r]] |= SF_READ;
}
}
@@ -200,7 +200,7 @@ int tm; /* time in millisecs for select
while((np = select(m+1,&rd,&wr,NIL(fd_set*),tmp)) < 0 )
{ if(errno == eintr)
errno = 0;
- else break;
+ else goto report;
}
if(np > 0)
np = c;
@@ -227,6 +227,7 @@ int tm; /* time in millisecs for select
}
#endif /*_lib_select*/
+ report:
for(r = c = 0; c < n; ++c)
{ if(status[c] == 0)
continue;
--- src/lib/libast/sfio/sfpool.c
+++ src/lib/libast/sfio/sfpool.c 2013-10-18 11:49:25.614237061 +0000
@@ -138,7 +138,7 @@ int n; /* current position in pool */
else /* write failed, recover buffer then quit */
{ if(w > 0)
{ v -= w;
- memcpy(head->data,(head->data+w),v);
+ memmove(head->data,(head->data+w),v);
}
head->next = head->data+v;
goto done;
@@ -147,7 +147,7 @@ int n; /* current position in pool */
/* move data from head to f */
if((head->data+k) != f->data )
- memcpy(f->data,(head->data+k),v);
+ memmove(f->data,(head->data+k),v);
f->next = f->data+v;
}
--- src/lib/libast/sfio/sfsetbuf.c
+++ src/lib/libast/sfio/sfsetbuf.c 2013-10-18 12:02:37.534736056 +0000
@@ -254,6 +254,15 @@ size_t size; /* buffer size, -1 for defa
#endif
}
+ /* set page size, this is also the desired default buffer size */
+ if(_Sfpage <= 0)
+ {
+#if _lib_getpagesize
+ if((_Sfpage = (size_t)getpagesize()) <= 0)
+#endif
+ _Sfpage = SF_PAGE;
+ }
+
#if SFSETLINEMODE
if(init)
f->flags |= sfsetlinemode();
@@ -308,15 +317,6 @@ size_t size; /* buffer size, -1 for defa
(void)_sfpopen(f,-1,-1,1);
}
}
-
- /* set page size, this is also the desired default buffer size */
- if(_Sfpage <= 0)
- {
-#if _lib_getpagesize
- if((_Sfpage = (size_t)getpagesize()) <= 0)
-#endif
- _Sfpage = SF_PAGE;
- }
}
#ifdef MAP_TYPE
--- src/lib/libast/string/stropt.c
+++ src/lib/libast/string/stropt.c 2013-01-03 17:20:37.000000000 +0100
@@ -90,7 +90,7 @@ stropt(const char* as, const void* tab,
{
for (p = (char**)tab; t = *p; p = (char**)((char*)p + siz))
{
- for (v = s; *t && *t++ == *v; v++);
+ for (v = s; *t && *t == *v; t++, v++);
if (!*t || isspace(*v) || *v == ',' || *v == '=')
break;
if (*v == ':' && *(v + 1) == '=')
--- src/lib/libast/vmalloc/vmopen.c
+++ src/lib/libast/vmalloc/vmopen.c 2013-10-18 13:54:50.918235639 +0000
@@ -68,19 +68,22 @@ int mode; /* type of region */
Block_t *bp, *np;
Seg_t *seg;
Vmuchar_t *addr;
- int rv;
+ int rv, mt;
if(!meth || !disc || !disc->memoryf )
return NIL(Vmalloc_t*);
GETPAGESIZE(_Vmpagesize);
+ mode = (mode&VM_FLAGS) | meth->meth; /* start with user-settable flags */
+
vmp = &vmproto; /* avoid memory allocation here! */
memset(vmp, 0, sizeof(Vmalloc_t));
memcpy(&vmp->meth, meth, sizeof(Vmethod_t));
+ mt = vmp->meth.meth;
+ vmp->meth.meth = 0;
vmp->disc = disc;
- mode &= VM_FLAGS; /* start with user-settable flags */
size = 0;
if(disc->exceptf)
@@ -155,6 +158,8 @@ int mode; /* type of region */
seg->free = bp;
else vd->wild = bp;
+ vmp->meth.meth = mt;
+
done: /* now make the region handle */
if(vd->mode&VM_MEMORYF)
vm = &init->vm.vm;

429
ksh93-shift_ijs.dif Normal file
View File

@ -0,0 +1,429 @@
--- src/cmd/ksh93/edit/edit.c
+++ src/cmd/ksh93/edit/edit.c 2007-12-20 17:50:28.000000000 +0000
@@ -28,6 +28,7 @@
*/
#include <ast.h>
+#include <ast_wchar.h>
#include <errno.h>
#include <ccode.h>
#include "FEATURE/options"
@@ -57,8 +58,20 @@ static char KILL_LINE[20] = { ESC, '[',
#if SHOPT_MULTIBYTE
-# define is_cntrl(c) ((c<=STRIP) && iscntrl(c))
-# define is_print(c) ((c&~STRIP) || isprint(c))
+# if _hdr_wctype
+# include <wctype.h>
+# define is_print(c) iswprint((c))
+# define is_cntrl(c) iswcntrl((c))
+# else
+# define is_cntrl(c) (((c)<=STRIP) && iscntrl((c)))
+# define is_print(c) (((c)&~STRIP) || isprint((c)))
+# endif
+# if !_lib_iswcntrl && !defined(iswcntrl)
+# define iswcntrl(c) (((c)<=STRIP) && iscntrl((c)))
+# endif
+# if !_lib_iswprint && !defined(iswprint)
+# define iswprint(c) (((c)&~STRIP) || isprint((c)))
+# endif
#else
# define is_cntrl(c) iscntrl(c)
# define is_print(c) isprint(c)
--- src/cmd/ksh93/edit/emacs.c
+++ src/cmd/ksh93/edit/emacs.c 2007-12-20 17:50:28.000000000 +0000
@@ -62,6 +62,7 @@ One line screen editor for any program
*/
#include <ast.h>
+#include <ast_wchar.h>
#include "FEATURE/cmds"
#if KSHELL
# include "defs.h"
@@ -84,6 +85,9 @@ One line screen editor for any program
#if SHOPT_MULTIBYTE
+# if _hdr_wctype
+# include <wctype.h>
+# endif
# define gencpy(a,b) ed_gencpy(a,b)
# define genncpy(a,b,n) ed_genncpy(a,b,n)
# define genlen(str) ed_genlen(str)
@@ -1563,11 +1567,19 @@ static void setcursor(register Emacs_t *
#if SHOPT_MULTIBYTE
static int print(register int c)
{
+#if _lib_iswprint || defined(iswprint)
+ return(iswprint(c));
+#else
return((c&~STRIP)==0 && isprint(c));
+#endif
}
static int _isword(register int c)
{
+#if _lib_iswalnum || defined(iswalnum)
+ return(iswalnum(c) || (c == '_'));
+#else
return((c&~STRIP) || isalnum(c) || c=='_');
+#endif
}
#endif /* SHOPT_MULTIBYTE */
--- src/cmd/ksh93/edit/vi.c
+++ src/cmd/ksh93/edit/vi.c 2007-12-20 17:50:28.000000000 +0000
@@ -28,6 +28,8 @@
* cbosgd!pds
-*/
+#include <ast.h>
+#include <ast_wchar.h>
#if KSHELL
# include "defs.h"
@@ -65,10 +67,19 @@
# define gencpy(a,b) ed_gencpy(a,b)
# define genncpy(a,b,n) ed_genncpy(a,b,n)
# define genlen(str) ed_genlen(str)
-# define digit(c) ((c&~STRIP)==0 && isdigit(c))
-# define is_print(c) ((c&~STRIP) || isprint(c))
+# if _hdr_wctype
+# include <wctype.h>
+# define digit(c) iswdigit((c))
+# define is_print(c) iswprint((c))
+# else
+# define digit(c) (((c)&~STRIP)==0 && isdigit((c)))
+# define is_print(c) (((c)&~STRIP) || isprint((c)))
+# endif
+# if !_lib_iswdigit && !defined(iswdigit)
+# define iswdigit(c) (((c)&~STRIP)==0 && isdigit((c)))
+# endif
# if !_lib_iswprint && !defined(iswprint)
-# define iswprint(c) ((c&~0177) || isprint(c))
+# define iswprint(c) (((c)&~STRIP) || isprint((c)))
# endif
static int _isalph(int);
static int _ismetach(int);
--- src/cmd/ksh93/sh/io.c
+++ src/cmd/ksh93/sh/io.c 2010-06-28 14:09:09.000000000 +0000
@@ -1536,6 +1536,7 @@ static int io_heredoc(Shell_t *shp,regis
if(traceon)
sfprintf(sfstderr,"< %s\n",name);
sfputr(outfile,name,'\n');
+ off = 0;
}
else
{
--- src/cmd/ksh93/sh/macro.c
+++ src/cmd/ksh93/sh/macro.c 2013-03-19 17:16:46.062074381 +0100
@@ -54,6 +54,7 @@
#if SHOPT_MULTIBYTE
# undef isascii
# define isacii(c) ((c)<=UCHAR_MAX)
+# include <lc.h>
#else
# define mbchar(p) (*(unsigned char*)p++)
#endif /* SHOPT_MULTIBYTE */
@@ -2026,6 +2027,11 @@ static void comsubst(Mac_t *mp,register
struct _mac_ savemac;
int savtop = stktell(stkp);
char lastc=0, *savptr = stkfreeze(stkp,0);
+#if SHOPT_MULTIBYTE
+ const Lc_t *lc=lcinfo(LC_CTYPE)->lc;
+ wchar_t lastw=0;
+#endif /* SHOPT_MULTIBYTE */
+ ssize_t len;
int was_history = sh_isstate(SH_HISTORY);
int was_verbose = sh_isstate(SH_VERBOSE);
int was_interactive = sh_isstate(SH_INTERACTIVE);
@@ -2127,7 +2133,7 @@ static void comsubst(Mac_t *mp,register
num = lseek(fd, (off_t)0, SEEK_CUR);
goto out_offset;
}
- if(!(sp=mp->shp->sftable[fd]))
+ if(!(sp=mp->shp->sftable[fd]) || (sffileno(sp)!=fd &&!(sfset(sp,0,0)&SF_STRING)))
sp = sfnew(NIL(Sfio_t*),(char*)malloc(IOBSIZE+1),IOBSIZE,fd,SF_READ|SF_MALLOC);
type = 3;
}
@@ -2209,17 +2215,36 @@ static void comsubst(Mac_t *mp,register
}
else if(lastc)
{
- mac_copy(mp,&lastc,1);
+ char mb[8];
+ mb[0] = lastc;
+ len = 1;
+#if SHOPT_MULTIBYTE
+ if(lastw)
+ len = mbconv(mb, lastw);
+ lastw = 0;
+#endif /* SHOPT_MULTIBYTE */
lastc = 0;
+ mac_copy(mp,mb,len);
}
newlines = nextnewlines;
if(++c < bufsize)
str[c] = 0;
else
{
- ssize_t len = 1;
+ len = 1;
/* can't write past buffer so save last character */
+#if SHOPT_MULTIBYTE
+ if ((lc->flags & LC_utf8)==0 && (len = mbsize(str))>1)
+ {
+ len = mb2wc(lastw,str,len);
+ if (len < 0)
+ {
+ lastw = 0;
+ len = 1;
+ }
+ }
+#endif /* SHOPT_MULTIBYTE */
c -= len;
lastc = str[c];
str[c] = 0;
@@ -2240,8 +2265,16 @@ static void comsubst(Mac_t *mp,register
}
if(lastc)
{
- mac_copy(mp,&lastc,1);
+ char mb[8];
+ mb[0] = lastc;
+ len = 1;
+#if SHOPT_MULTIBYTE
+ if(lastw)
+ len = mbconv(mb, lastw);
+ lastw = 0;
+#endif /* SHOPT_MULTIBYTE */
lastc = 0;
+ mac_copy(mp,mb,len);
}
sfclose(sp);
return;
@@ -2340,13 +2373,13 @@ static void mac_copy(register Mac_t *mp,
if(mp->pattern)
{
char *sp = "&|()";
- while(c = *sp++)
+ while((c = *sp++))
{
if(state[c]==0)
state[c] = S_EPAT;
}
sp = "*?[{";
- while(c = *sp++)
+ while((c = *sp++))
{
if(state[c]==0)
state[c] = S_PAT;
--- src/cmd/ksh93/sh/string.c
+++ src/cmd/ksh93/sh/string.c 2007-12-20 17:51:07.000000000 +0000
@@ -37,7 +37,7 @@
#endif
#if !_lib_iswprint && !defined(iswprint)
-# define iswprint(c) (((c)&~0377) || isprint(c))
+# define iswprint(c) (((c)&~STRIP) || isprint(c))
#endif
@@ -245,7 +245,7 @@ void sh_trim(register char *sp)
if(sp)
{
dp = sp;
- while(c= *sp)
+ while((c = *sp))
{
#if SHOPT_MULTIBYTE
int len;
--- src/cmd/ksh93/tests/sjis.sh
+++ src/cmd/ksh93/tests/sjis.sh 2011-05-20 15:11:29.000000000 +0000
@@ -0,0 +1,77 @@
+########################################################################
+# #
+# Copyright (c) 2007 SuSE Linux Products GmbH, Nuernberg, Germany #
+# #
+# This library is free software; you can redistribute it and/or #
+# modify it under the terms of the GNU Lesser General Public #
+# License as published by the Free Software Foundation; #
+# version 2.1 of the License. #
+# #
+# This library is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU Lesser General Public License at #
+# http://www.gnu.org/licenses/lgpl-2.1.html for more details #
+# #
+# Author: Werner Fink <werner@suse.de> #
+# #
+########################################################################
+
+#
+# Byte ranges for Shift-JIS encoding (hexadecimal):
+# First byte: 81-9F, E0-EF
+# Second byte: 40-7E, 80-FC
+#
+# Now test out some multi byte characters which
+# include 7bit aka ASCII bytes with 0x81 0x{40-7E}
+#
+
+typeset -i chr=0
+typeset -i err=0
+typeset printf=$(type -p printf 2>/dev/null)
+
+unset LC_ALL
+unset LC_CTYPE
+export LANG=ja_JP.SJIS
+
+for second in $(seq 64 126); do
+ let chr++
+ second=$(printf '%x' ${second})
+ 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
+ uq=$(echo ${mbchar})
+ dq=$(echo "${mbchar}")
+ test "$uq" != "$dq" && let err+=1
+ test ${#uq} -ne 1 -o ${#dq} -ne 1 && let err+=1
+done
+
+if test $err -ne 0 ; then
+ : err_exit
+ : err_exit
+ print -u2 -n "\t"
+ print -u2 -r ${0##*/}[$LINENO]: "Shift-JIS encoding failed"
+fi
+
+LANG=POSIX
+typeset -r utf8_euro_char1=$'\u[20ac]'
+typeset -r utf8_euro_char2=$'\342\202\254'
+(( (${#utf8_euro_char1} == 1) && (${#utf8_euro_char2} == 1) )) || export LC_ALL='en_US.UTF-8'
+if [[ "$(printf '\u[20ac]')" != $'\342\202\254' ]] ; then
+ : err_exit
+ print -u2 -n "\t"
+ print -u2 -r ${0##*/}[$LINENO]: "Locale overrride failed."
+fi
+exit $err
--- src/lib/libast/comp/setlocale.c
+++ src/lib/libast/comp/setlocale.c 2007-12-20 17:50:28.000000000 +0000
@@ -32,6 +32,7 @@
#include "lclib.h"
+#include <ast.h>
#include <ast_wchar.h>
#include <ctype.h>
#include <mc.h>
--- src/lib/libast/comp/wc.c
+++ src/lib/libast/comp/wc.c 2007-12-20 17:50:28.000000000 +0000
@@ -26,6 +26,7 @@
*/
#include <ast.h>
+#include <ast_wchar.h>
#include <wchar.h>
#define STUB 1
--- src/lib/libast/features/wchar
+++ src/lib/libast/features/wchar 2007-12-20 17:50:28.000000000 +0000
@@ -8,7 +8,8 @@ cat{
#define _AST_WCHAR_H 1
}end
-lib mbstowcs,wctomb,wcrtomb,wcslen,wcstombs,wcwidth stdlib.h stdio.h wchar.h
+lib mbstowcs,wctomb,wcrtomb,wcslen,wcstombs,wcscpy,wcwidth stdlib.h stdio.h wchar.h wctype.h
+lib iswprint,iswalpha,iswalnum,iswdigit,iswcntrl stdlib.h stdio.h ctype.h wctype.h
lib towlower,towupper stdlib.h stdio.h wchar.h
typ mbstate_t stdlib.h stdio.h wchar.h
nxt wchar
@@ -68,6 +69,12 @@ cat <<!
#undef putwc
#undef putwchar
#undef ungetwc
+ #undef fwprintf
+ #undef swprintf
+ #undef vfwprintf
+ #undef vswprintf
+ #undef vwprintf
+ #undef wprintf
#define fgetwc _ast_fgetwc
#define fgetws _ast_fgetws
@@ -118,6 +125,12 @@ cat <<!
#if !_lib_wcstombs
extern size_t wcstombs(char*, const wchar_t*, size_t);
#endif
+ #if !_lib_wcscpy
+ extern wchar_t *wcscpy(wchar_t*t, const wchar_t*);
+ #endif
+ #if !_lib_wcwidth
+ extern int int wcwidth(wchar_t c);
+ #endif
extern int fwprintf(FILE*, const wchar_t*, ...);
extern int fwscanf(FILE*, const wchar_t*, ...);
--- src/lib/libast/include/ast.h
+++ src/lib/libast/include/ast.h 2010-08-17 15:09:21.000000000 +0000
@@ -185,8 +185,6 @@ typedef struct
#define mbwide() (mbmax()>1)
#define mb2wc(w,p,n) (*ast.mb_towc)(&w,(char*)p,n)
-#define mbchar(p) (mbwide()?((ast.tmp_int=(*ast.mb_towc)(&ast.tmp_wchar,(char*)(p),mbmax()))>0?((p+=ast.tmp_int),ast.tmp_wchar):(p+=ast.mb_sync+1,ast.tmp_int)):(*(unsigned char*)(p++)))
-#define mbnchar(p,n) (mbwide()?((ast.tmp_int=(*ast.mb_towc)(&ast.tmp_wchar,(char*)(p),n))>0?((p+=ast.tmp_int),ast.tmp_wchar):(p+=ast.mb_sync+1,ast.tmp_int)):(*(unsigned char*)(p++)))
#define mbinit() (mbwide()?(*ast.mb_towc)((wchar_t*)0,(char*)0,mbmax()):0)
#define mbsize(p) (mbwide()?(*ast.mb_len)((char*)(p),mbmax()):((p),1))
#define mbnsize(p,n) (mbwide()?(*ast.mb_len)((char*)(p),n):((p),1))
@@ -195,6 +193,17 @@ typedef struct
#define mbxfrm(t,f,n) (mbcoll()?(*ast.mb_xfrm)((char*)(t),(char*)(f),n):0)
#define mbalpha(w) (ast.mb_alpha?(*ast.mb_alpha)(w):isalpha((w)&0xff))
+#define mbchar(p) (mbwide() ? \
+ (((ast.tmp_int=(*ast.mb_towc)(&ast.tmp_wchar,(char*)(p),mbmax()))>0) ? \
+ ({p+=ast.tmp_int;ast.tmp_wchar;}) : \
+ ({ast.tmp_int=*(unsigned char*)p;p+=ast.mb_sync+1;ast.tmp_int;})) : \
+ (*(unsigned char*)(p++)))
+#define mbnchar(p,n) (mbwide() ? \
+ (((ast.tmp_int=(*ast.mb_towc)(&ast.tmp_wchar,(char*)(p),n))>0) ? \
+ ({p+=ast.tmp_int;ast.tmp_wchar;}) : \
+ ({ast.tmp_int=*(unsigned char*)p;p+=ast.mb_sync+1;ast.tmp_int;})) : \
+ (*(unsigned char*)(p++)))
+
/*
* common macros
*/
--- src/lib/libast/regex/reglib.h
+++ src/lib/libast/regex/reglib.h 2007-12-20 17:50:28.000000000 +0000
@@ -57,6 +57,7 @@ typedef struct regsubop_s
char re_rhs[1]; /* substitution rhs */
#include <ast.h>
+#include <ast_wchar.h>
#include <cdt.h>
#include <stk.h>
--- src/lib/libcmd/Mamfile
+++ src/lib/libcmd/Mamfile 2013-02-05 15:11:03.153953100 +0000
@@ -509,7 +509,7 @@ make cat.o
prev cat.c
meta cat.o %.c>%.o cat.c cat
prev cat.c
-exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -DERROR_CATALOG=\""libcmd"\" -DUSAGE_LICENSE=\""[-author?Glenn Fowler <gsf@research.att.com>][-author?David Korn <dgk@research.att.com>][-copyright?Copyright (c) 1992-2012 AT&T Intellectual Property][-license?http://www.eclipse.org/org/documents/epl-v10.html][--catalog?libcmd]"\" -D_BLD_cmd -D_PACKAGE_ast -c cat.c
+exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -I${PACKAGE_ast_INCLUDE} -DERROR_CATALOG=\""libcmd"\" -DUSAGE_LICENSE=\""[-author?Glenn Fowler <gsf@research.att.com>][-author?David Korn <dgk@research.att.com>][-copyright?Copyright (c) 1992-2012 AT&T Intellectual Property][-license?http://www.eclipse.org/org/documents/epl-v10.html][--catalog?libcmd]"\" -D_BLD_cmd -D_PACKAGE_ast -DSHOPT_MULTIBYTE -c cat.c
done cat.o generated
make chgrp.o
prev chgrp.c

50
ksh93-signals.dif Normal file
View File

@ -0,0 +1,50 @@
--- src/cmd/ksh93/data/signals.c
+++ src/cmd/ksh93/data/signals.c 2012-02-06 10:16:54.000000000 +0000
@@ -18,6 +18,9 @@
* *
***********************************************************************/
#include "defs.h"
+#include <cmd.h>
+#include <jobs.h>
+
#if defined(SIGCLD) && !defined(SIGCHLD)
# define SIGCHLD SIGCLD
--- src/cmd/ksh93/sh/xec.c
+++ src/cmd/ksh93/sh/xec.c 2007-12-21 12:28:04.000000000 +0000
@@ -3834,6 +3834,7 @@ static pid_t sh_ntfork(Shell_t *shp,cons
{
signal(SIGTTIN,SIG_DFL);
signal(SIGTTOU,SIG_DFL);
+ signal(SIGTSTP,SIG_DFL);
}
#endif /* SIGTSTP */
#ifdef JOBS
@@ -3871,6 +3872,9 @@ static pid_t sh_ntfork(Shell_t *shp,cons
{
signal(SIGTTIN,SIG_IGN);
signal(SIGTTOU,SIG_IGN);
+ if(sh_isstate(SH_INTERACTIVE))
+ signal(SIGTSTP,SIG_IGN);
+ else signal(SIGTSTP,SIG_DFL);
}
#endif /* SIGTSTP */
if(spawnpid>0)
@@ -3951,6 +3955,7 @@ static pid_t sh_ntfork(Shell_t *shp,cons
{
signal(SIGTTIN,SIG_DFL);
signal(SIGTTOU,SIG_DFL);
+ signal(SIGTSTP,SIG_DFL);
jobwasset++;
}
#endif /* SIGTSTP */
@@ -4013,6 +4018,9 @@ static pid_t sh_ntfork(Shell_t *shp,cons
{
signal(SIGTTIN,SIG_IGN);
signal(SIGTTOU,SIG_IGN);
+ if(sh_isstate(SH_INTERACTIVE))
+ signal(SIGTSTP,SIG_IGN);
+ else signal(SIGTSTP,SIG_DFL);
}
#endif /* SIGTSTP */
if(sigwasset)

40
ksh93-spawnlock.dif Normal file
View File

@ -0,0 +1,40 @@
--- ./src/cmd/ksh93/sh/jobs.c.orig 2016-07-26 12:52:44.178281624 +0000
+++ ./src/cmd/ksh93/sh/jobs.c 2016-07-26 12:52:59.563281597 +0000
@@ -2071,6 +2071,10 @@ void job_fork(pid_t parent)
job_lock();
jobfork++;
break;
+ case -2:
+ jobfork--;
+ job_unlock();
+ break;
case 0:
jobfork=0;
job_unlock();
--- ./src/cmd/ksh93/sh/xec.c.orig 2016-07-26 12:52:37.322281636 +0000
+++ ./src/cmd/ksh93/sh/xec.c 2016-07-26 12:55:37.097281318 +0000
@@ -3952,6 +3952,7 @@ static pid_t sh_ntfork(Shell_t *shp,cons
# endif /* !_lib_fork */
sh_pushcontext(shp,buffp,SH_JMPCMD);
errorpush(&buffp->err,ERROR_SILENT);
+ job_lock(); /* errormsg will unlock */
jmpval = sigsetjmp(buffp->buff,0);
if(jmpval == 0)
{
@@ -4050,7 +4051,7 @@ static pid_t sh_ntfork(Shell_t *shp,cons
}
fail:
if(jobfork && spawnpid<0)
- job_fork(0);
+ job_fork(-2);
if(spawnpid < 0) switch(errno=shp->path_err)
{
case ENOENT:
@@ -4058,6 +4059,7 @@ static pid_t sh_ntfork(Shell_t *shp,cons
default:
errormsg(SH_DICT,ERROR_system(ERROR_NOEXEC),e_exec+4);
}
+ job_unlock();
}
else
exitset();

33
ksh93-stkalias.dif Normal file
View File

@ -0,0 +1,33 @@
--- ./src/lib/libast/misc/stk.c.orig 2014-11-26 16:01:29.606716557 +0000
+++ ./src/lib/libast/misc/stk.c 2014-11-26 16:03:06.031328609 +0000
@@ -505,7 +505,7 @@ static char *stkgrow(register Sfio_t *st
register char *cp, *dp=0;
register size_t m = stktell(stream);
size_t endoff;
- char *end=0;
+ char *end=0, *oldbase=0;
int nn=0,add=1;
n += (m + sizeof(struct frame)+1);
if(sp->stkflags&STK_SMALL)
@@ -521,6 +521,7 @@ static char *stkgrow(register Sfio_t *st
dp=sp->stkbase;
sp->stkbase = ((struct frame*)dp)->prev;
end = fp->end;
+ oldbase = dp;
}
endoff = end - dp;
cp = newof(dp, char, n, nn*sizeof(char*));
@@ -547,10 +548,10 @@ static char *stkgrow(register Sfio_t *st
if(fp->nalias=nn)
{
fp->aliases = (char**)fp->end;
- if(end && nn>1)
- memmove(fp->aliases,end,(nn-1)*sizeof(char*));
+ if(end && nn>add)
+ memmove(fp->aliases,end,(nn-add)*sizeof(char*));
if(add)
- fp->aliases[nn-1] = dp + roundof(sizeof(struct frame),STK_ALIGN);
+ fp->aliases[nn-1] = oldbase + roundof(sizeof(struct frame),STK_ALIGN);
}
if(m && !dp)
{

30
ksh93-stkfreeze.dif Normal file
View File

@ -0,0 +1,30 @@
--- ./src/cmd/ksh93/sh/xec.c.orig 2014-11-21 14:11:39.619645318 +0000
+++ ./src/cmd/ksh93/sh/xec.c 2014-11-21 14:13:55.409987787 +0000
@@ -514,8 +514,8 @@ int sh_debug(Shell_t *shp, const char *t
Stk_t *stkp=shp->stk;
struct sh_scoped savst;
Namval_t *np = SH_COMMANDNOD;
- char *sav = stkptr(stkp,0);
int n=4, offset=stktell(stkp);
+ char *sav = stkfreeze(stkp,0);
const char *cp = "+=( ";
Sfio_t *iop = stkstd;
short level;
@@ -570,7 +570,7 @@ int sh_debug(Shell_t *shp, const char *t
nv_putval(SH_FUNNAMENOD,shp->st.funname,NV_NOFREE);
shp->st = savst;
if(sav != stkptr(stkp,0))
- stkset(stkp,sav,0);
+ stkset(stkp,sav,offset);
else
stkseek(stkp,offset);
return(n);
@@ -998,7 +998,7 @@ int sh_exec(register const Shnode_t *t,
int ntflag = 0;
#endif
int topfd = shp->topfd;
- char *sav=stkptr(stkp,0);
+ char *sav=stkfreeze(stkp,0);
char *cp=0, **com=0, *comn;
int argn;
int skipexitset = 0;

11
ksh93-stkset-abort.dif Normal file
View File

@ -0,0 +1,11 @@
--- ./src/lib/libast/misc/stk.c.orig 2014-11-22 10:46:29.708285640 +0000
+++ ./src/lib/libast/misc/stk.c 2014-11-22 10:48:32.533777385 +0000
@@ -378,6 +378,8 @@ char *stkset(register Sfio_t * stream, r
frames++;
}
/* set stack back to the beginning */
+ if (loc)
+ abort();
cp = (char*)(fp+1);
if(frames)
sfsetbuf(stream,cp,sp->stkend-cp);

11
ksh93-subshellpwd.dif Normal file
View File

@ -0,0 +1,11 @@
--- ./src/cmd/ksh93/sh/subshell.c.orig 2014-11-13 15:56:44.331110277 +0000
+++ ./src/cmd/ksh93/sh/subshell.c 2014-11-13 15:58:05.104764274 +0000
@@ -547,7 +547,7 @@ Sfio_t *sh_subshell(Shell_t *shp,Shnode_
struct subshell *xp;
sp->shpwd = shp->pwd;
#ifdef _lib_fchdir
- for(xp=sp->prev; xp; xp=xp->prev)
+ for(xp=sp->prev; shp->pwd && xp; xp=xp->prev)
{
if(xp->pwdfd>0 && strcmp(xp->pwd,shp->pwd)==0)
{

147
ksh93-suid_exec.dif Normal file
View File

@ -0,0 +1,147 @@
--- src/cmd/ksh93/data/msg.c
+++ src/cmd/ksh93/data/msg.c 2007-04-02 14:59:19.000000000 +0000
@@ -205,7 +205,11 @@ const char e_bash_profile[] = "$HOME/.ba
const char e_crondir[] = "/var/spool/cron";
const char e_prohibited[] = "login setuid/setgid shells prohibited";
#if SHOPT_SUID_EXEC
+# ifdef THISPROG
+ const char e_suidexec[] = THISPROG;
+# else
const char e_suidexec[] = "/etc/suid_exec";
+# endif
#endif /* SHOPT_SUID_EXEC */
const char hist_fname[] = "/.sh_history";
const char e_dot[] = ".";
--- src/cmd/ksh93/sh/suid_exec.c
+++ src/cmd/ksh93/sh/suid_exec.c 2012-02-03 08:36:40.000000000 +0000
@@ -62,10 +62,24 @@
#define FDVERIFY 12 /* used to validate /tmp process */
#undef BLKSIZE
#define BLKSIZE sizeof(char*)*1024
-#define THISPROG "/etc/suid_exec"
-#define DEFSHELL "/bin/sh"
+#ifndef THISPROG
+# define THISPROG "/etc/suid_exec"
+#endif
+#ifndef DEFSHELL
+# define DEFSHELL "/bin/sh"
+#endif
+#if defined(__linux__)
+static void error_exit(const char*) __attribute__ ((noreturn));
+#ifndef _lib_setregid
+#define _lib_setregid 1
+#endif
+#ifndef _lib_setreuid
+#define _lib_setreuid 1
+#endif
+#else
static void error_exit(const char*);
+#endif
static int in_dir(const char*, const char*);
static int endsh(const char*);
#ifndef _lib_setregid
@@ -76,7 +90,7 @@ static int endsh(const char*);
static int mycopy(int, int);
static void maketemp(char*);
#else
- static void setids(int,int,int);
+ static void setids(int,uid_t,gid_t);
#endif /* _lib_setreuid */
static const char version[] = "\n@(#)$Id: suid_exec "SH_RELEASE" $\n";
@@ -221,7 +235,7 @@ int main(int argc,char *argv[])
if(effuid != ruserid)
mode |= S_ISUID;
}
- else if(effuid)
+ else if(effuid != euserid)
{
if(effuid != ruserid || setuid(ruserid) < 0)
mode = S_ISUID;
@@ -233,13 +247,18 @@ int main(int argc,char *argv[])
exec:
#endif /* _lib_setreuid */
/* only use SHELL if file is in trusted directory and ends in sh */
+#ifndef __linux__
shell = getenv("SHELL");
if(shell == 0 || !endsh(shell) || (
!in_dir("/bin",shell) &&
!in_dir("/usr/bin",shell) &&
- !in_dir("/usr/lbin",shell) &&
!in_dir("/usr/local/bin",shell)))
shell = DEFSHELL;
+#else
+ shell = DEFSHELL;
+ if(!endsh(shell))
+ error_exit(badexec);
+#endif
argv[0] = command;
argv[1] = (char*)devfd;
execv(shell,argv);
@@ -249,7 +268,7 @@ exec:
/*
* return true of shell ends in sh of ksh
*/
-
+#ifndef __linux__
static int endsh(register const char *shell)
{
while(*shell)
@@ -262,7 +281,20 @@ static int endsh(register const char *sh
return(1);
return(0);
}
-
+#else
+static int endsh(const char *shell)
+{
+ char * shx;
+ while ((shx = getusershell())) {
+ if (strcmp(shx, shell) == 0) {
+ endusershell();
+ return(1);
+ }
+ }
+ endusershell();
+ return(0);
+}
+#endif
/*
* return true of shell is in <dir> directory
@@ -341,16 +373,30 @@ int eaccess(register const char *name, r
}
#ifdef _lib_setreuid
-static void setids(int mode,int owner,int group)
+#include <sys/types.h>
+#include <pwd.h>
+#include <grp.h>
+static void setids(int mode,uid_t owner,gid_t group)
{
- if(mode & S_ISGID)
- setregid(rgroupid,group);
+ if(mode & S_ISGID) {
+ struct passwd *pwd;
+
+ if (setregid(rgroupid,group))
+ error_exit(badexec);
+
+ if (((pwd = getpwuid(owner)) == (struct passwd*)0) || !(pwd->pw_name))
+ error_exit(badexec);
+
+ if (initgroups (pwd->pw_name, group))
+ error_exit(badexec);
+ }
/* set effective uid even if S_ISUID is not set. This is because
* we are *really* executing EUID root at this point. Even if S_ISUID
* is not set, the value for owner that is passsed should be correct.
*/
- setreuid(ruserid,owner);
+ if (setreuid(ruserid,owner))
+ error_exit(badexec);
}
#else

36
ksh93-test.dif Normal file
View File

@ -0,0 +1,36 @@
--- src/cmd/ksh93/bltins/test.c
+++ src/cmd/ksh93/bltins/test.c 2011-05-20 13:45:25.000000000 +0000
@@ -47,12 +47,12 @@
#ifdef S_ISSOCK
# if _pipe_socketpair
# if _socketpair_shutdown_mode
-# define isapipe(f,p) (test_stat(f,p)>=0&&S_ISFIFO((p)->st_mode)||S_ISSOCK((p)->st_mode)&&(p)->st_ino&&((p)->st_mode&(S_IRUSR|S_IWUSR))!=(S_IRUSR|S_IWUSR))
+# define isapipe(f,p) (test_stat(f,p)>=0&&(S_ISFIFO((p)->st_mode)||(S_ISSOCK((p)->st_mode)&&(p)->st_ino&&((p)->st_mode&(S_IRUSR|S_IWUSR))!=(S_IRUSR|S_IWUSR))))
# else
-# define isapipe(f,p) (test_stat(f,p)>=0&&S_ISFIFO((p)->st_mode)||S_ISSOCK((p)->st_mode)&&(p)->st_ino)
+# define isapipe(f,p) (test_stat(f,p)>=0&&(S_ISFIFO((p)->st_mode)||S_ISSOCK((p)->st_mode)&&(p)->st_ino))
# endif
# else
-# define isapipe(f,p) (test_stat(f,p)>=0&&S_ISFIFO((p)->st_mode)||S_ISSOCK((p)->st_mode)&&(p)->st_ino)
+# define isapipe(f,p) (test_stat(f,p)>=0&&(S_ISFIFO((p)->st_mode)||S_ISSOCK((p)->st_mode)&&(p)->st_ino))
# endif
# define isasock(f,p) (test_stat(f,p)>=0&&S_ISSOCK((p)->st_mode))
#else
@@ -87,7 +87,7 @@ static int test_strmatch(Shell_t *shp,co
regoff_t match[2*(MATCH_MAX+1)],n;
register int c, m=0;
register const char *cp=pat;
- while(c = *cp++)
+ while((c = *cp++))
{
if(c=='(')
m++;
@@ -463,7 +463,7 @@ int test_unop(Shell_t *shp,register int
int test_binop(Shell_t *shp,register int op,const char *left,const char *right)
{
- register double lnum,rnum;
+ register double lnum = 0, rnum = 0;
if(op&TEST_ARITH)
{
while(*left=='0')

37
ksh93-typedef.dif Normal file
View File

@ -0,0 +1,37 @@
--- src/cmd/ksh93/bltins/typeset.c
+++ src/cmd/ksh93/bltins/typeset.c 2013-03-19 17:21:08.667413362 +0100
@@ -461,6 +461,7 @@ static void print_value(Sfio_t *iop, Nam
{
char *name;
int aflag=tp->aflag;
+ Namval_t *table;
if(nv_isnull(np))
{
if(!np->nvflag)
@@ -504,7 +505,9 @@ static void print_value(Sfio_t *iop, Nam
sfwrite(iop,"}\n",2);
return;
}
+ table = tp->sh->last_table;
sfputr(iop,nv_name(np),aflag=='+'?'\n':'=');
+ tp->sh->last_table = table;
if(aflag=='+')
return;
if(nv_isarray(np) && nv_arrayptr(np))
@@ -675,6 +678,7 @@ static int setall(char **argv,regist
{
if(comvar || (shp->last_root==shp->var_tree && (tp->tp || (!shp->st.real_fun && (nvflags&NV_STATIC)) || (!(flag&(NV_EXPORT|NV_RDONLY)) && nv_isattr(np,(NV_EXPORT|NV_IMPORT))==(NV_EXPORT|NV_IMPORT)))))
{
+ if((flag&(NV_HOST|NV_INTEGER))!=NV_HOST)
_nv_unset(np,0);
}
}
@@ -790,7 +794,7 @@ static int setall(char **argv,regist
else
{
char *oldname=0;
- int len=strlen(name);
+ size_t len=strlen(name);
if(tp->argnum==1 && newflag==NV_INTEGER && nv_isattr(np,NV_INTEGER))
tp->argnum = 10;
if(np->nvfun && !nv_isarray(np) && name[len-1]=='.')

128
ksh93-uname.dif Normal file
View File

@ -0,0 +1,128 @@
--- src/lib/libcmd/date.c
+++ src/lib/libcmd/date.c 2007-03-30 10:51:14.000000000 +0000
@@ -226,10 +226,19 @@ settime(Shbltin_t* context, const char*
if (!adjust && !network)
return tmxsettime(now);
argv = args;
+#ifdef __linux__
+ s = "/bin/date";
+#else
s = "/usr/bin/date";
+#endif
if (!streq(cmd, s) && (!eaccess(s, X_OK) || !eaccess(s+=4, X_OK)))
{
*argv++ = s;
+#ifdef __linux__
+ tmxfmt(buf, sizeof(buf), "%m%d%H" "%M%Y.%S", now);
+ if (tm_info.flags & TM_UTC)
+ *argv++ = "--utc";
+#else
if (streq(astconf("UNIVERSE", NiL, NiL), "att"))
{
tmxfmt(buf, sizeof(buf), "%m%d%H" "%M%Y.%S", now);
@@ -244,6 +253,7 @@ settime(Shbltin_t* context, const char*
if (tm_info.flags & TM_UTC)
*argv++ = "-u";
}
+#endif
*argv++ = buf;
*argv = 0;
if (!sh_run(context, argv - args, args))
--- src/lib/libcmd/uname.c
+++ src/lib/libcmd/uname.c 2007-03-28 16:38:01.000000000 +0000
@@ -79,6 +79,7 @@ __STDPP__directive pragma pp:hide getdom
#include <cmd.h>
#include <ctype.h>
+#include <stdio.h>
#include <proc.h>
#include "FEATURE/utsname"
@@ -86,9 +87,11 @@ __STDPP__directive pragma pp:hide getdom
#define MAXHOSTNAME 64
#if _lib_uname && _sys_utsname
+# include <sys/utsname.h>
+#endif
-#include <sys/utsname.h>
-
+#ifdef __linux__
+# include <sys/sysctl.h>
#endif
#if defined(__STDPP__directive) && defined(__STDPP__hide)
@@ -269,6 +272,9 @@ b_uname(int argc, char** argv, Shbltin_t
{
case 'a':
flags |= OPT_all|((1L<<OPT_ALL)-1);
+#ifdef __linux__
+ flags |= OPT_implementation;
+#endif
continue;
case 'b':
flags |= OPT_base;
@@ -325,7 +331,11 @@ b_uname(int argc, char** argv, Shbltin_t
sethost = opt_info.arg;
continue;
case ':':
+#ifdef __linux__
+ s = "/bin/uname";
+#else
s = "/usr/bin/uname";
+#endif
if (!streq(argv[0], s) && (!eaccess(s, X_OK) || !eaccess(s+=4, X_OK)))
{
argv[0] = s;
@@ -394,13 +404,49 @@ b_uname(int argc, char** argv, Shbltin_t
output(OPT_machine, ut.machine, "machine");
if (flags & OPT_processor)
{
- if (!*(s = astconf("ARCHITECTURE", NiL, NiL)))
+ s = NULL;
+#ifdef __linux__
+# ifdef UNAME_PROCESSOR
+ if (!s) {
+ size_t len = sizeof(buf) - 1;
+ int ctl[] = {CTL_HW, UNAME_PROCESSOR};
+ if (sysctl(ctl, 2, buf, &len, 0, 0) == 0)
+ s = buf;
+ }
+# endif
+ if (!s) {
+ strcpy((s = buf), ut.machine);
+ if (strcmp(s, "i686") == 0) {
+ char line[1024];
+ Sfio_t *io = sfopen((Sfio_t*)0, "/proc/cpuinfo", "r");
+ if (io) {
+ while (fgets(line, sizeof(line), io) > 0) {
+ if (strncmp(line, "vendor_id", 9) == 0) {
+ if (strstr(line, "AuthenticAMD"))
+ s = "athlon";
+ break;
+ }
+ }
+ sfclose(io);
+ }
+ }
+ }
+#endif
+ if (!s && !*(s = astconf("ARCHITECTURE", NiL, NiL)))
s = ut.machine;
output(OPT_processor, s, "processor");
}
if (flags & OPT_implementation)
{
- if (!*(s = astconf("PLATFORM", NiL, NiL)) && !*(s = astconf("HW_NAME", NiL, NiL)))
+ s = NULL;
+#ifdef __linux__
+ if (!s) {
+ strcpy((s = buf), ut.machine);
+ if (s[0] == 'i' && s[2] == '8' && s[3] == '6' && s[4] == '\0')
+ s[1] = '3';
+ }
+#endif
+ if (!s && !*(s = astconf("PLATFORM", NiL, NiL)) && !*(s = astconf("HW_NAME", NiL, NiL)))
{
if (t = strchr(hosttype, '.'))
t++;

361
ksh93-uninitialized.dif Normal file
View File

@ -0,0 +1,361 @@
--- src/cmd/builtin/pty.c
+++ src/cmd/builtin/pty.c 2013-10-25 13:30:22.019295258 +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/edit/edit.c
+++ src/cmd/ksh93/edit/edit.c 2013-10-25 13:30:22.020295166 +0000
@@ -1414,12 +1414,12 @@ int ed_internal(const char *src, genchar
int ed_external(const genchar *src, char *dest)
{
register genchar wc;
- register int c,size;
register char *dp = dest;
char *dpmax = dp+sizeof(genchar)*MAXLINE-2;
if((char*)src == dp)
{
- char buffer[MAXLINE*sizeof(genchar)];
+ int c;
+ char buffer[MAXLINE*sizeof(genchar)] = "";
c = ed_external(src,buffer);
#ifdef _lib_wcscpy
@@ -1431,6 +1431,7 @@ int ed_external(const genchar *src, char
}
while((wc = *src++) && dp<dpmax)
{
+ ssize_t size;
if((size = mbconv(dp, wc)) < 0)
{
/* copy the character as is */
--- src/cmd/ksh93/sh/init.c
+++ src/cmd/ksh93/sh/init.c 2013-10-25 13:30:22.020295166 +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-25 13:30:22.021295073 +0000
@@ -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-25 13:30:22.022294981 +0000
@@ -1344,7 +1344,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
@@ -1820,7 +1820,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-25 13:30:22.022294981 +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-25 13:30:22.023294889 +0000
@@ -583,7 +583,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)
@@ -696,7 +696,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-25 13:30:22.023294889 +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 <numnodes; i++)
{
np=nodes[i];
@@ -1100,7 +1102,6 @@ Namval_t *nv_mktype(Namval_t **nodes, in
nv_disc(nq, &pp->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-25 13:30:22.024294796 +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-25 13:30:22.025294704 +0000
@@ -1507,7 +1507,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)
{
@@ -1916,8 +1916,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
@@ -2409,7 +2409,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;
@@ -2877,7 +2877,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;
@@ -2911,7 +2911,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;
@@ -3376,7 +3376,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;
@@ -3492,10 +3492,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;
@@ -3584,11 +3584,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-25 13:30:22.025294704 +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-25 13:30:22.026294612 +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-25 13:30:22.026294612 +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-25 13:30:22.033293966 +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-25 13:30:22.027294520 +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

12
ksh93-unset-f.dif Normal file
View File

@ -0,0 +1,12 @@
--- src/cmd/ksh93/sh/xec.c
+++ src/cmd/ksh93/sh/xec.c 2011-07-04 15:42:21.000000000 +0000
@@ -3387,7 +3387,8 @@ int sh_funscope(int argn, char *argv[],i
shp->st.var_local = shp->var_tree;
if(!fun)
{
- shp->st.filename = fp->node->nvalue.rp->fname;
+ if (fp->node->nvalue.rp)
+ shp->st.filename = fp->node->nvalue.rp->fname;
shp->st.funname = nv_name(fp->node);
shp->last_root = nv_dict(DOTSHNOD);
nv_putval(SH_PATHNAMENOD,shp->st.filename,NV_NOFREE);

51
ksh93-untrustedenv.dif Normal file
View File

@ -0,0 +1,51 @@
--- src/cmd/ksh93/sh/arith.c.orig
+++ src/cmd/ksh93/sh/arith.c
@@ -513,21 +513,34 @@ Sfdouble_t sh_strnum(register const char *str, char** ptr, int mode)
char base=(shp->inarith?0:10), *last;
if(*str==0)
{
- if(ptr)
- *ptr = (char*)str;
- return(0);
- }
- errno = 0;
- d = strtonll(str,&last,&base,-1);
- if(*last || errno)
- {
- if(!last || *last!='.' || last[1]!='.')
- d = strval(shp,str,&last,arith,mode);
- if(!ptr && *last && mode>0)
- errormsg(SH_DICT,ERROR_exit(1),e_lexbadchar,*last,str);
+ d = 0.0;
+ last = (char*)str;
+ } else {
+ errno = 0;
+ d = strtonll(str,&last,&base,-1);
+ if (*last && !shp->inarith && sh_isstate(SH_INIT)) {
+ // This call is to handle "base#value" literals if we're importing untrusted env vars.
+ errno = 0;
+ d = strtonll(str, &last, NULL, -1);
+ }
+
+ if(*last || errno)
+ {
+ if (sh_isstate(SH_INIT)) {
+ // Initializing means importing untrusted env vars. Since the string does not appear
+ // to be a recognized numeric literal give up. We can't safely call strval() since
+ // that allows arbitrary expressions which would create a security vulnerability.
+ d = 0.0;
+ } else {
+ if(!last || *last!='.' || last[1]!='.')
+ d = strval(shp,str,&last,arith,mode);
+ if(!ptr && *last && mode>0)
+ errormsg(SH_DICT,ERROR_exit(1),e_lexbadchar,*last,str);
+ }
+ } else if (!d && *str=='-') {
+ d = -0.0;
+ }
}
- else if (!d && *str=='-')
- d = -0.0;
if(ptr)
*ptr = last;
return(d);

60
ksh93-vi.dif Normal file
View File

@ -0,0 +1,60 @@
--- src/cmd/ksh93/edit/vi.c
+++ src/cmd/ksh93/edit/vi.c 2007-03-28 16:41:47.000000000 +0000
@@ -401,6 +401,8 @@ int ed_viread(void *context, int fd, reg
if(!yankbuf)
yankbuf = (genchar*)malloc(MAXLINE*CHARSIZE);
+ if (!vp->lastline)
+ vp->lastline = (genchar*)malloc(MAXLINE*CHARSIZE);
if( vp->last_cmd == '\0' )
{
/*** first time for this shell ***/
@@ -410,6 +412,8 @@ int ed_viread(void *context, int fd, reg
vp->lastmotion = '\0';
vp->lastrepeat = 1;
vp->repeat = 1;
+ if (!yankbuf)
+ return(-1);
*yankbuf = 0;
}
@@ -1137,7 +1141,7 @@ static void cdelete(Vi_t *vp,register in
/*** save characters to be deleted ***/
- if( mode != 'c' )
+ if( mode != 'c' && yankbuf )
{
i = cp[nchars];
cp[nchars] = 0;
@@ -2169,6 +2173,9 @@ static void save_last(register Vi_t* vp)
{
register int i;
+ if (vp->lastline == NULL)
+ return;
+
if( (i = cur_virt - first_virt + 1) > 0 )
{
/*** save last thing user typed ***/
@@ -2417,6 +2424,11 @@ static int textmod(register Vi_t *vp,reg
p = yankbuf;
}
+ if (!p)
+ {
+ return(BAD);
+ }
+
addin:
switch( c )
{
@@ -2687,6 +2699,8 @@ yankeol:
vp->lastmotion = c;
if( c == 'y' )
{
+ if (!yankbuf)
+ return(BAD);
gencpy(yankbuf, virtual);
}
else if(!delmotion(vp, c, 'y'))

45
ksh93-vm.dif Normal file
View File

@ -0,0 +1,45 @@
--- src/lib/libast/vmalloc/vmhdr.h
+++ src/lib/libast/vmalloc/vmhdr.h 2012-01-19 09:45:14.000000000 +0000
@@ -152,6 +152,9 @@ extern void _vmmessage _ARG_((const cha
#endif /*DEBUG*/
#define VMPAGESIZE 8192
+#if defined(__linux__) && !defined(_lib_getpagesize)
+#define _lib_getpagesize 1
+#endif
#if _lib_getpagesize
#define GETPAGESIZE(x) ((x) ? (x) : ((x)=getpagesize()) )
#else
--- src/lib/libast/vmalloc/vmmopen.c
+++ src/lib/libast/vmalloc/vmmopen.c 2012-01-20 11:13:12.000000000 +0000
@@ -63,8 +63,10 @@ void _STUB_vmmapopen(){}
/* magic word signaling file/segment is ready */
#define MM_MAGIC ((unsigned int)(('P'<<24) | ('&'<<16) | ('N'<<8) | ('8')) )
+#ifndef __linux__
/* default mimimum region size */
#define MM_MINSIZE (64*_Vmpagesize)
+#endif
/* macros to get the data section and size */
#define MMHEAD(file) ROUND(sizeof(Mmvm_t)+strlen(file), ALIGN)
@@ -166,10 +168,18 @@ static int mminit(Mmdisc_t* mmdc)
if(mmdc->mmvm) /* already done this */
return 0;
-
+#ifdef MM_MINSIZE
/* fixed size region so make it reasonably large */
if((size = mmdc->size) < MM_MINSIZE )
size = MM_MINSIZE;
+#else
+ if (sizeof(void*) > 32)
+ extent = ROUND(0x80000,_Vmpagesize);
+ else
+ extent = ROUND(0x40000,_Vmpagesize);
+ if((size = mmdc->size) < extent)
+ size = extent;
+#endif
size += MMHEAD(mmdc->file) + ALIGN;
size = ROUND(size, _Vmpagesize);

515
ksh93.dif Normal file
View File

@ -0,0 +1,515 @@
--- src/cmd/ksh93/bltins/print.c
+++ src/cmd/ksh93/bltins/print.c 2008-05-05 11:20:21.000000000 +0000
@@ -105,7 +105,11 @@ static char* nullarg[] = { 0, 0 };
{
static char bsd_univ;
struct print prdata;
- prdata.options = sh_optecho+5;
+# if defined(__linux__)
+ prdata.options = sh_optecho;
+# else
+ prdata.options = sh_optecho + 5;
+# endif
prdata.raw = prdata.echon = 0;
prdata.sh = context->shp;
NOT_USED(argc);
@@ -118,7 +122,52 @@ static char* nullarg[] = { 0, 0 };
prdata.sh->universe = 1;
}
if(!bsd_univ)
+ {
+# if defined(__linux__)
+ char *opt = argv[1];
+ while ((opt = argv[1]) && (*opt == '-'))
+ {
+ int c;
+
+ opt++;
+
+ for (c = 0; opt[c]; c++)
+# if !SHOPT_ECHOE
+ if (strchr("neE", opt[c]) == 0)
+# else
+ if (strchr("n", opt[c]) == 0)
+# endif /* SHOPT_ECHOE */
+ break;
+
+ if (*opt == 0 || opt[c])
+ break;
+
+ while ((c = *opt++))
+ {
+ switch (c) {
+ case 'n':
+ prdata.echon = 1;
+ break;
+# if !SHOPT_ECHOE
+ case 'e':
+ prdata.raw = 0;
+ break;
+ case 'E':
+ prdata.raw = 1;
+ break;
+# endif /* SHOPT_ECHOE */
+ default:
+ goto out;
+ break;
+ }
+ }
+
+ argv++;
+ }
+ out:
+# endif
return(b_print(0,argv,(Shbltin_t*)&prdata));
+ }
prdata.options = sh_optecho;
prdata.raw = 1;
while(argv[1] && *argv[1]=='-')
--- src/cmd/ksh93/data/msg.c
+++ src/cmd/ksh93/data/msg.c 2007-12-20 18:01:26.000000000 +0000
@@ -202,7 +202,7 @@ const char e_bash_login[] = "$HOME/.bash
const char e_bash_logout[] = "$HOME/.bash_logout";
const char e_bash_profile[] = "$HOME/.bash_profile";
#endif
-const char e_crondir[] = "/usr/spool/cron/atjobs";
+const char e_crondir[] = "/var/spool/cron";
const char e_prohibited[] = "login setuid/setgid shells prohibited";
#if SHOPT_SUID_EXEC
const char e_suidexec[] = "/etc/suid_exec";
--- src/cmd/ksh93/data/variables.c
+++ src/cmd/ksh93/data/variables.c 2008-09-18 17:22:24.000000000 +0000
@@ -69,7 +69,7 @@ const struct shtable2 shtab_variables[]
"OPTARG", 0, (char*)0,
"OPTIND", NV_NOFREE|NV_INTEGER, (char*)0,
"PS4", 0, (char*)0,
- "FPATH", 0, (char*)0,
+ "FPATH", NV_NOFREE, "/usr/share/ksh/fun",
"LANG", 0, (char*)0,
"LC_ALL", 0, (char*)0,
"LC_COLLATE", 0, (char*)0,
--- src/cmd/ksh93/features/options
+++ src/cmd/ksh93/features/options 2007-12-20 18:01:26.000000000 +0000
@@ -36,7 +36,7 @@ tst cross{
option TEST_L $?
test -f /etc/ksh.kshrc -o -f /etc/bash.bashrc &&
option SYSRC 0
- test -f /bin/universe && univ=`/bin/universe` > /dev/null 2>&1 -a ucb = "$univ"
+ test -x /bin/universe && univ=`/bin/universe` > /dev/null 2>&1 && test ucb = "$univ"
option UCB $?
}end
--- src/cmd/ksh93/sh.1
+++ src/cmd/ksh93/sh.1 2008-09-22 12:11:56.000000000 +0000
@@ -200,7 +200,7 @@ separated by
.BR \(bv .
The standard output of each command but the last
is connected by a
-.IR pipe (2)
+.IR socketpair (2)
to the standard input of the next command.
Each command,
except possibly the last,
--- src/cmd/ksh93/sh/main.c
+++ src/cmd/ksh93/sh/main.c 2007-12-20 18:01:26.000000000 +0000
@@ -113,9 +113,9 @@ int sh_source(Shell_t *shp, Sfio_t *iop,
}
#ifdef S_ISSOCK
-#define REMOTE(m) (S_ISSOCK(m)||!(m))
+#define REMOTE(m) ((S_ISSOCK((m).st_mode)||!((m).st_mode))&&!((m).st_ino))
#else
-#define REMOTE(m) !(m)
+#define REMOTE(m) (!((m).st_mode)&&!((m).st_ino))
#endif
int sh_main(int ac, char *av[], Shinit_f userinit)
@@ -179,7 +179,7 @@ int sh_main(int ac, char *av[], Shinit_f
}
if(!sh_isoption(SH_RC) && (sh_isoption(SH_BASH) && !sh_isoption(SH_POSIX)
#if SHOPT_REMOTE
- || !fstat(0, &statb) && REMOTE(statb.st_mode)
+ || !fstat(0, &statb) && REMOTE(statb)
#endif
))
sh_onoption(SH_RC);
--- src/cmd/ksh93/sh/xec.c
+++ src/cmd/ksh93/sh/xec.c 2012-01-26 12:07:46.000000000 +0000
@@ -1015,7 +1015,7 @@ int sh_exec(register const Shnode_t *t,
{
case TCOM:
{
- register struct argnod *argp;
+ volatile struct argnod *argp;
char *trap;
Namval_t *np, *nq, *last_table;
struct ionod *io;
@@ -1131,7 +1131,7 @@ int sh_exec(register const Shnode_t *t,
comn = com[argn-1];
}
io = t->tre.treio;
- if(shp->envlist = argp = t->com.comset)
+ if((shp->envlist = argp = t->com.comset))
{
if(argn==0 || (np && nv_isattr(np,(BLT_DCL|BLT_SPC))))
{
--- src/cmd/ksh93/tests/attributes.sh
+++ src/cmd/ksh93/tests/attributes.sh 2009-07-09 13:14:05.000000000 +0000
@@ -199,7 +199,7 @@ hello worldhello worldhello world
[[ $v1 == "$b1" ]] || err_exit "v1=$v1 should be $b1"
[[ $v2 == "$x" ]] || err_exit "v1=$v2 should be $x"
if env '!=1' >/dev/null 2>&1
-then [[ $(env '!=1' $SHELL -c 'echo ok' 2>/dev/null) == ok ]] || err_exit 'malformed environment terminates shell'
+then [[ $(env "LD_LIBRARY_PATH=$LD_LIBRARY_PATH" '!=1' $SHELL -c 'echo ok' 2>/dev/null) == ok ]] || err_exit 'malformed environment terminates shell'
fi
unset var
typeset -b var
--- src/cmd/ksh93/tests/bracket.sh
+++ src/cmd/ksh93/tests/bracket.sh 2012-02-09 14:11:32.000000000 +0000
@@ -221,6 +221,10 @@ done
[[ abcdcdabcde == {5}(ab|cd)e ]] || err_exit 'abcdcdabcd == {5}(ab|cd)e'
) || err_exit 'errors with {..}(...) patterns'
[[ D290.2003.02.16.temp == D290.+(2003.02.16).temp* ]] || err_exit 'pattern match bug with +(...)'
+atime=$(stat -c '%X' $file)
+sleep 2
+cat $file > /dev/null
+if [[ $atime -lt $(stat -c '%X' $file) ]] then
rm -rf $file
{
[[ -N $file ]] && err_exit 'test -N $tmp/*: st_mtime>st_atime after creat'
@@ -231,6 +235,7 @@ sleep 2
read
[[ -N $file ]] && err_exit 'test -N $tmp/*: st_mtime>st_atime after read'
} > $file < $file
+fi
if rm -rf "$file" && ln -s / "$file"
then [[ -L "$file" ]] || err_exit '-L not working'
[[ -L "$file"/ ]] && err_exit '-L with file/ not working'
--- src/cmd/ksh93/tests/builtins.sh
+++ src/cmd/ksh93/tests/builtins.sh 2009-07-09 13:14:50.000000000 +0000
@@ -344,7 +344,7 @@ wait $pid1
(( $? == 1 )) || err_exit "wait not saving exit value"
wait $pid2
(( $? == 127 )) || err_exit "subshell job known to parent"
-env=
+env="LD_LIBRARY_PATH=\$LD_LIBRARY_PATH"
v=$(getconf LIBPATH)
for v in ${v//,/ }
do v=${v#*:}
--- src/cmd/ksh93/tests/coprocess.sh
+++ src/cmd/ksh93/tests/coprocess.sh 2013-02-01 15:22:31.000000000 +0000
@@ -113,15 +113,15 @@ do
cop=$!
exp=Done
print -p $'print hello | '$cat$'\nprint '$exp
- read -t 5 -p
- read -t 5 -p
+ read -t 50 -p
+ read -t 50 -p
got=$REPLY
if [[ $got != $exp ]]
then err_exit "${SHELL-ksh} $cat coprocess io failed -- got '$got', expected '$exp'"
fi
exec 5<&p 6>&p
exec 5<&- 6>&-
- { sleep 4; kill $cop; } 2>/dev/null &
+ { sleep 10; kill $cop; } 2>/dev/null &
spy=$!
if wait $cop 2>/dev/null
then kill $spy 2>/dev/null
@@ -134,10 +134,10 @@ do
echo line2 | grep 'line1'
} |&
SECONDS=0 count=0
- while read -p -t 10 line
+ while read -p -t 100 line
do ((count++))
done
- if (( SECONDS > 8 ))
+ if (( SECONDS > 80 ))
then err_exit "$cat coprocess read -p hanging (SECONDS=$SECONDS count=$count)"
fi
wait $!
@@ -160,7 +160,7 @@ do
wait $!
done
print
- ) 2>/dev/null | read -t 10 r
+ ) 2>/dev/null | read -t 100 r
[[ $r == $e ]] || err_exit "$cat coprocess timing bug -- expected $e, got '$r'"
r=
@@ -173,8 +173,9 @@ do
wait $!
done
print $r
- ) 2>/dev/null | read -t 10 r
+ ) 2>/dev/null | read -t 100 r
[[ $r == $e ]] || err_exit "$cat coprocess command substitution bug -- expected $e, got '$r'"
+ kill $(jobs -p) 2>/dev/null
(
$cat |&
@@ -212,7 +213,7 @@ do
done
trap 'sleep_pid=; kill $pid; err_exit "$cat coprocess 1 hung"' TERM
- { sleep 5; kill $$; } &
+ { sleep 10; kill $$; } &
sleep_pid=$!
$cat |&
pid=$!
@@ -226,7 +227,7 @@ do
[[ $sleep_pid ]] && kill $sleep_pid
trap 'sleep_pid=; kill $pid; err_exit "$cat coprocess 2 hung"' TERM
- { sleep 5; kill $$; } &
+ { sleep 10; kill $$; } &
sleep_pid=$!
$cat |&
pid=$!
@@ -238,7 +239,7 @@ do
[[ $sleep_pid ]] && kill $sleep_pid
trap 'sleep_pid=; kill $pid; err_exit "$cat coprocess 3 hung"' TERM
- { sleep 5; kill $$; } &
+ { sleep 10; kill $$; } &
sleep_pid=$!
$cat |&
pid=$!
--- src/cmd/ksh93/tests/locale.sh
+++ src/cmd/ksh93/tests/locale.sh 2011-05-24 14:46:02.000000000 +0000
@@ -62,7 +62,7 @@ done
# this locale is supported by ast on all platforms
# EU for { decimal_point="," thousands_sep="." }
-locale=C_EU.UTF-8
+locale=de_DE.UTF-8
export LC_ALL=C
@@ -111,11 +111,11 @@ set -- $($SHELL -c "
unset LC_CTYPE
export LANG=$locale
export LC_ALL=C
- command wc -C < $tmp/two_euro_chars.txt
+ command wc -m < $tmp/two_euro_chars.txt
unset LC_ALL
- command wc -C < $tmp/two_euro_chars.txt
+ command wc -m < $tmp/two_euro_chars.txt
export LC_ALL=C
- command wc -C < $tmp/two_euro_chars.txt
+ command wc -m < $tmp/two_euro_chars.txt
")
got=$*
[[ $got == $exp ]] || err_exit "command wc LC_ALL default failed -- expected '$exp', got '$got'"
@@ -124,11 +124,11 @@ set -- $($SHELL -c "
then unset LC_CTYPE
export LANG=$locale
export LC_ALL=C
- wc -C < $tmp/two_euro_chars.txt
+ wc -m < $tmp/two_euro_chars.txt
unset LC_ALL
- wc -C < $tmp/two_euro_chars.txt
+ wc -m < $tmp/two_euro_chars.txt
export LC_ALL=C
- wc -C < $tmp/two_euro_chars.txt
+ wc -m < $tmp/two_euro_chars.txt
fi
")
got=$*
@@ -336,7 +336,7 @@ then LC_ALL=en_US.UTF-8
[[ $(print -r -- "$x") == $'hello\u[20ac]\xee world' ]] || err_exit '%q with unicode and non-unicode not working'
if [[ $(whence od) ]]
then got='68 65 6c 6c 6f e2 82 ac ee 20 77 6f 72 6c 64 0a'
- [[ $(print -r -- "$x" | od -An -tx1) == "$got" ]] || err_exit "incorrect string from printf %q"
+ [[ $(print -r -- "$x" | od -An -tx1) =~ "$got" ]] || err_exit "incorrect string from printf %q"
fi
fi
--- src/cmd/ksh93/tests/options.sh
+++ src/cmd/ksh93/tests/options.sh 2012-01-16 16:50:59.000000000 +0000
@@ -510,7 +510,7 @@ z=$($SHELL 2>&1 -uc 'print ${X2345678901
[[ $z == *X23456789012345:* ]] || err_exit "error message garbled with set -u got $z"
# pipe hang bug fixed 2011-03-15
-float start=SECONDS toolong=3
+float start=SECONDS toolong=8
( $SHELL <<-EOF
set -o pipefail
(sleep $toolong;kill \$\$> /dev/null) &
--- src/cmd/ksh93/tests/path.sh
+++ src/cmd/ksh93/tests/path.sh 2008-09-11 16:02:46.000000000 +0000
@@ -269,7 +269,7 @@ builtin getconf
getconf UNIVERSE - att # override sticky default 'UNIVERSE = foo'
[[ $(PATH=/usr/ucb/bin:/usr/bin echo -n ucb) == 'ucb' ]] || err_exit "ucb universe echo ignores -n option"
-[[ $(PATH=/usr/xpg/bin:/usr/bin echo -n att) == '-n att' ]] || err_exit "att universe echo does not ignore -n option"
+[[ $(PATH=/usr/xpg/bin:/usr/bin echo -n att) == 'att' ]] || err_exit "att universe echo ignores -n option"
PATH=$path
--- src/cmd/ksh93/tests/pty.sh
+++ src/cmd/ksh93/tests/pty.sh 2012-03-15 11:51:40.000000000 +0000
@@ -428,15 +428,16 @@ r echo repeat-3
# err_exit #
whence -q less &&
-TERM=vt100 tst $LINENO <<"!"
+TERM=xterm tst $LINENO <<"!"
L process/terminal group exercise
-w m=yes; while true; do echo $m-$m; done | less
+w m=yes; while true; do echo $m-$m; done | less -b1 -c
u :$|:\E|lines
c \cZ
r Stopped
w fg
u yes-yes
+w q
!
exit $((Errors<125?Errors:125))
--- src/cmd/ksh93/tests/signal.sh
+++ src/cmd/ksh93/tests/signal.sh 2011-05-20 13:25:48.000000000 +0000
@@ -285,10 +285,10 @@ then for exp in TERM VTALRM PIPE
$SHELL <<- EOF
foo() { return 0; }
trap foo EXIT
- { sleep 2; kill -$exp \$\$; sleep 3; kill -0 \$\$ && kill -KILL \$\$; } &
+ { sleep 2; kill -$exp \$\$; sleep 8; kill -0 \$\$ && kill -KILL \$\$; } &
$yes |
while read yes
- do (/bin/date; sleep .1)
+ do (/bin/date; sleep .01)
done > /dev/null
EOF
} 2>> /dev/null
--- src/lib/libast/disc/memfatal.c
+++ src/lib/libast/disc/memfatal.c 2009-07-09 13:30:39.000000000 +0000
@@ -74,7 +74,7 @@ memfatal(void)
{
Vmdisc_t* disc;
- malloc(0);
+ void * ptr = malloc(0);
if (disc = vmdisc(Vmregion, NiL))
disc->exceptf = nomalloc;
}
--- src/lib/libast/features/align.c
+++ src/lib/libast/features/align.c 2007-12-20 18:01:26.000000000 +0000
@@ -32,6 +32,7 @@
#include "FEATURE/common"
#include <setjmp.h>
+#include <stdio.h>
union _u_
{
--- src/lib/libast/features/botch.c
+++ src/lib/libast/features/botch.c 2007-12-20 18:01:26.000000000 +0000
@@ -27,6 +27,7 @@
* generate ast traps for botched standard prototypes
*/
+#include <stdio.h>
#include <sys/types.h>
#include "FEATURE/lib"
--- src/lib/libast/features/lib
+++ src/lib/libast/features/lib 2007-12-20 18:01:26.000000000 +0000
@@ -538,14 +538,19 @@ tst lib_utime_now note{ utime works with
}end
tst cross{
- u=att
- case `/bin/cat -s /dev/null/foo 2>&1` in
- '') ;;
- *) case `/bin/echo '\\t'` in
- '\t') u=ucb ;;
+ if test -n "$UNIVERSE"
+ then
+ u=$UNIVERSE
+ else
+ u=att
+ case `/bin/cat -s /dev/null/foo 2>&1` in
+ '') ;;
+ *) case `/bin/echo '\\t'` in
+ '\t') u=ucb ;;
+ esac
+ ;;
esac
- ;;
- esac
+ fi
echo "#define _UNIV_DEFAULT \"$u\" /* default universe name */"
}end
--- src/lib/libast/misc/procopen.c
+++ src/lib/libast/misc/procopen.c 2007-12-20 18:01:26.000000000 +0000
@@ -599,7 +599,7 @@ procopen(const char* cmd, char** argv, c
if (!fork())
{
sfsprintf(path, sizeof(path), "%d", getppid());
- execlp("trace", "trace", "-p", path, NiL);
+ execlp("trace", "trace", "-p", path, NULL);
_exit(EXIT_NOTFOUND);
}
sleep(2);
--- src/lib/libast/port/astwinsize.c
+++ src/lib/libast/port/astwinsize.c 2012-02-03 08:58:43.000000000 +0000
@@ -29,6 +29,10 @@
#include <ast.h>
#include <ast_tty.h>
+#if _sys_ioctl
+#include <sys/ioctl.h>
+#endif
+
#if defined(__STDPP__directive) && defined(__STDPP__hide)
__STDPP__directive pragma pp:hide ioctl sleep
#else
@@ -36,10 +40,6 @@ __STDPP__directive pragma pp:hide ioctl
#define sleep ______sleep
#endif
-#if _sys_ioctl
-#include <sys/ioctl.h>
-#endif
-
#if defined(TIOCGWINSZ)
#if _sys_stream && _sys_ptem
#include <sys/stream.h>
--- src/lib/libast/sfio/sfstrtof.h
+++ src/lib/libast/sfio/sfstrtof.h 2007-12-20 18:01:26.000000000 +0000
@@ -54,7 +54,7 @@
#if !defined(S2F_function)
#define S2F_function _sfdscan
-#define S2F_static 1
+#define S2F_static -1
#define S2F_type 2
#define S2F_scan 1
#ifndef elementsof
--- src/lib/libcmd/Mamfile
+++ src/lib/libcmd/Mamfile 2013-02-05 10:41:01.310073683 +0000
@@ -897,7 +897,7 @@ exec - -e '/^b_[a-z_][a-z_0-9]*(/!d' \
exec - -e 's/^b_//' \
exec - -e 's/(.*//' \
exec - -e 's/.*/CMDLIST(&)/' \
-exec - |
+exec - cmdinit.c basename.c cat.c chgrp.c chmod.c chown.c cksum.c cmp.c comm.c cp.c cut.c dirname.c date.c expr.c fds.c fmt.c fold.c getconf.c head.c id.c join.c ln.c logname.c md5sum.c mkdir.c mkfifo.c mktemp.c mv.c paste.c pathchk.c pids.c rev.c rm.c rmdir.c stty.c sum.c sync.c tail.c tee.c tty.c uname.c uniq.c vmstate.c wc.c revlib.c wclib.c fts_fix.c lib.c |
exec - sort -u
exec - } > 1.${COTEMP}.h
exec - if cmp 2>/dev/null -s 1.${COTEMP}.h cmdlist.h
--- src/lib/libcmd/chmod.c
+++ src/lib/libcmd/chmod.c 2011-05-20 13:28:58.000000000 +0000
@@ -272,7 +272,7 @@ b_chmod(int argc, char** argv, Shbltin_t
case FTS_SLNONE:
if (chlink)
{
-#if _lib_lchmod
+#if !defined(__linux__) && _lib_lchmod
chmodf = lchmod;
goto commit;
#else

47
leak1.sh Normal file
View File

@ -0,0 +1,47 @@
#!/usr/bin/ksh
PATH=/bin:/usr/bin:/usr/sbin:/sbin
getSampleInterval() { return 0; }
typeset -lui count=${1:-4000}
typeset -ilu leak=0
typeset -a curstate=(0 0 0)
typeset -a oldstate=(0 0 0)
vm()
{
typeset size
typeset key unit result=""
while read key size unit; do
case "$key" in
VmSize*) result=${result:+"$result "}$size ;;
VmRSS*) result=${result:+"$result "}$size ;;
VmData*) result=${result:+"$result "}$size ;;
esac
done < /proc/$$/status
echo $result
}
lessequal()
{
typeset -i ret=0
((${curstate[0]} > ${oldstate[0]})) && let ret=1
((${curstate[1]} > ${oldstate[1]})) && let ret=1
((${curstate[2]} > ${oldstate[2]})) && let ret=1
return $ret
}
oldstate=($(vm))
while ((count-- > 0))
do
interval=$(getSampleInterval)
curstate=($(vm))
lessequal || let leak++
oldstate=(${curstate[@]})
done
echo "[${0##*/}: leak count at $leak]"
((leak < 20)) || exit 1

65
leak2.sh Normal file
View File

@ -0,0 +1,65 @@
#!/usr/bin/ksh
foo=0
LoopCountForMEMSAP=0
bla=234
typeset -lui count=${1:-4000}
typeset -lui leak=0
typeset -a curstate=(0 0 0)
typeset -a oldstate=(0 0 0)
vm()
{
typeset size
typeset key unit result=""
while read key size unit; do
case "$key" in
VmSize*) result=${result:+"$result "}$size ;;
VmRSS*) result=${result:+"$result "}$size ;;
VmData*) result=${result:+"$result "}$size ;;
esac
done < /proc/$$/status
echo $result
}
fusub()
{
datum=`date +%S`
interval=$((10 - datum%10))
}
fvsub()
{
datum=$(date +%S)
interval=$((10 - datum%10))
}
lessequal()
{
typeset -i ret=0
((${curstate[0]} > ${oldstate[0]})) && let ret=1
((${curstate[1]} > ${oldstate[1]})) && let ret=1
((${curstate[2]} > ${oldstate[2]})) && let ret=1
return $ret
}
oldstate=($(vm))
while ((count-- > 0))
do
foo=$((foo+1))
if ((count%2 == 0)) ; then
datum=`fusub`
else
datum=$(fvsub)
fi
curstate=($(vm))
lessequal || let leak++
oldstate=(${curstate[@]})
done
echo "[${0##*/}: leak count at $leak]"
((leak < 60)) || exit 1

22
leak3.sh Normal file
View File

@ -0,0 +1,22 @@
#!/bin/ksh
a_sh=$(mktemp ${TMPDIR:-/tmp}/${0##*/}.XXXXXX) || exit 1
trap "rm -f $a_sh" EXIT
(cat > $a_sh) <<-EOF
#!$SHELL
check_proc_handle ()
{
handleSoftLimit=$(ulimit -n)
echo \$handleSoftLimit > /dev/null
}
check_proc_handle
EOF
chmod +x $a_sh
typeset -lui count=${1:-4000}
while ((count-- > 0))
do
$a_sh
done

227
sigexec.c Normal file
View File

@ -0,0 +1,227 @@
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <errno.h>
#include <limits.h>
#include <pty.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <termios.h>
#include <unistd.h>
static sig_atomic_t died;
static void sigchld(int sig __attribute__((__unused__)))
{
const int old_errno = errno;
int status;
pid_t pid;
while ((pid = waitpid(-1, &status, WNOHANG|WUNTRACED)) != 0) {
if (errno == ECHILD)
break;
if (pid < 0)
continue;
died = 1;
}
errno = old_errno;
}
static pid_t pid = -1;
static void sigother(int sig)
{
printf("%s\n", strsignal(sig));
if (sig == SIGINT)
sig = SIGTERM;
if (pid > 0) kill(pid, sig);
}
int main(int argc, char* argv[])
{
int ptm, pts;
ssize_t len;
static struct termios o;
static struct winsize w;
char devname[NAME_MAX+1];
char buffer[65536];
sigset_t set;
struct sigaction sa;
if (ioctl(0, TIOCGWINSZ, &w) < 0) {
w.ws_row = 24;
w.ws_col = 160;
errno = 0;
}
if (tcgetattr(0, &o) < 0) {
#ifdef B115200
cfsetispeed(&o, B115200);
cfsetospeed(&o, B115200);
#elif defined(B57600)
cfsetispeed(&o, B57600);
cfsetospeed(&o, B57600);
#elif defined(B38400)
cfsetispeed(&o, B38400);
cfsetospeed(&o, B38400);
#endif
}
o.c_iflag = TTYDEF_IFLAG;
o.c_oflag = TTYDEF_OFLAG;
o.c_lflag = TTYDEF_LFLAG;
# ifdef CBAUD
o.c_lflag &= ~CBAUD;
# endif
#ifdef B115200
o.c_cflag = B115200;
#elif defined(B57600)
o.c_cflag = B57600;
#elif defined(B38400)
o.c_cflag = B38400;
#endif
o.c_cflag |= TTYDEF_CFLAG;
/* Sane setting, allow eight bit characters, no carriage return delay
* the same result as `stty sane cr0 pass8'
*/
o.c_iflag |= (BRKINT | ICRNL | IMAXBEL);
o.c_iflag &= ~(IGNBRK | INLCR | IGNCR | IXOFF | IUCLC | IXANY | INPCK | ISTRIP);
o.c_oflag |= (OPOST | ONLCR | NL0 | CR0 | TAB0 | BS0 | VT0 | FF0);
o.c_oflag &= ~(OLCUC | OCRNL | ONOCR | ONLRET | OFILL | OFDEL |\
NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY);
o.c_lflag |= (ISIG | ICANON | IEXTEN | ECHO|ECHOE|ECHOK|ECHOKE);
o.c_lflag &= ~(ECHONL|ECHOCTL|ECHOPRT | NOFLSH | XCASE | TOSTOP);
o.c_cflag |= (CREAD | CS8 | HUPCL);
o.c_cflag &= ~(PARODD | PARENB);
/*
* VTIME and VMIN can overlap with VEOF and VEOL since they are
* only used for non-canonical mode. We just set the at the
* beginning, so nothing bad should happen.
*/
o.c_cc[VTIME] = 0;
o.c_cc[VMIN] = CMIN;
o.c_cc[VINTR] = CINTR;
o.c_cc[VQUIT] = CQUIT;
o.c_cc[VERASE] = CERASE; /* ASCII DEL (0177) */
o.c_cc[VKILL] = CKILL;
o.c_cc[VEOF] = CEOF;
# ifdef VSWTC
o.c_cc[VSWTC] = _POSIX_VDISABLE;
# else
o.c_cc[VSWTCH] = _POSIX_VDISABLE;
# endif
o.c_cc[VSTART] = CSTART;
o.c_cc[VSTOP] = CSTOP;
o.c_cc[VSUSP] = CSUSP;
o.c_cc[VEOL] = _POSIX_VDISABLE;
o.c_cc[VREPRINT] = CREPRINT;
o.c_cc[VDISCARD] = CDISCARD;
o.c_cc[VWERASE] = CWERASE;
o.c_cc[VLNEXT] = CLNEXT;
o.c_cc[VEOL2] = _POSIX_VDISABLE;
if (openpty(&ptm, &pts, devname, &o, &w) < 0) {
perror("pty: can not open pty/tty pair");
exit(1);
}
(void)sigemptyset(&set);
(void)sigaddset(&set, SIGCHLD);
sigprocmask(SIG_UNBLOCK, &set, (sigset_t*)0);
sa.sa_flags = SA_RESTART;
sa.sa_handler = sigchld;
sigemptyset (&sa.sa_mask);
sigaction(SIGCHLD, &sa, (struct sigaction*)0);
(void)sigemptyset(&set);
(void)sigaddset(&set, SIGTERM);
sigprocmask(SIG_UNBLOCK, &set, (sigset_t*)0);
sa.sa_flags = SA_RESTART;
sa.sa_handler = sigother;
sigemptyset (&sa.sa_mask);
sigaction(SIGTERM, &sa, (struct sigaction*)0);
(void)sigemptyset(&set);
(void)sigaddset(&set, SIGHUP);
sigprocmask(SIG_UNBLOCK, &set, (sigset_t*)0);
sa.sa_flags = SA_RESTART;
sa.sa_handler = sigother;
sigemptyset (&sa.sa_mask);
sigaction(SIGHUP, &sa, (struct sigaction*)0);
switch ((pid = fork())) {
case 0:
ioctl(1, TIOCNOTTY);
if (setsid() < 0) {
perror("pty: can not get controlling tty");
exit(1);
}
dup2(pts, 0);
dup2(pts, 1);
dup2(pts, 2);
close(pts);
close(ptm);
if (ioctl (0, TIOCSCTTY, 1) < 0) {
perror("pty: can not get controlling tty");
exit(1);
}
break;
case -1:
close(pts);
close(ptm);
perror("pty: can not fork");
exit(1);
default:
dup2(ptm, 0);
close(pts);
close(ptm);
while ((len = read(0, buffer, sizeof(buffer)))) {
ssize_t p = 0;
const char* ptr = buffer;
while (len > 0) {
p = write(1, ptr, len);
if (p < 0) {
if (errno == EPIPE)
exit (0);
if (errno == EINTR || errno == EAGAIN)
continue;
return 1;
}
ptr += p;
len -= p;
}
if (died)
break;
}
return 0;
}
(void)sigfillset(&set);
sigprocmask(SIG_UNBLOCK, &set, (sigset_t*)0);
(void)sigemptyset(&set);
(void)sigaddset(&set, SIGCHLD);
sigprocmask(SIG_BLOCK, &set, (sigset_t*)0);
sa.sa_flags = SA_RESTART;
sa.sa_handler = SIG_DFL;
sigemptyset (&sa.sa_mask);
sigaction(SIGHUP, &sa, (struct sigaction*)0);
sigaction(SIGINT, &sa, (struct sigaction*)0);
sigaction(SIGPIPE, &sa, (struct sigaction*)0);
sigaction(SIGTERM, &sa, (struct sigaction*)0);
sigaction(SIGURG, &sa, (struct sigaction*)0);
sigaction(SIGXFSZ, &sa, (struct sigaction*)0);
sigaction(SIGQUIT, &sa, (struct sigaction*)0);
sa.sa_handler = SIG_IGN;
sigaction(SIGQUIT, &sa, (struct sigaction*)0);
return execv(argv[1], &argv[1]);
}

17
ulimit.sh Normal file
View File

@ -0,0 +1,17 @@
#!/usr/bin/ksh
PATH=/bin:/usr/bin:/usr/sbin:/sbin
typeset -lui count=${1:-4000}
typeset -ilu err=0
trap 'echo "[${0##*/}: error count at $err]"' ERR
while ((count-- > 0))
do
ulimit -s || let err++
ulimit -n || let err++
ulimit -q || let err++
done > /dev/null
echo "[${0##*/}: error count at $err]"
((err == 0)) || exit 1

47
vmbalance Normal file
View File

@ -0,0 +1,47 @@
#!/usr/bin/awk -f
#
# vmblance Awk script to detect endless growing memory alloctions
# in endless shell loops using in daemonized shell scripts
#
# Usage:
#
# strace -s 128 -e execve,mmap,mmap2,munmap -o '|./vmbalance' ksh leak1.sh
#
BEGIN {
FS="([[:blank:]]|[[:punct:]])"
ignore=""
script=""
sum=0
allocs=0
frees=0
left=0
peak=0
}
/^execve/ {
if (FNR == 1) {
script = gensub(/.*SOURCES\/([[:alnum:]_-]+\.sh).*/, "\\1", "g", $0)
}
}
/^mmap(2|64)?\(/ {
if ($0 !~ /.*MAP_PRIVATE\|MAP_ANONYMOUS.*/) {
if (ignore)
ignore=ignore "|" $NF
else
ignore=$NF
} else {
sum+=$4
allocs++
if (peak < sum)
peak = sum
}
}
/^munmap(2|64)?\(/ {
if ($0 !~ ignore) {
sum-=$4
frees++
}
}
END {
left=allocs-frees
print script ": " sum " bytes summed up, " peak " peak value, " left " chunks left over, " allocs " allocated, and " frees " freed" > "/dev/fd/3"
}

View File

@ -0,0 +1,292 @@
--- src/cmd/INIT/Mamfile
+++ src/cmd/INIT/Mamfile 2008-02-14 12:08:37.000000000 +0000
@@ -5,7 +5,7 @@ setv AR ${mam_cc_AR} ${mam_cc_AR_ARFLAGS
setv ARFLAGS rc
setv AS as
setv ASFLAGS
-setv CC cc
+setv CC gcc
setv mam_cc_FLAGS
setv CCFLAGS ${-debug-symbols?1?${mam_cc_DEBUG} -D_BLD_DEBUG?${mam_cc_OPTIMIZE}?}
setv CCLDFLAGS ${-strip-symbols?1?${mam_cc_LD_STRIP}??}
@@ -27,7 +27,7 @@ setv NMAKE nmake
setv NMAKEFLAGS
setv PR pr
setv PRFLAGS
-setv SHELL /bin/sh
+setv SHELL /bin/bash
setv SILENT
setv TAR tar
setv YACC yacc
--- src/cmd/INIT/iffe.sh
+++ src/cmd/INIT/iffe.sh 2008-02-14 12:15:59.000000000 +0000
@@ -1170,7 +1170,7 @@ case `(getopts '[-][123:xyz]' opt --xyz;
--*) echo $command: $1: unknown option >&2
exit 2
;;
- -*) REM=`echo X$1 | sed 's,X-,,'`
+ -*) REM=`echo -$1 | sed 's,^--,,'`
;;
*) break
;;
--- src/cmd/INIT/mamake.c
+++ src/cmd/INIT/mamake.c 2008-02-14 12:08:37.000000000 +0000
@@ -118,7 +118,7 @@ USAGE_LICENSE
#define set(b,o) ((b)->nxt=(b)->buf+(o))
#define use(b) (*(b)->nxt=0,(b)->nxt=(b)->buf)
-#define CHUNK 1024
+#define CHUNK 2048
#define KEY(a,b,c,d) ((((unsigned long)(a))<<15)|(((unsigned long)(b))<<10)|(((unsigned long)(c))<<5)|(((unsigned long)(d))))
#define NOW ((unsigned long)time((time_t*)0))
#define ROTATE(p,l,r,t) ((t)=(p)->l,(p)->l=(t)->r,(t)->r=(p),(p)=(t))
@@ -338,14 +338,14 @@ report(int level, char* text, char* item
*/
static void
-dont(Rule_t* r, int code, int keepgoing)
+dont(Rule_t* r, int code, int keepgoing, int line)
{
identify(stderr);
if (!code)
fprintf(stderr, "don't know how to make %s\n", r->name);
else
{
- fprintf(stderr, "*** exit code %d making %s%s\n", code, r->name, state.ignore ? " ignored" : "");
+ fprintf(stderr, "*** exit code %d making %s%s at line %d\n", code, r->name, state.ignore ? " ignored" : "", line);
unlink(r->name);
if (state.ignore)
return;
@@ -1259,7 +1259,7 @@ run(Rule_t* r, register char* s)
if (x)
{
if (c = execute(s))
- dont(r, c, state.keepgoing);
+ dont(r, c, state.keepgoing, __LINE__);
if (status((Buf_t*)0, 0, r->name, &st))
{
r->time = st.st_mtime;
@@ -1633,7 +1633,7 @@ make(Rule_t* r)
}
r->flags |= RULE_made;
if (!(r->flags & (RULE_dontcare|RULE_error|RULE_exists|RULE_generated|RULE_implicit|RULE_virtual)))
- dont(r, 0, state.keepgoing);
+ dont(r, 0, state.keepgoing, __LINE__);
break;
case KEY('e','x','e','c'):
r->flags |= RULE_generated;
@@ -1726,7 +1726,7 @@ verify(Dict_item_t* item, void* handle)
Rule_t* r = (Rule_t*)item->value;
if ((r->flags & (RULE_active|RULE_error|RULE_made)) == RULE_active)
- dont(r, 0, 1);
+ dont(r, 0, 1, __LINE__);
return 0;
}
--- src/cmd/ksh93/Mamfile
+++ src/cmd/ksh93/Mamfile 2012-02-10 14:30:31.000000000 +0000
@@ -7,7 +7,7 @@ setv AR ${mam_cc_AR} ${mam_cc_AR_ARFLAGS
setv ARFLAGS rc
setv AS as
setv ASFLAGS
-setv CC cc
+setv CC gcc
setv mam_cc_FLAGS
setv CCFLAGS ${-debug-symbols?1?${mam_cc_DEBUG} -D_BLD_DEBUG?${mam_cc_OPTIMIZE}?}
setv CCLDFLAGS ${-strip-symbols?1?${mam_cc_LD_STRIP}??}
@@ -29,7 +29,7 @@ setv NMAKE nmake
setv NMAKEFLAGS
setv PR pr
setv PRFLAGS
-setv SHELL /bin/sh
+setv SHELL /bin/bash
setv SILENT
setv TAR tar
setv YACC yacc
@@ -1337,7 +1337,7 @@ prev +ljobs
prev +li
prev ${mam_libsocket}
prev ${mam_libsecdb}
-exec - ${CC} ${CCLDFLAGS} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS} ${mam_cc_L+-L.} ${mam_cc_L+-L${INSTALLROOT}/lib} -o ksh pmain.o ${mam_libshell} ${mam_libnsl} ${mam_libast}
+exec - ${CC} ${CCLDFLAGS} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS} ${mam_cc_L+-L.} ${mam_cc_L+-L${INSTALLROOT}/lib} -o ksh pmain.o ${mam_libshell} ${mam_libnsl} ${mam_libcmd} ${mam_libast} ${mam_libm} ${mam_libast}
done ksh generated
make shcomp
make shcomp.o
@@ -1361,7 +1361,7 @@ prev ${mam_libsocket}
prev ${mam_libsecdb}
setv CC.DLL -UCC.DLL
setv SH_DICT -DSH_DICT="\"libshell\""
-exec - ${CC} ${CCLDFLAGS} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS} ${mam_cc_L+-L.} ${mam_cc_L+-L${INSTALLROOT}/lib} -o shcomp shcomp.o ${mam_libshell} ${mam_libnsl} ${mam_libast}
+exec - ${CC} ${CCLDFLAGS} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS} ${mam_cc_L+-L.} ${mam_cc_L+-L${INSTALLROOT}/lib} -o shcomp shcomp.o ${mam_libshell} ${mam_libnsl} ${mam_libcmd} ${mam_libast} ${mam_libm} ${mam_libast}
done shcomp generated
make suid_exec
make suid_exec.o
@@ -1377,14 +1377,14 @@ meta suid_exec.o %.c>%.o sh/suid_exec.c
prev sh/suid_exec.c
setv CC.DLL -UCC.DLL
setv _BLD_shell -U_BLD_shell
-exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -Iinclude -I${PACKAGE_ast_INCLUDE} -DERROR_CONTEXT_T=Error_context_t -D_API_ast=20100309 -D_PACKAGE_ast -c sh/suid_exec.c
+exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -fPIE -I. -Iinclude -I${PACKAGE_ast_INCLUDE} -DERROR_CONTEXT_T=Error_context_t -D_API_ast=20100309 -D_PACKAGE_ast -c sh/suid_exec.c
done suid_exec.o generated
prev +ljobs
prev +li
prev ${mam_libsocket}
prev ${mam_libsecdb}
setv CC.DLL -UCC.DLL
-exec - ${CC} ${CCLDFLAGS} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS} ${mam_cc_L+-L.} ${mam_cc_L+-L${INSTALLROOT}/lib} -o suid_exec suid_exec.o ${mam_libast} ${mam_libnsl} ${mam_libast}
+exec - ${CC} ${CCLDFLAGS} ${mam_cc_FLAGS} ${CCFLAGS} ${LDFLAGS} ${mam_cc_L+-L.} ${mam_cc_L+-L${INSTALLROOT}/lib} -pie -o suid_exec suid_exec.o ${mam_libast} ${mam_libnsl} ${mam_libast}
done suid_exec generated
make shell
prev libshell.a archive
--- src/lib/libast/Mamfile
+++ src/lib/libast/Mamfile 2013-02-05 15:08:23.757451837 +0000
@@ -5,7 +5,7 @@ setv AR ${mam_cc_AR} ${mam_cc_AR_ARFLAGS
setv ARFLAGS rc
setv AS as
setv ASFLAGS
-setv CC cc
+setv CC gcc
setv mam_cc_FLAGS ${mam_cc_DLL} -D_BLD_ast
setv CCFLAGS ${-debug-symbols?1?${mam_cc_DEBUG} -D_BLD_DEBUG?${mam_cc_OPTIMIZE}?}
setv CCLDFLAGS ${-strip-symbols?1?${mam_cc_LD_STRIP}??}
@@ -27,7 +27,7 @@ setv NMAKE nmake
setv NMAKEFLAGS
setv PR pr
setv PRFLAGS
-setv SHELL /bin/sh
+setv SHELL /bin/bash
setv SILENT
setv TAR tar
setv YACC yacc
@@ -1003,7 +1003,7 @@ make lcgen
make port/lcgen.c
prev std/stdio.h implicit
done port/lcgen.c
-exec - ${CC} -o lcgen port/lcgen.c
+exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -o lcgen port/lcgen.c
done lcgen generated
make port/lc.tab
done port/lc.tab
@@ -7291,58 +7291,31 @@ exec - test '' = 'misc/magic.tab' || ${S
done ${INSTALLROOT}/lib/file/magic generated
prev comp/fmtmsg.h
prev ast_lib.h
-exec - case ${mam_cc_HOSTTYPE} in
-exec - win32.*)proto -p -s -l ${PACKAGEROOT}/lib/package/ast.lic '-o since=1985,author=gsf+dgk+kpv' comp/fmtmsg.h > 1.${COTEMP}.x
-exec - if cmp 2>/dev/null -s ${INSTALLROOT}/include/ast/fmtmsg.h 1.${COTEMP}.x
-exec - then rm -f 1.${COTEMP}.x
-exec - else mv 1.${COTEMP}.x ${INSTALLROOT}/include/ast/fmtmsg.h
-exec - fi
-exec - ;;
-exec - *) silent grep -l 'define[ ][ ]*_[hl][di][rb]_fmtmsg' ast_lib.h > /dev/null || {
+exec - silent grep -l 'define[ ][ ]*_[hl][di][rb]_fmtmsg' ast_lib.h > /dev/null || {
exec - proto -p -s -l ${PACKAGEROOT}/lib/package/ast.lic '-o since=1985,author=gsf+dgk+kpv' comp/fmtmsg.h > 1.${COTEMP}.x
exec - if cmp 2>/dev/null -s ${INSTALLROOT}/include/ast/fmtmsg.h 1.${COTEMP}.x
exec - then rm -f 1.${COTEMP}.x
exec - else mv 1.${COTEMP}.x ${INSTALLROOT}/include/ast/fmtmsg.h
exec - fi
exec - }
-exec - ;;
-exec - esac
prev comp/libgen.h
prev ast_lib.h
-exec - case ${mam_cc_HOSTTYPE} in
-exec - win32.*)proto -p -s -l ${PACKAGEROOT}/lib/package/ast.lic '-o since=1985,author=gsf+dgk+kpv' comp/libgen.h > 1.${COTEMP}.x
-exec - if cmp 2>/dev/null -s ${INSTALLROOT}/include/ast/libgen.h 1.${COTEMP}.x
-exec - then rm -f 1.${COTEMP}.x
-exec - else mv 1.${COTEMP}.x ${INSTALLROOT}/include/ast/libgen.h
-exec - fi
-exec - ;;
-exec - *) silent grep -l 'define[ ][ ]*_[hl][di][rb]_libgen' ast_lib.h > /dev/null || {
+exec - silent grep -l 'define[ ][ ]*_[hl][di][rb]_libgen' ast_lib.h > /dev/null || {
exec - proto -p -s -l ${PACKAGEROOT}/lib/package/ast.lic '-o since=1985,author=gsf+dgk+kpv' comp/libgen.h > 1.${COTEMP}.x
exec - if cmp 2>/dev/null -s ${INSTALLROOT}/include/ast/libgen.h 1.${COTEMP}.x
exec - then rm -f 1.${COTEMP}.x
exec - else mv 1.${COTEMP}.x ${INSTALLROOT}/include/ast/libgen.h
exec - fi
exec - }
-exec - ;;
-exec - esac
prev comp/syslog.h
prev ast_lib.h
-exec - case ${mam_cc_HOSTTYPE} in
-exec - win32.*)proto -p -s -l ${PACKAGEROOT}/lib/package/ast.lic '-o since=1985,author=gsf+dgk+kpv' comp/syslog.h > 1.${COTEMP}.x
-exec - if cmp 2>/dev/null -s ${INSTALLROOT}/include/ast/syslog.h 1.${COTEMP}.x
-exec - then rm -f 1.${COTEMP}.x
-exec - else mv 1.${COTEMP}.x ${INSTALLROOT}/include/ast/syslog.h
-exec - fi
-exec - ;;
-exec - *) silent grep -l 'define[ ][ ]*_[hl][di][rb]_syslog' ast_lib.h > /dev/null || {
+exec - silent grep -l 'define[ ][ ]*_[hl][di][rb]_syslog' ast_lib.h > /dev/null || {
exec - proto -p -s -l ${PACKAGEROOT}/lib/package/ast.lic '-o since=1985,author=gsf+dgk+kpv' comp/syslog.h > 1.${COTEMP}.x
exec - if cmp 2>/dev/null -s ${INSTALLROOT}/include/ast/syslog.h 1.${COTEMP}.x
exec - then rm -f 1.${COTEMP}.x
exec - else mv 1.${COTEMP}.x ${INSTALLROOT}/include/ast/syslog.h
exec - fi
exec - }
-exec - ;;
-exec - esac
done install virtual
make test
done test dontcare virtual
--- src/lib/libcmd/Mamfile
+++ src/lib/libcmd/Mamfile 2013-02-05 15:13:53.797951789 +0000
@@ -7,7 +7,7 @@ setv AR ${mam_cc_AR} ${mam_cc_AR_ARFLAGS
setv ARFLAGS rc
setv AS as
setv ASFLAGS
-setv CC cc
+setv CC gcc
setv mam_cc_FLAGS ${mam_cc_DLL}
setv CCFLAGS ${-debug-symbols?1?${mam_cc_DEBUG} -D_BLD_DEBUG?${mam_cc_OPTIMIZE}?}
setv CCLDFLAGS ${-strip-symbols?1?${mam_cc_LD_STRIP}??}
@@ -29,7 +29,7 @@ setv NMAKE nmake
setv NMAKEFLAGS
setv PR pr
setv PRFLAGS
-setv SHELL /bin/sh
+setv SHELL /bin/bash
setv SILENT
setv TAR tar
setv YACC yacc
--- src/lib/libdll/Mamfile
+++ src/lib/libdll/Mamfile 2008-02-14 12:08:37.000000000 +0000
@@ -7,7 +7,7 @@ setv AR ${mam_cc_AR} ${mam_cc_AR_ARFLAGS
setv ARFLAGS rc
setv AS as
setv ASFLAGS
-setv CC cc
+setv CC gcc
setv mam_cc_FLAGS ${mam_cc_DLL}
setv CCFLAGS ${-debug-symbols?1?${mam_cc_DEBUG} -D_BLD_DEBUG?${mam_cc_OPTIMIZE}?}
setv CCLDFLAGS ${-strip-symbols?1?${mam_cc_LD_STRIP}??}
@@ -29,7 +29,7 @@ setv NMAKE nmake
setv NMAKEFLAGS
setv PR pr
setv PRFLAGS
-setv SHELL /bin/sh
+setv SHELL /bin/bash
setv SILENT
setv TAR tar
setv YACC yacc
--- src/lib/libpp/Mamfile
+++ src/lib/libpp/Mamfile 2012-01-24 18:31:22.000000000 +0000
@@ -663,7 +663,7 @@ exec - .
exec - w
exec - q
exec - !
-exec - ${CC} -o ${COTEMP}.exe 1.${COTEMP}.c
+exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -o ${COTEMP}.exe 1.${COTEMP}.c
exec - ./${COTEMP}.exe > pp.yacc
exec - rm -f 1.${COTEMP}.c ${COTEMP}.exe
done pp.yacc generated
@@ -705,7 +705,7 @@ exec - .
exec - w
exec - q
exec - !
-exec - ${CC} -o ${COTEMP}.exe 1.${COTEMP}.c
+exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -o ${COTEMP}.exe 1.${COTEMP}.c
exec - ./${COTEMP}.exe > ppkey.yacc
exec - rm -f 1.${COTEMP}.c ${COTEMP}.exe
done ppkey.yacc generated