uninit_write_proc_stat_context(&c);
return;
}
- int tmp, ncpu;
- if (fscanf(c.cpuf, "%d-%d\n", &tmp, &ncpu) < 2) {
- log_system_error("fscanf(cpuf) failed");
- uninit_write_proc_stat_context(&c);
- return;
+ unsigned int tmp = -1;
+ unsigned int ncpu = -1;
+ errno = 0;
+
+ if (fscanf(c.cpuf, "%u-%u\n", &tmp, &ncpu) == 2) {
+ ncpu = ncpu - tmp + 1;
+ } else {
+ rewind(c.cpuf);
+ if (fscanf(c.cpuf, "%u\n", &ncpu) == 1) {
+ ncpu = ncpu + 1;
+ } else {
+ if (errno) {
+ log_system_error("fscanf(cpuf) failed");
+ } else {
+ log_error("fscanf(cpuf) parsing error");
+ }
+ uninit_write_proc_stat_context(&c);
+ return;
+ }
}
+
fclose(c.cpuf);
c.cpuf = NULL;
- ncpu = ncpu - tmp + 1;
long psize = sysconf(_SC_PAGESIZE);
if (fprintf(stat_file_out, "psize %ld ncpu %d\n", psize, ncpu) < 0) {