]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Fixed integer overflow in QEMU guest CPU time
authorDaniel P. Berrange <berrange@redhat.com>
Sun, 15 Apr 2007 19:58:44 +0000 (19:58 +0000)
committerDaniel P. Berrange <berrange@redhat.com>
Sun, 15 Apr 2007 19:58:44 +0000 (19:58 +0000)
ChangeLog
qemud/driver.c

index fdab46b7344dc0319404920b317515edababe11b..d5f0fa43dd7b4ff710ba7100bf7fee2f5349c9c7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+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
index e3daaa915d6b4cbca598cad5e24e45f8d7594d38..0c3548679db90a64379a2af78471fee7d18324c9 100644 (file)
@@ -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);