unix/core.c
Go to the documentation of this file.
1 /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2  * Permission is hereby granted, free of charge, to any person obtaining a copy
3  * of this software and associated documentation files (the "Software"), to
4  * deal in the Software without restriction, including without limitation the
5  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
6  * sell copies of the Software, and to permit persons to whom the Software is
7  * furnished to do so, subject to the following conditions:
8  *
9  * The above copyright notice and this permission notice shall be included in
10  * all copies or substantial portions of the Software.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
18  * IN THE SOFTWARE.
19  */
20 
21 #include "uv.h"
22 #include "internal.h"
23 
24 #include <stddef.h> /* NULL */
25 #include <stdio.h> /* printf */
26 #include <stdlib.h>
27 #include <string.h> /* strerror */
28 #include <errno.h>
29 #include <assert.h>
30 #include <unistd.h>
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #include <fcntl.h> /* O_CLOEXEC */
34 #include <sys/ioctl.h>
35 #include <sys/socket.h>
36 #include <sys/un.h>
37 #include <netinet/in.h>
38 #include <arpa/inet.h>
39 #include <limits.h> /* INT_MAX, PATH_MAX, IOV_MAX */
40 #include <sys/uio.h> /* writev */
41 #include <sys/resource.h> /* getrusage */
42 #include <pwd.h>
43 #include <sys/utsname.h>
44 #include <sys/time.h>
45 
46 #ifdef __sun
47 # include <sys/filio.h>
48 # include <sys/types.h>
49 # include <sys/wait.h>
50 #endif
51 
52 #if defined(__APPLE__)
53 # include <sys/filio.h>
54 # endif /* defined(__APPLE__) */
55 
56 
57 #if defined(__APPLE__) && !TARGET_OS_IPHONE
58 # include <crt_externs.h>
59 # include <mach-o/dyld.h> /* _NSGetExecutablePath */
60 # define environ (*_NSGetEnviron())
61 #else /* defined(__APPLE__) && !TARGET_OS_IPHONE */
62 extern char** environ;
63 #endif /* !(defined(__APPLE__) && !TARGET_OS_IPHONE) */
64 
65 
66 #if defined(__DragonFly__) || \
67  defined(__FreeBSD__) || \
68  defined(__FreeBSD_kernel__) || \
69  defined(__NetBSD__) || \
70  defined(__OpenBSD__)
71 # include <sys/sysctl.h>
72 # include <sys/filio.h>
73 # include <sys/wait.h>
74 # if defined(__FreeBSD__)
75 # define uv__accept4 accept4
76 # endif
77 # if defined(__NetBSD__)
78 # define uv__accept4(a, b, c, d) paccept((a), (b), (c), NULL, (d))
79 # endif
80 #endif
81 
82 #if defined(__ANDROID_API__) && __ANDROID_API__ < 21
83 # include <dlfcn.h> /* for dlsym */
84 #endif
85 
86 #if defined(__MVS__)
87 #include <sys/ioctl.h>
88 #endif
89 
90 #if defined(__linux__)
91 # include <sys/syscall.h>
92 # define uv__accept4 accept4
93 #endif
94 
95 static int uv__run_pending(uv_loop_t* loop);
96 
97 /* Verify that uv_buf_t is ABI-compatible with struct iovec. */
98 STATIC_ASSERT(sizeof(uv_buf_t) == sizeof(struct iovec));
99 STATIC_ASSERT(sizeof(&((uv_buf_t*) 0)->base) ==
100  sizeof(((struct iovec*) 0)->iov_base));
101 STATIC_ASSERT(sizeof(&((uv_buf_t*) 0)->len) ==
102  sizeof(((struct iovec*) 0)->iov_len));
103 STATIC_ASSERT(offsetof(uv_buf_t, base) == offsetof(struct iovec, iov_base));
104 STATIC_ASSERT(offsetof(uv_buf_t, len) == offsetof(struct iovec, iov_len));
105 
106 
109 }
110 
111 
113  assert(!uv__is_closing(handle));
114 
115  handle->flags |= UV_HANDLE_CLOSING;
116  handle->close_cb = close_cb;
117 
118  switch (handle->type) {
119  case UV_NAMED_PIPE:
121  break;
122 
123  case UV_TTY:
125  break;
126 
127  case UV_TCP:
129  break;
130 
131  case UV_UDP:
133  break;
134 
135  case UV_PREPARE:
137  break;
138 
139  case UV_CHECK:
141  break;
142 
143  case UV_IDLE:
145  break;
146 
147  case UV_ASYNC:
149  break;
150 
151  case UV_TIMER:
153  break;
154 
155  case UV_PROCESS:
157  break;
158 
159  case UV_FS_EVENT:
161  break;
162 
163  case UV_POLL:
165  break;
166 
167  case UV_FS_POLL:
169  /* Poll handles use file system requests, and one of them may still be
170  * running. The poll code will call uv__make_close_pending() for us. */
171  return;
172 
173  case UV_SIGNAL:
175  break;
176 
177  default:
178  assert(0);
179  }
180 
182 }
183 
184 int uv__socket_sockopt(uv_handle_t* handle, int optname, int* value) {
185  int r;
186  int fd;
187  socklen_t len;
188 
189  if (handle == NULL || value == NULL)
190  return UV_EINVAL;
191 
192  if (handle->type == UV_TCP || handle->type == UV_NAMED_PIPE)
194  else if (handle->type == UV_UDP)
195  fd = ((uv_udp_t *) handle)->io_watcher.fd;
196  else
197  return UV_ENOTSUP;
198 
199  len = sizeof(*value);
200 
201  if (*value == 0)
202  r = getsockopt(fd, SOL_SOCKET, optname, value, &len);
203  else
204  r = setsockopt(fd, SOL_SOCKET, optname, (const void*) value, len);
205 
206  if (r < 0)
207  return UV__ERR(errno);
208 
209  return 0;
210 }
211 
213  assert(handle->flags & UV_HANDLE_CLOSING);
214  assert(!(handle->flags & UV_HANDLE_CLOSED));
215  handle->next_closing = handle->loop->closing_handles;
216  handle->loop->closing_handles = handle;
217 }
218 
219 int uv__getiovmax(void) {
220 #if defined(IOV_MAX)
221  return IOV_MAX;
222 #elif defined(_SC_IOV_MAX)
223  static int iovmax = -1;
224  if (iovmax == -1) {
225  iovmax = sysconf(_SC_IOV_MAX);
226  /* On some embedded devices (arm-linux-uclibc based ip camera),
227  * sysconf(_SC_IOV_MAX) can not get the correct value. The return
228  * value is -1 and the errno is EINPROGRESS. Degrade the value to 1.
229  */
230  if (iovmax == -1) iovmax = 1;
231  }
232  return iovmax;
233 #else
234  return 1024;
235 #endif
236 }
237 
238 
240  uv_signal_t* sh;
241 
242  /* Note: while the handle is in the UV_HANDLE_CLOSING state now, it's still
243  * possible for it to be active in the sense that uv__is_active() returns
244  * true.
245  *
246  * A good example is when the user calls uv_shutdown(), immediately followed
247  * by uv_close(). The handle is considered active at this point because the
248  * completion of the shutdown req is still pending.
249  */
250  assert(handle->flags & UV_HANDLE_CLOSING);
251  assert(!(handle->flags & UV_HANDLE_CLOSED));
252  handle->flags |= UV_HANDLE_CLOSED;
253 
254  switch (handle->type) {
255  case UV_PREPARE:
256  case UV_CHECK:
257  case UV_IDLE:
258  case UV_ASYNC:
259  case UV_TIMER:
260  case UV_PROCESS:
261  case UV_FS_EVENT:
262  case UV_FS_POLL:
263  case UV_POLL:
264  break;
265 
266  case UV_SIGNAL:
267  /* If there are any caught signals "trapped" in the signal pipe,
268  * we can't call the close callback yet. Reinserting the handle
269  * into the closing queue makes the event loop spin but that's
270  * okay because we only need to deliver the pending events.
271  */
272  sh = (uv_signal_t*) handle;
273  if (sh->caught_signals > sh->dispatched_signals) {
274  handle->flags ^= UV_HANDLE_CLOSED;
275  uv__make_close_pending(handle); /* Back into the queue. */
276  return;
277  }
278  break;
279 
280  case UV_NAMED_PIPE:
281  case UV_TCP:
282  case UV_TTY:
284  break;
285 
286  case UV_UDP:
288  break;
289 
290  default:
291  assert(0);
292  break;
293  }
294 
296  QUEUE_REMOVE(&handle->handle_queue);
297 
298  if (handle->close_cb) {
299  handle->close_cb(handle);
300  }
301 }
302 
303 
305  uv_handle_t* p;
306  uv_handle_t* q;
307 
308  p = loop->closing_handles;
309  loop->closing_handles = NULL;
310 
311  while (p) {
312  q = p->next_closing;
314  p = q;
315  }
316 }
317 
318 
320  return uv__is_closing(handle);
321 }
322 
323 
325  return loop->backend_fd;
326 }
327 
328 
330  if (loop->stop_flag != 0)
331  return 0;
332 
334  return 0;
335 
336  if (!QUEUE_EMPTY(&loop->idle_handles))
337  return 0;
338 
339  if (!QUEUE_EMPTY(&loop->pending_queue))
340  return 0;
341 
342  if (loop->closing_handles)
343  return 0;
344 
345  return uv__next_timeout(loop);
346 }
347 
348 
349 static int uv__loop_alive(const uv_loop_t* loop) {
350  return uv__has_active_handles(loop) ||
352  loop->closing_handles != NULL;
353 }
354 
355 
357  return uv__loop_alive(loop);
358 }
359 
360 
362  int timeout;
363  int r;
364  int ran_pending;
365 
366  r = uv__loop_alive(loop);
367  if (!r)
368  uv__update_time(loop);
369 
370  while (r != 0 && loop->stop_flag == 0) {
371  uv__update_time(loop);
373  ran_pending = uv__run_pending(loop);
376 
377  timeout = 0;
378  if ((mode == UV_RUN_ONCE && !ran_pending) || mode == UV_RUN_DEFAULT)
380 
384 
385  if (mode == UV_RUN_ONCE) {
386  /* UV_RUN_ONCE implies forward progress: at least one callback must have
387  * been invoked when it returns. uv__io_poll() can return without doing
388  * I/O (meaning: no callbacks) when its timeout expires - which means we
389  * have pending timers that satisfy the forward progress constraint.
390  *
391  * UV_RUN_NOWAIT makes no guarantees about progress so it's omitted from
392  * the check.
393  */
394  uv__update_time(loop);
396  }
397 
398  r = uv__loop_alive(loop);
399  if (mode == UV_RUN_ONCE || mode == UV_RUN_NOWAIT)
400  break;
401  }
402 
403  /* The if statement lets gcc compile it to a conditional store. Avoids
404  * dirtying a cache line.
405  */
406  if (loop->stop_flag != 0)
407  loop->stop_flag = 0;
408 
409  return r;
410 }
411 
412 
414  uv__update_time(loop);
415 }
416 
417 
419  return uv__is_active(handle);
420 }
421 
422 
423 /* Open a socket in non-blocking close-on-exec mode, atomically if possible. */
424 int uv__socket(int domain, int type, int protocol) {
425  int sockfd;
426  int err;
427 
428 #if defined(SOCK_NONBLOCK) && defined(SOCK_CLOEXEC)
429  sockfd = socket(domain, type | SOCK_NONBLOCK | SOCK_CLOEXEC, protocol);
430  if (sockfd != -1)
431  return sockfd;
432 
433  if (errno != EINVAL)
434  return UV__ERR(errno);
435 #endif
436 
437  sockfd = socket(domain, type, protocol);
438  if (sockfd == -1)
439  return UV__ERR(errno);
440 
441  err = uv__nonblock(sockfd, 1);
442  if (err == 0)
443  err = uv__cloexec(sockfd, 1);
444 
445  if (err) {
446  uv__close(sockfd);
447  return err;
448  }
449 
450 #if defined(SO_NOSIGPIPE)
451  {
452  int on = 1;
453  setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, &on, sizeof(on));
454  }
455 #endif
456 
457  return sockfd;
458 }
459 
460 /* get a file pointer to a file in read-only and close-on-exec mode */
461 FILE* uv__open_file(const char* path) {
462  int fd;
463  FILE* fp;
464 
465  fd = uv__open_cloexec(path, O_RDONLY);
466  if (fd < 0)
467  return NULL;
468 
469  fp = fdopen(fd, "r");
470  if (fp == NULL)
471  uv__close(fd);
472 
473  return fp;
474 }
475 
476 
477 int uv__accept(int sockfd) {
478  int peerfd;
479  int err;
480 
481  (void) &err;
482  assert(sockfd >= 0);
483 
484  do
485 #ifdef uv__accept4
486  peerfd = uv__accept4(sockfd, NULL, NULL, SOCK_NONBLOCK|SOCK_CLOEXEC);
487 #else
488  peerfd = accept(sockfd, NULL, NULL);
489 #endif
490  while (peerfd == -1 && errno == EINTR);
491 
492  if (peerfd == -1)
493  return UV__ERR(errno);
494 
495 #ifndef uv__accept4
496  err = uv__cloexec(peerfd, 1);
497  if (err == 0)
498  err = uv__nonblock(peerfd, 1);
499 
500  if (err != 0) {
501  uv__close(peerfd);
502  return err;
503  }
504 #endif
505 
506  return peerfd;
507 }
508 
509 
510 /* close() on macos has the "interesting" quirk that it fails with EINTR
511  * without closing the file descriptor when a thread is in the cancel state.
512  * That's why libuv calls close$NOCANCEL() instead.
513  *
514  * glibc on linux has a similar issue: close() is a cancellation point and
515  * will unwind the thread when it's in the cancel state. Work around that
516  * by making the system call directly. Musl libc is unaffected.
517  */
518 int uv__close_nocancel(int fd) {
519 #if defined(__APPLE__)
520 #pragma GCC diagnostic push
521 #pragma GCC diagnostic ignored "-Wdollar-in-identifier-extension"
522 #if defined(__LP64__) || TARGET_OS_IPHONE
523  extern int close$NOCANCEL(int);
524  return close$NOCANCEL(fd);
525 #else
526  extern int close$NOCANCEL$UNIX2003(int);
527  return close$NOCANCEL$UNIX2003(fd);
528 #endif
529 #pragma GCC diagnostic pop
530 #elif defined(__linux__)
531  return syscall(SYS_close, fd);
532 #else
533  return close(fd);
534 #endif
535 }
536 
537 
539  int saved_errno;
540  int rc;
541 
542  assert(fd > -1); /* Catch uninitialized io_watcher.fd bugs. */
543 
544  saved_errno = errno;
545  rc = uv__close_nocancel(fd);
546  if (rc == -1) {
547  rc = UV__ERR(errno);
548  if (rc == UV_EINTR || rc == UV__ERR(EINPROGRESS))
549  rc = 0; /* The close is in progress, not an error. */
550  errno = saved_errno;
551  }
552 
553  return rc;
554 }
555 
556 
557 int uv__close(int fd) {
558  assert(fd > STDERR_FILENO); /* Catch stdio close bugs. */
559 #if defined(__MVS__)
561 #endif
562  return uv__close_nocheckstdio(fd);
563 }
564 
565 
566 int uv__nonblock_ioctl(int fd, int set) {
567  int r;
568 
569  do
570  r = ioctl(fd, FIONBIO, &set);
571  while (r == -1 && errno == EINTR);
572 
573  if (r)
574  return UV__ERR(errno);
575 
576  return 0;
577 }
578 
579 
580 #if !defined(__CYGWIN__) && !defined(__MSYS__) && !defined(__HAIKU__)
581 int uv__cloexec_ioctl(int fd, int set) {
582  int r;
583 
584  do
585  r = ioctl(fd, set ? FIOCLEX : FIONCLEX);
586  while (r == -1 && errno == EINTR);
587 
588  if (r)
589  return UV__ERR(errno);
590 
591  return 0;
592 }
593 #endif
594 
595 
596 int uv__nonblock_fcntl(int fd, int set) {
597  int flags;
598  int r;
599 
600  do
601  r = fcntl(fd, F_GETFL);
602  while (r == -1 && errno == EINTR);
603 
604  if (r == -1)
605  return UV__ERR(errno);
606 
607  /* Bail out now if already set/clear. */
608  if (!!(r & O_NONBLOCK) == !!set)
609  return 0;
610 
611  if (set)
612  flags = r | O_NONBLOCK;
613  else
614  flags = r & ~O_NONBLOCK;
615 
616  do
617  r = fcntl(fd, F_SETFL, flags);
618  while (r == -1 && errno == EINTR);
619 
620  if (r)
621  return UV__ERR(errno);
622 
623  return 0;
624 }
625 
626 
627 int uv__cloexec_fcntl(int fd, int set) {
628  int flags;
629  int r;
630 
631  do
632  r = fcntl(fd, F_GETFD);
633  while (r == -1 && errno == EINTR);
634 
635  if (r == -1)
636  return UV__ERR(errno);
637 
638  /* Bail out now if already set/clear. */
639  if (!!(r & FD_CLOEXEC) == !!set)
640  return 0;
641 
642  if (set)
643  flags = r | FD_CLOEXEC;
644  else
645  flags = r & ~FD_CLOEXEC;
646 
647  do
648  r = fcntl(fd, F_SETFD, flags);
649  while (r == -1 && errno == EINTR);
650 
651  if (r)
652  return UV__ERR(errno);
653 
654  return 0;
655 }
656 
657 
658 ssize_t uv__recvmsg(int fd, struct msghdr* msg, int flags) {
659  struct cmsghdr* cmsg;
660  ssize_t rc;
661  int* pfd;
662  int* end;
663 #if defined(__linux__)
664  static int no_msg_cmsg_cloexec;
665  if (no_msg_cmsg_cloexec == 0) {
666  rc = recvmsg(fd, msg, flags | 0x40000000); /* MSG_CMSG_CLOEXEC */
667  if (rc != -1)
668  return rc;
669  if (errno != EINVAL)
670  return UV__ERR(errno);
671  rc = recvmsg(fd, msg, flags);
672  if (rc == -1)
673  return UV__ERR(errno);
674  no_msg_cmsg_cloexec = 1;
675  } else {
676  rc = recvmsg(fd, msg, flags);
677  }
678 #else
679  rc = recvmsg(fd, msg, flags);
680 #endif
681  if (rc == -1)
682  return UV__ERR(errno);
683  if (msg->msg_controllen == 0)
684  return rc;
685  for (cmsg = CMSG_FIRSTHDR(msg); cmsg != NULL; cmsg = CMSG_NXTHDR(msg, cmsg))
686  if (cmsg->cmsg_type == SCM_RIGHTS)
687  for (pfd = (int*) CMSG_DATA(cmsg),
688  end = (int*) ((char*) cmsg + cmsg->cmsg_len);
689  pfd < end;
690  pfd += 1)
691  uv__cloexec(*pfd, 1);
692  return rc;
693 }
694 
695 
696 int uv_cwd(char* buffer, size_t* size) {
697  char scratch[1 + UV__PATH_MAX];
698 
699  if (buffer == NULL || size == NULL)
700  return UV_EINVAL;
701 
702  /* Try to read directly into the user's buffer first... */
703  if (getcwd(buffer, *size) != NULL)
704  goto fixup;
705 
706  if (errno != ERANGE)
707  return UV__ERR(errno);
708 
709  /* ...or into scratch space if the user's buffer is too small
710  * so we can report how much space to provide on the next try.
711  */
712  if (getcwd(scratch, sizeof(scratch)) == NULL)
713  return UV__ERR(errno);
714 
715  buffer = scratch;
716 
717 fixup:
718 
719  *size = strlen(buffer);
720 
721  if (*size > 1 && buffer[*size - 1] == '/') {
722  *size -= 1;
723  buffer[*size] = '\0';
724  }
725 
726  if (buffer == scratch) {
727  *size += 1;
728  return UV_ENOBUFS;
729  }
730 
731  return 0;
732 }
733 
734 
735 int uv_chdir(const char* dir) {
736  if (chdir(dir))
737  return UV__ERR(errno);
738 
739  return 0;
740 }
741 
742 
744  int fd;
745 
746  /* Set the CLOEXEC flag on all open descriptors. Unconditionally try the
747  * first 16 file descriptors. After that, bail out after the first error.
748  */
749  for (fd = 0; ; fd++)
750  if (uv__cloexec(fd, 1) && fd > 15)
751  break;
752 }
753 
754 
756  int fd_out;
757 
758  switch (handle->type) {
759  case UV_TCP:
760  case UV_NAMED_PIPE:
761  case UV_TTY:
762  fd_out = uv__stream_fd((uv_stream_t*) handle);
763  break;
764 
765  case UV_UDP:
766  fd_out = ((uv_udp_t *) handle)->io_watcher.fd;
767  break;
768 
769  case UV_POLL:
770  fd_out = ((uv_poll_t *) handle)->io_watcher.fd;
771  break;
772 
773  default:
774  return UV_EINVAL;
775  }
776 
777  if (uv__is_closing(handle) || fd_out == -1)
778  return UV_EBADF;
779 
780  *fd = fd_out;
781  return 0;
782 }
783 
784 
786  QUEUE* q;
787  QUEUE pq;
788  uv__io_t* w;
789 
790  if (QUEUE_EMPTY(&loop->pending_queue))
791  return 0;
792 
793  QUEUE_MOVE(&loop->pending_queue, &pq);
794 
795  while (!QUEUE_EMPTY(&pq)) {
796  q = QUEUE_HEAD(&pq);
797  QUEUE_REMOVE(q);
798  QUEUE_INIT(q);
799  w = QUEUE_DATA(q, uv__io_t, pending_queue);
800  w->cb(loop, w, POLLOUT);
801  }
802 
803  return 1;
804 }
805 
806 
807 static unsigned int next_power_of_two(unsigned int val) {
808  val -= 1;
809  val |= val >> 1;
810  val |= val >> 2;
811  val |= val >> 4;
812  val |= val >> 8;
813  val |= val >> 16;
814  val += 1;
815  return val;
816 }
817 
818 static void maybe_resize(uv_loop_t* loop, unsigned int len) {
819  uv__io_t** watchers;
820  void* fake_watcher_list;
821  void* fake_watcher_count;
822  unsigned int nwatchers;
823  unsigned int i;
824 
825  if (len <= loop->nwatchers)
826  return;
827 
828  /* Preserve fake watcher list and count at the end of the watchers */
829  if (loop->watchers != NULL) {
830  fake_watcher_list = loop->watchers[loop->nwatchers];
831  fake_watcher_count = loop->watchers[loop->nwatchers + 1];
832  } else {
833  fake_watcher_list = NULL;
834  fake_watcher_count = NULL;
835  }
836 
837  nwatchers = next_power_of_two(len + 2) - 2;
838  watchers = uv__reallocf(loop->watchers,
839  (nwatchers + 2) * sizeof(loop->watchers[0]));
840 
841  if (watchers == NULL)
842  abort();
843  for (i = loop->nwatchers; i < nwatchers; i++)
844  watchers[i] = NULL;
845  watchers[nwatchers] = fake_watcher_list;
846  watchers[nwatchers + 1] = fake_watcher_count;
847 
848  loop->watchers = watchers;
849  loop->nwatchers = nwatchers;
850 }
851 
852 
853 void uv__io_init(uv__io_t* w, uv__io_cb cb, int fd) {
854  assert(cb != NULL);
855  assert(fd >= -1);
858  w->cb = cb;
859  w->fd = fd;
860  w->events = 0;
861  w->pevents = 0;
862 
863 #if defined(UV_HAVE_KQUEUE)
864  w->rcount = 0;
865  w->wcount = 0;
866 #endif /* defined(UV_HAVE_KQUEUE) */
867 }
868 
869 
870 void uv__io_start(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
871  assert(0 == (events & ~(POLLIN | POLLOUT | UV__POLLRDHUP | UV__POLLPRI)));
872  assert(0 != events);
873  assert(w->fd >= 0);
874  assert(w->fd < INT_MAX);
875 
876  w->pevents |= events;
877  maybe_resize(loop, w->fd + 1);
878 
879 #if !defined(__sun)
880  /* The event ports backend needs to rearm all file descriptors on each and
881  * every tick of the event loop but the other backends allow us to
882  * short-circuit here if the event mask is unchanged.
883  */
884  if (w->events == w->pevents)
885  return;
886 #endif
887 
888  if (QUEUE_EMPTY(&w->watcher_queue))
889  QUEUE_INSERT_TAIL(&loop->watcher_queue, &w->watcher_queue);
890 
891  if (loop->watchers[w->fd] == NULL) {
892  loop->watchers[w->fd] = w;
893  loop->nfds++;
894  }
895 }
896 
897 
898 void uv__io_stop(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
899  assert(0 == (events & ~(POLLIN | POLLOUT | UV__POLLRDHUP | UV__POLLPRI)));
900  assert(0 != events);
901 
902  if (w->fd == -1)
903  return;
904 
905  assert(w->fd >= 0);
906 
907  /* Happens when uv__io_stop() is called on a handle that was never started. */
908  if ((unsigned) w->fd >= loop->nwatchers)
909  return;
910 
911  w->pevents &= ~events;
912 
913  if (w->pevents == 0) {
916 
917  if (loop->watchers[w->fd] != NULL) {
918  assert(loop->watchers[w->fd] == w);
919  assert(loop->nfds > 0);
920  loop->watchers[w->fd] = NULL;
921  loop->nfds--;
922  w->events = 0;
923  }
924  }
925  else if (QUEUE_EMPTY(&w->watcher_queue))
926  QUEUE_INSERT_TAIL(&loop->watcher_queue, &w->watcher_queue);
927 }
928 
929 
931  uv__io_stop(loop, w, POLLIN | POLLOUT | UV__POLLRDHUP | UV__POLLPRI);
933 
934  /* Remove stale events for this file descriptor */
935  if (w->fd != -1)
937 }
938 
939 
941  if (QUEUE_EMPTY(&w->pending_queue))
942  QUEUE_INSERT_TAIL(&loop->pending_queue, &w->pending_queue);
943 }
944 
945 
946 int uv__io_active(const uv__io_t* w, unsigned int events) {
947  assert(0 == (events & ~(POLLIN | POLLOUT | UV__POLLRDHUP | UV__POLLPRI)));
948  assert(0 != events);
949  return 0 != (w->pevents & events);
950 }
951 
952 
953 int uv__fd_exists(uv_loop_t* loop, int fd) {
954  return (unsigned) fd < loop->nwatchers && loop->watchers[fd] != NULL;
955 }
956 
957 
958 int uv_getrusage(uv_rusage_t* rusage) {
959  struct rusage usage;
960 
961  if (getrusage(RUSAGE_SELF, &usage))
962  return UV__ERR(errno);
963 
964  rusage->ru_utime.tv_sec = usage.ru_utime.tv_sec;
965  rusage->ru_utime.tv_usec = usage.ru_utime.tv_usec;
966 
967  rusage->ru_stime.tv_sec = usage.ru_stime.tv_sec;
968  rusage->ru_stime.tv_usec = usage.ru_stime.tv_usec;
969 
970 #if !defined(__MVS__) && !defined(__HAIKU__)
971  rusage->ru_maxrss = usage.ru_maxrss;
972  rusage->ru_ixrss = usage.ru_ixrss;
973  rusage->ru_idrss = usage.ru_idrss;
974  rusage->ru_isrss = usage.ru_isrss;
975  rusage->ru_minflt = usage.ru_minflt;
976  rusage->ru_majflt = usage.ru_majflt;
977  rusage->ru_nswap = usage.ru_nswap;
978  rusage->ru_inblock = usage.ru_inblock;
979  rusage->ru_oublock = usage.ru_oublock;
980  rusage->ru_msgsnd = usage.ru_msgsnd;
981  rusage->ru_msgrcv = usage.ru_msgrcv;
982  rusage->ru_nsignals = usage.ru_nsignals;
983  rusage->ru_nvcsw = usage.ru_nvcsw;
984  rusage->ru_nivcsw = usage.ru_nivcsw;
985 #endif
986 
987  return 0;
988 }
989 
990 
991 int uv__open_cloexec(const char* path, int flags) {
992 #if defined(O_CLOEXEC)
993  int fd;
994 
995  fd = open(path, flags | O_CLOEXEC);
996  if (fd == -1)
997  return UV__ERR(errno);
998 
999  return fd;
1000 #else /* O_CLOEXEC */
1001  int err;
1002  int fd;
1003 
1004  fd = open(path, flags);
1005  if (fd == -1)
1006  return UV__ERR(errno);
1007 
1008  err = uv__cloexec(fd, 1);
1009  if (err) {
1010  uv__close(fd);
1011  return err;
1012  }
1013 
1014  return fd;
1015 #endif /* O_CLOEXEC */
1016 }
1017 
1018 
1019 int uv__dup2_cloexec(int oldfd, int newfd) {
1020 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__linux__)
1021  int r;
1022 
1023  r = dup3(oldfd, newfd, O_CLOEXEC);
1024  if (r == -1)
1025  return UV__ERR(errno);
1026 
1027  return r;
1028 #else
1029  int err;
1030  int r;
1031 
1032  r = dup2(oldfd, newfd); /* Never retry. */
1033  if (r == -1)
1034  return UV__ERR(errno);
1035 
1036  err = uv__cloexec(newfd, 1);
1037  if (err != 0) {
1038  uv__close(newfd);
1039  return err;
1040  }
1041 
1042  return r;
1043 #endif
1044 }
1045 
1046 
1047 int uv_os_homedir(char* buffer, size_t* size) {
1048  uv_passwd_t pwd;
1049  size_t len;
1050  int r;
1051 
1052  /* Check if the HOME environment variable is set first. The task of
1053  performing input validation on buffer and size is taken care of by
1054  uv_os_getenv(). */
1055  r = uv_os_getenv("HOME", buffer, size);
1056 
1057  if (r != UV_ENOENT)
1058  return r;
1059 
1060  /* HOME is not set, so call uv__getpwuid_r() */
1061  r = uv__getpwuid_r(&pwd);
1062 
1063  if (r != 0) {
1064  return r;
1065  }
1066 
1067  len = strlen(pwd.homedir);
1068 
1069  if (len >= *size) {
1070  *size = len + 1;
1071  uv_os_free_passwd(&pwd);
1072  return UV_ENOBUFS;
1073  }
1074 
1075  memcpy(buffer, pwd.homedir, len + 1);
1076  *size = len;
1077  uv_os_free_passwd(&pwd);
1078 
1079  return 0;
1080 }
1081 
1082 
1083 int uv_os_tmpdir(char* buffer, size_t* size) {
1084  const char* buf;
1085  size_t len;
1086 
1087  if (buffer == NULL || size == NULL || *size == 0)
1088  return UV_EINVAL;
1089 
1090 #define CHECK_ENV_VAR(name) \
1091  do { \
1092  buf = getenv(name); \
1093  if (buf != NULL) \
1094  goto return_buffer; \
1095  } \
1096  while (0)
1097 
1098  /* Check the TMPDIR, TMP, TEMP, and TEMPDIR environment variables in order */
1099  CHECK_ENV_VAR("TMPDIR");
1100  CHECK_ENV_VAR("TMP");
1101  CHECK_ENV_VAR("TEMP");
1102  CHECK_ENV_VAR("TEMPDIR");
1103 
1104 #undef CHECK_ENV_VAR
1105 
1106  /* No temp environment variables defined */
1107  #if defined(__ANDROID__)
1108  buf = "/data/local/tmp";
1109  #else
1110  buf = "/tmp";
1111  #endif
1112 
1113 return_buffer:
1114  len = strlen(buf);
1115 
1116  if (len >= *size) {
1117  *size = len + 1;
1118  return UV_ENOBUFS;
1119  }
1120 
1121  /* The returned directory should not have a trailing slash. */
1122  if (len > 1 && buf[len - 1] == '/') {
1123  len--;
1124  }
1125 
1126  memcpy(buffer, buf, len + 1);
1127  buffer[len] = '\0';
1128  *size = len;
1129 
1130  return 0;
1131 }
1132 
1133 
1135  struct passwd pw;
1136  struct passwd* result;
1137  char* buf;
1138  uid_t uid;
1139  size_t bufsize;
1140  size_t name_size;
1141  size_t homedir_size;
1142  size_t shell_size;
1143  long initsize;
1144  int r;
1145 #if defined(__ANDROID_API__) && __ANDROID_API__ < 21
1146  int (*getpwuid_r)(uid_t, struct passwd*, char*, size_t, struct passwd**);
1147 
1148  getpwuid_r = dlsym(RTLD_DEFAULT, "getpwuid_r");
1149  if (getpwuid_r == NULL)
1150  return UV_ENOSYS;
1151 #endif
1152 
1153  if (pwd == NULL)
1154  return UV_EINVAL;
1155 
1156  initsize = sysconf(_SC_GETPW_R_SIZE_MAX);
1157 
1158  if (initsize <= 0)
1159  bufsize = 4096;
1160  else
1161  bufsize = (size_t) initsize;
1162 
1163  uid = geteuid();
1164  buf = NULL;
1165 
1166  for (;;) {
1167  uv__free(buf);
1168  buf = uv__malloc(bufsize);
1169 
1170  if (buf == NULL)
1171  return UV_ENOMEM;
1172 
1173  r = getpwuid_r(uid, &pw, buf, bufsize, &result);
1174 
1175  if (r != ERANGE)
1176  break;
1177 
1178  bufsize *= 2;
1179  }
1180 
1181  if (r != 0) {
1182  uv__free(buf);
1183  return -r;
1184  }
1185 
1186  if (result == NULL) {
1187  uv__free(buf);
1188  return UV_ENOENT;
1189  }
1190 
1191  /* Allocate memory for the username, shell, and home directory */
1192  name_size = strlen(pw.pw_name) + 1;
1193  homedir_size = strlen(pw.pw_dir) + 1;
1194  shell_size = strlen(pw.pw_shell) + 1;
1195  pwd->username = uv__malloc(name_size + homedir_size + shell_size);
1196 
1197  if (pwd->username == NULL) {
1198  uv__free(buf);
1199  return UV_ENOMEM;
1200  }
1201 
1202  /* Copy the username */
1203  memcpy(pwd->username, pw.pw_name, name_size);
1204 
1205  /* Copy the home directory */
1206  pwd->homedir = pwd->username + name_size;
1207  memcpy(pwd->homedir, pw.pw_dir, homedir_size);
1208 
1209  /* Copy the shell */
1210  pwd->shell = pwd->homedir + homedir_size;
1211  memcpy(pwd->shell, pw.pw_shell, shell_size);
1212 
1213  /* Copy the uid and gid */
1214  pwd->uid = pw.pw_uid;
1215  pwd->gid = pw.pw_gid;
1216 
1217  uv__free(buf);
1218 
1219  return 0;
1220 }
1221 
1222 
1224  if (pwd == NULL)
1225  return;
1226 
1227  /*
1228  The memory for name, shell, and homedir are allocated in a single
1229  uv__malloc() call. The base of the pointer is stored in pwd->username, so
1230  that is the field that needs to be freed.
1231  */
1232  uv__free(pwd->username);
1233  pwd->username = NULL;
1234  pwd->shell = NULL;
1235  pwd->homedir = NULL;
1236 }
1237 
1238 
1240  return uv__getpwuid_r(pwd);
1241 }
1242 
1243 
1244 int uv_translate_sys_error(int sys_errno) {
1245  /* If < 0 then it's already a libuv error. */
1246  return sys_errno <= 0 ? sys_errno : -sys_errno;
1247 }
1248 
1249 
1250 int uv_os_environ(uv_env_item_t** envitems, int* count) {
1251  int i, j, cnt;
1252  uv_env_item_t* envitem;
1253 
1254  *envitems = NULL;
1255  *count = 0;
1256 
1257  for (i = 0; environ[i] != NULL; i++);
1258 
1259  *envitems = uv__calloc(i, sizeof(**envitems));
1260 
1261  if (*envitems == NULL)
1262  return UV_ENOMEM;
1263 
1264  for (j = 0, cnt = 0; j < i; j++) {
1265  char* buf;
1266  char* ptr;
1267 
1268  if (environ[j] == NULL)
1269  break;
1270 
1271  buf = uv__strdup(environ[j]);
1272  if (buf == NULL)
1273  goto fail;
1274 
1275  ptr = strchr(buf, '=');
1276  if (ptr == NULL) {
1277  uv__free(buf);
1278  continue;
1279  }
1280 
1281  *ptr = '\0';
1282 
1283  envitem = &(*envitems)[cnt];
1284  envitem->name = buf;
1285  envitem->value = ptr + 1;
1286 
1287  cnt++;
1288  }
1289 
1290  *count = cnt;
1291  return 0;
1292 
1293 fail:
1294  for (i = 0; i < cnt; i++) {
1295  envitem = &(*envitems)[cnt];
1296  uv__free(envitem->name);
1297  }
1298  uv__free(*envitems);
1299 
1300  *envitems = NULL;
1301  *count = 0;
1302  return UV_ENOMEM;
1303 }
1304 
1305 
1306 int uv_os_getenv(const char* name, char* buffer, size_t* size) {
1307  char* var;
1308  size_t len;
1309 
1310  if (name == NULL || buffer == NULL || size == NULL || *size == 0)
1311  return UV_EINVAL;
1312 
1313  var = getenv(name);
1314 
1315  if (var == NULL)
1316  return UV_ENOENT;
1317 
1318  len = strlen(var);
1319 
1320  if (len >= *size) {
1321  *size = len + 1;
1322  return UV_ENOBUFS;
1323  }
1324 
1325  memcpy(buffer, var, len + 1);
1326  *size = len;
1327 
1328  return 0;
1329 }
1330 
1331 
1332 int uv_os_setenv(const char* name, const char* value) {
1333  if (name == NULL || value == NULL)
1334  return UV_EINVAL;
1335 
1336  if (setenv(name, value, 1) != 0)
1337  return UV__ERR(errno);
1338 
1339  return 0;
1340 }
1341 
1342 
1343 int uv_os_unsetenv(const char* name) {
1344  if (name == NULL)
1345  return UV_EINVAL;
1346 
1347  if (unsetenv(name) != 0)
1348  return UV__ERR(errno);
1349 
1350  return 0;
1351 }
1352 
1353 
1354 int uv_os_gethostname(char* buffer, size_t* size) {
1355  /*
1356  On some platforms, if the input buffer is not large enough, gethostname()
1357  succeeds, but truncates the result. libuv can detect this and return ENOBUFS
1358  instead by creating a large enough buffer and comparing the hostname length
1359  to the size input.
1360  */
1361  char buf[UV_MAXHOSTNAMESIZE];
1362  size_t len;
1363 
1364  if (buffer == NULL || size == NULL || *size == 0)
1365  return UV_EINVAL;
1366 
1367  if (gethostname(buf, sizeof(buf)) != 0)
1368  return UV__ERR(errno);
1369 
1370  buf[sizeof(buf) - 1] = '\0'; /* Null terminate, just to be safe. */
1371  len = strlen(buf);
1372 
1373  if (len >= *size) {
1374  *size = len + 1;
1375  return UV_ENOBUFS;
1376  }
1377 
1378  memcpy(buffer, buf, len + 1);
1379  *size = len;
1380  return 0;
1381 }
1382 
1383 
1385  return fd;
1386 }
1387 
1389  return os_fd;
1390 }
1391 
1393  return getpid();
1394 }
1395 
1396 
1398  return getppid();
1399 }
1400 
1401 
1403  int r;
1404 
1405  if (priority == NULL)
1406  return UV_EINVAL;
1407 
1408  errno = 0;
1409  r = getpriority(PRIO_PROCESS, (int) pid);
1410 
1411  if (r == -1 && errno != 0)
1412  return UV__ERR(errno);
1413 
1414  *priority = r;
1415  return 0;
1416 }
1417 
1418 
1420  if (priority < UV_PRIORITY_HIGHEST || priority > UV_PRIORITY_LOW)
1421  return UV_EINVAL;
1422 
1423  if (setpriority(PRIO_PROCESS, (int) pid, priority) != 0)
1424  return UV__ERR(errno);
1425 
1426  return 0;
1427 }
1428 
1429 
1431  struct utsname buf;
1432  int r;
1433 
1434  if (buffer == NULL)
1435  return UV_EINVAL;
1436 
1437  if (uname(&buf) == -1) {
1438  r = UV__ERR(errno);
1439  goto error;
1440  }
1441 
1442  r = uv__strscpy(buffer->sysname, buf.sysname, sizeof(buffer->sysname));
1443  if (r == UV_E2BIG)
1444  goto error;
1445 
1446 #ifdef _AIX
1447  r = snprintf(buffer->release,
1448  sizeof(buffer->release),
1449  "%s.%s",
1450  buf.version,
1451  buf.release);
1452  if (r >= sizeof(buffer->release)) {
1453  r = UV_E2BIG;
1454  goto error;
1455  }
1456 #else
1457  r = uv__strscpy(buffer->release, buf.release, sizeof(buffer->release));
1458  if (r == UV_E2BIG)
1459  goto error;
1460 #endif
1461 
1462  r = uv__strscpy(buffer->version, buf.version, sizeof(buffer->version));
1463  if (r == UV_E2BIG)
1464  goto error;
1465 
1466 #if defined(_AIX) || defined(__PASE__)
1467  r = uv__strscpy(buffer->machine, "ppc64", sizeof(buffer->machine));
1468 #else
1469  r = uv__strscpy(buffer->machine, buf.machine, sizeof(buffer->machine));
1470 #endif
1471 
1472  if (r == UV_E2BIG)
1473  goto error;
1474 
1475  return 0;
1476 
1477 error:
1478  buffer->sysname[0] = '\0';
1479  buffer->release[0] = '\0';
1480  buffer->version[0] = '\0';
1481  buffer->machine[0] = '\0';
1482  return r;
1483 }
1484 
1487  struct sockaddr* name,
1488  int* namelen) {
1489  socklen_t socklen;
1490  uv_os_fd_t fd;
1491  int r;
1492 
1493  r = uv_fileno(handle, &fd);
1494  if (r < 0)
1495  return r;
1496 
1497  /* sizeof(socklen_t) != sizeof(int) on some systems. */
1498  socklen = (socklen_t) *namelen;
1499 
1500  if (func(fd, name, &socklen))
1501  return UV__ERR(errno);
1502 
1503  *namelen = (int) socklen;
1504  return 0;
1505 }
1506 
1508  struct timeval time;
1509 
1510  if (tv == NULL)
1511  return UV_EINVAL;
1512 
1513  if (gettimeofday(&time, NULL) != 0)
1514  return UV__ERR(errno);
1515 
1516  tv->tv_sec = (int64_t) time.tv_sec;
1517  tv->tv_usec = (int32_t) time.tv_usec;
1518  return 0;
1519 }
1520 
1521 void uv_sleep(unsigned int msec) {
1522  struct timespec timeout;
1523  int rc;
1524 
1525  timeout.tv_sec = msec / 1000;
1526  timeout.tv_nsec = (msec % 1000) * 1000 * 1000;
1527 
1528  do
1529  rc = nanosleep(&timeout, &timeout);
1530  while (rc == -1 && errno == EINTR);
1531 
1532  assert(rc == 0);
1533 }
uv__is_active
#define uv__is_active(h)
Definition: uv-common.h:235
uv__is_closing
#define uv__is_closing(h)
Definition: uv-common.h:238
ptr
char * ptr
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:45
async_greeter_server_with_graceful_shutdown.loop
loop
Definition: async_greeter_server_with_graceful_shutdown.py:59
uv_fs_event_s
Definition: uv.h:1533
_gevent_test_main.result
result
Definition: _gevent_test_main.py:96
uv__open_file
FILE * uv__open_file(const char *path)
Definition: unix/core.c:461
uv__stream_close
void uv__stream_close(uv_stream_t *handle)
Definition: unix/stream.c:1633
uv__dup2_cloexec
int uv__dup2_cloexec(int oldfd, int newfd)
Definition: unix/core.c:1019
uv_os_setenv
int uv_os_setenv(const char *name, const char *value)
Definition: unix/core.c:1332
uv_env_item_s::value
char * value
Definition: uv.h:1220
uv_backend_timeout
int uv_backend_timeout(const uv_loop_t *loop)
Definition: unix/core.c:329
UV_PRIORITY_LOW
#define UV_PRIORITY_LOW
Definition: uv.h:1199
UV_HANDLE_CLOSED
@ UV_HANDLE_CLOSED
Definition: uv-common.h:67
uv__run_prepare
void uv__run_prepare(uv_loop_t *loop)
uv_process_s
Definition: uv.h:1037
uv_rusage_t::ru_stime
uv_timeval_t ru_stime
Definition: uv.h:1164
uv_rusage_t::ru_idrss
uint64_t ru_idrss
Definition: uv.h:1167
uv__run_check
void uv__run_check(uv_loop_t *loop)
uv_os_getenv
int uv_os_getenv(const char *name, char *buffer, size_t *size)
Definition: unix/core.c:1306
uv__udp_finish_close
void uv__udp_finish_close(uv_udp_t *handle)
Definition: unix/udp.c:96
uv_rusage_t
Definition: uv.h:1162
uv_os_homedir
int uv_os_homedir(char *buffer, size_t *size)
Definition: unix/core.c:1047
priority
int priority
Definition: abseil-cpp/absl/synchronization/internal/graphcycles.cc:286
uv_passwd_s
Definition: uv.h:1099
uv__socket
int uv__socket(int domain, int type, int protocol)
Definition: unix/core.c:424
uv_chdir
int uv_chdir(const char *dir)
Definition: unix/core.c:735
CHECK_ENV_VAR
#define CHECK_ENV_VAR(name)
uv_prepare_s
Definition: uv.h:804
uv__malloc
void * uv__malloc(size_t size)
Definition: uv-common.c:75
UV_RUN_NOWAIT
@ UV_RUN_NOWAIT
Definition: uv.h:256
uv_passwd_s::username
char * username
Definition: uv.h:1100
uv__close_nocheckstdio
int uv__close_nocheckstdio(int fd)
Definition: unix/core.c:538
uv__tcp_close
void uv__tcp_close(uv_tcp_t *handle)
Definition: unix/tcp.c:456
uv_passwd_s::gid
long gid
Definition: uv.h:1102
uv_passwd_s::homedir
char * homedir
Definition: uv.h:1104
string.h
uv_timeval64_t::tv_sec
int64_t tv_sec
Definition: uv.h:1158
uv_pid_t
pid_t uv_pid_t
Definition: unix.h:129
buf
voidpf void * buf
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
uv__poll_close
void uv__poll_close(uv_poll_t *handle)
Definition: unix/poll.c:148
uv_os_gethostname
int uv_os_gethostname(char *buffer, size_t *size)
Definition: unix/core.c:1354
UV_MAXHOSTNAMESIZE
#define UV_MAXHOSTNAMESIZE
Definition: uv.h:1237
error
grpc_error_handle error
Definition: retry_filter.cc:499
uv__finish_close
static void uv__finish_close(uv_handle_t *handle)
Definition: unix/core.c:239
error_ref_leak.err
err
Definition: error_ref_leak.py:35
protocol
Protocol protocol
Definition: client_callback_end2end_test.cc:67
uv__hrtime
uint64_t uv__hrtime(uv_clocktype_t type)
Definition: aix-common.c:62
QUEUE_HEAD
#define QUEUE_HEAD(q)
Definition: queue.h:42
uv_is_closing
int uv_is_closing(const uv_handle_t *handle)
Definition: unix/core.c:319
uv_rusage_t::ru_nivcsw
uint64_t ru_nivcsw
Definition: uv.h:1178
uv_rusage_t::ru_majflt
uint64_t ru_majflt
Definition: uv.h:1170
uv__open_cloexec
int uv__open_cloexec(const char *path, int flags)
Definition: unix/core.c:991
uv_os_free_passwd
void uv_os_free_passwd(uv_passwd_t *pwd)
Definition: unix/core.c:1223
nanosleep
int nanosleep(const struct timespec *req, struct timespec *rem)
Definition: os390-syscalls.c:385
mode
const char int mode
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:135
setup.name
name
Definition: setup.py:542
uv_os_get_passwd
int uv_os_get_passwd(uv_passwd_t *pwd)
Definition: unix/core.c:1239
uv_os_environ
int uv_os_environ(uv_env_item_t **envitems, int *count)
Definition: unix/core.c:1250
check_documentation.path
path
Definition: check_documentation.py:57
uv__cloexec_fcntl
int uv__cloexec_fcntl(int fd, int set)
Definition: unix/core.c:627
UV__POLLPRI
#define UV__POLLPRI
Definition: third_party/libuv/src/unix/internal.h:126
uv__has_active_handles
#define uv__has_active_handles(loop)
Definition: uv-common.h:220
uv_run
int uv_run(uv_loop_t *loop, uv_run_mode mode)
Definition: unix/core.c:361
xds_manager.p
p
Definition: xds_manager.py:60
uv__io_init
void uv__io_init(uv__io_t *w, uv__io_cb cb, int fd)
Definition: unix/core.c:853
uv_env_item_s::name
char * name
Definition: uv.h:1219
QUEUE_DATA
#define QUEUE_DATA(ptr, type, field)
Definition: queue.h:30
uv_os_getpid
uv_pid_t uv_os_getpid(void)
Definition: unix/core.c:1392
uv_sleep
void uv_sleep(unsigned int msec)
Definition: unix/core.c:1521
uv__handle_unref
#define uv__handle_unref(h)
Definition: uv-common.h:266
uv__fs_event_close
void uv__fs_event_close(uv_fs_event_t *handle)
Definition: aix.c:823
uv__io_s::fd
int fd
Definition: unix.h:100
uv__io_s::watcher_queue
void * watcher_queue[2]
Definition: unix.h:97
uv_os_tmpdir
int uv_os_tmpdir(char *buffer, size_t *size)
Definition: unix/core.c:1083
QUEUE_MOVE
#define QUEUE_MOVE(h, n)
Definition: queue.h:72
uv_os_uname
int uv_os_uname(uv_utsname_t *buffer)
Definition: unix/core.c:1430
uv__io_s::events
unsigned int events
Definition: unix.h:99
uv_timeval_t::tv_sec
long tv_sec
Definition: uv.h:1153
uv_stream_s
Definition: uv.h:491
uv__run_idle
void uv__run_idle(uv_loop_t *loop)
uv__timer_close
void uv__timer_close(uv_timer_t *handle)
Definition: timer.c:174
uv_os_getppid
uv_pid_t uv_os_getppid(void)
Definition: unix/core.c:1397
QUEUE_INIT
#define QUEUE_INIT(q)
Definition: queue.h:45
uv_rusage_t::ru_isrss
uint64_t ru_isrss
Definition: uv.h:1168
memcpy
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
uv__async_close
void uv__async_close(uv_async_t *handle)
Definition: unix/async.c:102
uv_rusage_t::ru_nsignals
uint64_t ru_nsignals
Definition: uv.h:1176
uv_async_s
Definition: uv.h:834
uv_check_s
Definition: uv.h:814
uv_rusage_t::ru_oublock
uint64_t ru_oublock
Definition: uv.h:1173
ssize_t
intptr_t ssize_t
Definition: win.h:27
next_power_of_two
static unsigned int next_power_of_two(unsigned int val)
Definition: unix/core.c:807
xds_interop_client.int
int
Definition: xds_interop_client.py:113
end
char * end
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1008
maybe_resize
static void maybe_resize(uv_loop_t *loop, unsigned int len)
Definition: unix/core.c:818
int64_t
signed __int64 int64_t
Definition: stdint-msvc2008.h:89
uv__cloexec
#define uv__cloexec
Definition: third_party/libuv/src/unix/internal.h:173
uv__signal_close
void uv__signal_close(uv_signal_t *handle)
Definition: unix/signal.c:333
uv_passwd_s::shell
char * shell
Definition: uv.h:1103
uv__fd_exists
int uv__fd_exists(uv_loop_t *loop, int fd)
Definition: unix/core.c:953
uv_rusage_t::ru_msgsnd
uint64_t ru_msgsnd
Definition: uv.h:1174
uv_env_item_s
Definition: uv.h:1218
UV_RUN_DEFAULT
@ UV_RUN_DEFAULT
Definition: uv.h:254
uv__io_active
int uv__io_active(const uv__io_t *w, unsigned int events)
Definition: unix/core.c:946
uv__strdup
char * uv__strdup(const char *s)
Definition: uv-common.c:55
uv_disable_stdio_inheritance
void uv_disable_stdio_inheritance(void)
Definition: unix/core.c:743
uv__io_start
void uv__io_start(uv_loop_t *loop, uv__io_t *w, unsigned int events)
Definition: unix/core.c:870
uv_udp_s
Definition: uv.h:629
uv__make_close_pending
void uv__make_close_pending(uv_handle_t *handle)
Definition: unix/core.c:212
uv__close_nocancel
int uv__close_nocancel(int fd)
Definition: unix/core.c:518
uv__getsockpeername
int uv__getsockpeername(const uv_handle_t *handle, uv__peersockfunc func, struct sockaddr *name, int *namelen)
Definition: unix/core.c:1485
grpc_core::fail
Poll< absl::StatusOr< std::tuple< T... > > > fail()
Definition: try_join_test.cc:45
uint64_t
unsigned __int64 uint64_t
Definition: stdint-msvc2008.h:90
uv__io_poll
void uv__io_poll(uv_loop_t *loop, int timeout)
Definition: aix.c:132
uv_translate_sys_error
int uv_translate_sys_error(int sys_errno)
Definition: unix/core.c:1244
UV_CLOCK_PRECISE
@ UV_CLOCK_PRECISE
Definition: third_party/libuv/src/unix/internal.h:151
uv__platform_invalidate_fd
void uv__platform_invalidate_fd(uv_loop_t *loop, int fd)
Definition: aix.c:1222
uv__pipe_close
void uv__pipe_close(uv_pipe_t *handle)
Definition: unix/pipe.c:120
syscall
const char * syscall
Definition: third_party/libuv/src/win/internal.h:270
close
#define close
Definition: test-fs.c:48
uv__calloc
void * uv__calloc(size_t count, size_t size)
Definition: uv-common.c:92
uv__free
void uv__free(void *ptr)
Definition: uv-common.c:81
uv__run_closing_handles
static void uv__run_closing_handles(uv_loop_t *loop)
Definition: unix/core.c:304
epoll_file_close
int epoll_file_close(int fd)
Definition: os390-syscalls.c:354
UV__ERR
#define UV__ERR(x)
Definition: errno.h:29
gen_synthetic_protos.base
base
Definition: gen_synthetic_protos.py:31
uv_cwd
int uv_cwd(char *buffer, size_t *size)
Definition: unix/core.c:696
buffer
char buffer[1024]
Definition: libuv/docs/code/idle-compute/main.c:8
uv__next_timeout
int uv__next_timeout(const uv_loop_t *loop)
Definition: timer.c:133
uv__getpwuid_r
int uv__getpwuid_r(uv_passwd_t *pwd)
Definition: unix/core.c:1134
uv_timer_s
Definition: uv.h:850
uv__getiovmax
int uv__getiovmax(void)
Definition: unix/core.c:219
QUEUE_REMOVE
#define QUEUE_REMOVE(q)
Definition: queue.h:101
close_cb
static void close_cb(uv_handle_t *handle)
Definition: benchmark-million-timers.c:36
uv__recvmsg
ssize_t uv__recvmsg(int fd, struct msghdr *msg, int flags)
Definition: unix/core.c:658
uv__run_pending
static int uv__run_pending(uv_loop_t *loop)
Definition: unix/core.c:785
uv_timeval64_t::tv_usec
int32_t tv_usec
Definition: uv.h:1159
uv__reallocf
void * uv__reallocf(void *ptr, size_t size)
Definition: uv-common.c:103
uv_fileno
int uv_fileno(const uv_handle_t *handle, uv_os_fd_t *fd)
Definition: unix/core.c:755
uv_is_active
int uv_is_active(const uv_handle_t *handle)
Definition: unix/core.c:418
uv_rusage_t::ru_nvcsw
uint64_t ru_nvcsw
Definition: uv.h:1177
uv_rusage_t::ru_ixrss
uint64_t ru_ixrss
Definition: uv.h:1166
uv_tcp_s
Definition: uv.h:544
QUEUE_EMPTY
#define QUEUE_EMPTY(q)
Definition: queue.h:39
uv_rusage_t::ru_minflt
uint64_t ru_minflt
Definition: uv.h:1169
msg
std::string msg
Definition: client_interceptors_end2end_test.cc:372
uv__has_active_reqs
#define uv__has_active_reqs(loop)
Definition: uv-common.h:204
environ
char ** environ
Definition: bloaty/third_party/googletest/googlemock/test/gmock_leak_test.py:41
uv_gettimeofday
int uv_gettimeofday(uv_timeval64_t *tv)
Definition: unix/core.c:1507
uv__nonblock_fcntl
int uv__nonblock_fcntl(int fd, int set)
Definition: unix/core.c:596
uv_run_mode
uv_run_mode
Definition: uv.h:253
value
const char * value
Definition: hpack_parser_table.cc:165
uv.h
uv__accept
int uv__accept(int sockfd)
Definition: unix/core.c:477
uv_rusage_t::ru_msgrcv
uint64_t ru_msgrcv
Definition: uv.h:1175
uv_passwd_s::uid
long uid
Definition: uv.h:1101
uv__nonblock
#define uv__nonblock
Definition: third_party/libuv/src/unix/internal.h:174
UV_HANDLE_CLOSING
@ UV_HANDLE_CLOSING
Definition: uv-common.h:66
uv_timeval64_t
Definition: uv.h:1157
uv_signal_s
Definition: uv.h:1561
uv_backend_fd
int uv_backend_fd(const uv_loop_t *loop)
Definition: unix/core.c:324
uv_buf_t
Definition: unix.h:121
iovec
Definition: gsec.h:33
internal.h
timeval::tv_sec
long tv_sec
Definition: setup_once.h:121
uv__strscpy
ssize_t uv__strscpy(char *d, const char *s, size_t n)
Definition: strscpy.c:4
UV__POLLRDHUP
#define UV__POLLRDHUP
Definition: third_party/libuv/src/unix/internal.h:120
uv_rusage_t::ru_maxrss
uint64_t ru_maxrss
Definition: uv.h:1165
uv__io_feed
void uv__io_feed(uv_loop_t *loop, uv__io_t *w)
Definition: unix/core.c:940
func
const EVP_CIPHER *(* func)(void)
Definition: cipher_extra.c:73
uv_poll_s
Definition: uv.h:783
uv_loop_alive
int uv_loop_alive(const uv_loop_t *loop)
Definition: unix/core.c:356
uv__stream_destroy
void uv__stream_destroy(uv_stream_t *stream)
Definition: unix/stream.c:458
scratch
static char scratch[256]
Definition: test-random.c:27
benchmark.FILE
FILE
Definition: benchmark.py:21
uv__io_cb
void(* uv__io_cb)(struct uv_loop_s *loop, struct uv__io_s *w, unsigned int events)
Definition: unix.h:89
bloaty::usage
const char usage[]
Definition: bloaty.cc:1843
timeval::tv_usec
long tv_usec
Definition: setup_once.h:122
absl::flags_internal
Definition: abseil-cpp/absl/flags/commandlineflag.h:40
uv_os_fd_t
int uv_os_fd_t
Definition: unix.h:128
count
int * count
Definition: bloaty/third_party/googletest/googlemock/test/gmock_stress_test.cc:96
uv_fs_poll_s
Definition: uv.h:1544
uv__io_s::cb
uv__io_cb cb
Definition: unix.h:95
timeval
Definition: setup_once.h:113
uv__peersockfunc
int(* uv__peersockfunc)(int, struct sockaddr *, socklen_t *)
Definition: third_party/libuv/src/unix/internal.h:324
uv_os_getpriority
int uv_os_getpriority(uv_pid_t pid, int *priority)
Definition: unix/core.c:1402
uv_idle_s
Definition: uv.h:824
uv__io_close
void uv__io_close(uv_loop_t *loop, uv__io_t *w)
Definition: unix/core.c:930
uv__stream_fd
#define uv__stream_fd(handle)
Definition: third_party/libuv/src/unix/internal.h:285
fix_build_deps.r
r
Definition: fix_build_deps.py:491
uv__nonblock_ioctl
int uv__nonblock_ioctl(int fd, int set)
Definition: unix/core.c:566
SAVE_ERRNO
#define SAVE_ERRNO(block)
Definition: third_party/libuv/src/unix/internal.h:94
uv__idle_close
void uv__idle_close(uv_idle_t *handle)
uv_get_osfhandle
uv_os_fd_t uv_get_osfhandle(int fd)
Definition: unix/core.c:1384
uv_rusage_t::ru_nswap
uint64_t ru_nswap
Definition: uv.h:1171
cpp.gmock_class.set
set
Definition: bloaty/third_party/googletest/googlemock/scripts/generator/cpp/gmock_class.py:44
uv__socket_sockopt
int uv__socket_sockopt(uv_handle_t *handle, int optname, int *value)
Definition: unix/core.c:184
uv__io_s::pending_queue
void * pending_queue[2]
Definition: unix.h:96
uv__fs_poll_close
void uv__fs_poll_close(uv_fs_poll_t *handle)
Definition: fs-poll.c:164
UV_RUN_ONCE
@ UV_RUN_ONCE
Definition: uv.h:255
uv_pipe_s
Definition: uv.h:757
uv_os_setpriority
int uv_os_setpriority(uv_pid_t pid, int priority)
Definition: unix/core.c:1419
STATIC_ASSERT
STATIC_ASSERT(sizeof(uv_buf_t)==sizeof(struct iovec))
uv__io_s::pevents
unsigned int pevents
Definition: unix.h:98
uv_timeval_t::tv_usec
long tv_usec
Definition: uv.h:1154
uv__check_close
void uv__check_close(uv_check_t *handle)
uv__io_stop
void uv__io_stop(uv_loop_t *loop, uv__io_t *w, unsigned int events)
Definition: unix/core.c:898
uv_hrtime
uint64_t uv_hrtime(void)
Definition: unix/core.c:107
open
#define open
Definition: test-fs.c:46
uv__process_close
void uv__process_close(uv_process_t *handle)
Definition: unix/process.c:590
handle
static csh handle
Definition: test_arm_regression.c:16
uv_rusage_t::ru_utime
uv_timeval_t ru_utime
Definition: uv.h:1163
uv__loop_alive
static int uv__loop_alive(const uv_loop_t *loop)
Definition: unix/core.c:349
uv_handle_s
Definition: uv.h:441
test_server.socket
socket
Definition: test_server.py:65
uv_loop_s
Definition: uv.h:1767
flags
uint32_t flags
Definition: retry_filter.cc:632
uv_close_cb
void(* uv_close_cb)(uv_handle_t *handle)
Definition: uv.h:316
UV__PATH_MAX
#define UV__PATH_MAX
Definition: third_party/libuv/src/unix/internal.h:70
uv__prepare_close
void uv__prepare_close(uv_prepare_t *handle)
asyncio_get_stats.type
type
Definition: asyncio_get_stats.py:37
uv_open_osfhandle
int uv_open_osfhandle(uv_os_fd_t os_fd)
Definition: unix/core.c:1388
uv_rusage_t::ru_inblock
uint64_t ru_inblock
Definition: uv.h:1172
len
int len
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:46
uv__udp_close
void uv__udp_close(uv_udp_t *handle)
Definition: unix/udp.c:85
size
voidpf void uLong size
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
uv_update_time
void uv_update_time(uv_loop_t *loop)
Definition: unix/core.c:413
uv_close
void uv_close(uv_handle_t *handle, uv_close_cb close_cb)
Definition: unix/core.c:112
uv__io_s
Definition: unix.h:94
int32_t
signed int int32_t
Definition: stdint-msvc2008.h:77
getenv
#define getenv(ptr)
Definition: ares_private.h:106
uv_getrusage
int uv_getrusage(uv_rusage_t *rusage)
Definition: unix/core.c:958
QUEUE_INSERT_TAIL
#define QUEUE_INSERT_TAIL(h, q)
Definition: queue.h:92
uv__cloexec_ioctl
int uv__cloexec_ioctl(int fd, int set)
Definition: unix/core.c:581
uv__run_timers
void uv__run_timers(uv_loop_t *loop)
Definition: timer.c:154
timeout
uv_timer_t timeout
Definition: libuv/docs/code/uvwget/main.c:9
errno.h
cb
OPENSSL_EXPORT pem_password_cb * cb
Definition: pem.h:351
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
uv_os_unsetenv
int uv_os_unsetenv(const char *name)
Definition: unix/core.c:1343
QUEUE
void * QUEUE[2]
Definition: queue.h:21
uv_utsname_s
Definition: uv.h:1107
uv__close
int uv__close(int fd)
Definition: unix/core.c:557


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:57