hjl / source-git / glibc

Forked from source-git/glibc 3 years ago
Clone

Blame sunrpc/svc_run.c

Packit 6c4009
/*
Packit 6c4009
 * Copyright (c) 2010, Oracle America, Inc.
Packit 6c4009
 * Redistribution and use in source and binary forms, with or without
Packit 6c4009
 * modification, are permitted provided that the following conditions are
Packit 6c4009
 * met:
Packit 6c4009
 *
Packit 6c4009
 *     * Redistributions of source code must retain the above copyright
Packit 6c4009
 *       notice, this list of conditions and the following disclaimer.
Packit 6c4009
 *     * Redistributions in binary form must reproduce the above
Packit 6c4009
 *       copyright notice, this list of conditions and the following
Packit 6c4009
 *       disclaimer in the documentation and/or other materials
Packit 6c4009
 *       provided with the distribution.
Packit 6c4009
 *     * Neither the name of the "Oracle America, Inc." nor the names of its
Packit 6c4009
 *       contributors may be used to endorse or promote products derived
Packit 6c4009
 *       from this software without specific prior written permission.
Packit 6c4009
 *
Packit 6c4009
 *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit 6c4009
 *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit 6c4009
 *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
Packit 6c4009
 *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
Packit 6c4009
 *   COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
Packit 6c4009
 *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit 6c4009
 *   DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
Packit 6c4009
 *   GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Packit 6c4009
 *   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
Packit 6c4009
 *   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
Packit 6c4009
 *   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit 6c4009
 *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit 6c4009
 *
Packit 6c4009
 * This is the rpc server side idle loop
Packit 6c4009
 * Wait for input, call server program.
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
#include <errno.h>
Packit 6c4009
#include <unistd.h>
Packit 6c4009
#include <libintl.h>
Packit 6c4009
#include <sys/poll.h>
Packit 6c4009
#include <rpc/rpc.h>
Packit 6c4009
#include <shlib-compat.h>
Packit 6c4009
Packit 6c4009
/* This function can be used as a signal handler to terminate the
Packit 6c4009
   server loop.  */
Packit 6c4009
void
Packit 6c4009
svc_exit (void)
Packit 6c4009
{
Packit 6c4009
  free (svc_pollfd);
Packit 6c4009
  svc_pollfd = NULL;
Packit 6c4009
  svc_max_pollfd = 0;
Packit 6c4009
}
Packit 6c4009
libc_hidden_nolink_sunrpc (svc_exit, GLIBC_2_0)
Packit 6c4009
Packit 6c4009
void
Packit 6c4009
svc_run (void)
Packit 6c4009
{
Packit 6c4009
  int i;
Packit 6c4009
  struct pollfd *my_pollfd = NULL;
Packit 6c4009
  int last_max_pollfd = 0;
Packit 6c4009
Packit 6c4009
  for (;;)
Packit 6c4009
    {
Packit 6c4009
      int max_pollfd = svc_max_pollfd;
Packit 6c4009
      if (max_pollfd == 0 && svc_pollfd == NULL)
Packit 6c4009
	break;
Packit 6c4009
Packit 6c4009
      if (last_max_pollfd != max_pollfd)
Packit 6c4009
	{
Packit 6c4009
	  struct pollfd *new_pollfd
Packit 6c4009
	    = realloc (my_pollfd, sizeof (struct pollfd) * max_pollfd);
Packit 6c4009
Packit 6c4009
	  if (new_pollfd == NULL)
Packit 6c4009
	    {
Packit 6c4009
	      perror (_("svc_run: - out of memory"));
Packit 6c4009
	      break;
Packit 6c4009
	    }
Packit 6c4009
Packit 6c4009
	  my_pollfd = new_pollfd;
Packit 6c4009
	  last_max_pollfd = max_pollfd;
Packit 6c4009
	}
Packit 6c4009
Packit 6c4009
      for (i = 0; i < max_pollfd; ++i)
Packit 6c4009
	{
Packit 6c4009
	  my_pollfd[i].fd = svc_pollfd[i].fd;
Packit 6c4009
	  my_pollfd[i].events = svc_pollfd[i].events;
Packit 6c4009
	  my_pollfd[i].revents = 0;
Packit 6c4009
	}
Packit 6c4009
Packit 6c4009
      switch (i = __poll (my_pollfd, max_pollfd, -1))
Packit 6c4009
	{
Packit 6c4009
	case -1:
Packit 6c4009
	  if (errno == EINTR)
Packit 6c4009
	    continue;
Packit 6c4009
	  perror (_("svc_run: - poll failed"));
Packit 6c4009
	  break;
Packit 6c4009
	case 0:
Packit 6c4009
	  continue;
Packit 6c4009
	default:
Packit 6c4009
	  svc_getreq_poll (my_pollfd, i);
Packit 6c4009
	  continue;
Packit 6c4009
	}
Packit 6c4009
      break;
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  free (my_pollfd);
Packit 6c4009
}
Packit 6c4009
#ifdef EXPORT_RPC_SYMBOLS
Packit 6c4009
libc_hidden_def (svc_run)
Packit 6c4009
#else
Packit 6c4009
libc_hidden_nolink_sunrpc (svc_run, GLIBC_2_0)
Packit 6c4009
#endif