NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
kern/47232: Trailing whilte space(s) of rnd source is hard to know
>Number: 47232
>Category: kern
>Synopsis: Trailing whilte space(s) of rnd source is hard to know
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: kern-bug-people
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Wed Nov 21 17:35:01 +0000 2012
>Originator: SAITOH Masanobu
>Release: NetBSD 6.0
>Organization:
>Environment:
Architecture: all
>Description:
Sensor name may include white space.
e.g.:
# envstat
Current CritMax WarnMax WarnMin CritMin Unit
[coretemp0]
cpu0 temperature: 42.000 degC
[coretemp1]
cpu1 temperature: 41.000 degC
"cpu0 temperature" includes space.
sysmon_envsys_register() automatically call rnd_attach_source()
with using the following string:
snprintf(rnd_name, sizeof(rnd_name), "%s-%s",
sme->sme_name, edata->desc);
In this case sme->sme_name is "coretemp0" and edata->desc is
"cpu0 temperature". "%s-%s" becomes "coretemp0-cpu0 temperature".
The length is limited to 16, so the resul is "coretemp0-cpu0 ".
Note that there is a white space.
And then,
# rndctl -l
Source Bits Type Flags
wd1 56 disk estimate, collect
wd0 9124 disk estimate, collect
cpu1 149 vm estimate, collect
cpu0 43 vm estimate, collect
coretemp1-cpu1 3 env estimate, collect
coretemp0-cpu0 4 env estimate, collect
wm2 0 net
wm1 0 net
wm0 0 net
mskc0 0 net
system-power 0 power estimate, collect
callout 0 skew collect
# rndctl -EC -d coretemp1-cpu1
rndctl: ioctl(RNDCTL): No such file or directory <=== FAIL
# rndctl -EC -d "coretemp1-cpu1 " <=== With a white space
# <=== SUCCESS
It's hard to know.
>How-To-Repeat:
See above.
>Fix:
Remove trailing white space.
And also, changind space(s) in the middle with '-' is better (IMHO).
Index: sysmon_envsys.c
===================================================================
RCS file: /cvsroot/src/sys/dev/sysmon/sysmon_envsys.c,v
retrieving revision 1.125
diff -u -r1.125 sysmon_envsys.c
--- sysmon_envsys.c 6 Sep 2012 12:21:40 -0000 1.125
+++ sysmon_envsys.c 21 Nov 2012 17:35:16 -0000
@@ -778,8 +778,25 @@
*/
TAILQ_FOREACH(edata, &sme->sme_sensors_list, sensors_head) {
if (edata->flags & ENVSYS_FHAS_ENTROPY) {
+ size_t n;
+ int tail = 1;
+
snprintf(rnd_name, sizeof(rnd_name), "%s-%s",
sme->sme_name, edata->desc);
+ n = strlen(rnd_name);
+ /*
+ * 1) Remove trailing white space(s).
+ * 2) If space exist, replace it with '-'
+ */
+ while (--n) {
+ if (rnd_name[n] == ' ') {
+ if (tail != 0)
+ rnd_name[n] = '\0';
+ else
+ rnd_name[n] = '-';
+ } else
+ tail = 0;
+ }
rnd_attach_source(&edata->rnd_src, rnd_name,
RND_TYPE_ENV, 0);
}
Home |
Main Index |
Thread Index |
Old Index