From 585cc8a609dcb1471f1e9281881eebac8e5367f5 Mon Sep 17 00:00:00 2001 From: nightwing Date: Wed, 10 Jun 2015 11:40:40 +0000 Subject: [PATCH] better way to kill runner process --- node_modules/vfs-local/localfs.js | 19 ++++++++++++++----- package.json | 2 +- plugins/c9.fs/proc.js | 6 ++++++ plugins/c9.vfs.client/vfs_client.js | 1 + 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/node_modules/vfs-local/localfs.js b/node_modules/vfs-local/localfs.js index 9d7e2f0c..95553303 100644 --- a/node_modules/vfs-local/localfs.js +++ b/node_modules/vfs-local/localfs.js @@ -2248,12 +2248,12 @@ module.exports = function setup(fsOptions) { } function killtree(pid, options, callback) { - var code = options.code || "SIGKILL"; + var code = options.code || options.graceful ? "SIGTERM" : "SIGKILL"; - childrenOfPid(pid, function(err, pidlist){ + childrenOfPid(pid, function killList(err, pidlist){ if (err) return callback(err); - + pidlist.forEach(function (pid) { // if asked to kill ourselves do that only after killing all the children if (pid == process.pid) { @@ -2264,10 +2264,19 @@ module.exports = function setup(fsOptions) { try { process.kill(pid, code); } catch(e) { - // kill may throw if the pid does not exist. + if (e.code == "ESRCH") + return; // kill may throw if the pid does not exist. + // todo try killing with sudo in case of "EPERM" } }); - callback(null, {}); + if (options.graceful && code != "SIGKILL") { + code = "SIGKILL"; + setTimeout(function() { + killList(null, pidlist); + }, options.timeout || 800); + } else { + callback(null, {}); + } }); } diff --git a/package.json b/package.json index f0337f3b..fd2041cf 100644 --- a/package.json +++ b/package.json @@ -103,7 +103,7 @@ "c9.ide.recentfiles": "#7c099abf40", "c9.ide.remote": "#301d2ab519", "c9.ide.processlist": "#bc11818bb5", - "c9.ide.run": "#7fcd6173ba", + "c9.ide.run": "#9d632b19c0", "c9.ide.run.build": "#ad45874c88", "c9.ide.run.debug.xdebug": "#3b1520f83d", "c9.ide.save": "#a03709ef3f", diff --git a/plugins/c9.fs/proc.js b/plugins/c9.fs/proc.js index 9aac1923..d4a1c9e3 100644 --- a/plugins/c9.fs/proc.js +++ b/plugins/c9.fs/proc.js @@ -509,6 +509,12 @@ define(function(require, exports, module) { }); }); } + }, + /** + * @ignore + */ + killtree: function(pid, options, callback) { + vfs.killtree(pid, options, callback); } }); diff --git a/plugins/c9.vfs.client/vfs_client.js b/plugins/c9.vfs.client/vfs_client.js index 5339ee80..227dd9c2 100644 --- a/plugins/c9.vfs.client/vfs_client.js +++ b/plugins/c9.vfs.client/vfs_client.js @@ -410,6 +410,7 @@ define(function(require, exports, module) { pty: vfsCall.bind(null, "pty"), tmux: vfsCall.bind(null, "tmux"), execFile: vfsCall.bind(null, "execFile"), + killtree: vfsCall.bind(null, "killtree"), // Extending the API use: vfsCall.bind(null, "use"),