vm: replace vnode v_pages with a v_pagecache_list list_t
[unleashed.git] / usr / src / cmd / ypcmd / ypxfrd_svc.c
blobd368a66447f86f44aec593ac25c31c69e5e4b8f6
1 /*
2 * CDDL HEADER START
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
7 * with the License.
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]
20 * CDDL HEADER END
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * This source was formally rpcgen generated, but has been
31 * checked in.
34 #include "ypxfrd.h"
35 #include <stdio.h>
36 #include <stdlib.h> /* getenv, exit */
37 #include <signal.h>
38 #include <rpc/pmap_clnt.h> /* for pmap_unset */
39 #include <string.h> /* strcmp */
40 #include <unistd.h> /* setsid */
41 #include <sys/types.h>
42 #include <memory.h>
43 #include <stropts.h>
44 #include <netconfig.h>
45 #include <sys/resource.h> /* rlimit */
46 #include <syslog.h>
47 #include <ndbm.h>
48 #include "shim.h"
49 #include "yptol.h"
51 #ifndef SIG_PF
52 #define SIG_PF void(*)(int)
53 #endif
55 #ifdef DEBUG
56 #define RPC_SVC_FG
57 #endif
59 #define _RPCSVC_CLOSEDOWN 120
62 * Copyr 1989 Sun Micro
63 * #ident "@(#)ypxfrd.x 1.2 00/05/01 SMI"
64 * This is NOT source code!
65 * DO NOT EDIT THIS FILE!
67 static int _rpcpmstart; /* Started by a port monitor ? */
69 /* States a server can be in wrt request */
71 #define _IDLE 0
72 #define _SERVED 1
74 static int _rpcsvcstate = _IDLE; /* Set when a request is serviced */
75 static int _rpcsvccount = 0; /* Number of requests being serviced */
77 static void
78 _msgout(char *msg)
80 #ifdef RPC_SVC_FG
81 if (_rpcpmstart)
82 syslog(LOG_ERR, "%s", msg);
83 else
84 (void) fprintf(stderr, "%s\n", msg);
85 #else
86 syslog(LOG_ERR, "%s", msg);
87 #endif
90 static void
91 closedown(int sig)
93 if (_rpcsvcstate == _IDLE && _rpcsvccount == 0) {
94 int size;
95 int i, openfd = 0;
97 size = svc_max_pollfd;
98 for (i = 0; i < size && openfd < 2; i++)
99 if (svc_pollfd[i].fd >= 0)
100 openfd++;
101 if (openfd <= 1)
102 exit(0);
103 } else
104 _rpcsvcstate = _IDLE;
106 (void) signal(SIGALRM, (SIG_PF) closedown);
107 (void) alarm(_RPCSVC_CLOSEDOWN/2);
110 static void
111 ypxfrd_1(struct svc_req *rqstp, register SVCXPRT *transp)
113 union {
114 hosereq getdbm_1_arg;
115 } argument;
116 char *result;
117 xdrproc_t _xdr_argument, _xdr_result;
118 char *(*local)(char *, struct svc_req *);
120 _rpcsvccount++;
121 switch (rqstp->rq_proc) {
122 case NULLPROC:
123 (void) svc_sendreply(transp,
124 (xdrproc_t)xdr_void, NULL);
125 _rpcsvccount--;
126 _rpcsvcstate = _SERVED;
127 return;
129 case getdbm:
130 _xdr_argument = (xdrproc_t)xdr_hosereq;
131 _xdr_result = (xdrproc_t)xdr_dbmfyl;
132 local = (char *(*)(char *, struct svc_req *)) getdbm_1_svc;
133 break;
135 default:
136 svcerr_noproc(transp);
137 _rpcsvccount--;
138 _rpcsvcstate = _SERVED;
139 return;
141 (void) memset((char *)&argument, 0, sizeof (argument));
142 if (!svc_getargs(transp, _xdr_argument, (caddr_t)&argument)) {
143 svcerr_decode(transp);
144 _rpcsvccount--;
145 _rpcsvcstate = _SERVED;
146 return;
148 result = (*local)((char *)&argument, rqstp);
149 if (_xdr_result && result != NULL &&
150 !svc_sendreply(transp, _xdr_result, result)) {
151 svcerr_systemerr(transp);
153 if (!svc_freeargs(transp, _xdr_argument, (caddr_t)&argument)) {
154 _msgout("unable to free arguments");
155 exit(1);
157 _rpcsvccount--;
158 _rpcsvcstate = _SERVED;
162 main()
164 pid_t pid;
165 int i;
166 int stat;
168 (void) sigset(SIGPIPE, SIG_IGN);
171 * If stdin looks like a TLI endpoint, we assume
172 * that we were started by a port monitor. If
173 * t_getstate fails with TBADF, this is not a
174 * TLI endpoint.
176 if (t_getstate(0) != -1 || t_errno != TBADF) {
177 char *netid;
178 struct netconfig *nconf = NULL;
179 SVCXPRT *transp;
180 int pmclose;
182 _rpcpmstart = 1;
183 openlog("ypxfrd", LOG_NDELAY|LOG_PID, LOG_DAEMON);
185 if ((netid = getenv("NLSPROVIDER")) == NULL) {
186 /* started from inetd */
187 pmclose = 1;
188 } else {
189 if ((nconf = getnetconfigent(netid)) == NULL)
190 _msgout("cannot get transport info");
192 pmclose = (t_getstate(0) != T_DATAXFER);
194 if ((transp = svc_tli_create(0, nconf, NULL, 0, 0)) == NULL) {
195 _msgout("cannot create server handle");
196 exit(1);
198 if (nconf)
199 freenetconfigent(nconf);
200 if (!svc_reg(transp, YPXFRD, V1, ypxfrd_1, 0)) {
201 _msgout("unable to register (YPXFRD, V1).");
202 exit(1);
204 if (pmclose) {
205 (void) signal(SIGALRM, (SIG_PF) closedown);
206 (void) alarm(_RPCSVC_CLOSEDOWN/2);
209 if (yptol_mode) {
210 stat = parseConfig(NULL, NTOL_MAP_FILE);
211 if (stat == 1) {
212 _msgout("NIS to LDAP mapping inactive.");
213 } else if (stat != 0) {
214 _msgout("Aborting after NIS to LDAP "
215 "mapping error.");
216 exit(1);
220 svc_run();
221 exit(1);
222 /* NOTREACHED */
223 } else {
224 #ifndef RPC_SVC_FG
225 #pragma weak closefrom
226 extern void closefrom();
227 int size;
228 struct rlimit rl;
229 pid = fork();
230 if (pid < 0) {
231 perror("cannot fork");
232 exit(1);
234 if (pid)
235 exit(0);
236 closelog();
237 if (closefrom != NULL)
238 closefrom(0);
239 else {
240 rl.rlim_max = 0;
241 getrlimit(RLIMIT_NOFILE, &rl);
242 if ((size = rl.rlim_max) == 0)
243 exit(1);
244 for (i = 0; i < size; i++)
245 (void) close(i);
247 i = open("/dev/null", 2);
248 (void) dup2(i, 1);
249 (void) dup2(i, 2);
250 openlog("ypxfrd", LOG_NDELAY|LOG_PID, LOG_DAEMON);
251 setsid();
252 #endif
255 if (yptol_mode) {
256 stat = parseConfig(NULL, NTOL_MAP_FILE);
257 if (stat == 1) {
258 _msgout("NIS to LDAP mapping inactive.");
259 } else if (stat != 0) {
260 _msgout("Aborting after NIS to LDAP mapping error.");
261 exit(1);
265 if (!svc_create(ypxfrd_1, YPXFRD, V1, "visible")) {
266 _msgout("unable to create (YPXFRD, V1) for visible.");
267 exit(1);
270 svc_run();
271 _msgout("svc_run returned");
272 exit(1);
273 /* NOTREACHED */