diff --git a/ChangeLog b/ChangeLog index fdab46b734..d5f0fa43dd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sun Apr 15 15:57:04 EST 2007 Daniel P. Berrange + + * qemud/driver.c: Fixed integer overflow in calculating CPU time + for qemu guests - use long long throughout. + Fri Apr 13 10:07:04 EST 2007 Daniel P. Berrange * src/xend_internal.c: Back out accidental commit of code which diff --git a/qemud/driver.c b/qemud/driver.c index e3daaa915d..0c3548679d 100644 --- a/qemud/driver.c +++ b/qemud/driver.c @@ -197,7 +197,7 @@ int qemudGetCPUInfo(unsigned int *cpus, unsigned int *mhz, static int qemudGetProcessInfo(unsigned long long *cpuTime, int pid) { char proc[PATH_MAX]; FILE *pidinfo; - unsigned long usertime, systime; + unsigned long long usertime, systime; if (snprintf(proc, sizeof(proc), "/proc/%d/stat", pid) >= (int)sizeof(proc)) { return -1; @@ -210,7 +210,7 @@ static int qemudGetProcessInfo(unsigned long long *cpuTime, int pid) { return 0; } - if (fscanf(pidinfo, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %lu %lu", &usertime, &systime) != 2) { + if (fscanf(pidinfo, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %llu %llu", &usertime, &systime) != 2) { qemudDebug("not enough arg"); return -1; } @@ -220,9 +220,9 @@ static int qemudGetProcessInfo(unsigned long long *cpuTime, int pid) { * _SC_CLK_TCK is jiffies per second * So calulate thus.... */ - *cpuTime = 1000 * 1000 * 1000 * (usertime + systime) / sysconf(_SC_CLK_TCK); + *cpuTime = 1000ull * 1000ull * 1000ull * (usertime + systime) / (unsigned long long)sysconf(_SC_CLK_TCK); - qemudDebug("Got %lu %lu %lld", usertime, systime, *cpuTime); + qemudDebug("Got %llu %llu %llu", usertime, systime, *cpuTime); fclose(pidinfo);