diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2016-09-08 15:47:17 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2016-09-08 15:47:17 +0000 |
commit | 3c5f2cbc38384072a30069201b4b40fea651e3d2 (patch) | |
tree | 07f7406dd2fcc9ea04993ec00c3aa1b3b60dae94 | |
parent | b20234ac519101342c49ed6bce4a05e45d0b7e84 (diff) |
Allow "typeset -ir FOO" if FOO is not already marked read-only. OK tb@
-rw-r--r-- | bin/ksh/var.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/bin/ksh/var.c b/bin/ksh/var.c index 750ea590af1..b818df67d89 100644 --- a/bin/ksh/var.c +++ b/bin/ksh/var.c @@ -1,4 +1,4 @@ -/* $OpenBSD: var.c,v 1.55 2015/12/30 09:07:00 tedu Exp $ */ +/* $OpenBSD: var.c,v 1.56 2016/09/08 15:47:16 millert Exp $ */ #include <sys/stat.h> @@ -661,6 +661,7 @@ typeset(const char *var, int set, int clr, int field, int base) */ 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 clr, int field, int base) 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 clr, int field, int base) 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. |