diff options
author | Gaël PORTAY <gael.portay@savoirfairelinux.com> | 2018-10-21 18:37:45 -0400 |
---|---|---|
committer | Gaël PORTAY <gael.portay@savoirfairelinux.com> | 2018-10-21 20:51:53 -0400 |
commit | 0b8aa86ecbec930ef0315bc4627c0f48966769d2 (patch) | |
tree | 9c7a7e88bd598c01382892197a9d668ab1f6b261 /src/print_load.c | |
parent | 13f720ab752d61447cf7b4c06cd9a011b0d17bea (diff) |
print_cpu_usage: fix invalid %cpu placeholder output
Currently, the module cpu_usage prints %cpu0 information for the invalid
%cpu placeholder (i.e. the cpu number is missing).
Consider the following configuration.
order += "cpu_usage"
cpu_usage {
format = "cpu0=%cpu0 cpu1=%cpu1 cpu=%cpu"
# missing cpu number -------------------^
}
The configuration above produces the output below.
$ i3status -c config
i3status: trying to auto-detect output_format setting
i3status: auto-detected "term"
cpu0=-2% cpu1=-49% cpu=-2%
cpu0=06% cpu1=02% cpu=06%
cpu0=05% cpu1=06% cpu=05%
...
The module prints %cpu0 at the third placeholder where it should report
an error.
This commit fixes this behavior by initializing `number' to -1. If the
cpu is missing in %cpu placeholder, the sscanf function does not set
`number'. Because `number' is -1 (lower to 0), an error is reported and
the placeholder is skipped.
$ i3status -c ./config
i3status: trying to auto-detect output_format setting
i3status: auto-detected "term"
provided CPU number '-1' above detected number of CPU 4
cpu0= cpu1=-48% cpu=
provided CPU number '-1' above detected number of CPU 4
cpu0= cpu1=11% cpu=
provided CPU number '-1' above detected number of CPU 4
cpu0= cpu1=03% cpu=
...
Diffstat (limited to 'src/print_load.c')
0 files changed, 0 insertions, 0 deletions