summarylogtreecommitdiffstats
path: root/0001-Mono-Set-process-name.patch
blob: fea6bac6f6e4028b902734390b57399bd136474e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
From e18adba54c6e04c6960faa3904814e9d065fb2ab Mon Sep 17 00:00:00 2001
From: Lars <larsjohnsen@gmail.com>
Date: Thu, 3 Sep 2015 14:07:01 +0200
Subject: [PATCH] Mono: Set process name

---
 .../EnvironmentInfo/MonoRuntimeProvider.cs         | 23 ++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/src/NzbDrone.Mono/EnvironmentInfo/MonoRuntimeProvider.cs b/src/NzbDrone.Mono/EnvironmentInfo/MonoRuntimeProvider.cs
index b9884df..f881923 100644
--- a/src/NzbDrone.Mono/EnvironmentInfo/MonoRuntimeProvider.cs
+++ b/src/NzbDrone.Mono/EnvironmentInfo/MonoRuntimeProvider.cs
@@ -1,7 +1,10 @@
 using System;
 using System.Reflection;
+using System.Text;
+using System.Runtime.InteropServices;
 using NLog;
 using NzbDrone.Common.EnvironmentInfo;
+using Mono.Unix.Native;
 
 namespace NzbDrone.Mono.EnvironmentInfo
 {
@@ -13,6 +16,26 @@ public MonoRuntimeProvider(Common.IServiceProvider serviceProvider, Logger logge
             :base(serviceProvider, logger)
         {
             _logger = logger;
+            unixSetProcessName("sonarr");
+        }
+
+        [DllImport ("libc")] //Linux
+        private static extern int prctl (int option, byte [] arg2, IntPtr arg3, IntPtr arg4, IntPtr arg5);
+
+        public void unixSetProcessName (string name)
+        {
+            try {
+                var success = 0 == prctl(15 /* PR_SET_NAME */, Encoding.ASCII.GetBytes (name + "\0"), IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
+                if (!success)
+                {
+                    var error = Stdlib.GetLastError();
+                    throw new InvalidOperationException("prtctl call error: " + error);
+                }
+            }
+            catch (Exception ex)
+            {
+                _logger.ErrorException("Could not set process name, error: " + ex.Message, ex);
+            }
         }
 
         public override string RuntimeVersion
-- 
2.10.0