Do

Merge lp:~cszikszoy/do/core-nativecode-move into lp:do

Proposed by Chris S.
Status: Merged
Merged at revision: not available
Proposed branch: lp:~cszikszoy/do/core-nativecode-move
Merge into: lp:do
Diff against target: None lines
To merge this branch: bzr merge lp:~cszikszoy/do/core-nativecode-move
Reviewer Review Type Date Requested Status
Alex Launi (community) Approve
Review via email: mp+9890@code.launchpad.net

This proposal supersedes a proposal from 2009-08-08.

To post a comment you must log in.
Revision history for this message
Chris S. (cszikszoy) wrote : Posted in a previous version of this proposal

This moves the platform specific SetProcessName code out of core, and into the system service. With this core should be entirely platform independent!

Revision history for this message
Robert Dyer (psybers) wrote : Posted in a previous version of this proposal

Why comment it out on line 159? Just remove the old code.

Why add a period to the log on line 161/162?

While you're touching this, might as well merge the two prctl methods on lines 30 and 35, since one one is used (and then calls the other).

Delete the one on 30, make 35 into this:

35 + private static int prctl (int option, string arg2)
36 + {
37 + return prctl (option, Encoding.ASCII.GetBytes (arg2 + "\0"), IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
38 + }

Seems to be a simple move, I can't test this code atm but looking at the diff its fine.

review: Approve
Revision history for this message
Alex Launi (alexlauni) wrote :

Rock and roll, cut out the bsd jawn and git r done.

review: Approve
1290. By Chris S.

remove bsd junk, simplify code

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/SystemService.cs'
2--- Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/SystemService.cs 2009-07-01 18:04:57 +0000
3+++ Do.Platform.Linux/src/Do.Platform/Do.Platform.Linux/SystemService.cs 2009-08-08 21:33:34 +0000
4@@ -19,7 +19,9 @@
5
6 using System;
7 using System.IO;
8+using System.Text;
9 using System.Reflection;
10+using System.Runtime.InteropServices;
11
12 using NDesk.DBus;
13 using org.freedesktop.DBus;
14@@ -29,6 +31,8 @@
15
16 using Gnome;
17
18+using Mono.Unix.Native;
19+
20 namespace Do.Platform.Linux
21 {
22
23@@ -55,6 +59,22 @@
24 event Action OnChanged;
25 }
26
27+ [DllImport ("libc")] // Linux
28+ private static extern int prctl (int option, byte [] arg2, IntPtr arg3, IntPtr arg4, IntPtr arg5);
29+
30+ private static int prctl (int option, string arg2)
31+ {
32+ return prctl (option, Encoding.ASCII.GetBytes (arg2 + "\0"), IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
33+ }
34+
35+ [DllImport ("libc")] // BSD
36+ private static extern void setproctitle (byte [] fmt, byte [] name);
37+
38+ private static void setproctitle (string fmt, string name)
39+ {
40+ setproctitle (Encoding.ASCII.GetBytes (fmt + "\0"), Encoding.ASCII.GetBytes (name + "\0"));
41+ }
42+
43 bool on_battery;
44
45 IPowerManagement power;
46@@ -213,5 +233,45 @@
47 Log<SystemService>.Error ("Failed to update autostart file: {0}", e.Message);
48 }
49 }
50+
51+ /// <summary>
52+ /// Sets the name of the current process on Linux. Throws EntryPointNotFoundException
53+ /// if we are not on Linux.
54+ /// </summary>
55+ /// <param name="name">
56+ /// A <see cref="System.String"/> name to set the process name to.
57+ /// </param>
58+ /// <returns>
59+ /// A <see cref="System.Boolean"/> indicating whether the set was successful.
60+ /// </returns>
61+ private static bool SetLinuxProcessName (string name)
62+ {
63+ return prctl (15 /* PR_SET_NAME */, name) == 0;
64+ }
65+
66+ /// <summary>
67+ /// Sets the name of the current process on BSD. Throws EntryPointNotFoundException
68+ /// if we are not on BSD.
69+ /// </summary>
70+ /// <param name="name">
71+ /// A <see cref="System.String"/> name to set the process name to.
72+ /// </param>
73+ /// <returns>
74+ /// A <see cref="System.Boolean"/> indicating whether the set was successful.
75+ /// </returns>
76+ private static void SetBSDProcessName (string name)
77+ {
78+ setproctitle ("%s", name);
79+ }
80+
81+ public override void SetProcessName (string name)
82+ {
83+ try {
84+ if (!SetLinuxProcessName (name))
85+ throw new ApplicationException ("Error setting process name: " + Stdlib.GetLastError ());
86+ } catch (EntryPointNotFoundException) {
87+ SetBSDProcessName (name);
88+ }
89+ }
90 }
91 }
92
93=== modified file 'Do.Platform/src/Do.Platform/AbstractSystemService.cs'
94--- Do.Platform/src/Do.Platform/AbstractSystemService.cs 2009-05-19 04:37:27 +0000
95+++ Do.Platform/src/Do.Platform/AbstractSystemService.cs 2009-08-08 20:41:29 +0000
96@@ -49,5 +49,6 @@
97 {
98 }
99
100+ public abstract void SetProcessName (string name);
101 }
102 }
103
104=== modified file 'Do.Platform/src/Do.Platform/Do.Platform.Default/DefaultSystemService.cs'
105--- Do.Platform/src/Do.Platform/Do.Platform.Default/DefaultSystemService.cs 2009-01-20 04:56:39 +0000
106+++ Do.Platform/src/Do.Platform/Do.Platform.Default/DefaultSystemService.cs 2009-08-08 20:41:29 +0000
107@@ -37,5 +37,10 @@
108 {
109 Log<DefaultSystemService>.Debug ("Cannot EnsureSingleApplicationInstance");
110 }
111+
112+ public override void SetProcessName (string name)
113+ {
114+ Log<DefaultSystemService>.Debug ("Cannot SetProcessName");
115+ }
116 }
117 }
118
119=== modified file 'Do/Do.mdp'
120--- Do/Do.mdp 2009-06-23 16:25:39 +0000
121+++ Do/Do.mdp 2009-08-08 20:41:29 +0000
122@@ -18,7 +18,6 @@
123 <File name="gtk-gui/generated.cs" subtype="Code" buildaction="Compile" />
124 <File name="src/Do.cs" subtype="Code" buildaction="Compile" />
125 <File name="src/XKeybinder.cs" subtype="Code" buildaction="Compile" />
126- <File name="src/Util.cs" subtype="Code" buildaction="Compile" />
127 <File name="src/Do.Core/ItemExtensions.cs" subtype="Code" buildaction="Compile" />
128 <File name="src/Do.Universe/InternalItemSource.cs" subtype="Code" buildaction="Compile" />
129 <File name="src/Do.Universe/ItemSourceItemSource.cs" subtype="Code" buildaction="Compile" />
130
131=== modified file 'Do/Makefile.am'
132--- Do/Makefile.am 2009-07-23 09:29:41 +0000
133+++ Do/Makefile.am 2009-08-08 20:41:29 +0000
134@@ -71,8 +71,7 @@
135 src/Do.cs \
136 src/Mono.Addins/AddinExtensions.cs \
137 src/Mono.Addins/Mono.Addins.Setup/AddinRepositoryEntryExtensions.cs \
138- src/PathExtensions.cs \
139- src/Util.cs
140+ src/PathExtensions.cs
141
142 RESOURCES = \
143 gtk-gui/gui.stetic \
144
145=== modified file 'Do/src/Do.cs'
146--- Do/src/Do.cs 2009-08-03 20:31:41 +0000
147+++ Do/src/Do.cs 2009-08-08 21:33:34 +0000
148@@ -62,7 +62,7 @@
149 Log.DisplayLevel = LogLevel.Debug;
150
151 try {
152- Util.SetProcessName ("gnome-do");
153+ Services.System.SetProcessName ("gnome-do");
154 } catch (Exception e) {
155 Log.Error ("Failed to set process name: {0}", e.Message);
156 }
157
158=== removed file 'Do/src/Util.cs'
159--- Do/src/Util.cs 2008-12-29 21:46:07 +0000
160+++ Do/src/Util.cs 1970-01-01 00:00:00 +0000
161@@ -1,99 +0,0 @@
162-/* Util.cs
163- *
164- * GNOME Do is the legal property of its developers. Please refer to the
165- * COPYRIGHT file distributed with this source distribution.
166- *
167- * This program is free software: you can redistribute it and/or modify
168- * it under the terms of the GNU General Public License as published by
169- * the Free Software Foundation, either version 3 of the License, or
170- * (at your option) any later version.
171- *
172- * This program is distributed in the hope that it will be useful,
173- * but WITHOUT ANY WARRANTY; without even the implied warranty of
174- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
175- * GNU General Public License for more details.
176- *
177- * You should have received a copy of the GNU General Public License
178- * along with this program. If not, see <http://www.gnu.org/licenses/>.
179- */
180-
181-using System;
182-using System.Text;
183-using System.Runtime.InteropServices;
184-
185-using Mono.Unix.Native;
186-
187-namespace Do
188-{
189-
190- public static class Util
191- {
192-
193- [DllImport ("libc")] // Linux
194- private static extern int prctl (int option, byte [] arg2, IntPtr arg3, IntPtr arg4, IntPtr arg5);
195-
196- private static int prctl (int option, byte [] arg2)
197- {
198- return prctl (option, arg2, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
199- }
200-
201- private static int prctl (int option, string arg2)
202- {
203- return prctl (option, Encoding.ASCII.GetBytes (arg2 + "\0"));
204- }
205-
206- [DllImport ("libc")] // BSD
207- private static extern void setproctitle (byte [] fmt, byte [] name);
208-
209- private static void setproctitle (string fmt, string name)
210- {
211- setproctitle (Encoding.ASCII.GetBytes (fmt + "\0"), Encoding.ASCII.GetBytes (name + "\0"));
212- }
213-
214- /// <summary>
215- /// Sets the name of the current process on Linux. Throws EntryPointNotFoundException
216- /// if we are not on Linux.
217- /// </summary>
218- /// <param name="name">
219- /// A <see cref="System.String"/> name to set the process name to.
220- /// </param>
221- /// <returns>
222- /// A <see cref="System.Boolean"/> indicating whether the set was successful.
223- /// </returns>
224- private static bool SetLinuxProcessName (string name)
225- {
226- return prctl (15 /* PR_SET_NAME */, name) == 0;
227- }
228-
229- /// <summary>
230- /// Sets the name of the current process on BSD. Throws EntryPointNotFoundException
231- /// if we are not on BSD.
232- /// </summary>
233- /// <param name="name">
234- /// A <see cref="System.String"/> name to set the process name to.
235- /// </param>
236- /// <returns>
237- /// A <see cref="System.Boolean"/> indicating whether the set was successful.
238- /// </returns>
239- private static void SetBSDProcessName (string name)
240- {
241- setproctitle ("%s", name);
242- }
243-
244- /// <summary>
245- /// Sets the name of the current process.
246- /// </summary>
247- /// <param name="name">
248- /// A <see cref="System.String"/> name to set the process name to.
249- /// </param>
250- public static void SetProcessName (string name)
251- {
252- try {
253- if (!SetLinuxProcessName (name))
254- throw new ApplicationException ("Error setting process name: " + Stdlib.GetLastError ());
255- } catch (EntryPointNotFoundException) {
256- SetBSDProcessName (name);
257- }
258- }
259- }
260-}