Fix gen-tunables.awk to work with older awk

Awk 3.1.x does not support multi-dimensional arrays, so fix up to make
sure that gen-tunables.awk works on it.

	* scripts/gen-tunables.awk: Avoid multi-dimensional arrays.
This commit is contained in:
Adhemerval Zanella 2017-06-19 14:47:21 +05:30 committed by Siddhesh Poyarekar
parent 5e5b3b8866
commit a4de0a9008
2 changed files with 38 additions and 34 deletions

View File

@ -1,3 +1,7 @@
2017-06-19 Adhemerval Zanella <adhemerval.zanella@linaro.org>
* scripts/gen-tunables.awk: Avoid multi-dimensional arrays.
2017-06-19 Stefan Liebler <stli@linux.vnet.ibm.com> 2017-06-19 Stefan Liebler <stli@linux.vnet.ibm.com>
[BZ #21537] [BZ #21537]

View File

@ -39,20 +39,20 @@ $2 == "{" {
$1 == "}" { $1 == "}" {
if (tunable != "") { if (tunable != "") {
# Tunables definition ended, now fill in default attributes. # Tunables definition ended, now fill in default attributes.
if (!types[top_ns][ns][tunable]) { if (!types[top_ns,ns,tunable]) {
types[top_ns][ns][tunable] = "STRING" types[top_ns,ns,tunable] = "STRING"
} }
if (!minvals[top_ns][ns][tunable]) { if (!minvals[top_ns,ns,tunable]) {
minvals[top_ns][ns][tunable] = "0" minvals[top_ns,ns,tunable] = "0"
} }
if (!maxvals[top_ns][ns][tunable]) { if (!maxvals[top_ns,ns,tunable]) {
maxvals[top_ns][ns][tunable] = "0" maxvals[top_ns,ns,tunable] = "0"
} }
if (!env_alias[top_ns][ns][tunable]) { if (!env_alias[top_ns,ns,tunable]) {
env_alias[top_ns][ns][tunable] = "NULL" env_alias[top_ns,ns,tunable] = "NULL"
} }
if (!security_level[top_ns][ns][tunable]) { if (!security_level[top_ns,ns,tunable]) {
security_level[top_ns][ns][tunable] = "SXID_ERASE" security_level[top_ns,ns,tunable] = "SXID_ERASE"
} }
tunable = "" tunable = ""
@ -81,7 +81,7 @@ $1 == "}" {
if (tunable == "") { if (tunable == "") {
# We encountered a tunable without any attributes, so note it with a # We encountered a tunable without any attributes, so note it with a
# default. # default.
types[top_ns][ns][$1] = "STRING" types[top_ns,ns,$1] = "STRING"
next next
} }
@ -91,20 +91,20 @@ $1 == "}" {
val = gensub(/^[ \t]+|[ \t]+$/, "", "g", arr[2]) val = gensub(/^[ \t]+|[ \t]+$/, "", "g", arr[2])
if (attr == "type") { if (attr == "type") {
types[top_ns][ns][tunable] = val types[top_ns,ns,tunable] = val
} }
else if (attr == "minval") { else if (attr == "minval") {
minvals[top_ns][ns][tunable] = val minvals[top_ns,ns,tunable] = val
} }
else if (attr == "maxval") { else if (attr == "maxval") {
maxvals[top_ns][ns][tunable] = val maxvals[top_ns,ns,tunable] = val
} }
else if (attr == "env_alias") { else if (attr == "env_alias") {
env_alias[top_ns][ns][tunable] = sprintf("\"%s\"", val) env_alias[top_ns,ns,tunable] = sprintf("\"%s\"", val)
} }
else if (attr == "security_level") { else if (attr == "security_level") {
if (val == "SXID_ERASE" || val == "SXID_IGNORE" || val == "NONE") { if (val == "SXID_ERASE" || val == "SXID_IGNORE" || val == "NONE") {
security_level[top_ns][ns][tunable] = val security_level[top_ns,ns,tunable] = val
} }
else { else {
printf("Line %d: Invalid value (%s) for security_level: %s, ", NR, val, printf("Line %d: Invalid value (%s) for security_level: %s, ", NR, val,
@ -114,11 +114,11 @@ $1 == "}" {
} }
} }
else if (attr == "default") { else if (attr == "default") {
if (types[top_ns][ns][tunable] == "STRING") { if (types[top_ns,ns,tunable] == "STRING") {
default_val[top_ns][ns][tunable] = sprintf(".strval = \"%s\"", val); default_val[top_ns,ns,tunable] = sprintf(".strval = \"%s\"", val);
} }
else { else {
default_val[top_ns][ns][tunable] = sprintf(".numval = %s", val) default_val[top_ns,ns,tunable] = sprintf(".numval = %s", val)
} }
} }
} }
@ -139,27 +139,27 @@ END {
# Now, the enum names # Now, the enum names
print "\ntypedef enum" print "\ntypedef enum"
print "{" print "{"
for (t in types) { for (tnm in types) {
for (n in types[t]) { split (tnm, indices, SUBSEP);
for (m in types[t][n]) { t = indices[1];
printf (" TUNABLE_ENUM_NAME(%s, %s, %s),\n", t, n, m); n = indices[2];
} m = indices[3];
} printf (" TUNABLE_ENUM_NAME(%s, %s, %s),\n", t, n, m);
} }
print "} tunable_id_t;\n" print "} tunable_id_t;\n"
# Finally, the tunable list. # Finally, the tunable list.
print "\n#ifdef TUNABLES_INTERNAL" print "\n#ifdef TUNABLES_INTERNAL"
print "static tunable_t tunable_list[] attribute_relro = {" print "static tunable_t tunable_list[] attribute_relro = {"
for (t in types) { for (tnm in types) {
for (n in types[t]) { split (tnm, indices, SUBSEP);
for (m in types[t][n]) { t = indices[1];
printf (" {TUNABLE_NAME_S(%s, %s, %s)", t, n, m) n = indices[2];
printf (", {TUNABLE_TYPE_%s, %s, %s}, {%s}, NULL, TUNABLE_SECLEVEL_%s, %s},\n", m = indices[3];
types[t][n][m], minvals[t][n][m], maxvals[t][n][m], printf (" {TUNABLE_NAME_S(%s, %s, %s)", t, n, m)
default_val[t][n][m], security_level[t][n][m], env_alias[t][n][m]); printf (", {TUNABLE_TYPE_%s, %s, %s}, {%s}, NULL, TUNABLE_SECLEVEL_%s, %s},\n",
} types[t,n,m], minvals[t,n,m], maxvals[t,n,m],
} default_val[t,n,m], security_level[t,n,m], env_alias[t,n,m]);
} }
print "};" print "};"
print "#endif" print "#endif"