31 #include <sys/types.h>
34 #include <sys/ioctl.h>
35 #include <sys/socket.h>
37 #include <netinet/in.h>
38 #include <arpa/inet.h>
41 #include <sys/resource.h>
43 #include <sys/utsname.h>
47 # include <sys/filio.h>
48 # include <sys/types.h>
49 # include <sys/wait.h>
52 #if defined(__APPLE__)
53 # include <sys/filio.h>
57 #if defined(__APPLE__) && !TARGET_OS_IPHONE
58 # include <crt_externs.h>
59 # include <mach-o/dyld.h>
60 # define environ (*_NSGetEnviron())
66 #if defined(__DragonFly__) || \
67 defined(__FreeBSD__) || \
68 defined(__FreeBSD_kernel__) || \
69 defined(__NetBSD__) || \
71 # include <sys/sysctl.h>
72 # include <sys/filio.h>
73 # include <sys/wait.h>
74 # if defined(__FreeBSD__)
75 # define uv__accept4 accept4
77 # if defined(__NetBSD__)
78 # define uv__accept4(a, b, c, d) paccept((a), (b), (c), NULL, (d))
83 #include <sys/ioctl.h>
86 #if defined(__linux__)
87 # include <sys/syscall.h>
88 # define uv__accept4 accept4
96 sizeof(((
struct iovec*) 0)->iov_base));
98 sizeof(((
struct iovec*) 0)->iov_len));
112 handle->close_cb = close_cb;
188 if (
handle->type == UV_TCP ||
handle->type == UV_NAMED_PIPE)
190 else if (
handle->type == UV_UDP)
195 len =
sizeof(*value);
218 #elif defined(_SC_IOV_MAX)
219 static int iovmax_cached = -1;
230 iovmax = sysconf(_SC_IOV_MAX);
277 if (sh->caught_signals > sh->dispatched_signals) {
312 p =
loop->closing_handles;
329 return loop->backend_fd;
346 if (
loop->closing_handles)
372 uv__update_time(
loop);
375 uv__update_time(
loop);
406 uv__update_time(
loop);
426 uv__update_time(
loop);
440 #if defined(SOCK_NONBLOCK) && defined(SOCK_CLOEXEC)
462 #if defined(SO_NOSIGPIPE)
481 fp = fdopen(
fd,
"r");
498 peerfd = uv__accept4(
sockfd,
NULL,
NULL, SOCK_NONBLOCK|SOCK_CLOEXEC);
502 while (peerfd == -1 && errno ==
EINTR);
531 #if defined(__APPLE__)
532 #pragma GCC diagnostic push
533 #pragma GCC diagnostic ignored "-Wdollar-in-identifier-extension"
534 #if defined(__LP64__) || TARGET_OS_IPHONE
535 extern int close$NOCANCEL(
int);
538 extern int close$NOCANCEL$UNIX2003(
int);
539 return close$NOCANCEL$UNIX2003(
fd);
541 #pragma GCC diagnostic pop
542 #elif defined(__linux__)
583 while (
r == -1 && errno ==
EINTR);
592 #if !defined(__CYGWIN__) && !defined(__MSYS__) && !defined(__HAIKU__)
598 while (
r == -1 && errno ==
EINTR);
614 while (
r == -1 && errno ==
EINTR);
630 while (
r == -1 && errno ==
EINTR);
645 while (
r == -1 && errno ==
EINTR);
661 while (
r == -1 && errno ==
EINTR);
675 #if defined(__linux__)
676 static int no_msg_cmsg_cloexec;
695 if (
msg->msg_controllen == 0)
724 if (getcwd(scratch,
sizeof(scratch)) ==
NULL)
832 void* fake_watcher_list;
833 void* fake_watcher_count;
834 unsigned int nwatchers;
837 if (len <= loop->nwatchers)
842 fake_watcher_list =
loop->watchers[
loop->nwatchers];
843 fake_watcher_count =
loop->watchers[
loop->nwatchers + 1];
845 fake_watcher_list =
NULL;
846 fake_watcher_count =
NULL;
851 (nwatchers + 2) *
sizeof(
loop->watchers[0]));
853 if (watchers ==
NULL)
855 for (
i =
loop->nwatchers;
i < nwatchers;
i++)
857 watchers[nwatchers] = fake_watcher_list;
858 watchers[nwatchers + 1] = fake_watcher_count;
860 loop->watchers = watchers;
861 loop->nwatchers = nwatchers;
875 #if defined(UV_HAVE_KQUEUE)
888 w->pevents |= events;
896 if (
w->events ==
w->pevents)
904 loop->watchers[
w->fd] =
w;
920 if ((
unsigned)
w->fd >=
loop->nwatchers)
923 w->pevents &= ~events;
925 if (
w->pevents == 0) {
961 return 0 != (
w->pevents & events);
973 if (getrusage(RUSAGE_SELF, &
usage))
982 #if !defined(__MVS__) && !defined(__HAIKU__)
1004 #if defined(O_CLOEXEC)
1032 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__linux__)
1102 #define CHECK_ENV_VAR(name) \
1104 buf = getenv(name); \
1106 goto return_buffer; \
1116 #undef CHECK_ENV_VAR
1119 #if defined(__ANDROID__)
1120 buf =
"/data/local/tmp";
1148 struct passwd* result;
1153 size_t homedir_size;
1161 initsize = sysconf(_SC_GETPW_R_SIZE_MAX);
1166 bufsize = (
size_t) initsize;
1178 r = getpwuid_r(uid, &pw,
buf, bufsize, &result);
1191 if (result ==
NULL) {
1197 name_size = strlen(pw.pw_name) + 1;
1198 homedir_size = strlen(pw.pw_dir) + 1;
1199 shell_size = strlen(pw.pw_shell) + 1;
1219 pwd->
uid = pw.pw_uid;
1220 pwd->
gid = pw.pw_gid;
1251 return sys_errno <= 0 ? sys_errno : -sys_errno;
1266 if (*envitems ==
NULL)
1269 for (j = 0, cnt = 0; j <
i; j++) {
1280 ptr = strchr(
buf,
'=');
1288 envitem = &(*envitems)[cnt];
1290 envitem->
value = ptr + 1;
1299 for (
i = 0;
i < cnt;
i++) {
1300 envitem = &(*envitems)[cnt];
1352 if (unsetenv(
name) != 0)
1372 if (gethostname(
buf,
sizeof(
buf)) != 0)
1375 buf[
sizeof(
buf) - 1] =
'\0';
1410 if (priority ==
NULL)
1416 if (
r == -1 && errno != 0)
1457 if (
r >=
sizeof(
buffer->release)) {
1471 #if defined(_AIX) || defined(__PASE__)
1483 buffer->sysname[0] =
'\0';
1484 buffer->release[0] =
'\0';
1485 buffer->version[0] =
'\0';
1486 buffer->machine[0] =
'\0';
1505 if (func(
fd,
name, &socklen))
1508 *namelen = (
int) socklen;
1531 timeout.tv_nsec = (msec % 1000) * 1000 * 1000;
1535 while (rc == -1 && errno ==
EINTR);
1542 size_t abspath_size;
1561 if (realpath(
prog, abspath) != abspath)
1564 abspath_size = strlen(abspath);
1567 if (*
buflen > abspath_size)
1579 path_env =
getenv(
"PATH");
1581 if (path_env ==
NULL)
1585 if (cloned_path ==
NULL)
1588 token = strtok(cloned_path,
":");
1589 while (token !=
NULL) {
1590 snprintf(trypath,
sizeof(trypath) - 1,
"%s/%s", token,
prog);
1591 if (realpath(trypath, abspath) == abspath) {
1594 abspath_size = strlen(abspath);
1597 if (*
buflen > abspath_size)
1607 token = strtok(
NULL,
":");
uint64_t uv__hrtime(uv_clocktype_t type)
void uv__fs_event_close(uv_fs_event_t *handle)
void uv__platform_invalidate_fd(uv_loop_t *loop, int fd)
void uv__io_poll(uv_loop_t *loop, int timeout)
static mcore_handle handle
void usage(const char *message)
static static fork const void static count static fd const char const char static newpath const char static path const char path
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval tv
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg nanosleep
static static fork const void static count static fd const char const char static newpath chdir
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd domain
static static fork const void static count close
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd socket
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog gettimeofday
static static sync static getppid static getegid const char static filename ioctl
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags fcntl
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol getpriority
void uv__fs_poll_close(uv_fs_poll_t *handle)
#define offsetof(type, member)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static static fork const void static count static fd const char const char static newpath char char char static envp time
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc pid
static static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause access
static static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause const char static mode static sync const char const char static newpath const char static pathname unsigned long static filedes void static end_data_segment static handler static getegid char static len static pgid const char static path dup2
static static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause const char static mode static sync const char const char static newpath const char static pathname unsigned long static filedes void static end_data_segment static handler static getegid char static len static pgid const char static path oldfd
static const char struct stat static buf struct stat static buf static vhangup int struct rusage static rusage struct sysinfo static info unsigned static __unused uname
static const void static count static fd struct stat static buf struct pollfd unsigned static timeout void static offset void static length char static len const struct iovec static count unsigned long static filedes static sched_yield static flags static oldfd static pause unsigned static seconds static protocol accept
static void struct sockaddr socklen_t static fromlen static backlog static fork char char char static envp int struct rusage static rusage struct utsname static buf struct sembuf static nsops static fd const char static length unsigned struct dirent unsigned static count const char const char static newpath const char static pathname const char const char static newpath const char const char static newpath const char static mode const char static group const char static group struct timeval struct timezone static tz struct tms static buf static getuid static getgid static getegid static getppid static setsid static egid static suid static pid static fsgid static data const char static dev unsigned static persona const char struct statfs static buf unsigned char static buf setpriority
assert(limit<=UINT32_MAX/2)
int epoll_file_close(int fd)
#define QUEUE_DATA(ptr, type, field)
#define QUEUE_INSERT_TAIL(h, q)
static struct sockaddr static addrlen static backlog const void static flags void flags
static struct sockaddr static addrlen static backlog const void msg
#define CMSG_FIRSTHDR(mhdr)
#define CMSG_NXTHDR(mhdr, cmsg)
ssize_t uv__strscpy(char *d, const char *s, size_t n)
void uv__io_stop(uv_loop_t *loop, uv__io_t *w, unsigned int events)
void uv_os_free_passwd(uv_passwd_t *pwd)
int uv__open_cloexec(const char *path, int flags)
int uv_cwd(char *buffer, size_t *size)
void uv_update_time(uv_loop_t *loop)
int uv_fileno(const uv_handle_t *handle, uv_os_fd_t *fd)
int uv__close_nocheckstdio(int fd)
static int uv__run_pending(uv_loop_t *loop)
static void maybe_resize(uv_loop_t *loop, unsigned int len)
int uv_backend_timeout(const uv_loop_t *loop)
int uv_os_homedir(char *buffer, size_t *size)
int uv__nonblock_ioctl(int fd, int set)
int uv_chdir(const char *dir)
void uv_disable_stdio_inheritance(void)
int uv_is_active(const uv_handle_t *handle)
int uv_loop_alive(const uv_loop_t *loop)
int uv_is_closing(const uv_handle_t *handle)
int uv_os_setenv(const char *name, const char *value)
void uv__io_start(uv_loop_t *loop, uv__io_t *w, unsigned int events)
int uv_os_getenv(const char *name, char *buffer, size_t *size)
int uv__fd_exists(uv_loop_t *loop, int fd)
void uv__io_close(uv_loop_t *loop, uv__io_t *w)
STATIC_ASSERT(sizeof(uv_buf_t)==sizeof(struct iovec))
int uv_os_get_passwd(uv_passwd_t *pwd)
int uv_getrusage(uv_rusage_t *rusage)
int uv__getsockpeername(const uv_handle_t *handle, uv__peersockfunc func, struct sockaddr *name, int *namelen)
int uv__io_active(const uv__io_t *w, unsigned int events)
int uv__getpwuid_r(uv_passwd_t *pwd)
int uv_os_tmpdir(char *buffer, size_t *size)
uv_pid_t uv_os_getpid(void)
int uv__accept(int sockfd)
int uv__search_path(const char *prog, char *buf, size_t *buflen)
int uv_run(uv_loop_t *loop, uv_run_mode mode)
int uv_os_setpriority(uv_pid_t pid, int priority)
int uv__socket_sockopt(uv_handle_t *handle, int optname, int *value)
int uv_os_environ(uv_env_item_t **envitems, int *count)
int uv_os_gethostname(char *buffer, size_t *size)
static unsigned int next_power_of_two(unsigned int val)
#define CHECK_ENV_VAR(name)
int uv__socket(int domain, int type, int protocol)
ssize_t uv__recvmsg(int fd, struct msghdr *msg, int flags)
void uv__io_init(uv__io_t *w, uv__io_cb cb, int fd)
static void uv__finish_close(uv_handle_t *handle)
uv_pid_t uv_os_getppid(void)
int uv__close_nocancel(int fd)
int uv_os_uname(uv_utsname_t *buffer)
int uv_os_getpriority(uv_pid_t pid, int *priority)
int uv__dup2_cloexec(int oldfd, int newfd)
int uv_backend_fd(const uv_loop_t *loop)
int uv__nonblock_fcntl(int fd, int set)
int uv_gettimeofday(uv_timeval64_t *tv)
static void uv__run_closing_handles(uv_loop_t *loop)
int uv_open_osfhandle(uv_os_fd_t os_fd)
int uv__cloexec_ioctl(int fd, int set)
void uv__make_close_pending(uv_handle_t *handle)
void uv_sleep(unsigned int msec)
int uv_translate_sys_error(int sys_errno)
static int uv__loop_alive(const uv_loop_t *loop)
int uv_os_unsetenv(const char *name)
void uv_close(uv_handle_t *handle, uv_close_cb close_cb)
uv_os_fd_t uv_get_osfhandle(int fd)
int uv__cloexec_fcntl(int fd, int set)
void uv__io_feed(uv_loop_t *loop, uv__io_t *w)
FILE * uv__open_file(const char *path)
void uv__prepare_close(uv_prepare_t *handle)
void uv__udp_close(uv_udp_t *handle)
void uv__poll_close(uv_poll_t *handle)
void uv__idle_close(uv_idle_t *handle)
void uv__run_prepare(uv_loop_t *loop)
void uv__signal_close(uv_signal_t *handle)
void uv__check_close(uv_check_t *handle)
#define uv__stream_fd(handle)
void uv__pipe_close(uv_pipe_t *handle)
#define SAVE_ERRNO(block)
void uv__udp_finish_close(uv_udp_t *handle)
void uv__run_check(uv_loop_t *loop)
int(* uv__peersockfunc)(int, struct sockaddr *, socklen_t *)
void uv__stream_destroy(uv_stream_t *stream)
void uv__process_close(uv_process_t *handle)
void uv__stream_close(uv_stream_t *handle)
void uv__run_idle(uv_loop_t *loop)
void uv__tcp_close(uv_tcp_t *handle)
int uv__next_timeout(const uv_loop_t *loop)
void uv__run_timers(uv_loop_t *loop)
void uv__timer_close(uv_timer_t *handle)
void uv__async_close(uv_async_t *handle)
void(* uv__io_cb)(struct uv_loop_s *loop, struct uv__io_s *w, unsigned int events)
void error(const char *msg)
void * uv__reallocf(void *ptr, size_t size)
char * uv__strdup(const char *s)
void * uv__malloc(size_t size)
void * uv__calloc(size_t count, size_t size)
void uv__metrics_update_idle_time(uv_loop_t *loop)
#define uv__handle_unref(h)
#define uv__is_closing(h)
#define uv__load_relaxed(p)
#define uv__store_relaxed(p, v)
#define uv__has_active_handles(loop)
#define uv__has_active_reqs(loop)
#define UV_MAXHOSTNAMESIZE
void(* uv_close_cb)(uv_handle_t *handle)
static const z80_opcode fd[]