xref: /onnv-gate/usr/src/cmd/fs.d/cachefs/cfsd/cfsd_main.c (revision 1914:8a8c5f225b1b)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*1914Scasper  * Common Development and Distribution License (the "License").
6*1914Scasper  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*1914Scasper  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate /*
290Sstevel@tonic-gate  * Main routines for cachefs daemon.
300Sstevel@tonic-gate  */
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include <stdio.h>
33*1914Scasper #include <stdio_ext.h>
340Sstevel@tonic-gate #include <stdlib.h>
350Sstevel@tonic-gate #include <string.h>
360Sstevel@tonic-gate #include <errno.h>
370Sstevel@tonic-gate #include <rpc/rpc.h>
380Sstevel@tonic-gate #include <rpc/pmap_clnt.h> /* for pmap_unset */
390Sstevel@tonic-gate #include <string.h> /* strcmp */
400Sstevel@tonic-gate #include <signal.h>
410Sstevel@tonic-gate #include <unistd.h> /* setsid */
420Sstevel@tonic-gate #include <sys/types.h>
430Sstevel@tonic-gate #include <memory.h>
440Sstevel@tonic-gate #include <stropts.h>
450Sstevel@tonic-gate #include <netconfig.h>
460Sstevel@tonic-gate #include <libintl.h>
470Sstevel@tonic-gate #include <locale.h>
480Sstevel@tonic-gate #include <thread.h>
490Sstevel@tonic-gate #include <sys/resource.h> /* rlimit */
500Sstevel@tonic-gate #include <synch.h>
510Sstevel@tonic-gate #include <mdbug/mdbug.h>
520Sstevel@tonic-gate #include <common/cachefsd.h>
530Sstevel@tonic-gate #include <sys/fs/cachefs_fs.h>
540Sstevel@tonic-gate #include <sys/fs/cachefs_dlog.h>
550Sstevel@tonic-gate #include <sys/fs/cachefs_ioctl.h>
560Sstevel@tonic-gate #include "cfsd.h"
570Sstevel@tonic-gate #include "cfsd_kmod.h"
580Sstevel@tonic-gate #include "cfsd_maptbl.h"
590Sstevel@tonic-gate #include "cfsd_logfile.h"
600Sstevel@tonic-gate #include "cfsd_fscache.h"
610Sstevel@tonic-gate #include "cfsd_cache.h"
620Sstevel@tonic-gate #include "cfsd_all.h"
630Sstevel@tonic-gate #include "cfsd_subr.h"
640Sstevel@tonic-gate 
650Sstevel@tonic-gate #define	RPCGEN_ACTION(X) X
660Sstevel@tonic-gate #include "cachefsd_tbl.i"
670Sstevel@tonic-gate 
680Sstevel@tonic-gate #ifndef SIG_PF
690Sstevel@tonic-gate #define	SIG_PF void(*)(int)
700Sstevel@tonic-gate #endif
710Sstevel@tonic-gate 
720Sstevel@tonic-gate typedef bool_t (* LOCAL)(void *, void *, struct svc_req *);
730Sstevel@tonic-gate 
740Sstevel@tonic-gate /* global definitions */
750Sstevel@tonic-gate cfsd_all_object_t *all_object_p = NULL;
760Sstevel@tonic-gate 
770Sstevel@tonic-gate /* forward references */
780Sstevel@tonic-gate void msgout(char *msgp);
790Sstevel@tonic-gate void cachefsdprog_1(struct svc_req *rqstp, register SVCXPRT *transp);
800Sstevel@tonic-gate void sigusr1_handler(int, siginfo_t *, void *);
810Sstevel@tonic-gate static int void_close(void *, int);
820Sstevel@tonic-gate 
830Sstevel@tonic-gate /*
840Sstevel@tonic-gate  * -----------------------------------------------------------------
850Sstevel@tonic-gate  *			main
860Sstevel@tonic-gate  *
870Sstevel@tonic-gate  * Description:
880Sstevel@tonic-gate  *	main routine for the chart daemon.
890Sstevel@tonic-gate  * Arguments:
900Sstevel@tonic-gate  *	argc
910Sstevel@tonic-gate  *	argv
920Sstevel@tonic-gate  * Returns:
930Sstevel@tonic-gate  *	Returns 0 for a normal exit, !0 if an error occurred.
940Sstevel@tonic-gate  * Preconditions:
950Sstevel@tonic-gate  *	precond(argv)
960Sstevel@tonic-gate  */
970Sstevel@tonic-gate 
980Sstevel@tonic-gate int
main(int argc,char ** argv)990Sstevel@tonic-gate main(int argc, char **argv)
1000Sstevel@tonic-gate {
1010Sstevel@tonic-gate 	pid_t pid;
1020Sstevel@tonic-gate 	int xx;
1030Sstevel@tonic-gate 	char mname[FMNAMESZ + 1];
1040Sstevel@tonic-gate 	int opt_fork = 0;
1050Sstevel@tonic-gate 	int opt_mt = 0;
1060Sstevel@tonic-gate 	char *opt_root = NULL;
1070Sstevel@tonic-gate 	int c;
1080Sstevel@tonic-gate 	char *msgp;
1090Sstevel@tonic-gate 	int size;
1100Sstevel@tonic-gate 	struct rlimit rl;
1110Sstevel@tonic-gate 	struct sigaction nact;
1120Sstevel@tonic-gate 	int ofd = -1;
1130Sstevel@tonic-gate 	char *netid;
1140Sstevel@tonic-gate 	struct netconfig *nconf = NULL;
1150Sstevel@tonic-gate 	SVCXPRT *transp;
1160Sstevel@tonic-gate 	cfsd_fscache_object_t *fscache_object_p;
1170Sstevel@tonic-gate 	int mode;
1180Sstevel@tonic-gate 	/* selectable maximum RPC request record size */
1190Sstevel@tonic-gate 	int maxrecsz = RPC_MAXDATASIZE;
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate 	dbug_enter("main");
1220Sstevel@tonic-gate 	dbug_process("cfsadmin");
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
1250Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
1260Sstevel@tonic-gate #define	TEXT_DOMAIN	"SYS_TEST"
1270Sstevel@tonic-gate #endif
1280Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate 	/* verify root */
1310Sstevel@tonic-gate 	if (getuid() != 0) {
1320Sstevel@tonic-gate 		fprintf(stderr, gettext("%s: must be run by root\n"), argv[0]);
1330Sstevel@tonic-gate 		dbug_leave("main");
1340Sstevel@tonic-gate 		return (1);
1350Sstevel@tonic-gate 	}
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate 	/* Increase number of file descriptors to maximum allowable */
1380Sstevel@tonic-gate 	xx = getrlimit(RLIMIT_NOFILE, &rl);
1390Sstevel@tonic-gate 	if (xx < 0) {
1400Sstevel@tonic-gate 		dbug_print(("error",
1410Sstevel@tonic-gate 		    "getrlimit/RLIMIT_NOFILE failed %d", errno));
1420Sstevel@tonic-gate 		dbug_leave("main");
1430Sstevel@tonic-gate 		return (1);
1440Sstevel@tonic-gate 	}
1450Sstevel@tonic-gate 	rl.rlim_cur = rl.rlim_max;
1460Sstevel@tonic-gate 	xx = setrlimit(RLIMIT_NOFILE, &rl);
1470Sstevel@tonic-gate 	if (xx < 0) {
1480Sstevel@tonic-gate 		dbug_print(("error",
1490Sstevel@tonic-gate 		    "setrlimit/RLIMIT_NOFILE failed %d", errno));
1500Sstevel@tonic-gate 		dbug_leave("main");
1510Sstevel@tonic-gate 		return (1);
1520Sstevel@tonic-gate 	}
153*1914Scasper 	(void) enable_extended_FILE_stdio(-1, -1);
1540Sstevel@tonic-gate 
1550Sstevel@tonic-gate 	while ((c = getopt(argc, argv, "fmr:#:")) != EOF) {
1560Sstevel@tonic-gate 		switch (c) {
1570Sstevel@tonic-gate 		case 'f':
1580Sstevel@tonic-gate 			opt_fork = 1;
1590Sstevel@tonic-gate 			break;
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate 		case 'm':
1620Sstevel@tonic-gate 			/*
1630Sstevel@tonic-gate 			 * XXX don't use this until race between mount
1640Sstevel@tonic-gate 			 * and umount is fixed.
1650Sstevel@tonic-gate 			 */
1660Sstevel@tonic-gate 			opt_mt = 1;
1670Sstevel@tonic-gate 			break;
1680Sstevel@tonic-gate 
1690Sstevel@tonic-gate 		case 'r':
1700Sstevel@tonic-gate 			opt_root = optarg;
1710Sstevel@tonic-gate 			break;
1720Sstevel@tonic-gate 
1730Sstevel@tonic-gate 		case '#':	/* dbug args */
1740Sstevel@tonic-gate 			msgp = dbug_push(optarg);
1750Sstevel@tonic-gate 			if (msgp) {
1760Sstevel@tonic-gate 				printf("dbug_push failed \"%s\"\n", msgp);
1770Sstevel@tonic-gate 				dbug_leave("main");
1780Sstevel@tonic-gate 				return (1);
1790Sstevel@tonic-gate 			}
1800Sstevel@tonic-gate 			ofd = db_getfd();
1810Sstevel@tonic-gate 			break;
1820Sstevel@tonic-gate 
1830Sstevel@tonic-gate 		default:
1840Sstevel@tonic-gate 			printf(gettext("illegal switch\n"));
1850Sstevel@tonic-gate 			dbug_leave("main");
1860Sstevel@tonic-gate 			return (1);
1870Sstevel@tonic-gate 		}
1880Sstevel@tonic-gate 	}
1890Sstevel@tonic-gate 
1900Sstevel@tonic-gate 	/* XXX need some way to prevent multiple daemons from running */
1910Sstevel@tonic-gate 
1920Sstevel@tonic-gate 	dbug_print(("info", "cachefsd started..."));
1930Sstevel@tonic-gate 
1940Sstevel@tonic-gate 	if (opt_mt) {
1950Sstevel@tonic-gate 		dbug_print(("info", "MT_AUTO mode set"));
1960Sstevel@tonic-gate 		mode = RPC_SVC_MT_AUTO;
1970Sstevel@tonic-gate 		if (!rpc_control(RPC_SVC_MTMODE_SET, &mode)) {
1980Sstevel@tonic-gate 			msgout(gettext("unable to set automatic MT mode."));
1990Sstevel@tonic-gate 			dbug_leave("main");
2000Sstevel@tonic-gate 			return (1);
2010Sstevel@tonic-gate 		}
2020Sstevel@tonic-gate 	}
2030Sstevel@tonic-gate 
2040Sstevel@tonic-gate 	/*
2050Sstevel@tonic-gate 	 * Enable non-blocking mode and maximum record size checks for
2060Sstevel@tonic-gate 	 * connection oriented transports.
2070Sstevel@tonic-gate 	 */
2080Sstevel@tonic-gate 	if (!rpc_control(RPC_SVC_CONNMAXREC_SET, &maxrecsz)) {
2090Sstevel@tonic-gate 		msgout(gettext("unable to set max RPC record size"));
2100Sstevel@tonic-gate 	}
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate 	/* ignore sigpipe */
2130Sstevel@tonic-gate 	nact.sa_handler = SIG_IGN;
2140Sstevel@tonic-gate 	nact.sa_sigaction = NULL;
2150Sstevel@tonic-gate 	sigemptyset(&nact.sa_mask);
2160Sstevel@tonic-gate 	nact.sa_flags = 0;
2170Sstevel@tonic-gate 	xx = sigaction(SIGPIPE, &nact, NULL);
2180Sstevel@tonic-gate 	if (xx) {
2190Sstevel@tonic-gate 		dbug_print(("error", "sigaction/SIGPIPE failed %d", errno));
2200Sstevel@tonic-gate 	}
2210Sstevel@tonic-gate 
2220Sstevel@tonic-gate 	/* catch sigusr1 signals, used to wake up threads */
2230Sstevel@tonic-gate 	nact.sa_handler = NULL;
2240Sstevel@tonic-gate 	nact.sa_sigaction = sigusr1_handler;
2250Sstevel@tonic-gate 	sigemptyset(&nact.sa_mask);
2260Sstevel@tonic-gate 	nact.sa_flags = SA_SIGINFO;
2270Sstevel@tonic-gate 	xx = sigaction(SIGUSR1, &nact, NULL);
2280Sstevel@tonic-gate 	if (xx) {
2290Sstevel@tonic-gate 		dbug_print(("error", "sigaction failed %d", errno));
2300Sstevel@tonic-gate 	}
2310Sstevel@tonic-gate 
2320Sstevel@tonic-gate 	/* do not set up rpc services if just taking care of root */
2330Sstevel@tonic-gate 	if (opt_root) {
2340Sstevel@tonic-gate 		dbug_print(("info", "handling just root"));
2350Sstevel@tonic-gate 
2360Sstevel@tonic-gate 		/* make the fscache object */
2370Sstevel@tonic-gate 		fscache_object_p =
2380Sstevel@tonic-gate 		    cfsd_fscache_create("rootcache", opt_root, 1);
2390Sstevel@tonic-gate 
2400Sstevel@tonic-gate 		/* init the fscache object with mount information */
2410Sstevel@tonic-gate 		fscache_lock(fscache_object_p);
2420Sstevel@tonic-gate 		fscache_object_p->i_refcnt++;
2430Sstevel@tonic-gate 		fscache_setup(fscache_object_p);
2440Sstevel@tonic-gate 		fscache_object_p->i_mounted = 1;
2450Sstevel@tonic-gate 		fscache_unlock(fscache_object_p);
2460Sstevel@tonic-gate 
2470Sstevel@tonic-gate 		if (fscache_object_p->i_disconnectable &&
2480Sstevel@tonic-gate 		    fscache_object_p->i_mounted) {
2490Sstevel@tonic-gate 			pid = fork();
2500Sstevel@tonic-gate 			if (pid < 0) {
2510Sstevel@tonic-gate 				perror(gettext("cannot fork"));
2520Sstevel@tonic-gate 				cfsd_fscache_destroy(fscache_object_p);
2530Sstevel@tonic-gate 				dbug_leave("main");
2540Sstevel@tonic-gate 				return (1);
2550Sstevel@tonic-gate 			}
2560Sstevel@tonic-gate 			if (pid) {
2570Sstevel@tonic-gate 				cfsd_fscache_destroy(fscache_object_p);
2580Sstevel@tonic-gate 				dbug_leave("main");
2590Sstevel@tonic-gate 				return (0);
2600Sstevel@tonic-gate 			}
2610Sstevel@tonic-gate 			(void) fdwalk(void_close, &ofd);
2620Sstevel@tonic-gate 			xx = open("/dev/sysmsg", O_RDWR);
2630Sstevel@tonic-gate 			(void) dup2(xx, 1);
2640Sstevel@tonic-gate 			(void) dup2(xx, 2);
2650Sstevel@tonic-gate 			setsid();
2660Sstevel@tonic-gate 
2670Sstevel@tonic-gate 			fscache_process(fscache_object_p);
2680Sstevel@tonic-gate 		} else {
2690Sstevel@tonic-gate 			/* not disconnectable */
2700Sstevel@tonic-gate 			cfsd_fscache_destroy(fscache_object_p);
2710Sstevel@tonic-gate 			dbug_leave("main");
2720Sstevel@tonic-gate 			return (1);
2730Sstevel@tonic-gate 		}
2740Sstevel@tonic-gate 		cfsd_fscache_destroy(fscache_object_p);
2750Sstevel@tonic-gate 		dbug_leave("main");
2760Sstevel@tonic-gate 		return (0);
2770Sstevel@tonic-gate 	}
2780Sstevel@tonic-gate 
2790Sstevel@tonic-gate 	/* if a inetd started us */
2800Sstevel@tonic-gate 	else if (!ioctl(0, I_LOOK, mname) &&
2810Sstevel@tonic-gate 		((strcmp(mname, "sockmod") == 0) ||
2820Sstevel@tonic-gate 		(strcmp(mname, "timod") == 0))) {
2830Sstevel@tonic-gate 		dbug_print(("info", "started by inetd"));
2840Sstevel@tonic-gate 
2850Sstevel@tonic-gate 		if (freopen("/dev/null", "w", stderr) == NULL)
2860Sstevel@tonic-gate 			return (1);
2870Sstevel@tonic-gate 
2880Sstevel@tonic-gate 		/* started from inetd */
2890Sstevel@tonic-gate 		if ((netid = getenv("NLSPROVIDER")) == NULL)
2900Sstevel@tonic-gate 			netid = "ticotsord";
2910Sstevel@tonic-gate 		if ((nconf = getnetconfigent(netid)) == NULL)
2920Sstevel@tonic-gate 			msgout(gettext("cannot get transport info"));
2930Sstevel@tonic-gate 
2940Sstevel@tonic-gate 		if (strcmp(mname, "sockmod") == 0) {
2950Sstevel@tonic-gate 			if (ioctl(0, I_POP, 0) || ioctl(0, I_PUSH, "timod")) {
2960Sstevel@tonic-gate 				msgout(
2970Sstevel@tonic-gate 				    gettext("could not get the right module"));
2980Sstevel@tonic-gate 				dbug_leave("main");
2990Sstevel@tonic-gate 				return (1);
3000Sstevel@tonic-gate 			}
3010Sstevel@tonic-gate 		}
3020Sstevel@tonic-gate 		if ((transp = svc_tli_create(0, nconf, NULL, 0, 0)) == NULL) {
3030Sstevel@tonic-gate 			msgout(gettext("cannot create server handle"));
3040Sstevel@tonic-gate 			dbug_leave("main");
3050Sstevel@tonic-gate 			return (1);
3060Sstevel@tonic-gate 		}
3070Sstevel@tonic-gate 		if (nconf)
3080Sstevel@tonic-gate 			freenetconfigent(nconf);
3090Sstevel@tonic-gate 		xx = svc_reg(transp, CACHEFSDPROG, CACHEFSDVERS,
3100Sstevel@tonic-gate 			cachefsdprog_1, 0);
3110Sstevel@tonic-gate 		if (!xx) {
3120Sstevel@tonic-gate 			msgout(gettext(
3130Sstevel@tonic-gate 			    "unable to reg (CACHEFSDPROG, CACHEFSDVERS)."));
3140Sstevel@tonic-gate 			dbug_leave("main");
3150Sstevel@tonic-gate 			return (1);
3160Sstevel@tonic-gate 		}
3170Sstevel@tonic-gate 	}
3180Sstevel@tonic-gate 
3190Sstevel@tonic-gate 	/* else if started by hand */
3200Sstevel@tonic-gate 	else {
3210Sstevel@tonic-gate 		/* if we should fork */
3220Sstevel@tonic-gate 		if (opt_fork) {
3230Sstevel@tonic-gate 			dbug_print(("info", "forking"));
3240Sstevel@tonic-gate 			pid = fork();
3250Sstevel@tonic-gate 			if (pid < 0) {
3260Sstevel@tonic-gate 				perror(gettext("cannot fork"));
3270Sstevel@tonic-gate 				dbug_leave("main");
3280Sstevel@tonic-gate 				return (1);
3290Sstevel@tonic-gate 			}
3300Sstevel@tonic-gate 			if (pid) {
3310Sstevel@tonic-gate 				dbug_leave("main");
3320Sstevel@tonic-gate 				return (0);
3330Sstevel@tonic-gate 			}
3340Sstevel@tonic-gate 			(void) fdwalk(void_close, &ofd);
3350Sstevel@tonic-gate 			xx = open("/dev/sysmsg", 2);
3360Sstevel@tonic-gate 			(void) dup2(xx, 1);
3370Sstevel@tonic-gate 			(void) dup2(xx, 2);
3380Sstevel@tonic-gate 			setsid();
3390Sstevel@tonic-gate 		}
3400Sstevel@tonic-gate 
3410Sstevel@tonic-gate 		/* connect to *ANY* local loopback transport provider */
3420Sstevel@tonic-gate 		xx = svc_create(cachefsdprog_1, CACHEFSDPROG, CACHEFSDVERS,
3430Sstevel@tonic-gate 		    "local");
3440Sstevel@tonic-gate 		if (!xx) {
3450Sstevel@tonic-gate 			msgout(gettext("unable to create (CACHEFSDPROG, "
3460Sstevel@tonic-gate 				"CACHEFSDVERS) for netpath."));
3470Sstevel@tonic-gate 			dbug_leave("main");
3480Sstevel@tonic-gate 			return (1);
3490Sstevel@tonic-gate 		}
3500Sstevel@tonic-gate 	}
3510Sstevel@tonic-gate 
3520Sstevel@tonic-gate 	/* find existing caches and mounted file systems */
3530Sstevel@tonic-gate 	all_object_p = cfsd_all_create();
3540Sstevel@tonic-gate 	subr_cache_setup(all_object_p);
3550Sstevel@tonic-gate 
3560Sstevel@tonic-gate 	/* process requests */
3570Sstevel@tonic-gate 	svc_run();
3580Sstevel@tonic-gate 
3590Sstevel@tonic-gate 	msgout(gettext("svc_run returned"));
3600Sstevel@tonic-gate 	cfsd_all_destroy(all_object_p);
3610Sstevel@tonic-gate 	dbug_leave("main");
3620Sstevel@tonic-gate 	return (1);
3630Sstevel@tonic-gate }
3640Sstevel@tonic-gate 
3650Sstevel@tonic-gate /*
3660Sstevel@tonic-gate  * Callback function for fdwalk() to close all files.
3670Sstevel@tonic-gate  */
3680Sstevel@tonic-gate static int
void_close(void * ofdp,int fd)3690Sstevel@tonic-gate void_close(void *ofdp, int fd)
3700Sstevel@tonic-gate {
3710Sstevel@tonic-gate 	if (fd != *(int *)ofdp) {
3720Sstevel@tonic-gate 		if (close(fd) != 0)
3730Sstevel@tonic-gate 			dbug_print(("err",
3740Sstevel@tonic-gate 			    "cannot close fd %d, %d", fd, errno));
3750Sstevel@tonic-gate 	}
3760Sstevel@tonic-gate 	return (0);
3770Sstevel@tonic-gate }
3780Sstevel@tonic-gate 
3790Sstevel@tonic-gate /*
3800Sstevel@tonic-gate  * -----------------------------------------------------------------
3810Sstevel@tonic-gate  *			msgout
3820Sstevel@tonic-gate  *
3830Sstevel@tonic-gate  * Description:
3840Sstevel@tonic-gate  *	Outputs an error message to stderr.
3850Sstevel@tonic-gate  * Arguments:
3860Sstevel@tonic-gate  *	msgp
3870Sstevel@tonic-gate  * Returns:
3880Sstevel@tonic-gate  * Preconditions:
3890Sstevel@tonic-gate  *	precond(msgp)
3900Sstevel@tonic-gate  */
3910Sstevel@tonic-gate 
3920Sstevel@tonic-gate void
msgout(char * msgp)3930Sstevel@tonic-gate msgout(char *msgp)
3940Sstevel@tonic-gate {
3950Sstevel@tonic-gate 	dbug_enter("msgout");
3960Sstevel@tonic-gate 	dbug_precond(msgp);
3970Sstevel@tonic-gate 
3980Sstevel@tonic-gate 	(void) fprintf(stderr, "%s\n", msgp);
3990Sstevel@tonic-gate 	dbug_leave("msgout");
4000Sstevel@tonic-gate }
4010Sstevel@tonic-gate 
4020Sstevel@tonic-gate 
4030Sstevel@tonic-gate /*
4040Sstevel@tonic-gate  * -----------------------------------------------------------------
4050Sstevel@tonic-gate  *			cachefsdprog_1
4060Sstevel@tonic-gate  *
4070Sstevel@tonic-gate  * Description:
4080Sstevel@tonic-gate  * Arguments:
4090Sstevel@tonic-gate  *	rqstp
4100Sstevel@tonic-gate  *	transp
4110Sstevel@tonic-gate  * Returns:
4120Sstevel@tonic-gate  * Preconditions:
4130Sstevel@tonic-gate  *	precond(rqstp)
4140Sstevel@tonic-gate  *	precond(transp)
4150Sstevel@tonic-gate  */
4160Sstevel@tonic-gate void
cachefsdprog_1(struct svc_req * rqstp,register SVCXPRT * transp)4170Sstevel@tonic-gate cachefsdprog_1(struct svc_req *rqstp, register SVCXPRT *transp)
4180Sstevel@tonic-gate {
4190Sstevel@tonic-gate 	int index;
4200Sstevel@tonic-gate 	struct rpcgen_table *rtp;
4210Sstevel@tonic-gate 	void *argumentp = NULL;
4220Sstevel@tonic-gate 	void *resultp = NULL;
4230Sstevel@tonic-gate 	LOCAL local;
4240Sstevel@tonic-gate 	int xx;
4250Sstevel@tonic-gate 
4260Sstevel@tonic-gate 	dbug_enter("cachefsdprog_1");
4270Sstevel@tonic-gate 
4280Sstevel@tonic-gate 	dbug_precond(rqstp);
4290Sstevel@tonic-gate 	dbug_precond(transp);
4300Sstevel@tonic-gate 
4310Sstevel@tonic-gate 	/* make sure a valid command number */
4320Sstevel@tonic-gate 	index = rqstp->rq_proc;
4330Sstevel@tonic-gate 	if ((index < 0) || (cachefsdprog_1_nproc <= index)) {
4340Sstevel@tonic-gate 		msgout(gettext("bad message"));
4350Sstevel@tonic-gate 		svcerr_noproc(transp);
4360Sstevel@tonic-gate 		dbug_leave("cachefsdprog_1");
4370Sstevel@tonic-gate 		return;
4380Sstevel@tonic-gate 	}
4390Sstevel@tonic-gate 
4400Sstevel@tonic-gate 	/* get command information */
4410Sstevel@tonic-gate 	rtp = &cachefsdprog_1_table[index];
4420Sstevel@tonic-gate 
4430Sstevel@tonic-gate 	/* get memory for the arguments */
4440Sstevel@tonic-gate 	if (rtp->len_arg != 0)
4450Sstevel@tonic-gate 		argumentp = (void *)cfsd_calloc(rtp->len_arg);
4460Sstevel@tonic-gate 
4470Sstevel@tonic-gate 	/* get memory for the results */
4480Sstevel@tonic-gate 	if (rtp->len_res != 0)
4490Sstevel@tonic-gate 		resultp = (void *)cfsd_calloc(rtp->len_res);
4500Sstevel@tonic-gate 
4510Sstevel@tonic-gate 	/* get the arguments */
4520Sstevel@tonic-gate 	if (rtp->xdr_arg && argumentp) {
4530Sstevel@tonic-gate 		if (!svc_getargs(transp, rtp->xdr_arg, (caddr_t)argumentp)) {
4540Sstevel@tonic-gate 			svcerr_decode(transp);
4550Sstevel@tonic-gate 			cfsd_free(argumentp);
4560Sstevel@tonic-gate 			cfsd_free(resultp);
4570Sstevel@tonic-gate 			dbug_leave("cachefsdprog_1");
4580Sstevel@tonic-gate 			return;
4590Sstevel@tonic-gate 		}
4600Sstevel@tonic-gate 	}
4610Sstevel@tonic-gate 
4620Sstevel@tonic-gate 	/* call the routine to process the command */
4630Sstevel@tonic-gate 	local = (LOCAL)rtp->proc;
4640Sstevel@tonic-gate 	xx = (*local)(argumentp, resultp, rqstp);
4650Sstevel@tonic-gate 
4660Sstevel@tonic-gate 	/* if the command could not be processed */
4670Sstevel@tonic-gate 	if (xx == 0) {
4680Sstevel@tonic-gate 		svcerr_systemerr(transp);
4690Sstevel@tonic-gate 	}
4700Sstevel@tonic-gate 
4710Sstevel@tonic-gate 	/* else send the results back to the caller */
4720Sstevel@tonic-gate 	else {
4730Sstevel@tonic-gate 		xx = svc_sendreply(transp, rtp->xdr_res, (caddr_t)resultp);
4740Sstevel@tonic-gate 		if (!xx)
4750Sstevel@tonic-gate 			svcerr_systemerr(transp);
4760Sstevel@tonic-gate 
4770Sstevel@tonic-gate 		/* free the results */
4780Sstevel@tonic-gate 		xx = cachefsdprog_1_freeresult(transp, rtp->xdr_res,
4790Sstevel@tonic-gate 		    (caddr_t)resultp);
4800Sstevel@tonic-gate 		if (xx == 0)
4810Sstevel@tonic-gate 			msgout(gettext("unable to free results"));
4820Sstevel@tonic-gate 	}
4830Sstevel@tonic-gate 
4840Sstevel@tonic-gate 	/* free the passed in arguments */
4850Sstevel@tonic-gate 	if (!svc_freeargs(transp, rtp->xdr_arg, (caddr_t)argumentp)) {
4860Sstevel@tonic-gate 		msgout(gettext("unable to free arguments"));
4870Sstevel@tonic-gate 		abort();
4880Sstevel@tonic-gate 	}
4890Sstevel@tonic-gate 
4900Sstevel@tonic-gate 	if (argumentp)
4910Sstevel@tonic-gate 		cfsd_free(argumentp);
4920Sstevel@tonic-gate 	if (resultp)
4930Sstevel@tonic-gate 		cfsd_free(resultp);
4940Sstevel@tonic-gate 	dbug_leave("cachefsdprog_1");
4950Sstevel@tonic-gate }
4960Sstevel@tonic-gate 
4970Sstevel@tonic-gate /*
4980Sstevel@tonic-gate  *			sigusr1_handler
4990Sstevel@tonic-gate  *
5000Sstevel@tonic-gate  * Description:
5010Sstevel@tonic-gate  *	Catches sigusr1 signal so threads wake up.
5020Sstevel@tonic-gate  * Arguments:
5030Sstevel@tonic-gate  * Returns:
5040Sstevel@tonic-gate  * Preconditions:
5050Sstevel@tonic-gate  */
5060Sstevel@tonic-gate void
sigusr1_handler(int sig,siginfo_t * sp,void * vp)5070Sstevel@tonic-gate sigusr1_handler(int sig, siginfo_t *sp, void *vp)
5080Sstevel@tonic-gate {
5090Sstevel@tonic-gate }
510