From cd39ea7863f76970f1c871ceeb7961665c8d1e07 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Thu, 13 May 2021 02:20:50 +0200 Subject: [PATCH] Improve fix for not exporting readonly attribute (re: 7954855f) The bitmask of attributes to export was repeatedly defined in three different places, and that fix changed only one of them. src/cmd/ksh93/sh/name.c: - Single point of truth: define ATTR_TO_EXPORT macro with the bitmask of all the attributes to export (excluding NV_RDONLY). - attstore(), pushnam(), sh_envgen(): Use the ATTR_TO_EXPORT macro, removing superflous NV_RDONLY handling from the former two. --- src/cmd/ksh93/sh/name.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cmd/ksh93/sh/name.c b/src/cmd/ksh93/sh/name.c index 7e2422984..16090103e 100644 --- a/src/cmd/ksh93/sh/name.c +++ b/src/cmd/ksh93/sh/name.c @@ -34,6 +34,7 @@ #include "FEATURE/externs" #include "streval.h" +#define ATTR_TO_EXPORT (NV_UTOL|NV_LTOU|NV_RJUST|NV_LJUST|NV_ZFILL|NV_INTEGER) #define NVCACHE 8 /* must be a power of 2 */ static char *savesub = 0; static char Null[1]; @@ -2181,7 +2182,7 @@ static void attstore(register Namval_t *np, void *data) 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); + flag &= ATTR_TO_EXPORT; *ap->attval++ = '='; if((flag&NV_DOUBLE) == NV_DOUBLE) { @@ -2210,7 +2211,7 @@ static void pushnam(Namval_t *np, void *data) *ap->argnam++ = np->nvenv; else if(value=nv_getval(np)) *ap->argnam++ = staknam(np,value); - if(nv_isattr(np,NV_RDONLY|NV_UTOL|NV_LTOU|NV_RJUST|NV_LJUST|NV_ZFILL|NV_INTEGER)) + if(!sh_isoption(SH_POSIX) && nv_isattr(np,ATTR_TO_EXPORT)) ap->attsize += (strlen(nv_name(np))+4); } @@ -2242,7 +2243,7 @@ char **sh_envgen(void) /* Export variable attributes into env var named by e_envmarker, unless POSIX mode is on */ cp = data.attval = strcopy(*data.argnam,e_envmarker); if(!sh_isoption(SH_POSIX)) - nv_scan(shp->var_tree, attstore,&data,0,(NV_UTOL|NV_LTOU|NV_RJUST|NV_LJUST|NV_ZFILL|NV_INTEGER)); + nv_scan(shp->var_tree, attstore,&data,0,ATTR_TO_EXPORT); *data.attval = 0; if(cp!=data.attval) data.argnam++;