diff options
author | Bert Belder <bertbelder@gmail.com> | 2012-09-14 02:56:41 +0200 |
---|---|---|
committer | Bert Belder <bertbelder@gmail.com> | 2012-09-14 02:56:41 +0200 |
commit | d908b83f59fd6b3ccb83680172a28866bb255364 (patch) | |
tree | f682bd84f357a8b46d34fac6602a11d0100db2c4 /deps/uv/src/unix | |
parent | 7ab4a77d6fdb2b98b3c34fda9d001ed9d91297c7 (diff) | |
download | node-d908b83f59fd6b3ccb83680172a28866bb255364.tar.gz |
uv: upgrade to a28f145
Diffstat (limited to 'deps/uv/src/unix')
-rw-r--r-- | deps/uv/src/unix/aix.c | 393 | ||||
-rw-r--r-- | deps/uv/src/unix/eio/config_aix.h | 84 | ||||
-rw-r--r-- | deps/uv/src/unix/eio/eio.c | 2 | ||||
-rw-r--r-- | deps/uv/src/unix/eio/xthread.h | 4 | ||||
-rw-r--r-- | deps/uv/src/unix/error.c | 2 | ||||
-rw-r--r-- | deps/uv/src/unix/ev/config_aix.h | 122 | ||||
-rw-r--r-- | deps/uv/src/unix/ev/ev.c | 4 |
7 files changed, 606 insertions, 5 deletions
diff --git a/deps/uv/src/unix/aix.c b/deps/uv/src/unix/aix.c new file mode 100644 index 000000000..5637e8711 --- /dev/null +++ b/deps/uv/src/unix/aix.c @@ -0,0 +1,393 @@ +/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "uv.h" +#include "internal.h" + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include <assert.h> +#include <errno.h> + +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/ioctl.h> +#include <net/if.h> +#include <netinet/in.h> +#include <arpa/inet.h> + +#include <sys/time.h> +#include <unistd.h> +#include <fcntl.h> +#include <utmp.h> + +#include <sys/protosw.h> +#include <libperfstat.h> +#include <sys/proc.h> +#include <sys/procfs.h> + +uint64_t uv_hrtime() { + uint64_t G = 1000000000; + timebasestruct_t t; + read_wall_time(&t, TIMEBASE_SZ); + time_base_to_time(&t, TIMEBASE_SZ); + return (uint64_t) t.tb_high * G + t.tb_low; +} + + +/* + * We could use a static buffer for the path manipulations that we need outside + * of the function, but this function could be called by multiple consumers and + * we don't want to potentially create a race condition in the use of snprintf. + */ +int uv_exepath(char* buffer, size_t* size) { + ssize_t res; + char pp[64], cwdl[PATH_MAX]; + size_t cwdl_len; + struct psinfo ps; + int fd; + + if (buffer == NULL) + return (-1); + + if (size == NULL) + return (-1); + + (void) snprintf(pp, sizeof(pp), "/proc/%lu/cwd", (unsigned long) getpid()); + + res = readlink(pp, cwdl, sizeof(cwdl) - 1); + if (res < 0) + return res; + + cwdl[res] = '\0'; + cwdl_len = res; + + (void) snprintf(pp, sizeof(pp), "/proc/%lu/psinfo", (unsigned long) getpid()); + fd = open(pp, O_RDONLY); + if (fd < 0) + return fd; + + res = read(fd, &ps, sizeof(ps)); + close(fd); + if (res < 0) + return res; + + (void) snprintf(buffer, *size, "%s%s", cwdl, ps.pr_fname); + *size = strlen(buffer); + return 0; +} + + +uint64_t uv_get_free_memory(void) { + perfstat_memory_total_t mem_total; + int result = perfstat_memory_total(NULL, &mem_total, sizeof(mem_total), 1); + if (result == -1) { + return 0; + } + return mem_total.real_free * 4096; +} + + +uint64_t uv_get_total_memory(void) { + perfstat_memory_total_t mem_total; + int result = perfstat_memory_total(NULL, &mem_total, sizeof(mem_total), 1); + if (result == -1) { + return 0; + } + return mem_total.real_total * 4096; +} + + +void uv_loadavg(double avg[3]) { + perfstat_cpu_total_t ps_total; + int result = perfstat_cpu_total(NULL, &ps_total, sizeof(ps_total), 1); + if (result == -1) { + avg[0] = 0.; avg[1] = 0.; avg[2] = 0.; + return; + } + avg[0] = ps_total.loadavg[0] / (double)(1 << SBITS); + avg[1] = ps_total.loadavg[1] / (double)(1 << SBITS); + avg[2] = ps_total.loadavg[2] / (double)(1 << SBITS); +} + + +int uv_fs_event_init(uv_loop_t* loop, + uv_fs_event_t* handle, + const char* filename, + uv_fs_event_cb cb, + int flags) { + loop->counters.fs_event_init++; + uv__set_sys_error(loop, ENOSYS); + return -1; +} + + +void uv__fs_event_close(uv_fs_event_t* handle) { + UNREACHABLE(); +} + + +char** uv_setup_args(int argc, char** argv) { + return argv; +} + + +uv_err_t uv_set_process_title(const char* title) { + return uv_ok_; +} + + +uv_err_t uv_get_process_title(char* buffer, size_t size) { + if (size > 0) { + buffer[0] = '\0'; + } + return uv_ok_; +} + + +uv_err_t uv_resident_set_memory(size_t* rss) { + char pp[64]; + psinfo_t psinfo; + uv_err_t err; + int fd; + + (void) snprintf(pp, sizeof(pp), "/proc/%lu/psinfo", (unsigned long) getpid()); + + fd = open(pp, O_RDONLY); + if (fd == -1) + return uv__new_sys_error(errno); + + err = uv_ok_; + + if (read(fd, &psinfo, sizeof(psinfo)) == sizeof(psinfo)) + *rss = (size_t)psinfo.pr_rssize * 1024; + else + err = uv__new_sys_error(EINVAL); + + close(fd); + + return err; +} + + +uv_err_t uv_uptime(double* uptime) { + struct utmp *utmp_buf; + size_t entries = 0; + time_t boot_time; + + utmpname(UTMP_FILE); + + setutent(); + + while ((utmp_buf = getutent()) != NULL) { + if (utmp_buf->ut_user[0] && utmp_buf->ut_type == USER_PROCESS) + ++entries; + if (utmp_buf->ut_type == BOOT_TIME) + boot_time = utmp_buf->ut_time; + } + + endutent(); + + if (boot_time == 0) + return uv__new_artificial_error(UV_ENOSYS); + + *uptime = time(NULL) - boot_time; + return uv_ok_; +} + + +uv_err_t uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { + uv_cpu_info_t* cpu_info; + perfstat_cpu_total_t ps_total; + perfstat_cpu_t* ps_cpus; + perfstat_id_t cpu_id; + int result, ncpus, idx = 0; + + result = perfstat_cpu_total(NULL, &ps_total, sizeof(ps_total), 1); + if (result == -1) { + return uv__new_artificial_error(UV_ENOSYS); + } + + ncpus = result = perfstat_cpu(NULL, NULL, sizeof(perfstat_cpu_t), 0); + if (result == -1) { + return uv__new_artificial_error(UV_ENOSYS); + } + + ps_cpus = (perfstat_cpu_t*) malloc(ncpus * sizeof(perfstat_cpu_t)); + if (!ps_cpus) { + return uv__new_artificial_error(UV_ENOMEM); + } + + strcpy(cpu_id.name, FIRST_CPU); + result = perfstat_cpu(&cpu_id, ps_cpus, sizeof(perfstat_cpu_t), ncpus); + if (result == -1) { + free(ps_cpus); + return uv__new_artificial_error(UV_ENOSYS); + } + + *cpu_infos = (uv_cpu_info_t*) malloc(ncpus * sizeof(uv_cpu_info_t)); + if (!*cpu_infos) { + free(ps_cpus); + return uv__new_artificial_error(UV_ENOMEM); + } + + *count = ncpus; + + cpu_info = *cpu_infos; + while (idx < ncpus) { + cpu_info->speed = (int)(ps_total.processorHZ / 1000000); + cpu_info->model = strdup(ps_total.description); + cpu_info->cpu_times.user = ps_cpus[idx].user; + cpu_info->cpu_times.sys = ps_cpus[idx].sys; + cpu_info->cpu_times.idle = ps_cpus[idx].idle; + cpu_info->cpu_times.irq = ps_cpus[idx].wait; + cpu_info->cpu_times.nice = 0; + cpu_info++; + idx++; + } + + free(ps_cpus); + return uv_ok_; +} + + +void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) { + int i; + + for (i = 0; i < count; ++i) { + free(cpu_infos[i].model); + } + + free(cpu_infos); +} + + +uv_err_t uv_interface_addresses(uv_interface_address_t** addresses, + int* count) { + uv_interface_address_t* address; + int sockfd, size = 1; + struct ifconf ifc; + struct ifreq *ifr, *p, flg; + + *count = 0; + + if (0 > (sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP))) { + return uv__new_artificial_error(UV_ENOSYS); + } + + if (ioctl(sockfd, SIOCGSIZIFCONF, &size) == -1) { + close(sockfd); + return uv__new_artificial_error(UV_ENOSYS); + } + + ifc.ifc_req = (struct ifreq*)malloc(size); + ifc.ifc_len = size; + if (ioctl(sockfd, SIOCGIFCONF, &ifc) == -1) { + close(sockfd); + return uv__new_artificial_error(UV_ENOSYS); + } + +#define ADDR_SIZE(p) MAX((p).sa_len, sizeof(p)) + + /* Count all up and running ipv4/ipv6 addresses */ + ifr = ifc.ifc_req; + while ((char*)ifr < (char*)ifc.ifc_req + ifc.ifc_len) { + p = ifr; + ifr = (struct ifreq*) + ((char*)ifr + sizeof(ifr->ifr_name) + ADDR_SIZE(ifr->ifr_addr)); + + if (!(p->ifr_addr.sa_family == AF_INET6 || + p->ifr_addr.sa_family == AF_INET)) + continue; + + memcpy(flg.ifr_name, p->ifr_name, sizeof(flg.ifr_name)); + if (ioctl(sockfd, SIOCGIFFLAGS, &flg) == -1) { + close(sockfd); + return uv__new_artificial_error(UV_ENOSYS); + } + + if (!(flg.ifr_flags & IFF_UP && flg.ifr_flags & IFF_RUNNING)) + continue; + + (*count)++; + } + + /* Alloc the return interface structs */ + *addresses = (uv_interface_address_t*) + malloc(*count * sizeof(uv_interface_address_t)); + if (!(*addresses)) { + close(sockfd); + return uv__new_artificial_error(UV_ENOMEM); + } + address = *addresses; + + ifr = ifc.ifc_req; + while ((char*)ifr < (char*)ifc.ifc_req + ifc.ifc_len) { + p = ifr; + ifr = (struct ifreq*) + ((char*)ifr + sizeof(ifr->ifr_name) + ADDR_SIZE(ifr->ifr_addr)); + + if (!(p->ifr_addr.sa_family == AF_INET6 || + p->ifr_addr.sa_family == AF_INET)) + continue; + + memcpy(flg.ifr_name, p->ifr_name, sizeof(flg.ifr_name)); + if (ioctl(sockfd, SIOCGIFFLAGS, &flg) == -1) { + close(sockfd); + return uv__new_artificial_error(UV_ENOSYS); + } + + if (!(flg.ifr_flags & IFF_UP && flg.ifr_flags & IFF_RUNNING)) + continue; + + /* All conditions above must match count loop */ + + address->name = strdup(p->ifr_name); + + if (p->ifr_addr.sa_family == AF_INET6) { + address->address.address6 = *((struct sockaddr_in6 *)&p->ifr_addr); + } else { + address->address.address4 = *((struct sockaddr_in *)&p->ifr_addr); + } + + address->is_internal = flg.ifr_flags & IFF_LOOPBACK ? 1 : 0; + + address++; + } + +#undef ADDR_SIZE + + close(sockfd); + return uv_ok_; +} + + +void uv_free_interface_addresses(uv_interface_address_t* addresses, + int count) { + int i; + + for (i = 0; i < count; ++i) { + free(addresses[i].name); + } + + free(addresses); +} diff --git a/deps/uv/src/unix/eio/config_aix.h b/deps/uv/src/unix/eio/config_aix.h new file mode 100644 index 000000000..9e21e53da --- /dev/null +++ b/deps/uv/src/unix/eio/config_aix.h @@ -0,0 +1,84 @@ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the <dlfcn.h> header file. */ +#define HAVE_DLFCN_H 1 + +/* fdatasync(2) is available */ +/* #undef HAVE_FDATASYNC */ + +/* utimes(2) is available */ +#define HAVE_UTIMES 1 + +/* futimes(2) is available */ +/* #undef HAVE_FUTIMES */ + +/* Define to 1 if you have the <inttypes.h> header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the <memory.h> header file. */ +#define HAVE_MEMORY_H 1 + +/* pread(2) and pwrite(2) are available */ +#define HAVE_PREADWRITE 1 + +/* readahead(2) is available (linux) */ +/* #undef HAVE_READAHEAD */ + +/* sendfile(2) is available and supported */ +/* #undef HAVE_SENDFILE */ + +/* Define to 1 if you have the <stdint.h> header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the <stdlib.h> header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the <strings.h> header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the <string.h> header file. */ +#define HAVE_STRING_H 1 + +/* sync_file_range(2) is available */ +/* #undef HAVE_SYNC_FILE_RANGE */ + +/* Define to 1 if you have the <sys/stat.h> header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the <sys/types.h> header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the <unistd.h> header file. */ +#define HAVE_UNISTD_H 1 + +/* Define to the sub-directory in which libtool stores uninstalled libraries. + */ +#define LT_OBJDIR ".libs/" + +/* Name of package */ +#define PACKAGE "libeio" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "" + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Version number of package */ +#define VERSION "1.0" diff --git a/deps/uv/src/unix/eio/eio.c b/deps/uv/src/unix/eio/eio.c index 248af9e2f..3dfba0a4e 100644 --- a/deps/uv/src/unix/eio/eio.c +++ b/deps/uv/src/unix/eio/eio.c @@ -595,7 +595,7 @@ etp_start_thread (void) X_LOCK (wrklock); - if (thread_create (&wrk->tid, etp_proc, (void *)wrk)) + if (xthread_create (&wrk->tid, etp_proc, (void *)wrk)) { wrk->prev = &wrk_first; wrk->next = wrk_first.next; diff --git a/deps/uv/src/unix/eio/xthread.h b/deps/uv/src/unix/eio/xthread.h index 7184c7bb7..1d7aeba21 100644 --- a/deps/uv/src/unix/eio/xthread.h +++ b/deps/uv/src/unix/eio/xthread.h @@ -49,7 +49,7 @@ typedef pthread_t xthread_t; #define X_THREAD_ATFORK(a,b,c) static int -thread_create (xthread_t *tid, void *(*proc)(void *), void *arg) +xthread_create (xthread_t *tid, void *(*proc)(void *), void *arg) { int retval; pthread_attr_t attr; @@ -130,7 +130,7 @@ typedef pthread_t xthread_t; #endif static int -thread_create (xthread_t *tid, void *(*proc)(void *), void *arg) +xthread_create (xthread_t *tid, void *(*proc)(void *), void *arg) { int retval; sigset_t fullsigset, oldsigset; diff --git a/deps/uv/src/unix/error.c b/deps/uv/src/unix/error.c index b2add994a..2acc04799 100644 --- a/deps/uv/src/unix/error.c +++ b/deps/uv/src/unix/error.c @@ -96,7 +96,9 @@ uv_err_code uv_translate_sys_error(int sys_errno) { case ETIMEDOUT: return UV_ETIMEDOUT; case EXDEV: return UV_EXDEV; case EBUSY: return UV_EBUSY; +#if ENOTEMPTY != EEXIST case ENOTEMPTY: return UV_ENOTEMPTY; +#endif case ENOSPC: return UV_ENOSPC; case EROFS: return UV_EROFS; case ENOMEM: return UV_ENOMEM; diff --git a/deps/uv/src/unix/ev/config_aix.h b/deps/uv/src/unix/ev/config_aix.h new file mode 100644 index 000000000..4eb075de2 --- /dev/null +++ b/deps/uv/src/unix/ev/config_aix.h @@ -0,0 +1,122 @@ +/* config.h. Generated from config.h.in by configure. */ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the `clock_gettime' function. */ +#define HAVE_CLOCK_GETTIME 1 + +/* "use syscall interface for clock_gettime" */ +/* #undef HAVE_CLOCK_SYSCALL */ + +/* Define to 1 if you have the <dlfcn.h> header file. */ +#define HAVE_DLFCN_H 1 + +/* Define to 1 if you have the `epoll_ctl' function. */ +/* #undef HAVE_EPOLL_CTL */ + +/* Define to 1 if you have the `eventfd' function. */ +/* #undef HAVE_EVENTFD */ + +/* Define to 1 if you have the `inotify_init' function. */ +/* #undef HAVE_INOTIFY_INIT */ + +/* Define to 1 if you have the <inttypes.h> header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the `kqueue' function. */ +/* #undef HAVE_KQUEUE */ + +/* Define to 1 if you have the `m' library (-lm). */ +#define HAVE_LIBM 1 + +/* Define to 1 if you have the `rt' library (-lrt). */ +#define HAVE_LIBRT 1 + +/* Define to 1 if you have the <memory.h> header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the `nanosleep' function. */ +#define HAVE_NANOSLEEP 1 + +/* Define to 1 if you have the `poll' function. */ +#define HAVE_POLL 1 + +/* Define to 1 if you have the <poll.h> header file. */ +#define HAVE_POLL_H 1 + +/* Define to 1 if you have the `port_create' function. */ +/* #undef HAVE_PORT_CREATE */ + +/* Define to 1 if you have the <port.h> header file. */ +#define HAVE_PORT_H 1 + +/* Define to 1 if you have the `select' function. */ +#define HAVE_SELECT 1 + +/* Define to 1 if you have the `signalfd' function. */ +/* #undef HAVE_SIGNALFD */ + +/* Define to 1 if you have the <stdint.h> header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the <stdlib.h> header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the <strings.h> header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the <string.h> header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the <sys/epoll.h> header file. */ +/* #undef HAVE_SYS_EPOLL_H */ + +/* Define to 1 if you have the <sys/eventfd.h> header file. */ +/* #undef HAVE_SYS_EVENTFD_H */ + +/* Define to 1 if you have the <sys/event.h> header file. */ +/* #undef HAVE_SYS_EVENT_H */ + +/* Define to 1 if you have the <sys/inotify.h> header file. */ +/* #undef HAVE_SYS_INOTIFY_H */ + +/* Define to 1 if you have the <sys/queue.h> header file. */ +#define HAVE_SYS_QUEUE_H 1 + +/* Define to 1 if you have the <sys/select.h> header file. */ +#define HAVE_SYS_SELECT_H 1 + +/* Define to 1 if you have the <sys/signalfd.h> header file. */ +/* #undef HAVE_SYS_SIGNALFD_H */ + +/* Define to 1 if you have the <sys/stat.h> header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the <sys/types.h> header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the <unistd.h> header file. */ +#define HAVE_UNISTD_H 1 + +/* Name of package */ +#define PACKAGE "libev" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "" + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Version number of package */ +#define VERSION "3.9" diff --git a/deps/uv/src/unix/ev/ev.c b/deps/uv/src/unix/ev/ev.c index efd2ab991..d3dd75942 100644 --- a/deps/uv/src/unix/ev/ev.c +++ b/deps/uv/src/unix/ev/ev.c @@ -3912,8 +3912,8 @@ ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) wl = wn; } #endif -/* EV_STAT 0x00001000 /* stat data changed */ -/* EV_EMBED 0x00010000 /* embedded event loop needs sweep */ +/* EV_STAT 0x00001000 *//* stat data changed */ +/* EV_EMBED 0x00010000 *//* embedded event loop needs sweep */ } #endif |