File beagle-failsafe-memory-workaround.patch of Package beagle

Index: beagled/BeagleDaemon.cs
===================================================================
--- beagled/BeagleDaemon.cs	(revision 4910)
+++ beagled/BeagleDaemon.cs	(working copy)
@@ -53,6 +53,10 @@
 		private static bool arg_heap_shot = false;
 		private static bool arg_heap_shot_snapshots = true;
 
+		private static bool failsafe_memory_restart = true;
+		private const int failsafe_memory_limit = 300 * 1024;
+		private static bool failsafe_memory_already_restarted = false;
+
 		private static bool disable_textcache = false;
 		public static bool DisableTextCache {
 			get { return disable_textcache; }
@@ -131,7 +135,7 @@
 				if (arg_heap_shot && arg_heap_shot_snapshots)
 					MaybeSendSigprof (vm_rss, GC.GetTotalMemory (false));
 
-				if (vm_rss > 300 * 1024) {
+				if (vm_rss > 310 * 1024) {
 					Logger.Log.Debug ("VmRss too large --- shutting down");
 					Shutdown.BeginShutdown ();
 				}
@@ -140,6 +144,28 @@
 			}
 		}
 
+		// FIXME this is a hack to prevent beagled from using way too much RAM on a system
+		// see http://bugzilla.gnome.org/show_bug.cgi?id=573006
+		// and https://bugzilla.novell.com/show_bug.cgi?id=472552
+		private static void MemoryUsageFailsafe ()
+		{
+			while (!Shutdown.ShutdownRequested && !failsafe_memory_already_restarted) {
+				int vm_rss = SystemInformation.VmRss;
+
+				if (vm_rss > failsafe_memory_limit) {
+					Logger.Log.Debug ("VmRss too large --- restarting");
+					failsafe_memory_already_restarted = true;
+					try {
+						System.Diagnostics.Process.Start ("/usr/bin/beagled", "--replace");
+					} catch (Exception e) {
+						Logger.Log.Debug (e.ToString ());
+					}
+				}
+
+				Thread.Sleep (10000);
+			}
+		}
+
 		private static void PrintUsage ()
 		{
 			VersionFu.PrintHeader ();
@@ -483,6 +509,10 @@
 				ExceptionHandlingThread.Start (new ThreadStart (LogMemoryUsage));
 			}
 
+			if (failsafe_memory_restart) {
+				ExceptionHandlingThread.Start (new ThreadStart (MemoryUsageFailsafe));
+			}
+
 			// Do BEAGLE_EXERCISE_THE_DOG_HARDER-related processing.
 			ExerciseTheDogHarder ();
 
openSUSE Build Service is sponsored by