2 * Copyright (c) 1994 Christos Zoulas
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Christos Zoulas.
16 * 4. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * $FreeBSD: src/libexec/rpc.sprayd/sprayd.c,v 1.5 1999/08/28 00:09:59 peter Exp $
31 * $DragonFly: src/libexec/rpc.sprayd/sprayd.c,v 1.3 2003/11/14 03:54:31 dillon Exp $
35 #include <rpc/pmap_clnt.h>
36 #include <rpcsvc/spray.h>
41 #include <sys/socket.h>
45 static void spray_service (struct svc_req
*, SVCXPRT
*);
47 static int from_inetd
= 1;
49 #define timersub(tvp, uvp, vvp) \
51 (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
52 (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
53 if ((vvp)->tv_usec < 0) { \
55 (vvp)->tv_usec += 1000000; \
64 (void) pmap_unset(SPRAYPROG
, SPRAYVERS
);
82 struct sockaddr_in from
;
86 * See if inetd started us
88 fromlen
= sizeof(from
);
89 if (getsockname(0, (struct sockaddr
*)&from
, &fromlen
) < 0) {
98 (void) pmap_unset(SPRAYPROG
, SPRAYVERS
);
100 (void) signal(SIGINT
, cleanup
);
101 (void) signal(SIGTERM
, cleanup
);
102 (void) signal(SIGHUP
, cleanup
);
104 (void) signal(SIGALRM
, die
);
108 openlog("rpc.sprayd", LOG_CONS
|LOG_PID
, LOG_DAEMON
);
110 transp
= svcudp_create(sock
);
111 if (transp
== NULL
) {
112 syslog(LOG_ERR
, "cannot create udp service");
115 if (!svc_register(transp
, SPRAYPROG
, SPRAYVERS
, spray_service
, proto
)) {
117 "unable to register (SPRAYPROG, SPRAYVERS, %s)",
118 proto
? "udp" : "(inetd)");
123 syslog(LOG_ERR
, "svc_run returned");
129 spray_service(rqstp
, transp
)
130 struct svc_req
*rqstp
;
133 static spraycumul scum
;
134 static struct timeval clear
, get
;
136 switch (rqstp
->rq_proc
) {
137 case SPRAYPROC_CLEAR
:
139 (void) gettimeofday(&clear
, 0);
143 (void)svc_sendreply(transp
, (xdrproc_t
)xdr_void
, NULL
);
146 case SPRAYPROC_SPRAY
:
151 (void) gettimeofday(&get
, 0);
152 timersub(&get
, &clear
, &get
);
153 scum
.clock
.sec
= get
.tv_sec
;
154 scum
.clock
.usec
= get
.tv_usec
;
158 svcerr_noproc(transp
);
162 if (!svc_sendreply(transp
, (xdrproc_t
)xdr_spraycumul
, &scum
)) {
163 svcerr_systemerr(transp
);
164 syslog(LOG_ERR
, "bad svc_sendreply");