4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1998-2001 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
38 #include <netconfig.h>
40 #include <sys/termios.h>
42 #include <rpcsvc/bootparam_prot.h>
44 #include "bootparam_private.h"
46 #define _RPCSVC_CLOSEDOWN 120
50 static void bootparamprog_1(struct svc_req
*, register SVCXPRT
*);
51 static void closedown(int);
53 static int server_child
= 0; /* program was started by another server */
54 static int _rpcsvcdirty
; /* Still serving ? */
57 main(int argc
, char *argv
[])
61 char *progname
= argv
[0];
62 int connmaxrec
= RPC_MAXDATASIZE
;
64 while ((c
= getopt(argc
, argv
, "d")) != -1)
70 (void) fprintf(stderr
, "usage: %s [-d]\n", progname
);
76 * Set non-blocking mode and maximum record size for
77 * connection oriented RPC transports.
79 if (!rpc_control(RPC_SVC_CONNMAXREC_SET
, &connmaxrec
)) {
80 msgout("unable to set maximum RPC record size");
84 * If stdin looks like a TLI endpoint, we assume
85 * that we were started by a port monitor. If
86 * t_getstate fails with TBADF, this is not a
89 if (t_getstate(0) != -1 || t_errno
!= TBADF
) {
91 struct netconfig
*nconf
= NULL
;
95 if ((netid
= getenv("NLSPROVIDER")) == NULL
) {
97 msgout("cannot get transport name");
98 } else if ((nconf
= getnetconfigent(netid
)) == NULL
) {
100 msgout("cannot get transport info");
102 pmclose
= (t_getstate(0) != T_DATAXFER
);
103 if ((transp
= svc_tli_create(0, nconf
, NULL
, 0, 0)) == NULL
) {
104 msgout("cannot create server handle");
108 freenetconfigent(nconf
);
109 if (!svc_reg(transp
, BOOTPARAMPROG
, BOOTPARAMVERS
,
110 bootparamprog_1
, 0)) {
111 msgout("unable to register (BOOTPARAMPROG, "
116 (void) signal(SIGALRM
, closedown
);
117 (void) alarm(_RPCSVC_CLOSEDOWN
);
126 * run this process in the background only if it was started from
127 * a shell and the debug flag was not given.
129 if (!server_child
&& !debug
) {
132 perror("cannot fork");
143 * messges go to syslog if the program was started by
144 * another server, or if it was run from the command line without
147 if (server_child
|| !debug
)
148 openlog("bootparam_prot", LOG_PID
, LOG_DAEMON
);
152 msgout("in debug mode.");
154 msgout("in debug mode (level %d).", debug
);
157 if (!svc_create(bootparamprog_1
, BOOTPARAMPROG
, BOOTPARAMVERS
,
159 msgout("unable to create (BOOTPARAMPROG, BOOTPARAMVERS) "
165 msgout("svc_run returned");
166 return (EXIT_FAILURE
);
170 bootparamprog_1(struct svc_req
*rqstp
, register SVCXPRT
*transp
)
173 bp_whoami_arg bootparamproc_whoami_1_arg
;
174 bp_getfile_arg bootparamproc_getfile_1_arg
;
177 bool_t (*xdr_argument
)(), (*xdr_result
)();
181 switch (rqstp
->rq_proc
) {
183 (void) svc_sendreply(transp
, xdr_void
, (char *)NULL
);
187 case BOOTPARAMPROC_WHOAMI
:
188 xdr_argument
= xdr_bp_whoami_arg
;
189 xdr_result
= xdr_bp_whoami_res
;
190 local
= (char *(*)()) bootparamproc_whoami_1
;
193 case BOOTPARAMPROC_GETFILE
:
194 xdr_argument
= xdr_bp_getfile_arg
;
195 xdr_result
= xdr_bp_getfile_res
;
196 local
= (char *(*)()) bootparamproc_getfile_1
;
200 svcerr_noproc(transp
);
204 (void) memset((char *)&argument
, 0, sizeof (argument
));
205 if (!svc_getargs(transp
, xdr_argument
, (caddr_t
)&argument
)) {
206 svcerr_decode(transp
);
210 result
= (*local
)(&argument
, rqstp
);
211 if (result
!= NULL
&& !svc_sendreply(transp
, xdr_result
, result
)) {
212 svcerr_systemerr(transp
);
214 if (!svc_freeargs(transp
, xdr_argument
, (caddr_t
)&argument
)) {
215 msgout("unable to free arguments");
223 msgout(char *fmt
, ...)
229 * messges go to syslog if the program was started by
230 * another server, or if it was run from the command line without
233 if (server_child
|| !debug
)
234 vsyslog(LOG_ERR
, fmt
, ap
);
236 (void) vfprintf(stderr
, fmt
, ap
);
237 (void) fputc('\n', stderr
);
246 if (_rpcsvcdirty
== 0) {
251 if (!t_getinfo(0, &tinfo
) && (tinfo
.servtype
== T_CLTS
))
253 size
= svc_max_pollfd
;
254 for (i
= 0, openfd
= 0; i
< size
&& openfd
< 2; i
++)
255 if (svc_pollfd
[i
].fd
>= 0)
260 (void) alarm(_RPCSVC_CLOSEDOWN
);