Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
child_process_uv: Handle spawn errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Aug 1, 2011
1 parent 8da4831 commit b30ad11
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
12 changes: 9 additions & 3 deletions deps/uv/src/win/process.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -680,7 +680,9 @@ int uv_spawn(uv_process_t* process, uv_process_options_t options) {


/* Create stdio pipes. */ /* Create stdio pipes. */
if (options.stdin_stream) { if (options.stdin_stream) {
err = uv_create_stdio_pipe_pair(options.stdin_stream, &process->stdio_pipes[0].child_pipe, PIPE_ACCESS_OUTBOUND, GENERIC_READ | FILE_WRITE_ATTRIBUTES); err = uv_create_stdio_pipe_pair(options.stdin_stream,
&process->stdio_pipes[0].child_pipe, PIPE_ACCESS_OUTBOUND,
GENERIC_READ | FILE_WRITE_ATTRIBUTES);
if (err) { if (err) {
goto done; goto done;
} }
Expand All @@ -689,7 +691,9 @@ int uv_spawn(uv_process_t* process, uv_process_options_t options) {
} }


if (options.stdout_stream) { if (options.stdout_stream) {
err = uv_create_stdio_pipe_pair(options.stdout_stream, &process->stdio_pipes[1].child_pipe, PIPE_ACCESS_INBOUND, GENERIC_WRITE); err = uv_create_stdio_pipe_pair(options.stdout_stream,
&process->stdio_pipes[1].child_pipe, PIPE_ACCESS_INBOUND,
GENERIC_WRITE);
if (err) { if (err) {
goto done; goto done;
} }
Expand All @@ -698,7 +702,9 @@ int uv_spawn(uv_process_t* process, uv_process_options_t options) {
} }


if (options.stderr_stream) { if (options.stderr_stream) {
err = uv_create_stdio_pipe_pair(options.stderr_stream, &process->stdio_pipes[2].child_pipe, PIPE_ACCESS_INBOUND, GENERIC_WRITE); err = uv_create_stdio_pipe_pair(options.stderr_stream,
&process->stdio_pipes[2].child_pipe, PIPE_ACCESS_INBOUND,
GENERIC_WRITE);
if (err) { if (err) {
goto done; goto done;
} }
Expand Down
33 changes: 33 additions & 0 deletions lib/child_process_uv.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ var spawn = exports.spawn = function(file, args, options) {




function maybeExit(subprocess) { function maybeExit(subprocess) {
console.log("maybeExit");
subprocess._closesGot++; subprocess._closesGot++;


if (subprocess._closesGot == subprocess._closesNeeded) { if (subprocess._closesGot == subprocess._closesNeeded) {
Expand All @@ -213,6 +214,8 @@ function ChildProcess() {
if (signalCode) self.signalCode = signalCode; if (signalCode) self.signalCode = signalCode;
self.exitCode = exitCode; self.exitCode = exitCode;


console.error("onexit ", exitCode, signalCode);

if (self.stdin) { if (self.stdin) {
self.stdin.destroy(); self.stdin.destroy();
} }
Expand Down Expand Up @@ -250,8 +253,28 @@ ChildProcess.prototype.spawn = function(options) {


var r = this._internal.spawn(options); var r = this._internal.spawn(options);


if (r) {
if (options.stdinStream) {
options.stdinStream.close();
}

if (options.stdoutStream) {
options.stdoutStream.close();
}

if (options.stderrStream) {
options.stderrStream.close();
}

this._internal.close();
this._internal = null;
throw errnoException("spawn", errno)
}

this.pid = this._internal.pid; this.pid = this._internal.pid;


console.log("started pid ", this.pid);

if (options.stdinStream) { if (options.stdinStream) {
this.stdin = createSocket(options.stdinStream, false); this.stdin = createSocket(options.stdinStream, false);
} }
Expand All @@ -275,6 +298,16 @@ ChildProcess.prototype.spawn = function(options) {
return r; return r;
}; };


function errnoException(errorno, syscall) {
// TODO make this more compatible with ErrnoException from src/node.cc
// Once all of Node is using this function the ErrnoException from
// src/node.cc should be removed.
var e = new Error(syscall + ' ' + errorno);
e.errno = e.code = errorno;
e.syscall = syscall;
return e;
}



ChildProcess.prototype.kill = function(sig) { ChildProcess.prototype.kill = function(sig) {
throw new Error("implement me"); throw new Error("implement me");
Expand Down

0 comments on commit b30ad11

Please sign in to comment.