Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Proper libuv error handling

No more perror()
  • Loading branch information...
commit ab990ae2046e103a9b45403a63df82ee1efe42fb 1 parent 238bb9f
@felixge felixge authored piscisaureus committed
Showing with 10 additions and 10 deletions.
  1. +10 −10 src/unix/process.c
View
20 src/unix/process.c
@@ -331,23 +331,23 @@ int uv_spawn_sync(uv_loop_t* loop, uv_spawn_sync_t* spawn) {
spawn->stderr_read = 0;
if (spawn->stdout_buf && pipe(stdout_pipe)) {
- perror("pipe");
+ uv_err_new(loop, errno); /* pipe error */
return -1;
}
if (spawn->stderr_buf && pipe(stderr_pipe)) {
- perror("pipe");
+ uv_err_new(loop, errno); /* pipe error */
return -1;
}
if (pipe(sigchld_pipe)) {
- perror("pipe");
+ uv_err_new(loop, errno); /* pipe error */
return -1;
}
switch (spawn->pid = fork()) {
case -1:
- perror("fork");
+ uv_err_new(loop, errno); /* fork error */
return -1;
case 0: /* child */
@@ -367,7 +367,7 @@ int uv_spawn_sync(uv_loop_t* loop, uv_spawn_sync_t* spawn) {
}
execvp(spawn->file, spawn->args);
- perror("execvp()");
+ uv_err_new(loop, errno); /* execvp error */
_exit(127);
break;
}
@@ -394,7 +394,7 @@ int uv_spawn_sync(uv_loop_t* loop, uv_spawn_sync_t* spawn) {
siga.sa_mask = sigset;
siga.sa_flags = 0;
if (sigaction(SIGCHLD, &siga, (struct sigaction *)NULL) != 0) {
- perror("sigaction");
+ uv_err_new(loop, errno); /* sigaction error */
goto error;
}
@@ -428,7 +428,7 @@ int uv_spawn_sync(uv_loop_t* loop, uv_spawn_sync_t* spawn) {
continue;
}
- perror("select");
+ uv_err_new(loop, errno); /* select error */
goto error;
}
@@ -461,7 +461,7 @@ int uv_spawn_sync(uv_loop_t* loop, uv_spawn_sync_t* spawn) {
/* @TODO HANDLE EAGAIN / EINTR */
if (r == -1) {
- perror("read");
+ uv_err_new(loop, errno); /* read error */
goto error;
}
@@ -477,7 +477,7 @@ int uv_spawn_sync(uv_loop_t* loop, uv_spawn_sync_t* spawn) {
r = read(stderr_pipe[0], spawn->stderr_buf + spawn->stderr_read, spawn->stderr_size - spawn->stderr_read);
if (r == -1) {
- perror("read");
+ uv_err_new(loop, errno); /* read error */
goto error;
}
@@ -490,7 +490,7 @@ int uv_spawn_sync(uv_loop_t* loop, uv_spawn_sync_t* spawn) {
pid_t p = wait(&status);
if (p < 0) {
- perror("wait");
+ uv_err_new(loop, errno); /* wait error */
goto error;
}
Please sign in to comment.
Something went wrong with that request. Please try again.