+Sun Apr 15 15:57:04 EST 2007 Daniel P. Berrange <berrange@redhat.com>
+
+ * 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 <berrange@redhat.com>
* src/xend_internal.c: Back out accidental commit of code which
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;
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;
}
* _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);