diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2013-07-16 21:04:31 +0200 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2013-07-20 12:04:35 +0200 |
commit | 0e48cb4998a89a2adae95d97f3bce5f89c77d762 (patch) | |
tree | 754bf7e9765fbeb8f0fe9418d9d399335c7c7af8 /deps/uv/src/unix/sunos.c | |
parent | 221c689ebbac9bda42c005b7f0278ce420766b22 (diff) | |
download | android-node-v8-0e48cb4998a89a2adae95d97f3bce5f89c77d762.tar.gz android-node-v8-0e48cb4998a89a2adae95d97f3bce5f89c77d762.tar.bz2 android-node-v8-0e48cb4998a89a2adae95d97f3bce5f89c77d762.zip |
deps: upgrade libuv to 3ee4d3f
Diffstat (limited to 'deps/uv/src/unix/sunos.c')
-rw-r--r-- | deps/uv/src/unix/sunos.c | 125 |
1 files changed, 62 insertions, 63 deletions
diff --git a/deps/uv/src/unix/sunos.c b/deps/uv/src/unix/sunos.c index 2413105c0f..829f0723fc 100644 --- a/deps/uv/src/unix/sunos.c +++ b/deps/uv/src/unix/sunos.c @@ -62,13 +62,22 @@ int uv__platform_loop_init(uv_loop_t* loop, int default_loop) { + int err; + int fd; + loop->fs_fd = -1; - loop->backend_fd = port_create(); + loop->backend_fd = -1; - if (loop->backend_fd == -1) - return -1; + fd = port_create(); + if (fd == -1) + return -errno; - uv__cloexec(loop->backend_fd, 1); + err = uv__cloexec(fd, 1); + if (err) { + close(fd); + return err; + } + loop->backend_fd = fd; return 0; } @@ -243,21 +252,17 @@ int uv_exepath(char* buffer, size_t* size) { ssize_t res; char buf[128]; - if (buffer == NULL) - return (-1); - - if (size == NULL) - return (-1); + if (buffer == NULL || size == NULL) + return -EINVAL; (void) snprintf(buf, sizeof(buf), "/proc/%lu/path/a.out", (unsigned long) getpid()); res = readlink(buf, buffer, *size - 1); - - if (res < 0) - return (res); + if (res == -1) + return -errno; buffer[res] = '\0'; *size = res; - return (0); + return 0; } @@ -278,18 +283,20 @@ void uv_loadavg(double avg[3]) { #if defined(PORT_SOURCE_FILE) -static void uv__fs_event_rearm(uv_fs_event_t *handle) { +static int uv__fs_event_rearm(uv_fs_event_t *handle) { if (handle->fd == -1) - return; + return -EBADF; if (port_associate(handle->loop->fs_fd, PORT_SOURCE_FILE, (uintptr_t) &handle->fo, FILE_ATTRIB | FILE_MODIFIED, handle) == -1) { - uv__set_sys_error(handle->loop, errno); + return -errno; } handle->fd = PORT_LOADED; + + return 0; } @@ -340,7 +347,7 @@ static void uv__fs_event_read(uv_loop_t* loop, while (handle->fd != PORT_DELETED); if (handle != NULL && handle->fd != PORT_DELETED) - uv__fs_event_rearm(handle); + uv__fs_event_rearm(handle); /* FIXME(bnoordhuis) Check return code. */ } @@ -353,10 +360,9 @@ int uv_fs_event_init(uv_loop_t* loop, int first_run = 0; if (loop->fs_fd == -1) { - if ((portfd = port_create()) == -1) { - uv__set_sys_error(loop, errno); - return -1; - } + portfd = port_create(); + if (portfd == -1) + return -errno; loop->fs_fd = portfd; first_run = 1; } @@ -369,7 +375,7 @@ int uv_fs_event_init(uv_loop_t* loop, memset(&handle->fo, 0, sizeof handle->fo); handle->fo.fo_name = handle->filename; - uv__fs_event_rearm(handle); + uv__fs_event_rearm(handle); /* FIXME(bnoordhuis) Check return code. */ if (first_run) { uv__io_init(&loop->fs_event_watcher, uv__fs_event_read, portfd); @@ -398,8 +404,7 @@ int uv_fs_event_init(uv_loop_t* loop, const char* filename, uv_fs_event_cb cb, int flags) { - uv__set_sys_error(loop, ENOSYS); - return -1; + return -ENOSYS; } @@ -415,76 +420,74 @@ char** uv_setup_args(int argc, char** argv) { } -uv_err_t uv_set_process_title(const char* title) { - return uv_ok_; +int uv_set_process_title(const char* title) { + return 0; } -uv_err_t uv_get_process_title(char* buffer, size_t size) { +int uv_get_process_title(char* buffer, size_t size) { if (size > 0) { buffer[0] = '\0'; } - return uv_ok_; + return 0; } -uv_err_t uv_resident_set_memory(size_t* rss) { +int uv_resident_set_memory(size_t* rss) { psinfo_t psinfo; - uv_err_t err; + int err; int fd; fd = open("/proc/self/psinfo", O_RDONLY); if (fd == -1) - return uv__new_sys_error(errno); - - err = uv_ok_; + return -errno; - if (read(fd, &psinfo, sizeof(psinfo)) == sizeof(psinfo)) + /* FIXME(bnoordhuis) Handle EINTR. */ + err = -EINVAL; + if (read(fd, &psinfo, sizeof(psinfo)) == sizeof(psinfo)) { *rss = (size_t)psinfo.pr_rssize * 1024; - else - err = uv__new_sys_error(EINVAL); - + err = 0; + } close(fd); return err; } -uv_err_t uv_uptime(double* uptime) { +int uv_uptime(double* uptime) { kstat_ctl_t *kc; kstat_t *ksp; kstat_named_t *knp; long hz = sysconf(_SC_CLK_TCK); - if ((kc = kstat_open()) == NULL) - return uv__new_sys_error(errno); + kc = kstat_open(); + if (kc == NULL) + return -EPERM; ksp = kstat_lookup(kc, (char*) "unix", 0, (char*) "system_misc"); - if (kstat_read(kc, ksp, NULL) == -1) { *uptime = -1; } else { knp = (kstat_named_t*) kstat_data_lookup(ksp, (char*) "clk_intr"); *uptime = knp->value.ul / hz; } - kstat_close(kc); - return uv_ok_; + return 0; } -uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { +int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { int lookup_instance; kstat_ctl_t *kc; kstat_t *ksp; kstat_named_t *knp; uv_cpu_info_t* cpu_info; - if ((kc = kstat_open()) == NULL) { - return uv__new_sys_error(errno); - } + kc = kstat_open(); + if (kc == NULL) + return -EPERM; /* Get count of cpus */ lookup_instance = 0; @@ -492,10 +495,10 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { lookup_instance++; } - *cpu_infos = (uv_cpu_info_t*) - malloc(lookup_instance * sizeof(uv_cpu_info_t)); + *cpu_infos = malloc(lookup_instance * sizeof(**cpu_infos)); if (!(*cpu_infos)) { - return uv__new_artificial_error(UV_ENOMEM); + kstat_close(kc); + return -ENOMEM; } *count = lookup_instance; @@ -557,7 +560,7 @@ uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { kstat_close(kc); - return uv_ok_; + return 0; } @@ -572,18 +575,16 @@ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) { } -uv_err_t uv_interface_addresses(uv_interface_address_t** addresses, - int* count) { +int uv_interface_addresses(uv_interface_address_t** addresses, int* count) { #ifdef SUNOS_NO_IFADDRS - return uv__new_artificial_error(UV_ENOSYS); + return -ENOSYS; #else struct ifaddrs *addrs, *ent; char ip[INET6_ADDRSTRLEN]; uv_interface_address_t* address; - if (getifaddrs(&addrs) != 0) { - return uv__new_sys_error(errno); - } + if (getifaddrs(&addrs)) + return -errno; *count = 0; @@ -598,11 +599,9 @@ uv_err_t uv_interface_addresses(uv_interface_address_t** addresses, (*count)++; } - *addresses = (uv_interface_address_t*) - malloc(*count * sizeof(uv_interface_address_t)); - if (!(*addresses)) { - return uv__new_artificial_error(UV_ENOMEM); - } + *addresses = malloc(*count * sizeof(**addresses)); + if (!(*addresses)) + return -ENOMEM; address = *addresses; @@ -639,7 +638,7 @@ uv_err_t uv_interface_addresses(uv_interface_address_t** addresses, freeifaddrs(addrs); - return uv_ok_; + return 0; #endif /* SUNOS_NO_IFADDRS */ } |