[tasque] Move "set process title" fix to Program.cs



commit d920dd105aa2779f96374ba934d92582e01b0b0f
Author: Antonius Riha <antoniusriha gmail com>
Date:   Sat Jul 28 22:58:59 2012 +0200

    Move "set process title" fix to Program.cs
    
    Also got the latest version of this fix from banshee.
    
    Conflicts:
    
    	src/Tasque.Gtk/GnomeApplication.cs
    	src/tasque/Program.cs

 src/tasque/Program.cs    |   32 ++++++++++++++++++++++++++++++++
 src/tasque/tasque.csproj |    1 +
 2 files changed, 33 insertions(+), 0 deletions(-)
---
diff --git a/src/tasque/Program.cs b/src/tasque/Program.cs
index ec2f65b..8cd9e96 100644
--- a/src/tasque/Program.cs
+++ b/src/tasque/Program.cs
@@ -24,6 +24,9 @@
 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 // THE SOFTWARE.
 using System;
+using System.Runtime.InteropServices;
+using System.Text;
+using Mono.Unix.Native;
 
 namespace Tasque
 {
@@ -42,6 +45,31 @@ namespace Tasque
 			return nativeApp;
 		}
 		
+		#region Set process name
+		// From Banshee: Hyena/ApplicationContext.cs
+		[DllImport ("libc")] // Linux
+		static extern int prctl (int option, byte [] arg2, IntPtr arg3, IntPtr arg4, IntPtr arg5);
+
+		[DllImport ("libc")] // BSD
+		static extern void setproctitle (byte [] fmt, byte [] str_arg);
+
+		static void SetProcessName (string name)
+		{
+			if (Environment.OSVersion.Platform != PlatformID.Unix)
+				return;
+			
+			try {
+				var retVal = prctl (15 /* PR_SET_NAME */, Encoding.ASCII.GetBytes (name + "\0"),
+				                    IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
+				if (retVal != 0)
+					throw new ApplicationException ("Error setting process name: " +
+					                                Stdlib.GetLastError ());
+			} catch (EntryPointNotFoundException) {
+				setproctitle (Encoding.ASCII.GetBytes ("%s\0"), Encoding.ASCII.GetBytes (name + "\0"));
+			}
+		}
+		#endregion
+
 		static void Main (string[] args)
 		{
 			try {
@@ -50,6 +78,10 @@ namespace Tasque
 						return;
 
 					var nativeApp = CreateApplication ();
+					
+					// Fix process name not set on Unix
+					SetProcessName ("Tasque");
+					
 					application = new Application (nativeApp);
 					application.Init (args);
 					application.StartMainLoop ();
diff --git a/src/tasque/tasque.csproj b/src/tasque/tasque.csproj
index 64e37d6..a99f310 100644
--- a/src/tasque/tasque.csproj
+++ b/src/tasque/tasque.csproj
@@ -65,6 +65,7 @@
   </PropertyGroup>
   <ItemGroup>
     <Reference Include="System" />
+    <Reference Include="Mono.Posix" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\Gtk.Tasque\Gtk.Tasque.csproj">



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