Message ID | 20250321-gpioinfo-unnamed-quotes-v1-1-a806e9027adf@linaro.org |
---|---|
State | New |
Headers | show |
Series | tools: don't implicity unquote unnamed lines in gpioinfo | expand |
On Fri, Mar 21, 2025 at 12:05:24PM +0100, Bartosz Golaszewski wrote: > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> > > Consider the following output of `gpioinfo`: > > gpiochip1 - 2 lines: > line 0: "foo" output > line 1: unnamed output > > Now let's run: > > gpioset --chip=gpiochip1 0=active 1=active > > The output of `gpioinfo --unquoted` is correct: > > gpiochip1 - 2 lines: > line 0: foo output consumer=gpioset > line 1: unnamed output consumer=gpioset > > However, without the `unquoted` switch, it's inconsistent: > > gpiochip1 - 2 lines: > line 0: "foo" output consumer="gpioset" > line 1: unnamed output consumer=gpioset > > This is because gpioinfo drops the quotes for all subsequent attribute > strings when it encounters an unnamed line. We should instead keep a > separate instance of the `unquoted` flag just for the line name and pass > the original value of `unquoted_strings` down to > print_line_attributes(). > Oh nuts, originally the consumer was a separate field, so the line name was the only string in the info. I didn't consider that when making the consumer an attribute :(. The fix and test look good to me. Reviewed-by: Kent Gibson <warthog618@gmail.com> Cheers, Kent.
diff --git a/tools/gpioinfo.c b/tools/gpioinfo.c index d5e4751..4619ca7 100644 --- a/tools/gpioinfo.c +++ b/tools/gpioinfo.c @@ -137,6 +137,7 @@ static bool resolve_line(struct line_resolver *resolver, static void print_line_info(struct gpiod_line_info *info, bool unquoted_strings) { + bool unquoted_name = unquoted_strings; char quoted_name[17]; const char *name; int len; @@ -144,10 +145,10 @@ static void print_line_info(struct gpiod_line_info *info, bool unquoted_strings) name = gpiod_line_info_get_name(info); if (!name) { name = "unnamed"; - unquoted_strings = true; + unquoted_name = true; } - if (unquoted_strings) { + if (unquoted_name) { printf("%-16s\t", name); } else { len = strlen(name);