diff options
Diffstat (limited to 'libexec/rpc.rstatd')
-rw-r--r-- | libexec/rpc.rstatd/rstatd.c | 66 |
1 files changed, 40 insertions, 26 deletions
diff --git a/libexec/rpc.rstatd/rstatd.c b/libexec/rpc.rstatd/rstatd.c index 35650d9..e8aea46 100644 --- a/libexec/rpc.rstatd/rstatd.c +++ b/libexec/rpc.rstatd/rstatd.c @@ -40,7 +40,6 @@ static const char rcsid[] = #include <rpc/rpc.h> #include <signal.h> #include <syslog.h> -#include <rpc/pmap_clnt.h> #include <rpcsvc/rstat.h> extern void rstat_service(struct svc_req *, SVCXPRT *); @@ -51,9 +50,9 @@ int closedown = 20; /* how long to wait before going dormant */ void cleanup(int sig __unused) { - (void) pmap_unset(RSTATPROG, RSTATVERS_TIME); - (void) pmap_unset(RSTATPROG, RSTATVERS_SWTCH); - (void) pmap_unset(RSTATPROG, RSTATVERS_ORIG); + (void) rpcb_unset(RSTATPROG, RSTATVERS_TIME, NULL); + (void) rpcb_unset(RSTATPROG, RSTATVERS_SWTCH, NULL); + (void) rpcb_unset(RSTATPROG, RSTATVERS_ORIG, NULL); exit(0); } @@ -61,9 +60,8 @@ int main(int argc, char *argv[]) { SVCXPRT *transp; - int sock = 0; - int proto = 0; - struct sockaddr_in from; + int ok; + struct sockaddr_storage from; int fromlen; if (argc == 2) @@ -77,16 +75,14 @@ main(int argc, char *argv[]) fromlen = sizeof(from); if (getsockname(0, (struct sockaddr *)&from, &fromlen) < 0) { from_inetd = 0; - sock = RPC_ANYSOCK; - proto = IPPROTO_UDP; } if (!from_inetd) { daemon(0, 0); - (void)pmap_unset(RSTATPROG, RSTATVERS_TIME); - (void)pmap_unset(RSTATPROG, RSTATVERS_SWTCH); - (void)pmap_unset(RSTATPROG, RSTATVERS_ORIG); + (void)rpcb_unset(RSTATPROG, RSTATVERS_TIME, NULL); + (void)rpcb_unset(RSTATPROG, RSTATVERS_SWTCH, NULL); + (void)rpcb_unset(RSTATPROG, RSTATVERS_ORIG, NULL); (void) signal(SIGINT, cleanup); (void) signal(SIGTERM, cleanup); @@ -95,22 +91,40 @@ main(int argc, char *argv[]) openlog("rpc.rstatd", LOG_CONS|LOG_PID, LOG_DAEMON); - transp = svcudp_create(sock); - if (transp == NULL) { - syslog(LOG_ERR, "cannot create udp service"); - exit(1); + if (from_inetd) { + transp = svc_tli_create(0, NULL, NULL, 0, 0); + if (transp == NULL) { + syslog(LOG_ERR, "cannot create udp service."); + exit(1); + } + ok = svc_reg(transp, RSTATPROG, RSTATVERS_TIME, + rstat_service, NULL); + } else + ok = svc_create(rstat_service, + RSTATPROG, RSTATVERS_TIME, "udp"); + if (!ok) { + syslog(LOG_ERR, "unable to register (RSTATPROG, RSTATVERS_TIME, %s)", (!from_inetd)?"udp":"(inetd)"); + exit(1); } - if (!svc_register(transp, RSTATPROG, RSTATVERS_TIME, rstat_service, proto)) { - syslog(LOG_ERR, "unable to register (RSTATPROG, RSTATVERS_TIME, %s)", proto?"udp":"(inetd)"); - exit(1); + if (from_inetd) + ok = svc_reg(transp, RSTATPROG, RSTATVERS_SWTCH, + rstat_service, NULL); + else + ok = svc_create(rstat_service, + RSTATPROG, RSTATVERS_SWTCH, "udp"); + if (!ok) { + syslog(LOG_ERR, "unable to register (RSTATPROG, RSTATVERS_SWTCH, %s)", (!from_inetd)?"udp":"(inetd)"); + exit(1); } - if (!svc_register(transp, RSTATPROG, RSTATVERS_SWTCH, rstat_service, proto)) { - syslog(LOG_ERR, "unable to register (RSTATPROG, RSTATVERS_SWTCH, %s)", proto?"udp":"(inetd)"); - exit(1); - } - if (!svc_register(transp, RSTATPROG, RSTATVERS_ORIG, rstat_service, proto)) { - syslog(LOG_ERR, "unable to register (RSTATPROG, RSTATVERS_ORIG, %s)", proto?"udp":"(inetd)"); - exit(1); + if (from_inetd) + ok = svc_reg(transp, RSTATPROG, RSTATVERS_ORIG, + rstat_service, NULL); + else + ok = svc_create(rstat_service, + RSTATPROG, RSTATVERS_ORIG, "udp"); + if (!ok) { + syslog(LOG_ERR, "unable to register (RSTATPROG, RSTATVERS_ORIG, %s)", (!from_inetd)?"udp":"(inetd)"); + exit(1); } svc_run(); |