Home | History | Annotate | Line # | Download | only in yppush
yppush.c revision 1.8
      1  1.8    lukem /*	$NetBSD: yppush.c,v 1.8 1997/11/18 00:32:59 lukem Exp $	*/
      2  1.1  thorpej 
      3  1.1  thorpej /*
      4  1.8    lukem  *
      5  1.8    lukem  * Copyright (c) 1997 Charles D. Cranor
      6  1.1  thorpej  * All rights reserved.
      7  1.1  thorpej  *
      8  1.1  thorpej  * Redistribution and use in source and binary forms, with or without
      9  1.1  thorpej  * modification, are permitted provided that the following conditions
     10  1.1  thorpej  * are met:
     11  1.1  thorpej  * 1. Redistributions of source code must retain the above copyright
     12  1.1  thorpej  *    notice, this list of conditions and the following disclaimer.
     13  1.1  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.1  thorpej  *    notice, this list of conditions and the following disclaimer in the
     15  1.1  thorpej  *    documentation and/or other materials provided with the distribution.
     16  1.8    lukem  * 3. The name of the author may not be used to endorse or promote products
     17  1.1  thorpej  *    derived from this software without specific prior written permission.
     18  1.1  thorpej  *
     19  1.8    lukem  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     20  1.8    lukem  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     21  1.8    lukem  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     22  1.8    lukem  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     23  1.8    lukem  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     24  1.8    lukem  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  1.8    lukem  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  1.8    lukem  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  1.8    lukem  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     28  1.8    lukem  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  1.8    lukem  */
     30  1.1  thorpej 
     31  1.8    lukem /*
     32  1.8    lukem  * yppush
     33  1.8    lukem  * author: Chuck Cranor <chuck (at) ccrc.wustl.edu>
     34  1.8    lukem  * date: 05-Nov-97
     35  1.8    lukem  *
     36  1.8    lukem  * notes: this is a full rewrite of Mats O Jansson <moj (at) stacken.kth.se>'s
     37  1.8    lukem  * yppush.c.   i have restructured and cleaned up the entire file.
     38  1.8    lukem  */
     39  1.1  thorpej #include <sys/types.h>
     40  1.8    lukem #include <sys/errno.h>
     41  1.8    lukem #include <sys/param.h>
     42  1.1  thorpej #include <sys/stat.h>
     43  1.8    lukem #include <sys/time.h>
     44  1.4  thorpej #include <sys/wait.h>
     45  1.1  thorpej 
     46  1.4  thorpej #include <ctype.h>
     47  1.1  thorpej #include <err.h>
     48  1.1  thorpej #include <fcntl.h>
     49  1.8    lukem #include <signal.h>
     50  1.1  thorpej #include <stdio.h>
     51  1.1  thorpej #include <unistd.h>
     52  1.1  thorpej 
     53  1.1  thorpej #include <rpc/rpc.h>
     54  1.1  thorpej #include <rpcsvc/yp_prot.h>
     55  1.1  thorpej #include <rpcsvc/ypclnt.h>
     56  1.1  thorpej 
     57  1.8    lukem #include "ypdb.h"
     58  1.8    lukem #include "ypdef.h"
     59  1.1  thorpej #include "yplib_host.h"
     60  1.1  thorpej #include "yppush.h"
     61  1.1  thorpej 
     62  1.8    lukem /*
     63  1.8    lukem  * yppush: push a new YP map out YP servers
     64  1.8    lukem  *
     65  1.8    lukem  * usage:
     66  1.8    lukem  *   yppush [-d domain] [-h host] [-v] mapname
     67  1.8    lukem  *
     68  1.8    lukem  *   -d: the domainname the map lives in [if different from default]
     69  1.8    lukem  *   -h: push only to this host [otherwise, push to all hosts]
     70  1.8    lukem  *   -v: verbose
     71  1.8    lukem  */
     72  1.8    lukem 
     73  1.8    lukem /*
     74  1.8    lukem  * structures
     75  1.8    lukem  */
     76  1.8    lukem 
     77  1.8    lukem struct yppush_info {
     78  1.8    lukem 	char   *ourdomain;	/* domain of interest */
     79  1.8    lukem 	char   *map;		/* map we are pushing */
     80  1.8    lukem 	char   *owner;		/* owner of map */
     81  1.8    lukem 	int     order;		/* order number of map (version) */
     82  1.8    lukem };
     83  1.8    lukem /*
     84  1.8    lukem  * global vars
     85  1.8    lukem  */
     86  1.8    lukem 
     87  1.8    lukem extern char *__progname;	/* from crt0.o */
     88  1.8    lukem int     verbo = 0;		/* verbose */
     89  1.8    lukem 
     90  1.8    lukem /*
     91  1.8    lukem  * prototypes
     92  1.8    lukem  */
     93  1.1  thorpej 
     94  1.4  thorpej int	main __P((int, char *[]));
     95  1.1  thorpej int	pushit __P((int, char *, int, char *, int, char *));
     96  1.8    lukem void	push __P((char *, int, struct yppush_info *));
     97  1.1  thorpej void	_svc_run __P((void));
     98  1.1  thorpej void	usage __P((void));
     99  1.1  thorpej 
    100  1.1  thorpej 
    101  1.8    lukem /*
    102  1.8    lukem  * main
    103  1.8    lukem  */
    104  1.1  thorpej 
    105  1.1  thorpej int
    106  1.1  thorpej main(argc, argv)
    107  1.8    lukem 	int     argc;
    108  1.8    lukem 	char   *argv[];
    109  1.8    lukem 
    110  1.1  thorpej {
    111  1.8    lukem 	char   *targhost = NULL;
    112  1.8    lukem 	struct yppush_info ypi = {NULL, NULL, NULL, 0};
    113  1.8    lukem 	int     c, rv;
    114  1.8    lukem 	const char *cp;
    115  1.8    lukem 	char   *master;
    116  1.8    lukem 	DBM    *ypdb;
    117  1.8    lukem 	datum   datum;
    118  1.8    lukem 	CLIENT *ypserv;
    119  1.8    lukem 	struct timeval tv;
    120  1.8    lukem 	enum clnt_stat retval;
    121  1.8    lukem 	struct ypall_callback ypallcb;
    122  1.1  thorpej 
    123  1.8    lukem 	/*
    124  1.8    lukem          * parse command line
    125  1.8    lukem          */
    126  1.1  thorpej 	while ((c = getopt(argc, argv, "d:h:v")) != -1) {
    127  1.8    lukem 		switch (c) {
    128  1.1  thorpej 		case 'd':
    129  1.8    lukem 			ypi.ourdomain = optarg;
    130  1.1  thorpej 			break;
    131  1.1  thorpej 		case 'h':
    132  1.8    lukem 			targhost = optarg;
    133  1.1  thorpej 			break;
    134  1.8    lukem 		case 'v':
    135  1.8    lukem 			verbo = 1;
    136  1.1  thorpej 			break;
    137  1.1  thorpej 		default:
    138  1.8    lukem 			usage();
    139  1.8    lukem 			/* NOTREACHED */
    140  1.1  thorpej 		}
    141  1.1  thorpej 	}
    142  1.8    lukem 	argc -= optind;
    143  1.8    lukem 	argv += optind;
    144  1.1  thorpej 	if (argc != 1)
    145  1.1  thorpej 		usage();
    146  1.8    lukem 	ypi.map = argv[0];
    147  1.8    lukem 	if (strlen(ypi.map) > YPMAXMAP)
    148  1.8    lukem 		errx(1, "%s: map name too long (limit %d)", ypi.map, YPMAXMAP);
    149  1.8    lukem 
    150  1.8    lukem 	/*
    151  1.8    lukem          * ensure we have a domain
    152  1.8    lukem          */
    153  1.8    lukem 	if (ypi.ourdomain == NULL) {
    154  1.8    lukem 		c = yp_get_default_domain(&ypi.ourdomain);
    155  1.8    lukem 		if (ypi.ourdomain == NULL)
    156  1.8    lukem 			errx(1, "unable to get default domain: %s",
    157  1.3  thorpej 			    yperr_string(c));
    158  1.8    lukem 	}
    159  1.8    lukem 	/*
    160  1.8    lukem          * verify that the domain and specified database exsists
    161  1.8    lukem          *
    162  1.8    lukem          * XXXCDC: this effectively prevents us from pushing from any
    163  1.8    lukem          * host but the master.   an alternate plan is to find the master
    164  1.8    lukem          * host for a map, clear it, ask for the order number, and then
    165  1.8    lukem          * send xfr requests.   if that was used we would not need local
    166  1.8    lukem          * file access.
    167  1.8    lukem          */
    168  1.8    lukem 	if (chdir(YP_DB_PATH) < 0)
    169  1.8    lukem 		err(1, "%s", YP_DB_PATH);
    170  1.8    lukem 	if (chdir(ypi.ourdomain) < 0)
    171  1.8    lukem 		err(1, "%s/%s", YP_DB_PATH, ypi.ourdomain);
    172  1.8    lukem 
    173  1.8    lukem 	/*
    174  1.8    lukem          * now open the database so we can extract "order number"
    175  1.8    lukem          * (i.e. timestamp) of the map.
    176  1.8    lukem          */
    177  1.8    lukem 	ypdb = ypdb_open(ypi.map, 0, O_RDONLY);
    178  1.8    lukem 	if (ypdb == NULL)
    179  1.8    lukem 		err(1, "ypdb_open %s/%s/%s", YP_DB_PATH, ypi.ourdomain,
    180  1.8    lukem 		    ypi.map);
    181  1.8    lukem 	datum.dptr = YP_LAST_KEY;
    182  1.8    lukem 	datum.dsize = YP_LAST_LEN;
    183  1.8    lukem 	datum = ypdb_fetch(ypdb, datum);
    184  1.8    lukem 	ypdb_close(ypdb);
    185  1.8    lukem 	if (datum.dptr == NULL)
    186  1.8    lukem 		errx(1,
    187  1.8    lukem 		    "unable to fetch %s key: check database with 'makedbm -u'",
    188  1.8    lukem 		    YP_LAST_KEY);
    189  1.8    lukem 	ypi.order = 0;
    190  1.8    lukem 	cp = datum.dptr;
    191  1.8    lukem 	while (cp < datum.dptr + datum.dsize) {
    192  1.8    lukem 		if (!isdigit(*cp))
    193  1.8    lukem 			errx(1,
    194  1.8    lukem 		    "invalid order number: check database with 'makedbm -u'");
    195  1.8    lukem 		ypi.order = (ypi.order * 10) + *cp - '0';
    196  1.8    lukem 		cp++;
    197  1.8    lukem 	}
    198  1.1  thorpej 
    199  1.8    lukem 	if (verbo)
    200  1.8    lukem 		printf("pushing %s [order=%d] in domain %s\n", ypi.map,
    201  1.8    lukem 		    ypi.order, ypi.ourdomain);
    202  1.8    lukem 
    203  1.8    lukem 	/*
    204  1.8    lukem          * ok, we are ready to do it.   first we send a clear_2 request
    205  1.8    lukem          * to the local server [should be the master] to make sure it has
    206  1.8    lukem          * the correct database open.
    207  1.8    lukem          *
    208  1.8    lukem          * XXXCDC: note that yp_bind_local exits on failure so ypserv can't
    209  1.8    lukem          * be null.   this makes it difficult to print a useful error message.
    210  1.8    lukem          * [it will print "clntudp_create: no contact with localhost"]
    211  1.8    lukem          */
    212  1.8    lukem 	tv.tv_sec = 10;
    213  1.8    lukem 	tv.tv_usec = 0;
    214  1.8    lukem 	ypserv = yp_bind_local(YPPROG, YPVERS);
    215  1.8    lukem 	retval = clnt_call(ypserv, YPPROC_CLEAR, xdr_void, 0, xdr_void, 0, tv);
    216  1.8    lukem 	if (retval != RPC_SUCCESS)
    217  1.8    lukem 		errx(1, "clnt_call CLEAR to local ypserv: %s",
    218  1.8    lukem 		    clnt_sperrno(retval));
    219  1.8    lukem 	clnt_destroy(ypserv);
    220  1.8    lukem 
    221  1.8    lukem 	/*
    222  1.8    lukem          * now use normal yplib functions to bind to the domain.
    223  1.8    lukem          */
    224  1.8    lukem 	rv = yp_bind(ypi.ourdomain);
    225  1.8    lukem 	if (rv)
    226  1.8    lukem 		errx(1, "error binding to %s: %s", ypi.ourdomain,
    227  1.8    lukem 		    yperr_string(rv));
    228  1.8    lukem 
    229  1.8    lukem 	/*
    230  1.8    lukem          * find 'owner' of the map (see pushit for usage)
    231  1.8    lukem          */
    232  1.8    lukem 	rv = yp_master(ypi.ourdomain, ypi.map, &ypi.owner);
    233  1.8    lukem 	if (rv)
    234  1.8    lukem 		errx(1, "error finding master for %s in %s: %s", ypi.map,
    235  1.8    lukem 		    ypi.ourdomain, yperr_string(rv));
    236  1.8    lukem 
    237  1.8    lukem 	/*
    238  1.8    lukem          * inform user of our progress
    239  1.8    lukem          */
    240  1.8    lukem 	if (verbo) {
    241  1.8    lukem 		printf("pushing map %s in %s: order=%d, owner=%s\n", ypi.map,
    242  1.8    lukem 		    ypi.ourdomain, ypi.order, ypi.owner);
    243  1.8    lukem 		printf("pushing to %s\n",
    244  1.8    lukem 		    (targhost) ? targhost : "<all ypservs>");
    245  1.8    lukem 	}
    246  1.1  thorpej 
    247  1.8    lukem 	/*
    248  1.8    lukem          * finally, do it.
    249  1.8    lukem          */
    250  1.8    lukem 	if (targhost) {
    251  1.8    lukem 		push(targhost, strlen(targhost), &ypi);
    252  1.8    lukem 	} else {
    253  1.8    lukem 
    254  1.8    lukem 		/*
    255  1.8    lukem 	         * no host specified, do all hosts the master knows about via
    256  1.8    lukem 	         * the ypservers map.
    257  1.8    lukem 	         */
    258  1.8    lukem 		rv = yp_master(ypi.ourdomain, "ypservers", &master);
    259  1.8    lukem 		if (rv)
    260  1.8    lukem 			errx(1, "error finding master for ypservers in %s: %s",
    261  1.8    lukem 			    ypi.ourdomain, yperr_string(rv));
    262  1.8    lukem 
    263  1.8    lukem 		if (verbo)
    264  1.8    lukem 			printf(
    265  1.8    lukem 		"contacting ypservers %s master on %s for list of ypservs...\n",
    266  1.8    lukem 			    ypi.ourdomain, master);
    267  1.8    lukem 
    268  1.8    lukem 		ypserv = yp_bind_host(master, YPPROG, YPVERS, 0, 1);
    269  1.8    lukem 
    270  1.8    lukem 		ypallcb.foreach = pushit;	/* callback function */
    271  1.8    lukem 		ypallcb.data = (char *) &ypi;	/* data to pass into callback */
    272  1.8    lukem 
    273  1.8    lukem 		rv = yp_all_host(ypserv, ypi.ourdomain, "ypservers", &ypallcb);
    274  1.8    lukem 		if (rv)
    275  1.8    lukem 			errx(1, "pushing %s in %s failed: %s", ypi.map,
    276  1.8    lukem 			    ypi.ourdomain, yperr_string(rv));
    277  1.1  thorpej 	}
    278  1.8    lukem 	exit(0);
    279  1.1  thorpej }
    280  1.1  thorpej 
    281  1.8    lukem /*
    282  1.8    lukem  * usage: print usage and exit
    283  1.8    lukem  */
    284  1.1  thorpej void
    285  1.1  thorpej usage()
    286  1.1  thorpej {
    287  1.8    lukem 	fprintf(stderr, "usage: %s [-d domain] [-h host] [-v] map\n",
    288  1.1  thorpej 	    __progname);
    289  1.1  thorpej 	exit(1);
    290  1.1  thorpej }
    291  1.1  thorpej 
    292  1.8    lukem /*
    293  1.8    lukem  * pushit: called from yp_all_host to push a specific host.
    294  1.8    lukem  * the key/value pairs are from the ypservers map.
    295  1.8    lukem  */
    296  1.8    lukem int
    297  1.8    lukem pushit(instatus, inkey, inkeylen, inval, invallen, indata)
    298  1.8    lukem 	int     instatus, inkeylen, invallen;
    299  1.8    lukem 	char   *inkey, *inval, *indata;
    300  1.1  thorpej {
    301  1.8    lukem 	struct yppush_info *ypi = (struct yppush_info *) indata;
    302  1.1  thorpej 
    303  1.8    lukem 	if (instatus != YP_TRUE)		/* failure? */
    304  1.8    lukem 		return (instatus);
    305  1.1  thorpej 
    306  1.8    lukem 	push(inkey, inkeylen, ypi);		/* do it! */
    307  1.8    lukem 	return (0);
    308  1.1  thorpej }
    309  1.1  thorpej 
    310  1.8    lukem /*
    311  1.8    lukem  * push: push a specific map on a specific host
    312  1.8    lukem  */
    313  1.1  thorpej void
    314  1.8    lukem push(host, hostlen, ypi)
    315  1.8    lukem 	char   *host;
    316  1.8    lukem 	int     hostlen;
    317  1.8    lukem 	struct yppush_info *ypi;
    318  1.8    lukem {
    319  1.8    lukem 	char    target[YPMAXPEER];
    320  1.8    lukem 	CLIENT *ypserv;
    321  1.1  thorpej 	SVCXPRT *transp;
    322  1.8    lukem 	int     prog, pid, rv;
    323  1.1  thorpej 	struct timeval tv;
    324  1.8    lukem 	struct ypreq_xfr req;
    325  1.1  thorpej 
    326  1.8    lukem 	/*
    327  1.8    lukem          * get our target host in a null terminated string
    328  1.8    lukem          */
    329  1.8    lukem 	snprintf(target, sizeof(target), "%*.*s", hostlen, hostlen, host);
    330  1.8    lukem 
    331  1.8    lukem 	/*
    332  1.8    lukem          * XXXCDC: arg!  we would like to use yp_bind_host here, except that
    333  1.8    lukem          * it exits on failure and we don't want to give up just because
    334  1.8    lukem          * one host fails.  thus, we have to do it the hard way.
    335  1.8    lukem          */
    336  1.8    lukem 	ypserv = clnt_create(target, YPPROG, YPVERS, "tcp");
    337  1.8    lukem 	if (ypserv == NULL) {
    338  1.8    lukem 		clnt_pcreateerror(target);
    339  1.1  thorpej 		return;
    340  1.1  thorpej 	}
    341  1.1  thorpej 
    342  1.8    lukem 	/*
    343  1.8    lukem          * our XFR rpc request to the client just starts the transfer.
    344  1.8    lukem          * when the client is done, it wants to call a procedure that
    345  1.8    lukem          * we are serving to tell us that it is done.   so we must create
    346  1.8    lukem          * and register a procedure for us for it to call.
    347  1.8    lukem          */
    348  1.8    lukem 	transp = svcudp_create(RPC_ANYSOCK);
    349  1.1  thorpej 	if (transp == NULL) {
    350  1.8    lukem 		warnx("callback svcudp_create failed");
    351  1.8    lukem 		goto error;
    352  1.1  thorpej 	}
    353  1.1  thorpej 
    354  1.8    lukem 	/* register it with portmap */
    355  1.1  thorpej 	for (prog = 0x40000000; prog < 0x5fffffff; prog++) {
    356  1.8    lukem 		if (svc_register(transp, prog, 1, yppush_xfrrespprog_1,
    357  1.8    lukem 		    IPPROTO_UDP))
    358  1.1  thorpej 			break;
    359  1.1  thorpej 	}
    360  1.8    lukem 	if (prog >= 0x5fffffff) {
    361  1.8    lukem 		warnx("unable to register callback");
    362  1.8    lukem 		goto error;
    363  1.8    lukem 	}
    364  1.1  thorpej 
    365  1.8    lukem 	/*
    366  1.8    lukem          * now fork off a server to catch our reply
    367  1.8    lukem          */
    368  1.8    lukem 	pid = fork();
    369  1.8    lukem 	if (pid == -1) {
    370  1.8    lukem 		svc_unregister(prog, 1);	/* drop our mapping with
    371  1.8    lukem 						 * portmap */
    372  1.8    lukem 		warn("fork failed");
    373  1.8    lukem 		goto error;
    374  1.1  thorpej 	}
    375  1.1  thorpej 
    376  1.8    lukem 	/*
    377  1.8    lukem          * child process becomes the server
    378  1.8    lukem          */
    379  1.8    lukem 	if (pid == 0) {
    380  1.1  thorpej 		_svc_run();
    381  1.1  thorpej 		exit(0);
    382  1.8    lukem 	}
    383  1.8    lukem 
    384  1.8    lukem 	/*
    385  1.8    lukem          * we are the parent process: send XFR request to server.
    386  1.8    lukem          * the "owner" field isn't used by ypserv (and shouldn't be, since
    387  1.8    lukem          * the ypserv has no idea if we are a legitimate yppush or not).
    388  1.8    lukem          * instead, the owner of the map is determined by the master value
    389  1.8    lukem          * currently cached on the slave server.
    390  1.8    lukem          */
    391  1.8    lukem 	close(transp->xp_sock);	/* close child's socket, we don't need it */
    392  1.8    lukem 	/* don't wait for anything here, we will wait for child's exit */
    393  1.8    lukem 	tv.tv_sec = 0;
    394  1.8    lukem 	tv.tv_usec = 0;
    395  1.8    lukem 	req.map_parms.domain = ypi->ourdomain;
    396  1.8    lukem 	req.map_parms.map = ypi->map;
    397  1.8    lukem 	req.map_parms.owner = ypi->owner;	/* NOT USED */
    398  1.8    lukem 	req.map_parms.ordernum = ypi->order;
    399  1.8    lukem 	req.transid = (u_int) pid;
    400  1.8    lukem 	req.proto = prog;
    401  1.8    lukem 	req.port = transp->xp_port;
    402  1.8    lukem 
    403  1.8    lukem 	if (verbo)
    404  1.8    lukem 		printf("asking host %s to transfer map (xid=%d)\n", target,
    405  1.8    lukem 		    req.transid);
    406  1.8    lukem 
    407  1.8    lukem 	rv = clnt_call(ypserv, YPPROC_XFR, xdr_ypreq_xfr, &req,
    408  1.8    lukem 	    		xdr_void, NULL, tv);			/* do it! */
    409  1.1  thorpej 
    410  1.8    lukem 	if (rv != RPC_SUCCESS && rv != RPC_TIMEDOUT) {
    411  1.8    lukem 		warnx("unable to xfr to host %s: %s", target, clnt_sperrno(rv));
    412  1.8    lukem 		kill(pid, SIGTERM);
    413  1.1  thorpej 	}
    414  1.8    lukem 
    415  1.8    lukem 	/*
    416  1.8    lukem          * now wait for child to get the reply and exit
    417  1.8    lukem          */
    418  1.8    lukem 	wait4(pid, NULL, 0, NULL);
    419  1.8    lukem 	svc_unregister(prog, 1);
    420  1.8    lukem 
    421  1.8    lukem 	/*
    422  1.8    lukem          * ... and we are done.   fall through
    423  1.8    lukem          */
    424  1.8    lukem 
    425  1.8    lukem error:
    426  1.8    lukem 	if (transp)
    427  1.8    lukem 		svc_destroy(transp);
    428  1.8    lukem 	clnt_destroy(ypserv);
    429  1.8    lukem 	return;
    430  1.1  thorpej }
    431  1.1  thorpej 
    432  1.8    lukem /*
    433  1.8    lukem  * _svc_run: this is the main loop for the RPC server that we fork off
    434  1.8    lukem  * to await the reply from ypxfr.
    435  1.8    lukem  */
    436  1.8    lukem void
    437  1.8    lukem _svc_run()
    438  1.1  thorpej {
    439  1.8    lukem 	fd_set  readfds;
    440  1.8    lukem 	struct timeval tv;
    441  1.8    lukem 	int     rv, nfds;
    442  1.1  thorpej 
    443  1.8    lukem 	nfds = sysconf(_SC_OPEN_MAX);
    444  1.8    lukem 	while (1) {
    445  1.1  thorpej 
    446  1.8    lukem 		readfds = svc_fdset;	/* structure copy from global var */
    447  1.8    lukem 		tv.tv_sec = 60;
    448  1.8    lukem 		tv.tv_usec = 0;
    449  1.8    lukem 
    450  1.8    lukem 		rv = select(nfds, &readfds, NULL, NULL, &tv);
    451  1.8    lukem 
    452  1.8    lukem 		if (rv < 0) {
    453  1.8    lukem 			if (errno == EINTR)
    454  1.8    lukem 				continue;
    455  1.8    lukem 			warn("_svc_run: select failed");
    456  1.8    lukem 			return;
    457  1.8    lukem 		}
    458  1.8    lukem 		if (rv == 0)
    459  1.8    lukem 			errx(0, "_svc_run: callback timed out");
    460  1.1  thorpej 
    461  1.8    lukem 		/*
    462  1.8    lukem 	         * got something
    463  1.8    lukem 	         */
    464  1.8    lukem 		svc_getreqset(&readfds);
    465  1.1  thorpej 
    466  1.8    lukem 	}
    467  1.1  thorpej }
    468