Blame misc/pselect.c

Packit Service 82fcde
/* Copyright (C) 1996-2018 Free Software Foundation, Inc.
Packit Service 82fcde
   This file is part of the GNU C Library.
Packit Service 82fcde
   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 82fcde
   modify it under the terms of the GNU Lesser General Public
Packit Service 82fcde
   License as published by the Free Software Foundation; either
Packit Service 82fcde
   version 2.1 of the License, or (at your option) any later version.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 82fcde
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 82fcde
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 82fcde
   Lesser General Public License for more details.
Packit Service 82fcde
Packit Service 82fcde
   You should have received a copy of the GNU Lesser General Public
Packit Service 82fcde
   License along with the GNU C Library; if not, see
Packit Service 82fcde
   <http://www.gnu.org/licenses/>.  */
Packit Service 82fcde
Packit Service 82fcde
#include <errno.h>
Packit Service 82fcde
#include <signal.h>
Packit Service 82fcde
#include <stddef.h>	/* For NULL.  */
Packit Service 82fcde
#include <sys/time.h>
Packit Service 82fcde
#include <sys/select.h>
Packit Service 82fcde
#include <sysdep-cancel.h>
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
/* Check the first NFDS descriptors each in READFDS (if not NULL) for read
Packit Service 82fcde
   readiness, in WRITEFDS (if not NULL) for write readiness, and in EXCEPTFDS
Packit Service 82fcde
   (if not NULL) for exceptional conditions.  If TIMEOUT is not NULL, time out
Packit Service 82fcde
   after waiting the interval specified therein.  Additionally set the sigmask
Packit Service 82fcde
   SIGMASK for this call.  Returns the number of ready descriptors, or -1 for
Packit Service 82fcde
   errors.  */
Packit Service 82fcde
int
Packit Service 82fcde
__pselect (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
Packit Service 82fcde
	   const struct timespec *timeout, const sigset_t *sigmask)
Packit Service 82fcde
{
Packit Service 82fcde
  struct timeval tval;
Packit Service 82fcde
  int retval;
Packit Service 82fcde
  sigset_t savemask;
Packit Service 82fcde
Packit Service 82fcde
  /* Change nanosecond number to microseconds.  This might mean losing
Packit Service 82fcde
     precision and therefore the `pselect` should be available.  But
Packit Service 82fcde
     for now it is hardly found.  */
Packit Service 82fcde
  if (timeout != NULL)
Packit Service 82fcde
    {
Packit Service 82fcde
      /* Catch bugs which would be hidden by the TIMESPEC_TO_TIMEVAL
Packit Service 82fcde
	 computations.  The division by 1000 truncates values.  */
Packit Service 82fcde
      if (__glibc_unlikely (timeout->tv_nsec < 0))
Packit Service 82fcde
	{
Packit Service 82fcde
	  __set_errno (EINVAL);
Packit Service 82fcde
	  return -1;
Packit Service 82fcde
	}
Packit Service 82fcde
Packit Service 82fcde
      TIMESPEC_TO_TIMEVAL (&tval, timeout);
Packit Service 82fcde
    }
Packit Service 82fcde
Packit Service 82fcde
  /* The setting and restoring of the signal mask and the select call
Packit Service 82fcde
     should be an atomic operation.  This can't be done without kernel
Packit Service 82fcde
     help.  */
Packit Service 82fcde
  if (sigmask != NULL)
Packit Service 82fcde
    __sigprocmask (SIG_SETMASK, sigmask, &savemask);
Packit Service 82fcde
Packit Service 82fcde
  /* Note the pselect() is a cancellation point.  But since we call
Packit Service 82fcde
     select() which itself is a cancellation point we do not have
Packit Service 82fcde
     to do anything here.  */
Packit Service 82fcde
  retval = __select (nfds, readfds, writefds, exceptfds,
Packit Service 82fcde
		     timeout != NULL ? &tval : NULL);
Packit Service 82fcde
Packit Service 82fcde
  if (sigmask != NULL)
Packit Service 82fcde
    __sigprocmask (SIG_SETMASK, &savemask, NULL);
Packit Service 82fcde
Packit Service 82fcde
  return retval;
Packit Service 82fcde
}
Packit Service 82fcde
#ifndef __pselect
Packit Service 82fcde
weak_alias (__pselect, pselect)
Packit Service 82fcde
/* __select handles cancellation.  */
Packit Service 82fcde
LIBC_CANCEL_HANDLED ();
Packit Service 82fcde
#endif