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

Commit

Permalink
uv: upgrade to aea5db5da1
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus committed Apr 27, 2012
1 parent 76de7c0 commit e221cd4
Show file tree
Hide file tree
Showing 14 changed files with 287 additions and 16 deletions.
5 changes: 5 additions & 0 deletions deps/uv/include/uv-private/uv-unix.h
Expand Up @@ -33,6 +33,7 @@
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <pwd.h>
#include <termios.h>

/* Note: May be cast to struct iovec. See writev(2). */
Expand All @@ -43,6 +44,10 @@ typedef struct {

typedef int uv_file;

/* Platform-specific definitions for uv_spawn support. */
typedef gid_t uv_gid_t;
typedef uid_t uv_uid_t;

/* Platform-specific definitions for uv_dlopen support. */
typedef void* uv_lib_t;
#define UV_DYNAMIC /* empty */
Expand Down
4 changes: 4 additions & 0 deletions deps/uv/include/uv-private/uv-win.h
Expand Up @@ -137,6 +137,10 @@ typedef struct uv_buf_t {

typedef int uv_file;

/* Platform-specific definitions for uv_spawn support. */
typedef unsigned char uv_uid_t;
typedef unsigned char uv_gid_t;

/* Platform-specific definitions for uv_dlopen support. */
typedef HMODULE uv_lib_t;
#define UV_DYNAMIC FAR WINAPI
Expand Down
28 changes: 28 additions & 0 deletions deps/uv/include/uv.h
Expand Up @@ -1058,6 +1058,34 @@ struct uv_process_s {
UV_EXTERN int uv_spawn(uv_loop_t*, uv_process_t*,
uv_process_options_t options);


/* Temporary fix for node. Do no use. */
enum uv_process_flags {
UV_PROCESS_SETUID = (1 << 0),
UV_PROCESS_SETGID = (1 << 1),
UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS = (1 << 2)
};

/* Temporary fix for node. Do not use. */
typedef struct uv_process_options2_s {
uv_exit_cb exit_cb; /* Called after the process exits. */
const char* file; /* Path to program to execute. */
char** args;
char** env;
char* cwd;
unsigned int flags;
uv_pipe_t* stdin_stream;
uv_pipe_t* stdout_stream;
uv_pipe_t* stderr_stream;
uv_uid_t uid;
uv_gid_t gid;
} uv_process_options2_t;

/* Temporary fix for node. Do not use. */
UV_EXTERN int uv_spawn2(uv_loop_t*, uv_process_t*,
uv_process_options2_t options);


/*
* Kills the process with the specified signal. The user must still
* call uv_close on the process.
Expand Down
4 changes: 4 additions & 0 deletions deps/uv/src/unix/error.c
Expand Up @@ -68,6 +68,9 @@ uv_err_code uv_translate_sys_error(int sys_errno) {
case EBADF: return UV_EBADF;
case EPIPE: return UV_EPIPE;
case EAGAIN: return UV_EAGAIN;
#if EWOULDBLOCK != EAGAIN
case EWOULDBLOCK: return UV_EAGAIN;
#endif
case ECONNRESET: return UV_ECONNRESET;
case EFAULT: return UV_EFAULT;
case EMFILE: return UV_EMFILE;
Expand All @@ -91,6 +94,7 @@ uv_err_code uv_translate_sys_error(int sys_errno) {
case EBUSY: return UV_EBUSY;
case ENOTEMPTY: return UV_ENOTEMPTY;
case ENOSPC: return UV_ENOSPC;
case ENOMEM: return UV_ENOMEM;
default: return UV_UNKNOWN;
}

Expand Down
1 change: 1 addition & 0 deletions deps/uv/src/unix/linux.c
Expand Up @@ -271,6 +271,7 @@ int uv_fs_event_init(uv_loop_t* loop,
| IN_MODIFY
| IN_DELETE
| IN_DELETE_SELF
| IN_MOVE_SELF
| IN_MOVED_FROM
| IN_MOVED_TO;

Expand Down
7 changes: 3 additions & 4 deletions deps/uv/src/unix/pipe.c
Expand Up @@ -254,16 +254,15 @@ void uv__pipe_accept(EV_P_ ev_io* watcher, int revents) {

sockfd = uv__accept(pipe->fd, (struct sockaddr *)&saddr, sizeof saddr);
if (sockfd == -1) {
if (errno == EAGAIN || errno == EWOULDBLOCK) {
assert(0 && "EAGAIN on uv__accept(pipefd)");
} else {
if (errno != EAGAIN && errno != EWOULDBLOCK) {
uv__set_sys_error(pipe->loop, errno);
pipe->connection_cb((uv_stream_t*)pipe, -1);
}
} else {
pipe->accepted_fd = sockfd;
pipe->connection_cb((uv_stream_t*)pipe, 0);
if (pipe->accepted_fd == sockfd) {
/* The user hasn't yet accepted called uv_accept() */
/* The user hasn't called uv_accept() yet */
ev_io_stop(pipe->loop->ev, &pipe->read_watcher);
}
}
Expand Down
20 changes: 18 additions & 2 deletions deps/uv/src/unix/process.c
Expand Up @@ -161,8 +161,8 @@ static int uv__process_init_pipe(uv_pipe_t* handle, int fds[2], int flags) {
# define SPAWN_WAIT_EXEC 1
#endif

int uv_spawn(uv_loop_t* loop, uv_process_t* process,
uv_process_options_t options) {
int uv_spawn2(uv_loop_t* loop, uv_process_t* process,
uv_process_options2_t options) {
/*
* Save environ in the case that we get it clobbered
* by the child process.
Expand All @@ -179,6 +179,12 @@ int uv_spawn(uv_loop_t* loop, uv_process_t* process,
pid_t pid;
int flags;

assert(options.file != NULL);
assert(!(options.flags & ~(UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS |
UV_PROCESS_SETGID |
UV_PROCESS_SETUID)));


uv__handle_init(loop, (uv_handle_t*)process, UV_PROCESS);
loop->counters.process_init++;

Expand Down Expand Up @@ -268,6 +274,16 @@ int uv_spawn(uv_loop_t* loop, uv_process_t* process,
_exit(127);
}

if ((options.flags & UV_PROCESS_SETGID) && setgid(options.gid)) {
perror("setgid()");
_exit(127);
}

if ((options.flags & UV_PROCESS_SETUID) && setuid(options.uid)) {
perror("setuid()");
_exit(127);
}

environ = options.env;

execvp(options.file, options.args);
Expand Down
6 changes: 3 additions & 3 deletions deps/uv/src/unix/stream.c
Expand Up @@ -176,7 +176,7 @@ void uv__server_io(EV_P_ ev_io* watcher, int revents) {
fd = uv__accept(stream->fd, (struct sockaddr*)&addr, sizeof addr);

if (fd < 0) {
if (errno == EAGAIN) {
if (errno == EAGAIN || errno == EWOULDBLOCK) {
/* No problem. */
return;
} else if (errno == EMFILE) {
Expand Down Expand Up @@ -416,7 +416,7 @@ static void uv__write(uv_stream_t* stream) {
}

if (n < 0) {
if (errno != EAGAIN) {
if (errno != EAGAIN && errno != EWOULDBLOCK) {
/* Error */
req->error = errno;
stream->write_queue_size -= uv__write_req_size(req);
Expand Down Expand Up @@ -562,7 +562,7 @@ static void uv__read(uv_stream_t* stream) {

if (nread < 0) {
/* Error */
if (errno == EAGAIN) {
if (errno == EAGAIN || errno == EWOULDBLOCK) {
/* Wait for the next one. */
if (stream->flags & UV_READING) {
ev_io_start(ev, &stream->read_watcher);
Expand Down
26 changes: 26 additions & 0 deletions deps/uv/src/uv-common.c
Expand Up @@ -261,3 +261,29 @@ int uv_tcp_connect6(uv_connect_t* req,

return uv__tcp_connect6(req, handle, address, cb);
}


/* Thunk that converts uv_process_options_t into uv_process_options2_t, */
/* and then calls uv_spawn2. */
int uv_spawn(uv_loop_t* loop, uv_process_t* process,
uv_process_options_t options) {
uv_process_options2_t options2;

options2.exit_cb = options.exit_cb;
options2.file = options.file;
options2.args = options.args;
options2.cwd = options.cwd;
options2.env = options.env;
options2.stdin_stream = options.stdin_stream;
options2.stdout_stream = options.stdout_stream;
options2.stderr_stream = options.stderr_stream;

options2.flags = 0;
if (options.windows_verbatim_arguments) {
options2.flags |= UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS;
}

/* No need to set gid and uid. */

return uv_spawn2(loop, process, options2);
}
2 changes: 2 additions & 0 deletions deps/uv/src/win/error.c
Expand Up @@ -68,6 +68,8 @@ uv_err_code uv_translate_sys_error(int sys_errno) {
switch (sys_errno) {
case ERROR_SUCCESS: return UV_OK;
case ERROR_FILE_NOT_FOUND: return UV_ENOENT;
case ERROR_INVALID_NAME: return UV_ENOENT;
case ERROR_MOD_NOT_FOUND: return UV_ENOENT;
case ERROR_PATH_NOT_FOUND: return UV_ENOENT;
case ERROR_ACCESS_DENIED: return UV_EPERM;
case ERROR_NOACCESS: return UV_EACCES;
Expand Down
2 changes: 1 addition & 1 deletion deps/uv/src/win/fs.c
Expand Up @@ -913,7 +913,7 @@ static DWORD WINAPI uv_fs_thread_proc(void* parameter) {
fs__fsync(req, (uv_file)req->arg0);
break;
case UV_FS_FTRUNCATE:
fs__ftruncate(req, (uv_file)req->arg0, (off_t)req->stat.st_atime);
fs__ftruncate(req, (uv_file)req->arg0, req->stat.st_atime);
break;
case UV_FS_SENDFILE:
fs__sendfile(req,
Expand Down
15 changes: 10 additions & 5 deletions deps/uv/src/win/process.c
Expand Up @@ -860,8 +860,8 @@ static int duplicate_std_handle(uv_loop_t* loop, DWORD id, HANDLE* dup) {
}


int uv_spawn(uv_loop_t* loop, uv_process_t* process,
uv_process_options_t options) {
int uv_spawn2(uv_loop_t* loop, uv_process_t* process,
uv_process_options2_t options) {
int err = 0, keep_child_stdio_open = 0;
wchar_t* path = NULL;
int size;
Expand All @@ -872,17 +872,22 @@ int uv_spawn(uv_loop_t* loop, uv_process_t* process,
STARTUPINFOW startup;
PROCESS_INFORMATION info;

if (!options.file) {
uv__set_artificial_error(loop, UV_EINVAL);
if (options.flags & (UV_PROCESS_SETGID | UV_PROCESS_SETUID)) {
uv__set_sys_error(loop, UV_ENOTSUP);
return -1;
}

assert(options.file != NULL);
assert(!(options.flags & ~(UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS |
UV_PROCESS_SETGID |
UV_PROCESS_SETUID)));

uv_process_init(loop, process);

process->exit_cb = options.exit_cb;
UTF8_TO_UTF16(options.file, application);
arguments = options.args ? make_program_args(options.args,
options.windows_verbatim_arguments) : NULL;
options.flags & UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS) : NULL;
env = options.env ? make_program_env(options.env) : NULL;

if (options.cwd) {
Expand Down
10 changes: 9 additions & 1 deletion deps/uv/test/test-list.h
Expand Up @@ -110,6 +110,8 @@ TEST_DECLARE (spawn_stdout)
TEST_DECLARE (spawn_stdin)
TEST_DECLARE (spawn_and_kill)
TEST_DECLARE (spawn_and_ping)
TEST_DECLARE (spawn_setuid_fails)
TEST_DECLARE (spawn_setgid_fails)
TEST_DECLARE (kill)
TEST_DECLARE (fs_file_noent)
TEST_DECLARE (fs_file_nametoolong)
Expand All @@ -133,7 +135,7 @@ TEST_DECLARE (fs_event_watch_file_current_dir)
TEST_DECLARE (fs_event_no_callback_on_close)
TEST_DECLARE (fs_event_immediate_close)
TEST_DECLARE (fs_event_close_with_pending_event)
TEST_DECLARE (fs_event_close_in_callback);
TEST_DECLARE (fs_event_close_in_callback)
TEST_DECLARE (fs_readdir_empty_dir)
TEST_DECLARE (fs_readdir_file)
TEST_DECLARE (fs_open_dir)
Expand All @@ -147,6 +149,8 @@ TEST_DECLARE (environment_creation)
TEST_DECLARE (listen_with_simultaneous_accepts)
TEST_DECLARE (listen_no_simultaneous_accepts)
TEST_DECLARE (fs_stat_root)
#else
TEST_DECLARE (spawn_setuid_setgid)
#endif
HELPER_DECLARE (tcp4_echo_server)
HELPER_DECLARE (tcp6_echo_server)
Expand Down Expand Up @@ -289,6 +293,8 @@ TASK_LIST_START
TEST_ENTRY (spawn_stdin)
TEST_ENTRY (spawn_and_kill)
TEST_ENTRY (spawn_and_ping)
TEST_ENTRY (spawn_setuid_fails)
TEST_ENTRY (spawn_setgid_fails)
TEST_ENTRY (kill)
#ifdef _WIN32
TEST_ENTRY (spawn_detect_pipe_name_collisions_on_windows)
Expand All @@ -297,6 +303,8 @@ TASK_LIST_START
TEST_ENTRY (listen_with_simultaneous_accepts)
TEST_ENTRY (listen_no_simultaneous_accepts)
TEST_ENTRY (fs_stat_root)
#else
TEST_ENTRY (spawn_setuid_setgid)
#endif

TEST_ENTRY (fs_file_noent)
Expand Down

0 comments on commit e221cd4

Please sign in to comment.