]> git.decadent.org.uk Git - nfs-utils.git/blob - support/nfs/rpcdispatch.c
libnfs.a: fix a bug when parse section's arg
[nfs-utils.git] / support / nfs / rpcdispatch.c
1 /*
2  * support/nfs/rcpdispatch.c
3  *
4  * Generic RPC dispatcher.
5  *
6  * Copyright (C) 1995, 1996, Olaf Kirch <okir@monad.swb.de>
7  */
8
9 #ifdef HAVE_CONFIG_H
10 #include <config.h>
11 #endif
12
13 #include <stdio.h>
14 #include <rpc/rpc.h>
15 #include <rpc/pmap_clnt.h>
16 #include <signal.h>
17 #include <arpa/inet.h>
18 #include <netdb.h>
19 #include <string.h>
20 #include "rpcmisc.h"
21 #include "xlog.h"
22
23 void
24 rpc_dispatch(struct svc_req *rqstp, SVCXPRT *transp,
25                         struct rpc_dtable *dtable, int nvers,
26                         void *argp, void *resp)
27 {
28         struct rpc_dentry       *dent;
29
30         if (((int)rqstp->rq_vers) > nvers) {
31                 svcerr_progvers(transp, 1, nvers);
32                 return;
33         }
34         dtable += (rqstp->rq_vers - 1);
35         if (((int)rqstp->rq_proc) > dtable->nproc) {
36                 svcerr_noproc(transp);
37                 return;
38         }
39
40         dent = dtable->entries + rqstp->rq_proc;
41
42         if (dent->func == NULL) {
43                 svcerr_noproc(transp);
44                 return;
45         }
46
47         memset(argp, 0, dent->xdr_arg_size);
48         memset(resp, 0, dent->xdr_res_size);
49
50         if (!svc_getargs(transp, dent->xdr_arg_fn, argp)) {
51                 svcerr_decode(transp);
52                 return;
53         }
54
55         if ((dent->func)(rqstp, argp, resp) && resp != 0) {
56                 if (!svc_sendreply(transp, dent->xdr_res_fn, (caddr_t)resp)) 
57                         svcerr_systemerr(transp);
58         }
59         if (!svc_freeargs(transp, dent->xdr_arg_fn, argp)) {
60                 xlog(L_ERROR, "failed to free RPC arguments");
61                 exit (2);
62         }
63 }