mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Fix multiple problems with the getconf builtin (#280)
This commit fixes three problems with getconf pathbound builtin: 1. The -l/--lowercase option did not change all variable names to lower case. 2. The -q/--quote option now quotes all string values. Previously, it only quoted string values that had a space or other non-shellsafe character. 3. The -c/--call, -n/--name and -s/--standard options matched all variable names provided by 'getconf -a', even if none were actual matches. Additionally, references to the confstr and sysconf functions have been updated to reference section 3 of the man pages instead of section 2. src/lib/libast/port/astconf.c: - Previously, only values that had spaces in them were quoted. Change that behavior to quote all string values by using the FMT_ALWAYS flag. Bug report: https://github.com/att/ast/issues/1173 - Not all variable names were printed in lowercase by 'getconf -l'. Fix it by adding a few missing instances of fmtlower. Bug report: https://github.com/att/ast/issues/1171 - Add the missing code to the '#if _pth_getconf_a' block to handle -c/-n/-s while parsing the OS's native 'getconf -a' output. This approach reuses code for name matching from other parts of astconflist(). Resolves: https://github.com/ksh93/ksh/issues/279 src/lib/libcmd/getconf.c: - Update the documentation to note the -q flag only quotes strings. src/cmd/ksh93/tests/bulitins.sh: - Add regression tests for the getconf bugs fixed in this commit. Co-authored-by: Martijn Dekker <martijn@inlv.org>
This commit is contained in:
parent
61e0f90460
commit
f28bce61a7
8 changed files with 76 additions and 22 deletions
|
|
@ -367,7 +367,7 @@ IFS=$ifs; set +f
|
|||
export CONF_getconf CONF_getconf_a
|
||||
|
||||
case $verbose in
|
||||
1) echo "$command: check ${CONF_getconf:+$CONF_getconf(1),}confstr(2),pathconf(2),sysconf(2),sysinfo(2) configuration names" >&2 ;;
|
||||
1) echo "$command: check ${CONF_getconf:+$CONF_getconf(1),}confstr(3),pathconf(2),sysconf(3),sysinfo(2) configuration names" >&2 ;;
|
||||
esac
|
||||
{
|
||||
echo "#include <unistd.h>$systeminfo
|
||||
|
|
|
|||
|
|
@ -52,10 +52,10 @@ int astquery(int \fIfd\fP, const char* \fIformat\fP , ...);
|
|||
.SH DESCRIPTION
|
||||
.L astconf
|
||||
is a string interface to the
|
||||
.IR confstr (2),
|
||||
.IR confstr (3),
|
||||
.IR pathconf (2),
|
||||
and
|
||||
.IR sysconf (2)
|
||||
.IR sysconf (3)
|
||||
calls.
|
||||
If
|
||||
.I value
|
||||
|
|
@ -269,4 +269,4 @@ and the environment variable
|
|||
is used to set
|
||||
.IR *cols .
|
||||
.SH "SEE ALSO"
|
||||
getconf(1), confstr(2), mmap(2), pathconf(2), read(2), sysconf(2), write(2)
|
||||
getconf(1), confstr(3), mmap(2), pathconf(2), read(2), sysconf(3), write(2)
|
||||
|
|
|
|||
|
|
@ -1251,14 +1251,14 @@ print(Sfio_t* sp, register Lookup_t* look, const char* name, const char* path, i
|
|||
if (p->flags & CONF_LIMIT_DEF)
|
||||
{
|
||||
if (p->limit.string)
|
||||
sfprintf(sp, "L[%s] ", (listflags & ASTCONF_quote) ? fmtquote(p->limit.string, "\"", "\"", strlen(p->limit.string), FMT_SHELL) : p->limit.string);
|
||||
sfprintf(sp, "L[%s] ", (listflags & ASTCONF_quote) ? fmtquote(p->limit.string, "\"", "\"", strlen(p->limit.string), FMT_SHELL|FMT_ALWAYS) : p->limit.string);
|
||||
else
|
||||
sfprintf(sp, "L[%I*d] ", sizeof(p->limit.number), p->limit.number);
|
||||
}
|
||||
if (p->flags & CONF_MINMAX_DEF)
|
||||
{
|
||||
if (p->minmax.string)
|
||||
sfprintf(sp, "M[%s] ", (listflags & ASTCONF_quote) ? fmtquote(p->minmax.string, "\"", "\"", strlen(p->minmax.string), FMT_SHELL) : p->minmax.string);
|
||||
sfprintf(sp, "M[%s] ", (listflags & ASTCONF_quote) ? fmtquote(p->minmax.string, "\"", "\"", strlen(p->minmax.string), FMT_SHELL|FMT_ALWAYS) : p->minmax.string);
|
||||
else
|
||||
sfprintf(sp, "M[%I*d] ", sizeof(p->minmax.number), p->minmax.number);
|
||||
}
|
||||
|
|
@ -1267,7 +1267,7 @@ print(Sfio_t* sp, register Lookup_t* look, const char* name, const char* path, i
|
|||
else if (defined)
|
||||
{
|
||||
if (s)
|
||||
sfprintf(sp, "%s", (listflags & ASTCONF_quote) ? fmtquote(s, "\"", "\"", strlen(s), FMT_SHELL) : s);
|
||||
sfprintf(sp, "%s", (listflags & ASTCONF_quote) ? fmtquote(s, "\"", "\"", strlen(s), FMT_SHELL|FMT_ALWAYS) : s);
|
||||
else if (v != -1)
|
||||
sfprintf(sp, "%I*d", sizeof(v), v);
|
||||
else
|
||||
|
|
@ -1297,7 +1297,7 @@ print(Sfio_t* sp, register Lookup_t* look, const char* name, const char* path, i
|
|||
else if (defined)
|
||||
{
|
||||
if (s)
|
||||
sfprintf(sp, "%s", (listflags & ASTCONF_quote) ? fmtquote(s, "\"", "\"", strlen(s), FMT_SHELL) : s);
|
||||
sfprintf(sp, "%s", (listflags & ASTCONF_quote) ? fmtquote(s, "\"", "\"", strlen(s), FMT_SHELL|FMT_ALWAYS) : s);
|
||||
else if (v != -1)
|
||||
sfprintf(sp, "%I*d", sizeof(v), v);
|
||||
else
|
||||
|
|
@ -1636,6 +1636,25 @@ astconflist(Sfio_t* sp, const char* path, int flags, const char* pattern)
|
|||
for (*s++ = 0; isspace(*s); s++);
|
||||
if (!lookup(&look, f, flags))
|
||||
{
|
||||
if(pattern)
|
||||
{
|
||||
|
||||
if (flags & ASTCONF_matchcall)
|
||||
{
|
||||
if (regexec(&re, prefix[look.conf->call + CONF_call].name, 0, NiL, 0))
|
||||
continue;
|
||||
}
|
||||
else if (flags & ASTCONF_matchname)
|
||||
{
|
||||
if (regexec(&re, f, 0, NiL, 0))
|
||||
continue;
|
||||
}
|
||||
else if (flags & ASTCONF_matchstandard)
|
||||
{
|
||||
if (regexec(&re, prefix[look.standard].name, 0, NiL, 0))
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (flags & ASTCONF_table)
|
||||
{
|
||||
if (look.standard < 0)
|
||||
|
|
@ -1645,9 +1664,9 @@ astconflist(Sfio_t* sp, const char* path, int flags, const char* pattern)
|
|||
sfprintf(sp, "%*s %*s %d %2s %4d %5s %s\n", sizeof(conf[0].name), f, sizeof(prefix[look.standard].name), prefix[look.standard].name, look.section, call, 0, "N", s);
|
||||
}
|
||||
else if (flags & ASTCONF_parse)
|
||||
sfprintf(sp, "%s %s - %s\n", state.id, f, s);
|
||||
sfprintf(sp, "%s %s - %s\n", state.id, (flags & ASTCONF_lower) ? fmtlower(f) : f, fmtquote(s, "\"", "\"", strlen(s), FMT_SHELL|FMT_ALWAYS));
|
||||
else
|
||||
sfprintf(sp, "%s=%s\n", f, (flags & ASTCONF_quote) ? fmtquote(s, "\"", "\"", strlen(s), FMT_SHELL) : s);
|
||||
sfprintf(sp, "%s=%s\n", (flags & ASTCONF_lower) ? fmtlower(f) : f, (flags & ASTCONF_quote) ? fmtquote(s, "\"", "\"", strlen(s), FMT_SHELL|FMT_ALWAYS) : s);
|
||||
}
|
||||
}
|
||||
sfclose(pp);
|
||||
|
|
@ -1693,9 +1712,9 @@ astconflist(Sfio_t* sp, const char* path, int flags, const char* pattern)
|
|||
sfprintf(sp, "%*s %*s %d %2s %4d %5s %s\n", sizeof(conf[0].name), fp->name, sizeof(prefix[fp->standard].name), prefix[fp->standard].name, 1, call, 0, flg, s);
|
||||
}
|
||||
else if (flags & ASTCONF_parse)
|
||||
sfprintf(sp, "%s %s - %s\n", state.id, (flags & ASTCONF_lower) ? fmtlower(fp->name) : fp->name, fmtquote(s, "\"", "\"", strlen(s), FMT_SHELL));
|
||||
sfprintf(sp, "%s %s - %s\n", state.id, (flags & ASTCONF_lower) ? fmtlower(fp->name) : fp->name, fmtquote(s, "\"", "\"", strlen(s), FMT_SHELL|FMT_ALWAYS));
|
||||
else
|
||||
sfprintf(sp, "%s=%s\n", (flags & ASTCONF_lower) ? fmtlower(fp->name) : fp->name, (flags & ASTCONF_quote) ? fmtquote(s, "\"", "\"", strlen(s), FMT_SHELL) : s);
|
||||
sfprintf(sp, "%s=%s\n", (flags & ASTCONF_lower) ? fmtlower(fp->name) : fp->name, (flags & ASTCONF_quote) ? fmtquote(s, "\"", "\"", strlen(s), FMT_SHELL|FMT_ALWAYS) : s);
|
||||
}
|
||||
}
|
||||
if (pattern)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue