On Wednesday, 13 December 2017 17:10:19 CET Andrea Bolognani wrote: > From: Bjoern Walk <[email protected]> > > All different architectures use the same copy-pasted code to parse > processor frequency information from /proc/cpuinfo. Let's extract that > code into a function to avoid repetition. > > We now also tolerate if the parsing of /proc/cpuinfo is not successful > and just report a warning instead of bailing out and abandoning the rest > of the CPU information. > > Reviewed-by: Marc Hartmayer <[email protected]> > Reviewed-by: Boris Fiuczynski <[email protected]> > Reviewed-by: Andrea Bolognani <[email protected]> > Signed-off-by: Bjoern Walk <[email protected]> > --- > [...] > +static int > +virHostCPUParseFrequency(FILE *cpuinfo, > + virArch arch, > + unsigned int *mhz) > +{ > + const char *prefix = NULL; > + char line[1024]; > + > + if (ARCH_IS_X86(arch)) > + prefix = "cpu MHz"; > + else if (ARCH_IS_PPC(arch)) > + prefix = "clock"; > + else if (ARCH_IS_ARM(arch)) > + prefix = "BogoMIPS"; > + > + if (!prefix) { > + VIR_WARN("Parser for /proc/cpuinfo needs to be adapted for your > architecture"); > + return 1;
I'd print the architecture in the warning, so sysadmins can see easily
which architecture it is, even when looking at logs collected from
different libvirt installations.
> + while (fgets(line, sizeof(line), cpuinfo) != NULL) {
> + if (!STRPREFIX(line, prefix))
> + continue;
IMHO here it would be a good idea to check that line[strlen(prefix)]
is either a space or ':', to avoid prefix matching more keys than the
actual intended one(s) -- something like:
char c = line[strlen(prefix)];
if (c != ':' && !c_isspace(*str))
continue;
--
Pino Toscano
signature.asc
Description: This is a digitally signed message part.
-- libvir-list mailing list [email protected] https://www.redhat.com/mailman/listinfo/libvir-list
