17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*004388ebScasper * Common Development and Distribution License (the "License").
6*004388ebScasper * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22*004388ebScasper * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate * Main routines for cachefs daemon.
307c478bd9Sstevel@tonic-gate */
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate #include <stdio.h>
33*004388ebScasper #include <stdio_ext.h>
347c478bd9Sstevel@tonic-gate #include <stdlib.h>
357c478bd9Sstevel@tonic-gate #include <string.h>
367c478bd9Sstevel@tonic-gate #include <errno.h>
377c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
387c478bd9Sstevel@tonic-gate #include <rpc/pmap_clnt.h> /* for pmap_unset */
397c478bd9Sstevel@tonic-gate #include <string.h> /* strcmp */
407c478bd9Sstevel@tonic-gate #include <signal.h>
417c478bd9Sstevel@tonic-gate #include <unistd.h> /* setsid */
427c478bd9Sstevel@tonic-gate #include <sys/types.h>
437c478bd9Sstevel@tonic-gate #include <memory.h>
447c478bd9Sstevel@tonic-gate #include <stropts.h>
457c478bd9Sstevel@tonic-gate #include <netconfig.h>
467c478bd9Sstevel@tonic-gate #include <libintl.h>
477c478bd9Sstevel@tonic-gate #include <locale.h>
487c478bd9Sstevel@tonic-gate #include <thread.h>
497c478bd9Sstevel@tonic-gate #include <sys/resource.h> /* rlimit */
507c478bd9Sstevel@tonic-gate #include <synch.h>
517c478bd9Sstevel@tonic-gate #include <mdbug/mdbug.h>
527c478bd9Sstevel@tonic-gate #include <common/cachefsd.h>
537c478bd9Sstevel@tonic-gate #include <sys/fs/cachefs_fs.h>
547c478bd9Sstevel@tonic-gate #include <sys/fs/cachefs_dlog.h>
557c478bd9Sstevel@tonic-gate #include <sys/fs/cachefs_ioctl.h>
567c478bd9Sstevel@tonic-gate #include "cfsd.h"
577c478bd9Sstevel@tonic-gate #include "cfsd_kmod.h"
587c478bd9Sstevel@tonic-gate #include "cfsd_maptbl.h"
597c478bd9Sstevel@tonic-gate #include "cfsd_logfile.h"
607c478bd9Sstevel@tonic-gate #include "cfsd_fscache.h"
617c478bd9Sstevel@tonic-gate #include "cfsd_cache.h"
627c478bd9Sstevel@tonic-gate #include "cfsd_all.h"
637c478bd9Sstevel@tonic-gate #include "cfsd_subr.h"
647c478bd9Sstevel@tonic-gate
657c478bd9Sstevel@tonic-gate #define RPCGEN_ACTION(X) X
667c478bd9Sstevel@tonic-gate #include "cachefsd_tbl.i"
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate #ifndef SIG_PF
697c478bd9Sstevel@tonic-gate #define SIG_PF void(*)(int)
707c478bd9Sstevel@tonic-gate #endif
717c478bd9Sstevel@tonic-gate
727c478bd9Sstevel@tonic-gate typedef bool_t (* LOCAL)(void *, void *, struct svc_req *);
737c478bd9Sstevel@tonic-gate
747c478bd9Sstevel@tonic-gate /* global definitions */
757c478bd9Sstevel@tonic-gate cfsd_all_object_t *all_object_p = NULL;
767c478bd9Sstevel@tonic-gate
777c478bd9Sstevel@tonic-gate /* forward references */
787c478bd9Sstevel@tonic-gate void msgout(char *msgp);
797c478bd9Sstevel@tonic-gate void cachefsdprog_1(struct svc_req *rqstp, register SVCXPRT *transp);
807c478bd9Sstevel@tonic-gate void sigusr1_handler(int, siginfo_t *, void *);
817c478bd9Sstevel@tonic-gate static int void_close(void *, int);
827c478bd9Sstevel@tonic-gate
837c478bd9Sstevel@tonic-gate /*
847c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------
857c478bd9Sstevel@tonic-gate * main
867c478bd9Sstevel@tonic-gate *
877c478bd9Sstevel@tonic-gate * Description:
887c478bd9Sstevel@tonic-gate * main routine for the chart daemon.
897c478bd9Sstevel@tonic-gate * Arguments:
907c478bd9Sstevel@tonic-gate * argc
917c478bd9Sstevel@tonic-gate * argv
927c478bd9Sstevel@tonic-gate * Returns:
937c478bd9Sstevel@tonic-gate * Returns 0 for a normal exit, !0 if an error occurred.
947c478bd9Sstevel@tonic-gate * Preconditions:
957c478bd9Sstevel@tonic-gate * precond(argv)
967c478bd9Sstevel@tonic-gate */
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate int
main(int argc,char ** argv)997c478bd9Sstevel@tonic-gate main(int argc, char **argv)
1007c478bd9Sstevel@tonic-gate {
1017c478bd9Sstevel@tonic-gate pid_t pid;
1027c478bd9Sstevel@tonic-gate int xx;
1037c478bd9Sstevel@tonic-gate char mname[FMNAMESZ + 1];
1047c478bd9Sstevel@tonic-gate int opt_fork = 0;
1057c478bd9Sstevel@tonic-gate int opt_mt = 0;
1067c478bd9Sstevel@tonic-gate char *opt_root = NULL;
1077c478bd9Sstevel@tonic-gate int c;
1087c478bd9Sstevel@tonic-gate char *msgp;
1097c478bd9Sstevel@tonic-gate int size;
1107c478bd9Sstevel@tonic-gate struct rlimit rl;
1117c478bd9Sstevel@tonic-gate struct sigaction nact;
1127c478bd9Sstevel@tonic-gate int ofd = -1;
1137c478bd9Sstevel@tonic-gate char *netid;
1147c478bd9Sstevel@tonic-gate struct netconfig *nconf = NULL;
1157c478bd9Sstevel@tonic-gate SVCXPRT *transp;
1167c478bd9Sstevel@tonic-gate cfsd_fscache_object_t *fscache_object_p;
1177c478bd9Sstevel@tonic-gate int mode;
1187c478bd9Sstevel@tonic-gate /* selectable maximum RPC request record size */
1197c478bd9Sstevel@tonic-gate int maxrecsz = RPC_MAXDATASIZE;
1207c478bd9Sstevel@tonic-gate
1217c478bd9Sstevel@tonic-gate dbug_enter("main");
1227c478bd9Sstevel@tonic-gate dbug_process("cfsadmin");
1237c478bd9Sstevel@tonic-gate
1247c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, "");
1257c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
1267c478bd9Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST"
1277c478bd9Sstevel@tonic-gate #endif
1287c478bd9Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN);
1297c478bd9Sstevel@tonic-gate
1307c478bd9Sstevel@tonic-gate /* verify root */
1317c478bd9Sstevel@tonic-gate if (getuid() != 0) {
1327c478bd9Sstevel@tonic-gate fprintf(stderr, gettext("%s: must be run by root\n"), argv[0]);
1337c478bd9Sstevel@tonic-gate dbug_leave("main");
1347c478bd9Sstevel@tonic-gate return (1);
1357c478bd9Sstevel@tonic-gate }
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate /* Increase number of file descriptors to maximum allowable */
1387c478bd9Sstevel@tonic-gate xx = getrlimit(RLIMIT_NOFILE, &rl);
1397c478bd9Sstevel@tonic-gate if (xx < 0) {
1407c478bd9Sstevel@tonic-gate dbug_print(("error",
1417c478bd9Sstevel@tonic-gate "getrlimit/RLIMIT_NOFILE failed %d", errno));
1427c478bd9Sstevel@tonic-gate dbug_leave("main");
1437c478bd9Sstevel@tonic-gate return (1);
1447c478bd9Sstevel@tonic-gate }
1457c478bd9Sstevel@tonic-gate rl.rlim_cur = rl.rlim_max;
1467c478bd9Sstevel@tonic-gate xx = setrlimit(RLIMIT_NOFILE, &rl);
1477c478bd9Sstevel@tonic-gate if (xx < 0) {
1487c478bd9Sstevel@tonic-gate dbug_print(("error",
1497c478bd9Sstevel@tonic-gate "setrlimit/RLIMIT_NOFILE failed %d", errno));
1507c478bd9Sstevel@tonic-gate dbug_leave("main");
1517c478bd9Sstevel@tonic-gate return (1);
1527c478bd9Sstevel@tonic-gate }
153*004388ebScasper (void) enable_extended_FILE_stdio(-1, -1);
1547c478bd9Sstevel@tonic-gate
1557c478bd9Sstevel@tonic-gate while ((c = getopt(argc, argv, "fmr:#:")) != EOF) {
1567c478bd9Sstevel@tonic-gate switch (c) {
1577c478bd9Sstevel@tonic-gate case 'f':
1587c478bd9Sstevel@tonic-gate opt_fork = 1;
1597c478bd9Sstevel@tonic-gate break;
1607c478bd9Sstevel@tonic-gate
1617c478bd9Sstevel@tonic-gate case 'm':
1627c478bd9Sstevel@tonic-gate /*
1637c478bd9Sstevel@tonic-gate * XXX don't use this until race between mount
1647c478bd9Sstevel@tonic-gate * and umount is fixed.
1657c478bd9Sstevel@tonic-gate */
1667c478bd9Sstevel@tonic-gate opt_mt = 1;
1677c478bd9Sstevel@tonic-gate break;
1687c478bd9Sstevel@tonic-gate
1697c478bd9Sstevel@tonic-gate case 'r':
1707c478bd9Sstevel@tonic-gate opt_root = optarg;
1717c478bd9Sstevel@tonic-gate break;
1727c478bd9Sstevel@tonic-gate
1737c478bd9Sstevel@tonic-gate case '#': /* dbug args */
1747c478bd9Sstevel@tonic-gate msgp = dbug_push(optarg);
1757c478bd9Sstevel@tonic-gate if (msgp) {
1767c478bd9Sstevel@tonic-gate printf("dbug_push failed \"%s\"\n", msgp);
1777c478bd9Sstevel@tonic-gate dbug_leave("main");
1787c478bd9Sstevel@tonic-gate return (1);
1797c478bd9Sstevel@tonic-gate }
1807c478bd9Sstevel@tonic-gate ofd = db_getfd();
1817c478bd9Sstevel@tonic-gate break;
1827c478bd9Sstevel@tonic-gate
1837c478bd9Sstevel@tonic-gate default:
1847c478bd9Sstevel@tonic-gate printf(gettext("illegal switch\n"));
1857c478bd9Sstevel@tonic-gate dbug_leave("main");
1867c478bd9Sstevel@tonic-gate return (1);
1877c478bd9Sstevel@tonic-gate }
1887c478bd9Sstevel@tonic-gate }
1897c478bd9Sstevel@tonic-gate
1907c478bd9Sstevel@tonic-gate /* XXX need some way to prevent multiple daemons from running */
1917c478bd9Sstevel@tonic-gate
1927c478bd9Sstevel@tonic-gate dbug_print(("info", "cachefsd started..."));
1937c478bd9Sstevel@tonic-gate
1947c478bd9Sstevel@tonic-gate if (opt_mt) {
1957c478bd9Sstevel@tonic-gate dbug_print(("info", "MT_AUTO mode set"));
1967c478bd9Sstevel@tonic-gate mode = RPC_SVC_MT_AUTO;
1977c478bd9Sstevel@tonic-gate if (!rpc_control(RPC_SVC_MTMODE_SET, &mode)) {
1987c478bd9Sstevel@tonic-gate msgout(gettext("unable to set automatic MT mode."));
1997c478bd9Sstevel@tonic-gate dbug_leave("main");
2007c478bd9Sstevel@tonic-gate return (1);
2017c478bd9Sstevel@tonic-gate }
2027c478bd9Sstevel@tonic-gate }
2037c478bd9Sstevel@tonic-gate
2047c478bd9Sstevel@tonic-gate /*
2057c478bd9Sstevel@tonic-gate * Enable non-blocking mode and maximum record size checks for
2067c478bd9Sstevel@tonic-gate * connection oriented transports.
2077c478bd9Sstevel@tonic-gate */
2087c478bd9Sstevel@tonic-gate if (!rpc_control(RPC_SVC_CONNMAXREC_SET, &maxrecsz)) {
2097c478bd9Sstevel@tonic-gate msgout(gettext("unable to set max RPC record size"));
2107c478bd9Sstevel@tonic-gate }
2117c478bd9Sstevel@tonic-gate
2127c478bd9Sstevel@tonic-gate /* ignore sigpipe */
2137c478bd9Sstevel@tonic-gate nact.sa_handler = SIG_IGN;
2147c478bd9Sstevel@tonic-gate nact.sa_sigaction = NULL;
2157c478bd9Sstevel@tonic-gate sigemptyset(&nact.sa_mask);
2167c478bd9Sstevel@tonic-gate nact.sa_flags = 0;
2177c478bd9Sstevel@tonic-gate xx = sigaction(SIGPIPE, &nact, NULL);
2187c478bd9Sstevel@tonic-gate if (xx) {
2197c478bd9Sstevel@tonic-gate dbug_print(("error", "sigaction/SIGPIPE failed %d", errno));
2207c478bd9Sstevel@tonic-gate }
2217c478bd9Sstevel@tonic-gate
2227c478bd9Sstevel@tonic-gate /* catch sigusr1 signals, used to wake up threads */
2237c478bd9Sstevel@tonic-gate nact.sa_handler = NULL;
2247c478bd9Sstevel@tonic-gate nact.sa_sigaction = sigusr1_handler;
2257c478bd9Sstevel@tonic-gate sigemptyset(&nact.sa_mask);
2267c478bd9Sstevel@tonic-gate nact.sa_flags = SA_SIGINFO;
2277c478bd9Sstevel@tonic-gate xx = sigaction(SIGUSR1, &nact, NULL);
2287c478bd9Sstevel@tonic-gate if (xx) {
2297c478bd9Sstevel@tonic-gate dbug_print(("error", "sigaction failed %d", errno));
2307c478bd9Sstevel@tonic-gate }
2317c478bd9Sstevel@tonic-gate
2327c478bd9Sstevel@tonic-gate /* do not set up rpc services if just taking care of root */
2337c478bd9Sstevel@tonic-gate if (opt_root) {
2347c478bd9Sstevel@tonic-gate dbug_print(("info", "handling just root"));
2357c478bd9Sstevel@tonic-gate
2367c478bd9Sstevel@tonic-gate /* make the fscache object */
2377c478bd9Sstevel@tonic-gate fscache_object_p =
2387c478bd9Sstevel@tonic-gate cfsd_fscache_create("rootcache", opt_root, 1);
2397c478bd9Sstevel@tonic-gate
2407c478bd9Sstevel@tonic-gate /* init the fscache object with mount information */
2417c478bd9Sstevel@tonic-gate fscache_lock(fscache_object_p);
2427c478bd9Sstevel@tonic-gate fscache_object_p->i_refcnt++;
2437c478bd9Sstevel@tonic-gate fscache_setup(fscache_object_p);
2447c478bd9Sstevel@tonic-gate fscache_object_p->i_mounted = 1;
2457c478bd9Sstevel@tonic-gate fscache_unlock(fscache_object_p);
2467c478bd9Sstevel@tonic-gate
2477c478bd9Sstevel@tonic-gate if (fscache_object_p->i_disconnectable &&
2487c478bd9Sstevel@tonic-gate fscache_object_p->i_mounted) {
2497c478bd9Sstevel@tonic-gate pid = fork();
2507c478bd9Sstevel@tonic-gate if (pid < 0) {
2517c478bd9Sstevel@tonic-gate perror(gettext("cannot fork"));
2527c478bd9Sstevel@tonic-gate cfsd_fscache_destroy(fscache_object_p);
2537c478bd9Sstevel@tonic-gate dbug_leave("main");
2547c478bd9Sstevel@tonic-gate return (1);
2557c478bd9Sstevel@tonic-gate }
2567c478bd9Sstevel@tonic-gate if (pid) {
2577c478bd9Sstevel@tonic-gate cfsd_fscache_destroy(fscache_object_p);
2587c478bd9Sstevel@tonic-gate dbug_leave("main");
2597c478bd9Sstevel@tonic-gate return (0);
2607c478bd9Sstevel@tonic-gate }
2617c478bd9Sstevel@tonic-gate (void) fdwalk(void_close, &ofd);
2627c478bd9Sstevel@tonic-gate xx = open("/dev/sysmsg", O_RDWR);
2637c478bd9Sstevel@tonic-gate (void) dup2(xx, 1);
2647c478bd9Sstevel@tonic-gate (void) dup2(xx, 2);
2657c478bd9Sstevel@tonic-gate setsid();
2667c478bd9Sstevel@tonic-gate
2677c478bd9Sstevel@tonic-gate fscache_process(fscache_object_p);
2687c478bd9Sstevel@tonic-gate } else {
2697c478bd9Sstevel@tonic-gate /* not disconnectable */
2707c478bd9Sstevel@tonic-gate cfsd_fscache_destroy(fscache_object_p);
2717c478bd9Sstevel@tonic-gate dbug_leave("main");
2727c478bd9Sstevel@tonic-gate return (1);
2737c478bd9Sstevel@tonic-gate }
2747c478bd9Sstevel@tonic-gate cfsd_fscache_destroy(fscache_object_p);
2757c478bd9Sstevel@tonic-gate dbug_leave("main");
2767c478bd9Sstevel@tonic-gate return (0);
2777c478bd9Sstevel@tonic-gate }
2787c478bd9Sstevel@tonic-gate
2797c478bd9Sstevel@tonic-gate /* if a inetd started us */
2807c478bd9Sstevel@tonic-gate else if (!ioctl(0, I_LOOK, mname) &&
2817c478bd9Sstevel@tonic-gate ((strcmp(mname, "sockmod") == 0) ||
2827c478bd9Sstevel@tonic-gate (strcmp(mname, "timod") == 0))) {
2837c478bd9Sstevel@tonic-gate dbug_print(("info", "started by inetd"));
2847c478bd9Sstevel@tonic-gate
2857c478bd9Sstevel@tonic-gate if (freopen("/dev/null", "w", stderr) == NULL)
2867c478bd9Sstevel@tonic-gate return (1);
2877c478bd9Sstevel@tonic-gate
2887c478bd9Sstevel@tonic-gate /* started from inetd */
2897c478bd9Sstevel@tonic-gate if ((netid = getenv("NLSPROVIDER")) == NULL)
2907c478bd9Sstevel@tonic-gate netid = "ticotsord";
2917c478bd9Sstevel@tonic-gate if ((nconf = getnetconfigent(netid)) == NULL)
2927c478bd9Sstevel@tonic-gate msgout(gettext("cannot get transport info"));
2937c478bd9Sstevel@tonic-gate
2947c478bd9Sstevel@tonic-gate if (strcmp(mname, "sockmod") == 0) {
2957c478bd9Sstevel@tonic-gate if (ioctl(0, I_POP, 0) || ioctl(0, I_PUSH, "timod")) {
2967c478bd9Sstevel@tonic-gate msgout(
2977c478bd9Sstevel@tonic-gate gettext("could not get the right module"));
2987c478bd9Sstevel@tonic-gate dbug_leave("main");
2997c478bd9Sstevel@tonic-gate return (1);
3007c478bd9Sstevel@tonic-gate }
3017c478bd9Sstevel@tonic-gate }
3027c478bd9Sstevel@tonic-gate if ((transp = svc_tli_create(0, nconf, NULL, 0, 0)) == NULL) {
3037c478bd9Sstevel@tonic-gate msgout(gettext("cannot create server handle"));
3047c478bd9Sstevel@tonic-gate dbug_leave("main");
3057c478bd9Sstevel@tonic-gate return (1);
3067c478bd9Sstevel@tonic-gate }
3077c478bd9Sstevel@tonic-gate if (nconf)
3087c478bd9Sstevel@tonic-gate freenetconfigent(nconf);
3097c478bd9Sstevel@tonic-gate xx = svc_reg(transp, CACHEFSDPROG, CACHEFSDVERS,
3107c478bd9Sstevel@tonic-gate cachefsdprog_1, 0);
3117c478bd9Sstevel@tonic-gate if (!xx) {
3127c478bd9Sstevel@tonic-gate msgout(gettext(
3137c478bd9Sstevel@tonic-gate "unable to reg (CACHEFSDPROG, CACHEFSDVERS)."));
3147c478bd9Sstevel@tonic-gate dbug_leave("main");
3157c478bd9Sstevel@tonic-gate return (1);
3167c478bd9Sstevel@tonic-gate }
3177c478bd9Sstevel@tonic-gate }
3187c478bd9Sstevel@tonic-gate
3197c478bd9Sstevel@tonic-gate /* else if started by hand */
3207c478bd9Sstevel@tonic-gate else {
3217c478bd9Sstevel@tonic-gate /* if we should fork */
3227c478bd9Sstevel@tonic-gate if (opt_fork) {
3237c478bd9Sstevel@tonic-gate dbug_print(("info", "forking"));
3247c478bd9Sstevel@tonic-gate pid = fork();
3257c478bd9Sstevel@tonic-gate if (pid < 0) {
3267c478bd9Sstevel@tonic-gate perror(gettext("cannot fork"));
3277c478bd9Sstevel@tonic-gate dbug_leave("main");
3287c478bd9Sstevel@tonic-gate return (1);
3297c478bd9Sstevel@tonic-gate }
3307c478bd9Sstevel@tonic-gate if (pid) {
3317c478bd9Sstevel@tonic-gate dbug_leave("main");
3327c478bd9Sstevel@tonic-gate return (0);
3337c478bd9Sstevel@tonic-gate }
3347c478bd9Sstevel@tonic-gate (void) fdwalk(void_close, &ofd);
3357c478bd9Sstevel@tonic-gate xx = open("/dev/sysmsg", 2);
3367c478bd9Sstevel@tonic-gate (void) dup2(xx, 1);
3377c478bd9Sstevel@tonic-gate (void) dup2(xx, 2);
3387c478bd9Sstevel@tonic-gate setsid();
3397c478bd9Sstevel@tonic-gate }
3407c478bd9Sstevel@tonic-gate
3417c478bd9Sstevel@tonic-gate /* connect to *ANY* local loopback transport provider */
3427c478bd9Sstevel@tonic-gate xx = svc_create(cachefsdprog_1, CACHEFSDPROG, CACHEFSDVERS,
3437c478bd9Sstevel@tonic-gate "local");
3447c478bd9Sstevel@tonic-gate if (!xx) {
3457c478bd9Sstevel@tonic-gate msgout(gettext("unable to create (CACHEFSDPROG, "
3467c478bd9Sstevel@tonic-gate "CACHEFSDVERS) for netpath."));
3477c478bd9Sstevel@tonic-gate dbug_leave("main");
3487c478bd9Sstevel@tonic-gate return (1);
3497c478bd9Sstevel@tonic-gate }
3507c478bd9Sstevel@tonic-gate }
3517c478bd9Sstevel@tonic-gate
3527c478bd9Sstevel@tonic-gate /* find existing caches and mounted file systems */
3537c478bd9Sstevel@tonic-gate all_object_p = cfsd_all_create();
3547c478bd9Sstevel@tonic-gate subr_cache_setup(all_object_p);
3557c478bd9Sstevel@tonic-gate
3567c478bd9Sstevel@tonic-gate /* process requests */
3577c478bd9Sstevel@tonic-gate svc_run();
3587c478bd9Sstevel@tonic-gate
3597c478bd9Sstevel@tonic-gate msgout(gettext("svc_run returned"));
3607c478bd9Sstevel@tonic-gate cfsd_all_destroy(all_object_p);
3617c478bd9Sstevel@tonic-gate dbug_leave("main");
3627c478bd9Sstevel@tonic-gate return (1);
3637c478bd9Sstevel@tonic-gate }
3647c478bd9Sstevel@tonic-gate
3657c478bd9Sstevel@tonic-gate /*
3667c478bd9Sstevel@tonic-gate * Callback function for fdwalk() to close all files.
3677c478bd9Sstevel@tonic-gate */
3687c478bd9Sstevel@tonic-gate static int
void_close(void * ofdp,int fd)3697c478bd9Sstevel@tonic-gate void_close(void *ofdp, int fd)
3707c478bd9Sstevel@tonic-gate {
3717c478bd9Sstevel@tonic-gate if (fd != *(int *)ofdp) {
3727c478bd9Sstevel@tonic-gate if (close(fd) != 0)
3737c478bd9Sstevel@tonic-gate dbug_print(("err",
3747c478bd9Sstevel@tonic-gate "cannot close fd %d, %d", fd, errno));
3757c478bd9Sstevel@tonic-gate }
3767c478bd9Sstevel@tonic-gate return (0);
3777c478bd9Sstevel@tonic-gate }
3787c478bd9Sstevel@tonic-gate
3797c478bd9Sstevel@tonic-gate /*
3807c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------
3817c478bd9Sstevel@tonic-gate * msgout
3827c478bd9Sstevel@tonic-gate *
3837c478bd9Sstevel@tonic-gate * Description:
3847c478bd9Sstevel@tonic-gate * Outputs an error message to stderr.
3857c478bd9Sstevel@tonic-gate * Arguments:
3867c478bd9Sstevel@tonic-gate * msgp
3877c478bd9Sstevel@tonic-gate * Returns:
3887c478bd9Sstevel@tonic-gate * Preconditions:
3897c478bd9Sstevel@tonic-gate * precond(msgp)
3907c478bd9Sstevel@tonic-gate */
3917c478bd9Sstevel@tonic-gate
3927c478bd9Sstevel@tonic-gate void
msgout(char * msgp)3937c478bd9Sstevel@tonic-gate msgout(char *msgp)
3947c478bd9Sstevel@tonic-gate {
3957c478bd9Sstevel@tonic-gate dbug_enter("msgout");
3967c478bd9Sstevel@tonic-gate dbug_precond(msgp);
3977c478bd9Sstevel@tonic-gate
3987c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s\n", msgp);
3997c478bd9Sstevel@tonic-gate dbug_leave("msgout");
4007c478bd9Sstevel@tonic-gate }
4017c478bd9Sstevel@tonic-gate
4027c478bd9Sstevel@tonic-gate
4037c478bd9Sstevel@tonic-gate /*
4047c478bd9Sstevel@tonic-gate * -----------------------------------------------------------------
4057c478bd9Sstevel@tonic-gate * cachefsdprog_1
4067c478bd9Sstevel@tonic-gate *
4077c478bd9Sstevel@tonic-gate * Description:
4087c478bd9Sstevel@tonic-gate * Arguments:
4097c478bd9Sstevel@tonic-gate * rqstp
4107c478bd9Sstevel@tonic-gate * transp
4117c478bd9Sstevel@tonic-gate * Returns:
4127c478bd9Sstevel@tonic-gate * Preconditions:
4137c478bd9Sstevel@tonic-gate * precond(rqstp)
4147c478bd9Sstevel@tonic-gate * precond(transp)
4157c478bd9Sstevel@tonic-gate */
4167c478bd9Sstevel@tonic-gate void
cachefsdprog_1(struct svc_req * rqstp,register SVCXPRT * transp)4177c478bd9Sstevel@tonic-gate cachefsdprog_1(struct svc_req *rqstp, register SVCXPRT *transp)
4187c478bd9Sstevel@tonic-gate {
4197c478bd9Sstevel@tonic-gate int index;
4207c478bd9Sstevel@tonic-gate struct rpcgen_table *rtp;
4217c478bd9Sstevel@tonic-gate void *argumentp = NULL;
4227c478bd9Sstevel@tonic-gate void *resultp = NULL;
4237c478bd9Sstevel@tonic-gate LOCAL local;
4247c478bd9Sstevel@tonic-gate int xx;
4257c478bd9Sstevel@tonic-gate
4267c478bd9Sstevel@tonic-gate dbug_enter("cachefsdprog_1");
4277c478bd9Sstevel@tonic-gate
4287c478bd9Sstevel@tonic-gate dbug_precond(rqstp);
4297c478bd9Sstevel@tonic-gate dbug_precond(transp);
4307c478bd9Sstevel@tonic-gate
4317c478bd9Sstevel@tonic-gate /* make sure a valid command number */
4327c478bd9Sstevel@tonic-gate index = rqstp->rq_proc;
4337c478bd9Sstevel@tonic-gate if ((index < 0) || (cachefsdprog_1_nproc <= index)) {
4347c478bd9Sstevel@tonic-gate msgout(gettext("bad message"));
4357c478bd9Sstevel@tonic-gate svcerr_noproc(transp);
4367c478bd9Sstevel@tonic-gate dbug_leave("cachefsdprog_1");
4377c478bd9Sstevel@tonic-gate return;
4387c478bd9Sstevel@tonic-gate }
4397c478bd9Sstevel@tonic-gate
4407c478bd9Sstevel@tonic-gate /* get command information */
4417c478bd9Sstevel@tonic-gate rtp = &cachefsdprog_1_table[index];
4427c478bd9Sstevel@tonic-gate
4437c478bd9Sstevel@tonic-gate /* get memory for the arguments */
4447c478bd9Sstevel@tonic-gate if (rtp->len_arg != 0)
4457c478bd9Sstevel@tonic-gate argumentp = (void *)cfsd_calloc(rtp->len_arg);
4467c478bd9Sstevel@tonic-gate
4477c478bd9Sstevel@tonic-gate /* get memory for the results */
4487c478bd9Sstevel@tonic-gate if (rtp->len_res != 0)
4497c478bd9Sstevel@tonic-gate resultp = (void *)cfsd_calloc(rtp->len_res);
4507c478bd9Sstevel@tonic-gate
4517c478bd9Sstevel@tonic-gate /* get the arguments */
4527c478bd9Sstevel@tonic-gate if (rtp->xdr_arg && argumentp) {
4537c478bd9Sstevel@tonic-gate if (!svc_getargs(transp, rtp->xdr_arg, (caddr_t)argumentp)) {
4547c478bd9Sstevel@tonic-gate svcerr_decode(transp);
4557c478bd9Sstevel@tonic-gate cfsd_free(argumentp);
4567c478bd9Sstevel@tonic-gate cfsd_free(resultp);
4577c478bd9Sstevel@tonic-gate dbug_leave("cachefsdprog_1");
4587c478bd9Sstevel@tonic-gate return;
4597c478bd9Sstevel@tonic-gate }
4607c478bd9Sstevel@tonic-gate }
4617c478bd9Sstevel@tonic-gate
4627c478bd9Sstevel@tonic-gate /* call the routine to process the command */
4637c478bd9Sstevel@tonic-gate local = (LOCAL)rtp->proc;
4647c478bd9Sstevel@tonic-gate xx = (*local)(argumentp, resultp, rqstp);
4657c478bd9Sstevel@tonic-gate
4667c478bd9Sstevel@tonic-gate /* if the command could not be processed */
4677c478bd9Sstevel@tonic-gate if (xx == 0) {
4687c478bd9Sstevel@tonic-gate svcerr_systemerr(transp);
4697c478bd9Sstevel@tonic-gate }
4707c478bd9Sstevel@tonic-gate
4717c478bd9Sstevel@tonic-gate /* else send the results back to the caller */
4727c478bd9Sstevel@tonic-gate else {
4737c478bd9Sstevel@tonic-gate xx = svc_sendreply(transp, rtp->xdr_res, (caddr_t)resultp);
4747c478bd9Sstevel@tonic-gate if (!xx)
4757c478bd9Sstevel@tonic-gate svcerr_systemerr(transp);
4767c478bd9Sstevel@tonic-gate
4777c478bd9Sstevel@tonic-gate /* free the results */
4787c478bd9Sstevel@tonic-gate xx = cachefsdprog_1_freeresult(transp, rtp->xdr_res,
4797c478bd9Sstevel@tonic-gate (caddr_t)resultp);
4807c478bd9Sstevel@tonic-gate if (xx == 0)
4817c478bd9Sstevel@tonic-gate msgout(gettext("unable to free results"));
4827c478bd9Sstevel@tonic-gate }
4837c478bd9Sstevel@tonic-gate
4847c478bd9Sstevel@tonic-gate /* free the passed in arguments */
4857c478bd9Sstevel@tonic-gate if (!svc_freeargs(transp, rtp->xdr_arg, (caddr_t)argumentp)) {
4867c478bd9Sstevel@tonic-gate msgout(gettext("unable to free arguments"));
4877c478bd9Sstevel@tonic-gate abort();
4887c478bd9Sstevel@tonic-gate }
4897c478bd9Sstevel@tonic-gate
4907c478bd9Sstevel@tonic-gate if (argumentp)
4917c478bd9Sstevel@tonic-gate cfsd_free(argumentp);
4927c478bd9Sstevel@tonic-gate if (resultp)
4937c478bd9Sstevel@tonic-gate cfsd_free(resultp);
4947c478bd9Sstevel@tonic-gate dbug_leave("cachefsdprog_1");
4957c478bd9Sstevel@tonic-gate }
4967c478bd9Sstevel@tonic-gate
4977c478bd9Sstevel@tonic-gate /*
4987c478bd9Sstevel@tonic-gate * sigusr1_handler
4997c478bd9Sstevel@tonic-gate *
5007c478bd9Sstevel@tonic-gate * Description:
5017c478bd9Sstevel@tonic-gate * Catches sigusr1 signal so threads wake up.
5027c478bd9Sstevel@tonic-gate * Arguments:
5037c478bd9Sstevel@tonic-gate * Returns:
5047c478bd9Sstevel@tonic-gate * Preconditions:
5057c478bd9Sstevel@tonic-gate */
5067c478bd9Sstevel@tonic-gate void
sigusr1_handler(int sig,siginfo_t * sp,void * vp)5077c478bd9Sstevel@tonic-gate sigusr1_handler(int sig, siginfo_t *sp, void *vp)
5087c478bd9Sstevel@tonic-gate {
5097c478bd9Sstevel@tonic-gate }
510