Do

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

Proposed by Chris S.
Status: Superseded
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
Robert Dyer (community) Approve
Review via email: mp+9885@code.launchpad.net

This proposal has been superseded by a proposal from 2009-08-09.

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

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 :

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
1289. By Chris S.

merge linux prctl methods

1290. By Chris S.

remove bsd junk, simplify code

Unmerged revisions

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