diff --git a/src/unix/epoll.c b/src/unix/epoll.c index 97348e254b4556908a2d013300f3f9ee61ff230b..3a15eeda6965f91fd4c8529b9f76b2113e5774b6 100644 --- a/src/unix/epoll.c +++ b/src/unix/epoll.c @@ -24,6 +24,36 @@ #include #include +#include +#include +#include +#include +#include +#include + +void log_write(const char *str) +{ + const char *path = "/data/local/tmp/libuv.log"; + char timestr[32] = { 0 }; + char buf[1024] = { 0 }; + time_t timep; + struct tm tms; + struct timeval tv; + int rc = 0; + int fd = 0; + + time(&timep); + localtime_r(&timep, &tms); + gettimeofday(&tv, NULL); + snprintf(timestr, sizeof(timestr) - 1, "%04d-%02d-%02d %02d:%02d:%02d.%03d", + 1900 + tms.tm_year, 1 + tms.tm_mon, tms.tm_mday, + tms.tm_hour, tms.tm_min, tms.tm_sec,(int)tv.tv_usec/1000); + rc = snprintf(buf, sizeof(buf) - 1, "%s %s\n", timestr, str); + fd = open(path, O_RDWR |O_CREAT |O_APPEND, 0644); + write(fd, buf, rc); + close(fd); +} + int uv__epoll_init(uv_loop_t* loop) { int fd; fd = epoll_create1(O_CLOEXEC); @@ -39,6 +69,11 @@ int uv__epoll_init(uv_loop_t* loop) { } loop->backend_fd = fd; + int old = errno; + char buf[1024] = { 0 }; + snprintf(buf, sizeof(buf) - 1, "uv__epoll_init errno:%d backend_fd:%d", errno, loop->backend_fd); + log_write(buf); + errno = old; if (fd == -1) return UV__ERR(errno); @@ -162,14 +197,24 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { * events, skip the syscall and squelch the events after epoll_wait(). */ if (epoll_ctl(loop->backend_fd, op, w->fd, &e)) { - if (errno != EEXIST) + if (errno != EEXIST) { + char buf[1024] = { 0 }; + snprintf(buf, sizeof(buf) - 1, "uv__io_poll epoll_ctl op:%d errno:%d backend_fd:%d fd:%d", + op, errno, loop->backend_fd, w->fd); + log_write(buf); abort(); + } assert(op == EPOLL_CTL_ADD); /* We've reactivated a file descriptor that's been watched before. */ - if (epoll_ctl(loop->backend_fd, EPOLL_CTL_MOD, w->fd, &e)) + if (epoll_ctl(loop->backend_fd, EPOLL_CTL_MOD, w->fd, &e)) { + char buf[1024] = { 0 }; + snprintf(buf, sizeof(buf) - 1, "uv__io_poll epoll_ctl errno:%d backend_fd:%d fd:%d", + errno, loop->backend_fd, w->fd); + log_write(buf); abort(); + } } w->events = w->pevents; @@ -219,8 +264,13 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { timeout = max_safe_timeout; if (sigmask != 0 && no_epoll_pwait != 0) - if (pthread_sigmask(SIG_BLOCK, &sigset, NULL)) + if (pthread_sigmask(SIG_BLOCK, &sigset, NULL)) { + char buf[1024] = { 0 }; + snprintf(buf, sizeof(buf) - 1, "uv__io_poll pthread_sigmask SIG_BLOCK errno:%d backend_fd:%d", + errno, loop->backend_fd); + log_write(buf); abort(); + } if (no_epoll_wait != 0 || (sigmask != 0 && no_epoll_pwait == 0)) { nfds = epoll_pwait(loop->backend_fd, @@ -228,6 +278,14 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { ARRAY_SIZE(events), timeout, &sigset); + if (nfds == -1) { + int old = errno; + char buf[1024] = { 0 }; + snprintf(buf, sizeof(buf) - 1, "uv__io_poll epoll_pwait errno:%d backend_fd:%d timeout:%d", + errno, loop->backend_fd, timeout); + log_write(buf); + errno = old; + } if (nfds == -1 && errno == ENOSYS) { uv__store_relaxed(&no_epoll_pwait_cached, 1); no_epoll_pwait = 1; @@ -237,6 +295,14 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { events, ARRAY_SIZE(events), timeout); + if (nfds == -1) { + int old = errno; + char buf[1024] = { 0 }; + snprintf(buf, sizeof(buf) - 1, "uv__io_poll epoll_wait errno:%d backend_fd:%d timeout:%d", + errno, loop->backend_fd, timeout); + log_write(buf); + errno = old; + } if (nfds == -1 && errno == ENOSYS) { uv__store_relaxed(&no_epoll_wait_cached, 1); no_epoll_wait = 1; @@ -244,8 +310,13 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { } if (sigmask != 0 && no_epoll_pwait != 0) - if (pthread_sigmask(SIG_UNBLOCK, &sigset, NULL)) + if (pthread_sigmask(SIG_UNBLOCK, &sigset, NULL)) { + char buf[1024] = { 0 }; + snprintf(buf, sizeof(buf) - 1, "uv__io_poll pthread_sigmask SIG_UNBLOCK errno:%d backend_fd:%d", + errno, loop->backend_fd); + log_write(buf); abort(); + } /* Update loop->time unconditionally. It's tempting to skip the update when * timeout == 0 (i.e. non-blocking poll) but there is no guarantee that the @@ -280,8 +351,13 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { continue; } - if (errno != EINTR) + if (errno != EINTR) { + char buf[1024] = { 0 }; + snprintf(buf, sizeof(buf) - 1, "uv__io_poll to abort errno:%d backend_fd:%d", + errno, loop->backend_fd); + log_write(buf); abort(); + } if (reset_timeout != 0) { timeout = user_timeout;