[mistelix] Move set process name to Unix class



commit c1ed6105d4dc1c12e0a7bdeded93c7f0b341f581
Author: Jordi Mas <jmas softcatala org>
Date:   Sun Dec 27 18:05:34 2009 +0100

    Move set process name to Unix class

 src/Backends/OS/Unix.cs |   27 ++++++++++++++++++++++++++-
 src/mistelix.cs         |   30 +++---------------------------
 2 files changed, 29 insertions(+), 28 deletions(-)
---
diff --git a/src/Backends/OS/Unix.cs b/src/Backends/OS/Unix.cs
index 41b1882..4e1701b 100644
--- a/src/Backends/OS/Unix.cs
+++ b/src/Backends/OS/Unix.cs
@@ -24,6 +24,7 @@
 using System;
 using System.IO;
 using System.Runtime.InteropServices;
+using System.Text;
 
 using Mistelix.DataModel;
 using Mistelix.Core;
@@ -38,6 +39,12 @@ namespace Mistelix.Backends.OS
 		[DllImport ("libmistelix")]
 		static extern void mistelix_launchtool (string app, string args, string in_file, string out_file, string err_file);
 
+		[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);
+
 		static Unix ()
 		{
 
@@ -85,9 +92,27 @@ namespace Mistelix.Backends.OS
 				return directory;
 		}
 
-		static public void LaunchTool (string app, string args, string in_file, string out_file, string err_file)
+		public static void LaunchTool (string app, string args, string in_file, string out_file, string err_file)
 		{
 			mistelix_launchtool (app, args, in_file, out_file, err_file);
 		}
+
+		public static void SetProcessName (string name)
+		{
+			int platform = (int) Environment.OSVersion.Platform;		
+			if (platform != 4 && platform != 128)
+				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"));
+			}
+		}
 	}
 }
diff --git a/src/mistelix.cs b/src/mistelix.cs
index df9beb1..84d6eb3 100644
--- a/src/mistelix.cs
+++ b/src/mistelix.cs
@@ -26,7 +26,6 @@ using Gtk;
 using Gdk;
 using Gnome;
 using System.Runtime.InteropServices;
-using System.Text;
 using System.Collections.Generic;
 using System.Diagnostics;
 using System.IO;
@@ -38,6 +37,7 @@ using Mistelix.Widgets;
 using Mistelix.Dialogs;
 using Mistelix.DataModel;
 using Mistelix.Core;
+using Mistelix.Backends.OS;
 
 namespace Mistelix
 {
@@ -201,9 +201,9 @@ namespace Mistelix
 			Mistelix gui = new Mistelix (args);
 
 			try {
-				SetProcessName (Defines.APPNAME_LOWER);
+				Backends.OS.Unix.SetProcessName (Defines.APPNAME_LOWER);
 			} catch (Exception) {
-				Logger.Error ("Mistelix.Main. Cannot set process");
+				Logger.Error ("Mistelix.Main. Cannot set process name");
 			}
 
 			gui.Run ();
@@ -616,30 +616,6 @@ namespace Mistelix
 			recent = (RecentFile) menu_item.Data;
 			OpenProject (recent.filename);
 		}
-
-		[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)
-		{
-			int platform = (int) Environment.OSVersion.Platform;		
-			if (platform != 4 && platform != 128)
-				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"));
-			}
-		}
 	}
 }
 



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