> Quoting Christian Brauner (christianvanbrauner at gmail.com): > > > > > > + else if (sscanf(cpu_char, "%d", &cpu) != 1) { > > > > > > This is an unorthodox (for lxc) coding style. Could you explain > > > exactly what you're doing here? I would expect just: > > > > > > if (sscanf(cpu_char, "%d", &cpu) != 1)) > > > continue; > > > if (!cpu_in_cpuset(cpu, cpuset)) > > > continue; > > > > Your way is the better way to do it. I adjusted and squased the PR and > > post the patch again here as well: > > > > commit 21c3c7ace34eaf5f19074e332222d050896b5cc3 > > Author: Christian Brauner <christianvanbrauner at gmail.com> > > Date: Sun Feb 15 11:31:31 2015 +0100 > > > > Show cpu-average in /proc/stat and start cup numbering at 0 > > Note, your previous patch had a signed-off-by, but this one does not. > I'll let Stéphane decide whether that's good enough :) > > Thanks, Christian. > > Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>
Well, then I'll do it again :) commit 21c3c7ace34eaf5f19074e332222d050896b5cc3 Signed-off-by: Christian Brauner <christianvanbrau...@gmail.com> Date: Sun Feb 15 11:31:31 2015 +0100 Show cpu-average in /proc/stat and start cup numbering at 0 diff --git a/lxcfs.c b/lxcfs.c index d6fb101..d358829 100644 --- a/lxcfs.c +++ b/lxcfs.c @@ -1642,7 +1642,7 @@ static int proc_stat_read(char *buf, size_t size, off_t offset, nih_local char *cpuset = NULL; char *line = NULL; size_t linelen = 0, total_len = 0; - int curcpu = 0; + int curcpu = -1; /* cpu numbering starts at 0 */ FILE *f; if (offset) @@ -1662,16 +1662,21 @@ static int proc_stat_read(char *buf, size_t size, off_t offset, while (getline(&line, &linelen, f) != -1) { size_t l; int cpu; + char cpu_char[10]; /* That's a lot of cores */ char *c; - if (sscanf(line, "cpu%d", &cpu) != 1) { - /* not a ^cpu line, just print it */ + if (sscanf(line, "cpu%9[^ ]", cpu_char) != 1) { + /* not a ^cpuN line containing a number N, just print it */ l = snprintf(buf, size, "%s", line); buf += l; size -= l; total_len += l; continue; } + + if (sscanf(cpu_char, "%d", &cpu) != 1) + continue; + if (!cpu_in_cpuset(cpu, cpuset)) continue; curcpu ++; Christian > > > > > diff --git a/lxcfs.c b/lxcfs.c > > index d6fb101..d358829 100644 > > --- a/lxcfs.c > > +++ b/lxcfs.c > > @@ -1642,7 +1642,7 @@ static int proc_stat_read(char *buf, size_t size, > > off_t offset, > > nih_local char *cpuset = NULL; > > char *line = NULL; > > size_t linelen = 0, total_len = 0; > > - int curcpu = 0; > > + int curcpu = -1; /* cpu numbering starts at 0 */ > > FILE *f; > > > > if (offset) > > @@ -1662,16 +1662,21 @@ static int proc_stat_read(char *buf, size_t size, > > off_t offset, > > while (getline(&line, &linelen, f) != -1) { > > size_t l; > > int cpu; > > + char cpu_char[10]; /* That's a lot of cores */ > > char *c; > > > > - if (sscanf(line, "cpu%d", &cpu) != 1) { > > - /* not a ^cpu line, just print it */ > > + if (sscanf(line, "cpu%9[^ ]", cpu_char) != 1) { > > + /* not a ^cpuN line containing a number N, just print it */ > > l = snprintf(buf, size, "%s", line); > > buf += l; > > size -= l; > > total_len += l; > > continue; > > } > > + > > + if (sscanf(cpu_char, "%d", &cpu) != 1) > > + continue; > > + > > if (!cpu_in_cpuset(cpu, cpuset)) > > continue; > > curcpu ++; > > > > Christian >
pgp4pEOCAgJRk.pgp
Description: PGP signature
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel