Skip to content

Commit

Permalink
Make sure spawn_as_logged_user gets an error if there was one.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas committed May 21, 2014
1 parent 32667c6 commit 335b204
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions lib/system/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ system.tempfile_path = function(filename){
return join(system.paths.temp, filename);
};

system.spawn_as_logged_user = function(command, args, callback){
as_logged_user('spawn', command, args, callback);
system.spawn_as_logged_user = function(command, args, cb){
as_logged_user('spawn', command, args, cb);
}

system.run_as_logged_user = function(command, args, callback){
as_logged_user('exec', command, args, callback);
system.run_as_logged_user = function(command, args, cb){
as_logged_user('exec', command, args, cb);
};

system.get_running_user = function(){
Expand Down Expand Up @@ -71,12 +71,12 @@ system.get_os_info = remember(function(cb){
});
})

var as_logged_user = function(type, bin, args, callback){
var as_logged_user = function(type, bin, args, cb) {

var runner, command;
var finished, runner, command;

system.get_logged_user(function(err, user){
if (err) return callback(err);
if (err) return cb(err);

if (user == system.get_running_user()) {
runner = bin;
Expand All @@ -99,15 +99,26 @@ var as_logged_user = function(type, bin, args, callback){
}

if (type == 'exec')
return cp.exec(runner + ' ' + command.join(' '), callback);
return cp.exec(runner + ' ' + command.join(' '), cb);

var done = function(e) {
if (finished) return;

finished = true;
cb(e, child);
}

// ok, so they want spawn mode. let's fire up the command.
var child = cp.spawn(runner, command)

// set a listener on error, so if it fails the app doesn't crash!
child.on('error', function(err) { /* */ })
child.on('error', function(err) {
if (err.code == 'ENOENT')
err.message = 'ENOENT - Executable not found: ' + runner;

done(err);
})

// now, back to you at the studio.
callback(null, child);
process.nextTick(done)
});
};

0 comments on commit 335b204

Please sign in to comment.