[banshee: 6/12] Move TrySetProcessName to Hyena



commit c8601d6cafe6a08fa978eb1a582e0fcdd61911f2
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Thu Aug 6 12:16:52 2009 -0700

    Move TrySetProcessName to Hyena

 .../Banshee.Core/Banshee.Base/PlatformHacks.cs     |   33 -------------------
 .../Banshee.Gui/GtkBaseClient.cs                   |    2 +-
 src/Libraries/Hyena/Hyena/ApplicationContext.cs    |   34 ++++++++++++++++++++
 3 files changed, 35 insertions(+), 34 deletions(-)
---
diff --git a/src/Core/Banshee.Core/Banshee.Base/PlatformHacks.cs b/src/Core/Banshee.Core/Banshee.Base/PlatformHacks.cs
index d11073e..5e4cf1a 100644
--- a/src/Core/Banshee.Core/Banshee.Base/PlatformHacks.cs
+++ b/src/Core/Banshee.Core/Banshee.Base/PlatformHacks.cs
@@ -27,7 +27,6 @@
 //
 
 using System;
-using System.Text;
 using System.Runtime.InteropServices;
 
 namespace Banshee.Base
@@ -72,37 +71,5 @@ namespace Banshee.Base
             } catch {
             }
         }
-        
-        [DllImport ("libc")] // Linux
-        private static extern int prctl (int option, byte [] arg2, IntPtr arg3, IntPtr arg4, IntPtr arg5);
-        
-        [DllImport ("libc")] // BSD
-        private static extern void setproctitle (byte [] fmt, byte [] str_arg);
-
-        public static void SetProcessName (string name)
-        {
-            if (Environment.OSVersion.Platform != PlatformID.Unix) {
-                return;
-            }
-        
-            try {
-                if (prctl (15 /* PR_SET_NAME */, Encoding.ASCII.GetBytes (name + "\0"), 
-                    IntPtr.Zero, IntPtr.Zero, IntPtr.Zero) != 0) {
-                    throw new ApplicationException ("Error setting process name: " + 
-                        Mono.Unix.Native.Stdlib.GetLastError ());
-                }
-            } catch (EntryPointNotFoundException) {
-                setproctitle (Encoding.ASCII.GetBytes ("%s\0"), 
-                    Encoding.ASCII.GetBytes (name + "\0"));
-            }
-        }
-        
-        public static void TrySetProcessName (string name)
-        {
-            try {
-                SetProcessName (name);
-            } catch {
-            }
-        }
     }
 }
diff --git a/src/Core/Banshee.ThickClient/Banshee.Gui/GtkBaseClient.cs b/src/Core/Banshee.ThickClient/Banshee.Gui/GtkBaseClient.cs
index 53e6825..44b0ee8 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Gui/GtkBaseClient.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Gui/GtkBaseClient.cs
@@ -99,7 +99,7 @@ namespace Banshee.Gui
         protected void Initialize (bool registerCommonServices)
         {
             // Set the process name so system process listings and commands are pretty
-            PlatformHacks.TrySetProcessName (Application.InternalName);
+            ApplicationContext.TrySetProcessName (Application.InternalName);
             
             Application.Initialize ();
             
diff --git a/src/Libraries/Hyena/Hyena/ApplicationContext.cs b/src/Libraries/Hyena/Hyena/ApplicationContext.cs
index 0cab32b..9085f19 100644
--- a/src/Libraries/Hyena/Hyena/ApplicationContext.cs
+++ b/src/Libraries/Hyena/Hyena/ApplicationContext.cs
@@ -27,6 +27,8 @@
 //
 
 using System;
+using System.Text;
+using System.Runtime.InteropServices;
 
 using Hyena.CommandLine;
 
@@ -74,5 +76,37 @@ namespace Hyena
         public static System.Globalization.CultureInfo InternalCultureInfo {
             get { return System.Globalization.CultureInfo.InvariantCulture; }
         }
+
+        [DllImport ("libc")] // Linux
+        private static extern int prctl (int option, byte [] arg2, IntPtr arg3, IntPtr arg4, IntPtr arg5);
+        
+        [DllImport ("libc")] // BSD
+        private static extern void setproctitle (byte [] fmt, byte [] str_arg);
+
+        private static void SetProcessName (string name)
+        {
+            if (Environment.OSVersion.Platform != PlatformID.Unix) {
+                return;
+            }
+        
+            try {
+                if (prctl (15 /* PR_SET_NAME */, Encoding.ASCII.GetBytes (name + "\0"), 
+                    IntPtr.Zero, IntPtr.Zero, IntPtr.Zero) != 0) {
+                    throw new ApplicationException ("Error setting process name: " + 
+                        Mono.Unix.Native.Stdlib.GetLastError ());
+                }
+            } catch (EntryPointNotFoundException) {
+                setproctitle (Encoding.ASCII.GetBytes ("%s\0"), 
+                    Encoding.ASCII.GetBytes (name + "\0"));
+            }
+        }
+        
+        public static void TrySetProcessName (string name)
+        {
+            try {
+                SetProcessName (name);
+            } catch {
+            }
+        }
     }
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]