~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric-updates

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Core/MonoDevelop.Core.Execution/ProcessService.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-18 08:40:51 UTC
  • mfrom: (1.2.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090218084051-gh8m6ukvokbwj7cf
Tags: 1.9.2+dfsg-1ubuntu1
* Merge from Debian Experimental (LP: #330519), remaining Ubuntu changes:
  + debian/control:
    - Update for Gnome# 2.24
    - Add libmono-cairo1.0-cil to build-deps to fool pkg-config check

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
using System.IO;
32
32
using System.Collections.Generic;
33
33
using System.Threading;
 
34
using System.Collections;
34
35
using System.Diagnostics;
35
36
using Mono.Remoting.Channels.Unix;
36
37
using System.Runtime.Remoting;
43
44
 
44
45
namespace MonoDevelop.Core.Execution
45
46
{
46
 
        public class ProcessService : AbstractService
 
47
        public class ProcessService : IDisposable
47
48
        {
48
49
                ProcessHostController externalProcess;
49
50
                List<ExtensionNode> executionHandlers;
72
73
                        }
73
74
                }
74
75
                
75
 
                public override void InitializeService ()
 
76
                internal ProcessService ()
76
77
                {
77
78
                        if (PlatformID.Unix != Environment.OSVersion.Platform) {
78
79
                                remotingChannel = "tcp";
138
139
                                
139
140
                        p.StartInfo = startInfo;
140
141
                        ProcessEnvironmentVariableOverrides (p.StartInfo);
141
 
                        p.EnableRaisingEvents = true;
 
142
                        
 
143
                        // WORKAROUND for "Bug 410743 - wapi leak in System.Diagnostic.Process"
 
144
                        // Process leaks when an exit event is registered
 
145
                        // instead we use another thread to monitor I/O and wait for exit
 
146
                        // p.EnableRaisingEvents = true;
142
147
                        
143
148
                        p.Start ();
144
149
                        return p;
177
182
                public ProcessWrapper StartConsoleProcess (string command, string arguments, string workingDirectory, IDictionary<string, string> environmentVariables, IConsole console, EventHandler exited)
178
183
                {
179
184
                        if (console == null || (console is ExternalConsole)) {
180
 
                                string additionalCommands = "";
181
 
                                if (!console.CloseOnDispose)
182
 
                                        additionalCommands = @"echo; read -p 'Press any key to continue...' -n1;";
183
 
                                string xtermCommand = String.Format (
184
 
                                        @" -title ""{4}"" -e ""cd {3} ; '{0}' {1} ; {2}""",
185
 
                                        command,
186
 
                                        arguments.Replace ("\\", "\\\\").Replace ("\"", "\\\""),
187
 
                                        additionalCommands,
188
 
                                        workingDirectory.Replace (" ", "\\ "),
189
 
                                    GettextCatalog.GetString ("MonoDevelop External Console")
190
 
                                );
191
 
                                ProcessStartInfo psi = new ProcessStartInfo("xterm",xtermCommand);
192
 
                                psi.UseShellExecute = false;
193
 
                                
194
 
                                if (workingDirectory != null)
195
 
                                        psi.WorkingDirectory = workingDirectory;
 
185
                                ProcessStartInfo psi = ExternalConsoleLocator.GetConsoleProcess (command, arguments, workingDirectory, 
 
186
                                    GettextCatalog.GetString ("MonoDevelop External Console"), !console.CloseOnDispose);
196
187
 
197
 
                                psi.UseShellExecute  =  false;
198
 
                                
199
188
                                if (environmentVariables != null)
200
189
                                        foreach (KeyValuePair<string, string> kvp in environmentVariables)
201
190
                                                psi.EnvironmentVariables [kvp.Key] = kvp.Value;
232
221
                        return null;
233
222
                }
234
223
                
 
224
                public IExecutionMode[] GetExecutionModes ()
 
225
                {
 
226
                        ExtensionNodeList nodes = AddinManager.GetExtensionNodes ("/MonoDevelop/Core/ExecutionModes", typeof(ExecutionModeNode));
 
227
                        IExecutionMode[] modes = new IExecutionMode [nodes.Count];
 
228
                        nodes.CopyTo (modes, 0);
 
229
                        return modes;
 
230
                }
 
231
                
 
232
                public IExecutionMode DefaultExecutionMode {
 
233
                        get {
 
234
                                return AddinManager.GetExtensionNode ("/MonoDevelop/Core/ExecutionModes/Default") as IExecutionMode;
 
235
                        }
 
236
                }
 
237
                
235
238
                void OnExtensionChange (object s, ExtensionNodeEventArgs args)
236
239
                {
237
240
                        if (args.Change == ExtensionChange.Add)
293
296
                {
294
297
                        if (remotingChannel == "tcp") {
295
298
                                IChannel ch = ChannelServices.GetChannel ("tcp");
296
 
                                if (ch == null)
297
 
                                        ChannelServices.RegisterChannel (new TcpChannel (0), false);
 
299
                                if (ch == null) {
 
300
                                        IDictionary dict = new Hashtable ();
 
301
                                        BinaryClientFormatterSinkProvider clientProvider = new BinaryClientFormatterSinkProvider();
 
302
                                        BinaryServerFormatterSinkProvider serverProvider = new BinaryServerFormatterSinkProvider();
 
303
 
 
304
                                        dict ["port"] = 0;
 
305
                                        serverProvider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
 
306
 
 
307
                                        ChannelServices.RegisterChannel (new TcpChannel (dict, clientProvider, serverProvider), false);
 
308
                                }
298
309
                        } else {
299
310
                                IChannel ch = ChannelServices.GetChannel ("unix");
300
311
                                if (ch == null) {
305
316
                        return remotingChannel;
306
317
                }
307
318
                
308
 
                public override void UnloadService ()
 
319
                public virtual void Dispose ()
309
320
                {
310
321
                        if (unixRemotingFile != null)
311
322
                                File.Delete (unixRemotingFile);
316
327
        {
317
328
                public IConsole console;
318
329
                EventHandler exited;
319
 
                IAsyncOperation operation;
 
330
                IProcessAsyncOperation operation;
320
331
 
321
 
                public ProcessMonitor (IConsole console, IAsyncOperation operation, EventHandler exited)
 
332
                public ProcessMonitor (IConsole console, IProcessAsyncOperation operation, EventHandler exited)
322
333
                {
323
334
                        this.exited = exited;
324
335
                        this.operation = operation;
332
343
                        try {
333
344
                                if (exited != null)
334
345
                                        exited (op, null);
 
346
                                
 
347
                                if (Mono.Unix.Native.Syscall.WIFSIGNALED (operation.ExitCode))
 
348
                                        console.Log.WriteLine (GettextCatalog.GetString ("The application was terminated by a signal: {0}"), Mono.Unix.Native.Syscall.WTERMSIG (operation.ExitCode));
 
349
                                else if (operation.ExitCode != 0)
 
350
                                        console.Log.WriteLine (GettextCatalog.GetString ("The application exited with code: {0}"), operation.ExitCode);
335
351
                        } finally {
336
352
                                console.Dispose ();
337
353
                        }
357
373
                
358
374
                public void WriteOut (object sender, string s)
359
375
                {
360
 
                        writer.WriteLine (s);
 
376
                        writer.Write (s);
361
377
                }
362
378
                
363
379
                public static ProcessEventHandler GetWriteHandler (TextWriter tw)