Re: ksh(1): manual says $PPID is read-only
I've committed my fix to make "typeset -ir PPID" work and adjusted the PPID line in initcoms[] accordingly. - todd
Re: ksh(1): manual says $PPID is read-only
On Thu, 08 Sep 2016 17:33:37 +0200, Theo Buehler wrote: > Your fix looks correct to me and accomplishes the desired effect. Should > we perhaps introduce > > #define NO_RO_CHECK 0x4 > > and replace the 5 occurrences of the magic number in var.c? Yes, I would like that. - todd
Re: ksh(1): manual says $PPID is read-only
On Thu, Sep 08, 2016 at 09:22:28AM -0600, Todd C. Miller wrote: > On Thu, 08 Sep 2016 10:08:23 -0400, Anthony Coulter wrote: > > > We can fix either the manual or ksh itself; this diff takes the latter > > approach. It is tempting to do this with "typeset -ir PPID" but that > > actually doesn't work: > > > > $ FOO=123 > > $ typeset -ir FOO > > ksh: FOO: is read only > > Perhaps we should fix the above issue as well, other ksh versions > don't throw an error there. Below is a simple fix, though a bit > gross due to the magic 0x4. Your fix looks correct to me and accomplishes the desired effect. Should we perhaps introduce #define NO_RO_CHECK 0x4 and replace the 5 occurrences of the magic number in var.c?
Re: ksh(1): manual says $PPID is read-only
On Thu, 08 Sep 2016 10:08:23 -0400, Anthony Coulter wrote: > We can fix either the manual or ksh itself; this diff takes the latter > approach. It is tempting to do this with "typeset -ir PPID" but that > actually doesn't work: > > $ FOO=123 > $ typeset -ir FOO > ksh: FOO: is read only Perhaps we should fix the above issue as well, other ksh versions don't throw an error there. Below is a simple fix, though a bit gross due to the magic 0x4. - todd Index: bin/ksh/var.c === RCS file: /cvs/src/bin/ksh/var.c,v retrieving revision 1.55 diff -u -p -u -r1.55 var.c --- bin/ksh/var.c 30 Dec 2015 09:07:00 - 1.55 +++ bin/ksh/var.c 8 Sep 2016 15:20:20 - @@ -661,6 +661,7 @@ typeset(const char *var, int set, int cl */ for (t = vpbase; t; t = t->u.array) { int fake_assign; + int error_ok = KSH_RETURN_ERROR; char *s = NULL; char *free_me = NULL; @@ -683,6 +684,10 @@ typeset(const char *var, int set, int cl t->type = 0; t->flag &= ~ALLOC; } + if (!(t->flag & RDONLY) && (set & RDONLY)) { + /* allow var to be initialized read-only */ + error_ok |= 0x4; + } t->flag = (t->flag | set) & ~clr; /* Don't change base if assignment is to be done, * in case assignment fails. @@ -692,7 +697,7 @@ typeset(const char *var, int set, int cl if (set & (LJUST|RJUST|ZEROFIL)) t->u2.field = field; if (fake_assign) { - if (!setstr(t, s, KSH_RETURN_ERROR)) { + if (!setstr(t, s, error_ok)) { /* Somewhat arbitrary action here: * zap contents of variable, but keep * the flag settings.
Re: ksh(1): manual says $PPID is read-only
On Thu, Sep 08, 2016 at 10:08:23AM -0400, Anthony Coulter wrote: [..] > We can fix either the manual or ksh itself; this diff takes the latter > approach. It is tempting to do this with "typeset -ir PPID" but that > actually doesn't work: > > $ FOO=123 > $ typeset -ir FOO > ksh: FOO: is read only $ echo $FOO $ This looks like a bug to me. Note that $ typeset -ir BAR=123 does the expected thing: $ BAR=1 ksh: BAR: is read only $ echo $BAR 123 So, while I agree that PPID should be read-only and your patch appears to accomplish the desired effect, I think we should try to fix the underlying problem, not work around it.
ksh(1): manual says $PPID is read-only
The ksh(1) manual says that PPID should be read-only. But: $ man ksh | grep PPID PPID The process ID of the shell's parent (read-only). $ echo ${PPID} 5967 $ PPID=123 $ echo ${PPID} 123 We can fix either the manual or ksh itself; this diff takes the latter approach. It is tempting to do this with "typeset -ir PPID" but that actually doesn't work: $ FOO=123 $ typeset -ir FOO ksh: FOO: is read only So we fix this by putting "typeset -r PPID" on its own line. One could imagine shortening the section below with something like: "typeset", "-i", "PPID", "OPTIND=1", NULL, "typeset", "-r", "KSH_VERSION", "PPID", NULL, "typeset", "-x", "SHELL", "PATH", "HOME", NULL, but that involves some reordering: the -i's MUST come before the -r's. Index: bin/ksh/main.c === RCS file: /open/anoncvs/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 8 Sep 2016 13:17:29 - @@ -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",