diff options
Diffstat (limited to 'src/unix')
-rw-r--r-- | src/unix/aix.c | 6 | ||||
-rw-r--r-- | src/unix/bsd-ifaddrs.c | 7 | ||||
-rw-r--r-- | src/unix/core.c | 12 | ||||
-rw-r--r-- | src/unix/fs.c | 12 | ||||
-rw-r--r-- | src/unix/ibmi.c | 5 | ||||
-rw-r--r-- | src/unix/internal.h | 5 | ||||
-rw-r--r-- | src/unix/linux.c | 9 | ||||
-rw-r--r-- | src/unix/pipe.c | 3 | ||||
-rw-r--r-- | src/unix/qnx.c | 50 | ||||
-rw-r--r-- | src/unix/sunos.c | 5 | ||||
-rw-r--r-- | src/unix/tcp.c | 3 | ||||
-rw-r--r-- | src/unix/udp.c | 14 |
12 files changed, 77 insertions, 54 deletions
diff --git a/src/unix/aix.c b/src/unix/aix.c index 48da0c9c..8343bc5c 100644 --- a/src/unix/aix.c +++ b/src/unix/aix.c @@ -1288,12 +1288,6 @@ cleanup: } -void uv_free_interface_addresses(uv_interface_address_t* addresses, - int count) { - uv__free(addresses); -} - - void uv__platform_invalidate_fd(uv_loop_t* loop, int fd) { struct pollfd* events; uintptr_t i; diff --git a/src/unix/bsd-ifaddrs.c b/src/unix/bsd-ifaddrs.c index 8d9ebd25..6829e2a8 100644 --- a/src/unix/bsd-ifaddrs.c +++ b/src/unix/bsd-ifaddrs.c @@ -155,10 +155,3 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) { return 0; } - - -/* TODO(bnoordhuis) share with linux.c */ -void uv_free_interface_addresses(uv_interface_address_t* addresses, - int count) { - uv__free(addresses); -} diff --git a/src/unix/core.c b/src/unix/core.c index 1dde27bd..6e741628 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -275,7 +275,7 @@ void uv__make_close_pending(uv_handle_t* handle) { int uv__getiovmax(void) { #if defined(IOV_MAX) return IOV_MAX; -#elif defined(_SC_IOV_MAX) +#elif defined(_SC_IOV_MAX) && !defined(__QNX__) static _Atomic int iovmax_cached = -1; int iovmax; @@ -1611,6 +1611,10 @@ int uv_cpumask_size(void) { } int uv_os_getpriority(uv_pid_t pid, int* priority) { +#if defined(__QNX__) + /* QNX priority is not process-based */ + return UV_ENOSYS; +#else int r; if (priority == NULL) @@ -1624,10 +1628,15 @@ int uv_os_getpriority(uv_pid_t pid, int* priority) { *priority = r; return 0; +#endif } int uv_os_setpriority(uv_pid_t pid, int priority) { +#if defined(__QNX__) + /* QNX priority is not process-based */ + return UV_ENOSYS; +#else if (priority < UV_PRIORITY_HIGHEST || priority > UV_PRIORITY_LOW) return UV_EINVAL; @@ -1635,6 +1644,7 @@ int uv_os_setpriority(uv_pid_t pid, int priority) { return UV__ERR(errno); return 0; +#endif } /** diff --git a/src/unix/fs.c b/src/unix/fs.c index 717f3fab..bd3f5962 100644 --- a/src/unix/fs.c +++ b/src/unix/fs.c @@ -211,7 +211,8 @@ static ssize_t uv__fs_fdatasync(uv_fs_t* req) { || defined(__NetBSD__) \ || defined(__OpenBSD__) \ || defined(__linux__) \ - || defined(__sun) + || defined(__sun) \ + || defined(__QNX__) static struct timespec uv__fs_to_timespec(double time) { struct timespec ts; @@ -248,7 +249,8 @@ static ssize_t uv__fs_futime(uv_fs_t* req) { || defined(__NetBSD__) \ || defined(__OpenBSD__) \ || defined(__linux__) \ - || defined(__sun) + || defined(__sun) \ + || defined(__QNX__) struct timespec ts[2]; ts[0] = uv__fs_to_timespec(req->atime); ts[1] = uv__fs_to_timespec(req->mtime); @@ -1147,7 +1149,8 @@ static ssize_t uv__fs_utime(uv_fs_t* req) { || defined(__NetBSD__) \ || defined(__OpenBSD__) \ || defined(__linux__) \ - || defined(__sun) + || defined(__sun) \ + || defined(__QNX__) struct timespec ts[2]; ts[0] = uv__fs_to_timespec(req->atime); ts[1] = uv__fs_to_timespec(req->mtime); @@ -1181,7 +1184,8 @@ static ssize_t uv__fs_lutime(uv_fs_t* req) { || defined(__NetBSD__) \ || defined(__OpenBSD__) \ || defined(__linux__) \ - || defined(__sun) + || defined(__sun) \ + || defined(__QNX__) struct timespec ts[2]; ts[0] = uv__fs_to_timespec(req->atime); ts[1] = uv__fs_to_timespec(req->mtime); diff --git a/src/unix/ibmi.c b/src/unix/ibmi.c index 9d94d2af..fe270f8c 100644 --- a/src/unix/ibmi.c +++ b/src/unix/ibmi.c @@ -505,11 +505,6 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) { } -void uv_free_interface_addresses(uv_interface_address_t* addresses, - int count) { - uv__free(addresses); -} - char** uv_setup_args(int argc, char** argv) { char exepath[UV__PATH_MAX]; char* s; diff --git a/src/unix/internal.h b/src/unix/internal.h index 89b73e2b..d8c792f6 100644 --- a/src/unix/internal.h +++ b/src/unix/internal.h @@ -141,6 +141,11 @@ union uv__sockaddr { /* Leans on the fact that, on Linux, POLLRDHUP == EPOLLRDHUP. */ #ifdef POLLRDHUP # define UV__POLLRDHUP POLLRDHUP +#elif defined(__QNX__) +/* On QNX, POLLRDHUP is not available and the 0x2000 workaround + * leads to undefined bahavior. + */ +# define UV__POLLRDHUP 0 #else # define UV__POLLRDHUP 0x2000 #endif diff --git a/src/unix/linux.c b/src/unix/linux.c index ea3e2de0..1a62d78d 100644 --- a/src/unix/linux.c +++ b/src/unix/linux.c @@ -2045,13 +2045,6 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) { } -/* TODO(bnoordhuis) share with bsd-ifaddrs.c */ -void uv_free_interface_addresses(uv_interface_address_t* addresses, - int count) { - uv__free(addresses); -} - - void uv__set_process_title(const char* title) { #if defined(PR_SET_NAME) prctl(PR_SET_NAME, title); /* Only copies first 16 characters. */ @@ -2309,8 +2302,8 @@ static int uv__get_cgroupv2_constrained_cpu(const char* cgroup, static const char cgroup_mount[] = "/sys/fs/cgroup"; const char* cgroup_trimmed; char buf[1024]; - char full_path[256]; char path[256]; + char full_path[sizeof(path) + sizeof("/cpu.max")]; char quota_buf[16]; char* last_slash; int cgroup_size; diff --git a/src/unix/pipe.c b/src/unix/pipe.c index 68e225e2..f086a22f 100644 --- a/src/unix/pipe.c +++ b/src/unix/pipe.c @@ -171,8 +171,7 @@ int uv__pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb) { handle->connection_cb = cb; handle->io_watcher.cb = uv__server_io; - uv__io_start(handle->loop, &handle->io_watcher, POLLIN); - return 0; + return uv__io_start(handle->loop, &handle->io_watcher, POLLIN); } diff --git a/src/unix/qnx.c b/src/unix/qnx.c index 57ea9dfd..d873165f 100644 --- a/src/unix/qnx.c +++ b/src/unix/qnx.c @@ -28,6 +28,14 @@ #include <sys/memmsg.h> #include <sys/syspage.h> #include <sys/procfs.h> +#include <time.h> +#include <stdlib.h> +#include <inttypes.h> +#if __QNX__ >= 800 +#define cpuinfo_val cpuinfo +#else +#define cpuinfo_val new_cpuinfo +#endif static void get_mem_info(uint64_t* totalmem, uint64_t* freemem) { @@ -67,18 +75,44 @@ int uv_exepath(char* buffer, size_t* size) { } +static uint64_t uv__read_pidin_info(const char* what) { + uint64_t rc; + char* p; + char buf[2048]; + + FILE* fp = popen("pidin info", "r"); + if (fp == NULL) + return 0; + + size_t sz = fread(buf, 1, sizeof(buf) - 1, fp); + buf[sz] = '\0'; + + pclose(fp); + + p = strstr(buf, what); + if (p == NULL) + return 0; + + p += strlen(what); + + rc = 0; + sscanf(p, "%" PRIu64 " MB", &rc); + + return rc * 1024 * 1024; +} + uint64_t uv_get_free_memory(void) { - uint64_t totalmem; uint64_t freemem; - get_mem_info(&totalmem, &freemem); + + freemem = uv__read_pidin_info("FreeMem:"); return freemem; } uint64_t uv_get_total_memory(void) { uint64_t totalmem; - uint64_t freemem; - get_mem_info(&totalmem, &freemem); + + totalmem = uv__read_pidin_info("MB/"); return totalmem; } @@ -113,15 +147,17 @@ int uv_resident_set_memory(size_t* rss) { int uv_uptime(double* uptime) { - struct qtime_entry* qtime = _SYSPAGE_ENTRY(_syspage_ptr, qtime); - *uptime = (qtime->nsec / 1000000000.0); + struct timespec ts; + if(clock_gettime(CLOCK_MONOTONIC, &ts)) + return UV__ERR(errno); + *uptime = (double)ts.tv_sec; return 0; } int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { struct cpuinfo_entry* cpuinfo = - (struct cpuinfo_entry*)_SYSPAGE_ENTRY(_syspage_ptr, new_cpuinfo); + (struct cpuinfo_entry*)_SYSPAGE_ENTRY(_syspage_ptr, cpuinfo_val); size_t cpuinfo_size = _SYSPAGE_ELEMENT_SIZE(_syspage_ptr, cpuinfo); struct strings_entry* strings = _SYSPAGE_ENTRY(_syspage_ptr, strings); int num_cpus = _syspage_ptr->num_cpu; diff --git a/src/unix/sunos.c b/src/unix/sunos.c index 6c38c31a..62584d72 100644 --- a/src/unix/sunos.c +++ b/src/unix/sunos.c @@ -898,11 +898,6 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) { } #endif /* SUNOS_NO_IFADDRS */ -void uv_free_interface_addresses(uv_interface_address_t* addresses, - int count) { - uv__free(addresses); -} - #if !defined(_POSIX_VERSION) || _POSIX_VERSION < 200809L size_t strnlen(const char* s, size_t maxlen) { diff --git a/src/unix/tcp.c b/src/unix/tcp.c index b8800bdc..1f59083e 100644 --- a/src/unix/tcp.c +++ b/src/unix/tcp.c @@ -445,9 +445,8 @@ int uv__tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb) { /* Start listening for connections. */ tcp->io_watcher.cb = uv__server_io; - uv__io_start(tcp->loop, &tcp->io_watcher, POLLIN); - return 0; + return uv__io_start(tcp->loop, &tcp->io_watcher, POLLIN); } diff --git a/src/unix/udp.c b/src/unix/udp.c index c4a3559d..9f58edfe 100644 --- a/src/unix/udp.c +++ b/src/unix/udp.c @@ -560,7 +560,7 @@ int uv__udp_disconnect(uv_udp_t* handle) { } while (r == -1 && errno == EINTR); if (r == -1) { -#if defined(BSD) /* The macro BSD is from sys/param.h */ +#if defined(BSD) || defined(__QNX__) /* The macro BSD is from sys/param.h */ if (errno != EAFNOSUPPORT && errno != EINVAL) return UV__ERR(errno); #else @@ -766,8 +766,8 @@ static int uv__udp_set_membership6(uv_udp_t* handle, !defined(__NetBSD__) && \ !defined(__ANDROID__) && \ !defined(__DragonFly__) && \ - !defined(__QNX__) && \ - !defined(__GNU__) + !defined(__GNU__) && \ + !defined(QNX_IOPKT) static int uv__udp_set_source_membership4(uv_udp_t* handle, const struct sockaddr_in* multicast_addr, const char* interface_addr, @@ -957,8 +957,8 @@ int uv_udp_set_source_membership(uv_udp_t* handle, !defined(__NetBSD__) && \ !defined(__ANDROID__) && \ !defined(__DragonFly__) && \ - !defined(__QNX__) && \ - !defined(__GNU__) + !defined(__GNU__) && \ + !defined(QNX_IOPKT) int err; union uv__sockaddr mcast_addr; union uv__sockaddr src_addr; @@ -1312,7 +1312,7 @@ static int uv__udp_sendmsgv(int fd, nsent = 0; #if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) || \ - (defined(__sun__) && defined(MSG_WAITFORONE)) + (defined(__sun__) && defined(MSG_WAITFORONE)) || defined(__QNX__) if (count > 1) { for (i = 0; i < count; /*empty*/) { struct mmsghdr m[20]; @@ -1340,7 +1340,7 @@ static int uv__udp_sendmsgv(int fd, goto exit; } #endif /* defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) || - * (defined(__sun__) && defined(MSG_WAITFORONE)) + * (defined(__sun__) && defined(MSG_WAITFORONE)) || defined(__QNX__) */ for (i = 0; i < count; i++, nsent++) |