gentoo: use /var/run for new /run compatibility
[util-vserver.git] / src / vserver-stat.c
index 636c6b7..2b55f15 100644 (file)
@@ -318,6 +318,7 @@ registerXidCgroups(struct Vector *vec, struct process_info *process)
     ssize_t                    len;
     unsigned long long         stime_total, utime_total;
     int                                per_ss = 0;
+    FILE                       *fp;
 
 
     if (vc_virt_stat(xid, &vstat) == -1) {
@@ -334,8 +335,14 @@ registerXidCgroups(struct Vector *vec, struct process_info *process)
     }
 
     if ((fd = open(DEFAULTCONFDIR "/cgroup/mnt", O_RDONLY)) == -1) {
-      strcpy(cgroup, "/dev/cgroup/");
-      cgroup_len = sizeof("/dev/cgroup");
+      if (utilvserver_isDirectory("/sys/fs/cgroup/memory", false)) {
+        strcpy(cgroup, "/sys/fs/cgroup/");
+        cgroup_len = sizeof("/sys/fs/cgroup");
+        per_ss = 1;
+      } else {
+        strcpy(cgroup, "/dev/cgroup/");
+        cgroup_len = sizeof("/dev/cgroup");
+      }
     }
     else {
       cgroup_len = read(fd, cgroup, sizeof(cgroup));
@@ -389,7 +396,7 @@ registerXidCgroups(struct Vector *vec, struct process_info *process)
       char *dir = strrchr(vhi_name, '/');
       if (dir == NULL) {
         WRITE_MSG(2, "invalid context name: ");
-        WRITE_STR(2, dir);
+        WRITE_STR(2, vhi_name);
         WRITE_MSG(2, "\n");
         return;
       }
@@ -416,27 +423,35 @@ registerXidCgroups(struct Vector *vec, struct process_info *process)
       close(fd);
     }
 
-    if ((cgroup_len + name_len + sizeof("/memory/memory.usage_in_bytes")) > sizeof(filename)) {
+    if ((cgroup_len + name_len + sizeof("/memory/memory.stat")) > sizeof(filename)) {
       WRITE_MSG(2, "cgroup name too long: ");
       WRITE_STR(2, cgroup);
       WRITE_MSG(2, "\n");
       return;
     }
-    snprintf(filename, sizeof(filename), "%s%s%s/memory.usage_in_bytes", cgroup, (per_ss ? "/memory" : ""), name);
+    snprintf(filename, sizeof(filename), "%s%s%s/memory.stat", cgroup, (per_ss ? "/memory" : ""), name);
 
-    if ((fd = open(filename, O_RDONLY)) == -1)
-      perror("open(memory.usage_in_bytes)");
+    if ((fp = fopen(filename, "r")) == NULL)
+      perror("open(memory.stat)");
     else {
-      if (read(fd, buf, sizeof(buf)) == -1) {
-       perror("read(memory.usage_in_bytes)");
-       return;
-      }
-      close(fd);
-      if ((rss = strtoull(buf, &endptr, 0)) == ULLONG_MAX ||
-         (*endptr != '\n' && *endptr != '\0')) {
-       perror("strtoull(memory.usage_in_bytes)");
-       return;
+      unsigned long long _rss = 0, _mapped_file = 0;
+      while (fgets(buf, sizeof(buf), fp) != NULL) {
+       if (strncmp(buf, "rss ", 4) == 0) {
+         if ((_rss = strtoull(buf + 4, &endptr, 0)) == ULLONG_MAX ||
+             (*endptr != '\n' && *endptr != '\0')) {
+           perror("strtoull(memory.stat:rss)");
+           return;
+         }
+       }
+        else if (strncmp(buf, "mapped_file ", 12) == 0) {
+         if ((_mapped_file = strtoull(buf + 12, &endptr, 0)) == ULLONG_MAX ||
+             (*endptr != '\n' && *endptr != '\0')) {
+           perror("strtoull(memory.stat:mapped_file)");
+           return;
+         }
+       }
       }
+      rss = _rss + _mapped_file;
     }
 
     snprintf(filename, sizeof(filename), "%s%s%s/cpuacct.stat", cgroup, (per_ss ? "/cpuacct" : ""), name);