1 #include "rpc_test.h" 2 #include <stdio.h> 3 #include <string.h> 4 #include <stdlib.h> /* getenv, exit */ 5 #include <sys/types.h> 6 #include <syslog.h> 7 8 /* States a server can be in wrt request */ 9 10 #define _IDLE 0 11 #define _SERVED 1 12 13 static int _rpcsvcstate = _IDLE; /* Set when a request is serviced */ 14 static int _rpcsvccount = 0; /* Number of requests being serviced */ 15 16 void 17 rpc_test_prog_1_svc(struct svc_req *rqstp, SVCXPRT *transp) 18 { 19 union { 20 char *rpc_test_echo_1_arg; 21 } argument; 22 char *result; 23 xdrproc_t xdr_argument, xdr_result; 24 char *(*local)(char *, struct svc_req *); 25 26 _rpcsvccount++; 27 switch (rqstp->rq_proc) { 28 case NULLPROC: 29 (void) svc_sendreply(transp, xdr_void, 30 (char *)NULL); 31 _rpcsvccount--; 32 _rpcsvcstate = _SERVED; 33 return; 34 35 case RPC_TEST_ECHO: 36 xdr_argument = (xdrproc_t)xdr_wrapstring; 37 xdr_result = (xdrproc_t)xdr_wrapstring; 38 local = (char *(*)(char *, struct svc_req *)) rpc_test_echo_1_svc; 39 break; 40 41 default: 42 svcerr_noproc(transp); 43 _rpcsvccount--; 44 _rpcsvcstate = _SERVED; 45 return; 46 } 47 (void) memset(&argument, 0, sizeof (argument)); 48 if (!svc_getargs(transp, xdr_argument, &argument)) { 49 svcerr_decode(transp); 50 _rpcsvccount--; 51 _rpcsvcstate = _SERVED; 52 return; 53 } 54 result = (*local)((char *)&argument, rqstp); 55 if (result != NULL && !svc_sendreply(transp, xdr_result, result)) { 56 svcerr_systemerr(transp); 57 } 58 if (!svc_freeargs(transp, xdr_argument, &argument)) { 59 syslog(LOG_ERR, "unable to free arguments"); 60 exit(1); 61 } 62 _rpcsvccount--; 63 _rpcsvcstate = _SERVED; 64 return; 65 } 66