From 4923d8dcb56a50965040d0658dc4734d3b4972b0 Mon Sep 17 00:00:00 2001
From: Zooko O'Whielacronx <zooko@zooko.com>
Date: Thu, 6 Dec 2007 17:27:40 -0700
Subject: [PATCH] make control.get_memory_usage() return all zeroes if reading
 /proc/mem/whatsit raises an exception

---
 src/allmydata/control.py | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/allmydata/control.py b/src/allmydata/control.py
index 31a94359..dc27d9f7 100644
--- a/src/allmydata/control.py
+++ b/src/allmydata/control.py
@@ -1,5 +1,5 @@
 
-import os, time
+import os, sys, time
 from zope.interface import implements
 from twisted.application import service
 from twisted.internet import defer
@@ -15,12 +15,17 @@ def get_memory_usage():
                   #"VmHWM",
                   "VmData")
     stats = {}
-    for line in open("/proc/self/status", "r").readlines():
-        name, right = line.split(":",2)
-        if name in stat_names:
-            assert right.endswith(" kB\n")
-            right = right[:-4]
-            stats[name] = int(right) * 1024
+    try:
+        for line in open("/proc/self/status", "r").readlines():
+            name, right = line.split(":",2)
+            if name in stat_names:
+                assert right.endswith(" kB\n")
+                right = right[:-4]
+                stats[name] = int(right) * 1024
+    except:
+        # Probably not on (a compatible version of) Linux
+        stats['VmSize'] = 0
+        stats['VmPeak'] = 0
     return stats
 
 def log_memory_usage(where=""):
-- 
2.45.2