2 * support/nfs/rcpdispatch.c
4 * Generic RPC dispatcher.
6 * Copyright (C) 1995, 1996, Olaf Kirch <okir@monad.swb.de>
13 #include <rpc/pmap_clnt.h>
15 #include <arpa/inet.h>
22 rpc_dispatch(struct svc_req *rqstp, SVCXPRT *transp,
23 struct rpc_dtable *dtable, int nvers,
24 void *argp, void *resp)
26 struct rpc_dentry *dent;
28 if (rqstp->rq_vers > nvers) {
29 svcerr_progvers(transp, 1, nvers);
32 dtable += (rqstp->rq_vers - 1);
33 if (rqstp->rq_proc > dtable->nproc) {
34 svcerr_noproc(transp);
38 dent = dtable->entries + rqstp->rq_proc;
40 if (dent->func == NULL) {
41 svcerr_noproc(transp);
45 memset(argp, 0, dent->xdr_arg_size);
46 memset(resp, 0, dent->xdr_res_size);
48 if (!svc_getargs(transp, dent->xdr_arg_fn, argp)) {
49 svcerr_decode(transp);
53 if ((dent->func)(rqstp, argp, resp) && resp != 0) {
54 if (!svc_sendreply(transp, dent->xdr_res_fn, (caddr_t)resp))
55 svcerr_systemerr(transp);
57 if (!svc_freeargs(transp, dent->xdr_arg_fn, argp)) {
58 xlog(L_ERROR, "failed to free RPC arguments");
65 * This is our replacement for svc_run. It turns off some signals while
66 * executing the server procedures to avoid nasty race conditions.
69 rpc_svcrun(fd_set *morefds, void (*func)(int fd))
71 sigset_t block, current;
80 for (i = 0; i < FD_SETSIZE; i++)
81 if (FD_ISSET(i, morefds))
84 switch (select(FD_SETSIZE, &readfds, NULL, NULL, NULL)) {
88 xlog(L_ERROR, "svc_run: - select failed");
97 for (i = 0; i < FD_SETSIZE; i++)
98 if (FD_ISSET(i, morefds) &&
99 FD_ISSET(i, &readfds))
103 sigaddset(&block, SIGALRM);
104 sigaddset(&block, SIGVTALRM);
105 sigaddset(&block, SIGIO);
106 sigprocmask(SIG_BLOCK, &block, ¤t);
107 svc_getreqset(&readfds);
108 sigprocmask(SIG_SETMASK, ¤t, NULL);