Fix runsc --debug config output.

For non-string flags, `reflect.Value.String()` returns something like
`<bool Value>` or `<time.Duration value>` rather than the stringified
version of the value. So we convert the `reflect.Value` to an `interface{}`
first so that stringification works as expected.

PiperOrigin-RevId: 614879158
This commit is contained in:
Etienne Perot
2024-03-11 19:45:12 -07:00
committed by gVisor bot
parent 6ad1af2b9c
commit 7220bea2b7
+8 -2
View File
@@ -404,9 +404,15 @@ func (c *Config) Log() {
st := obj.Type()
for i := 0; i < st.NumField(); i++ {
f := st.Field(i)
val := obj.Field(i).String()
if val == "" {
var val any
if strVal := obj.Field(i).String(); strVal == "" {
val = "(empty)"
} else if !f.IsExported() {
// Cannot convert to `interface{}` for non-exported fields,
// so just use `strVal`.
val = fmt.Sprintf("%s (unexported)", strVal)
} else {
val = obj.Field(i).Interface()
}
if flagName, hasFlag := f.Tag.Lookup("flag"); hasFlag {
log.Debugf("Config.%s (--%s): %v", f.Name, flagName, val)