Re: ksh 641 should be read-only

2016-05-27 Thread Anthony Coulter

> ksh won't start after this change.  The problem is that it will try to
> assign the return value of getppid() to PPID *after* PPID was made read
> only.

Such is the price of not testing last-minute changes. When ksh
processes a typeset command, it sets the read-only flag before
attempting to convert the string to an integer. We can reproduce
the issue like so:
  $ NUM=42
  $ typeset -ir NUM
  ksh: NUM: is read only

We can get around this problem by separating out the two lines.


Index: main.c
===
RCS file: /cvs/src/bin/ksh/main.c,v
retrieving revision 1.79
diff -u -p -r1.79 main.c
--- main.c  4 Mar 2016 15:11:06 -   1.79
+++ main.c  27 May 2016 13:18:01 -
@@ -85,6 +85,7 @@ static const char *initcoms [] = {
"typeset", "-r", "KSH_VERSION", NULL,
"typeset", "-x", "SHELL", "PATH", "HOME", NULL,
"typeset", "-i", "PPID", NULL,
+   "typeset", "-r", "PPID", NULL,
"typeset", "-i", "OPTIND=1", NULL,
"eval", "typeset -i RANDOM MAILCHECK=\"${MAILCHECK-600}\" 
SECONDS=\"${SECONDS-0}\" TMOUT=\"${TMOUT-0}\"", NULL,
"alias",



Re: ksh 641 should be read-only

2016-05-27 Thread Theo Buehler
On Thu, May 26, 2016 at 11:00:39PM -0400, Anthony Coulter wrote:
> The man page for ksh says that ${PPID} should be read-only but
> apparently it is not. There is also a line nearby that is more
> than 80 characters long but I'm not comfortable enough with KNF
> to select the best way to fix that.
> 
> 
> Index: main.c
> ===
> RCS file: /cvs/src/bin/ksh/main.c,v
> retrieving revision 1.79
> diff -u -p -r1.79 main.c
> --- main.c4 Mar 2016 15:11:06 -   1.79
> +++ main.c27 May 2016 02:37:41 -
> @@ -84,7 +84,7 @@ static const char initsubs[] = "${PS2=> 
>  static const char *initcoms [] = {
>   "typeset", "-r", "KSH_VERSION", NULL,
>   "typeset", "-x", "SHELL", "PATH", "HOME", NULL,
> - "typeset", "-i", "PPID", NULL,
> + "typeset", "-ir", "PPID", NULL,

ksh won't start after this change.  The problem is that it will try to
assign the return value of getppid() to PPID *after* PPID was made read
only.

$ obj/ksh
obj/ksh: PPID: is read only
$ echo $?
1



ksh 641 should be read-only

2016-05-27 Thread Anthony Coulter
The man page for ksh says that ${PPID} should be read-only but
apparently it is not. There is also a line nearby that is more
than 80 characters long but I'm not comfortable enough with KNF
to select the best way to fix that.


Index: main.c
===
RCS file: /cvs/src/bin/ksh/main.c,v
retrieving revision 1.79
diff -u -p -r1.79 main.c
--- main.c  4 Mar 2016 15:11:06 -   1.79
+++ main.c  27 May 2016 02:37:41 -
@@ -84,7 +84,7 @@ static const char initsubs[] = "${PS2=> 
 static const char *initcoms [] = {
"typeset", "-r", "KSH_VERSION", NULL,
"typeset", "-x", "SHELL", "PATH", "HOME", NULL,
-   "typeset", "-i", "PPID", NULL,
+   "typeset", "-ir", "PPID", NULL,
"typeset", "-i", "OPTIND=1", NULL,
"eval", "typeset -i RANDOM MAILCHECK=\"${MAILCHECK-600}\" 
SECONDS=\"${SECONDS-0}\" TMOUT=\"${TMOUT-0}\"", NULL,
"alias",