1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 1998-2000, 2002 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate /* 30*0Sstevel@tonic-gate * Main routines for cachefs daemon. 31*0Sstevel@tonic-gate */ 32*0Sstevel@tonic-gate 33*0Sstevel@tonic-gate #include <stdio.h> 34*0Sstevel@tonic-gate #include <stdlib.h> 35*0Sstevel@tonic-gate #include <string.h> 36*0Sstevel@tonic-gate #include <errno.h> 37*0Sstevel@tonic-gate #include <rpc/rpc.h> 38*0Sstevel@tonic-gate #include <rpc/pmap_clnt.h> /* for pmap_unset */ 39*0Sstevel@tonic-gate #include <string.h> /* strcmp */ 40*0Sstevel@tonic-gate #include <signal.h> 41*0Sstevel@tonic-gate #include <unistd.h> /* setsid */ 42*0Sstevel@tonic-gate #include <sys/types.h> 43*0Sstevel@tonic-gate #include <memory.h> 44*0Sstevel@tonic-gate #include <stropts.h> 45*0Sstevel@tonic-gate #include <netconfig.h> 46*0Sstevel@tonic-gate #include <libintl.h> 47*0Sstevel@tonic-gate #include <locale.h> 48*0Sstevel@tonic-gate #include <thread.h> 49*0Sstevel@tonic-gate #include <sys/resource.h> /* rlimit */ 50*0Sstevel@tonic-gate #include <synch.h> 51*0Sstevel@tonic-gate #include <mdbug/mdbug.h> 52*0Sstevel@tonic-gate #include <common/cachefsd.h> 53*0Sstevel@tonic-gate #include <sys/fs/cachefs_fs.h> 54*0Sstevel@tonic-gate #include <sys/fs/cachefs_dlog.h> 55*0Sstevel@tonic-gate #include <sys/fs/cachefs_ioctl.h> 56*0Sstevel@tonic-gate #include "cfsd.h" 57*0Sstevel@tonic-gate #include "cfsd_kmod.h" 58*0Sstevel@tonic-gate #include "cfsd_maptbl.h" 59*0Sstevel@tonic-gate #include "cfsd_logfile.h" 60*0Sstevel@tonic-gate #include "cfsd_fscache.h" 61*0Sstevel@tonic-gate #include "cfsd_cache.h" 62*0Sstevel@tonic-gate #include "cfsd_all.h" 63*0Sstevel@tonic-gate #include "cfsd_subr.h" 64*0Sstevel@tonic-gate 65*0Sstevel@tonic-gate #define RPCGEN_ACTION(X) X 66*0Sstevel@tonic-gate #include "cachefsd_tbl.i" 67*0Sstevel@tonic-gate 68*0Sstevel@tonic-gate #ifndef SIG_PF 69*0Sstevel@tonic-gate #define SIG_PF void(*)(int) 70*0Sstevel@tonic-gate #endif 71*0Sstevel@tonic-gate 72*0Sstevel@tonic-gate typedef bool_t (* LOCAL)(void *, void *, struct svc_req *); 73*0Sstevel@tonic-gate 74*0Sstevel@tonic-gate /* global definitions */ 75*0Sstevel@tonic-gate cfsd_all_object_t *all_object_p = NULL; 76*0Sstevel@tonic-gate 77*0Sstevel@tonic-gate /* forward references */ 78*0Sstevel@tonic-gate void msgout(char *msgp); 79*0Sstevel@tonic-gate void cachefsdprog_1(struct svc_req *rqstp, register SVCXPRT *transp); 80*0Sstevel@tonic-gate void sigusr1_handler(int, siginfo_t *, void *); 81*0Sstevel@tonic-gate static int void_close(void *, int); 82*0Sstevel@tonic-gate 83*0Sstevel@tonic-gate /* 84*0Sstevel@tonic-gate * ----------------------------------------------------------------- 85*0Sstevel@tonic-gate * main 86*0Sstevel@tonic-gate * 87*0Sstevel@tonic-gate * Description: 88*0Sstevel@tonic-gate * main routine for the chart daemon. 89*0Sstevel@tonic-gate * Arguments: 90*0Sstevel@tonic-gate * argc 91*0Sstevel@tonic-gate * argv 92*0Sstevel@tonic-gate * Returns: 93*0Sstevel@tonic-gate * Returns 0 for a normal exit, !0 if an error occurred. 94*0Sstevel@tonic-gate * Preconditions: 95*0Sstevel@tonic-gate * precond(argv) 96*0Sstevel@tonic-gate */ 97*0Sstevel@tonic-gate 98*0Sstevel@tonic-gate int 99*0Sstevel@tonic-gate main(int argc, char **argv) 100*0Sstevel@tonic-gate { 101*0Sstevel@tonic-gate pid_t pid; 102*0Sstevel@tonic-gate int xx; 103*0Sstevel@tonic-gate char mname[FMNAMESZ + 1]; 104*0Sstevel@tonic-gate int opt_fork = 0; 105*0Sstevel@tonic-gate int opt_mt = 0; 106*0Sstevel@tonic-gate char *opt_root = NULL; 107*0Sstevel@tonic-gate int c; 108*0Sstevel@tonic-gate char *msgp; 109*0Sstevel@tonic-gate int size; 110*0Sstevel@tonic-gate struct rlimit rl; 111*0Sstevel@tonic-gate struct sigaction nact; 112*0Sstevel@tonic-gate int ofd = -1; 113*0Sstevel@tonic-gate char *netid; 114*0Sstevel@tonic-gate struct netconfig *nconf = NULL; 115*0Sstevel@tonic-gate SVCXPRT *transp; 116*0Sstevel@tonic-gate cfsd_fscache_object_t *fscache_object_p; 117*0Sstevel@tonic-gate int mode; 118*0Sstevel@tonic-gate /* selectable maximum RPC request record size */ 119*0Sstevel@tonic-gate int maxrecsz = RPC_MAXDATASIZE; 120*0Sstevel@tonic-gate 121*0Sstevel@tonic-gate dbug_enter("main"); 122*0Sstevel@tonic-gate dbug_process("cfsadmin"); 123*0Sstevel@tonic-gate 124*0Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 125*0Sstevel@tonic-gate #if !defined(TEXT_DOMAIN) 126*0Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST" 127*0Sstevel@tonic-gate #endif 128*0Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN); 129*0Sstevel@tonic-gate 130*0Sstevel@tonic-gate /* verify root */ 131*0Sstevel@tonic-gate if (getuid() != 0) { 132*0Sstevel@tonic-gate fprintf(stderr, gettext("%s: must be run by root\n"), argv[0]); 133*0Sstevel@tonic-gate dbug_leave("main"); 134*0Sstevel@tonic-gate return (1); 135*0Sstevel@tonic-gate } 136*0Sstevel@tonic-gate 137*0Sstevel@tonic-gate /* Increase number of file descriptors to maximum allowable */ 138*0Sstevel@tonic-gate xx = getrlimit(RLIMIT_NOFILE, &rl); 139*0Sstevel@tonic-gate if (xx < 0) { 140*0Sstevel@tonic-gate dbug_print(("error", 141*0Sstevel@tonic-gate "getrlimit/RLIMIT_NOFILE failed %d", errno)); 142*0Sstevel@tonic-gate dbug_leave("main"); 143*0Sstevel@tonic-gate return (1); 144*0Sstevel@tonic-gate } 145*0Sstevel@tonic-gate rl.rlim_cur = rl.rlim_max; 146*0Sstevel@tonic-gate xx = setrlimit(RLIMIT_NOFILE, &rl); 147*0Sstevel@tonic-gate if (xx < 0) { 148*0Sstevel@tonic-gate dbug_print(("error", 149*0Sstevel@tonic-gate "setrlimit/RLIMIT_NOFILE failed %d", errno)); 150*0Sstevel@tonic-gate dbug_leave("main"); 151*0Sstevel@tonic-gate return (1); 152*0Sstevel@tonic-gate } 153*0Sstevel@tonic-gate 154*0Sstevel@tonic-gate while ((c = getopt(argc, argv, "fmr:#:")) != EOF) { 155*0Sstevel@tonic-gate switch (c) { 156*0Sstevel@tonic-gate case 'f': 157*0Sstevel@tonic-gate opt_fork = 1; 158*0Sstevel@tonic-gate break; 159*0Sstevel@tonic-gate 160*0Sstevel@tonic-gate case 'm': 161*0Sstevel@tonic-gate /* 162*0Sstevel@tonic-gate * XXX don't use this until race between mount 163*0Sstevel@tonic-gate * and umount is fixed. 164*0Sstevel@tonic-gate */ 165*0Sstevel@tonic-gate opt_mt = 1; 166*0Sstevel@tonic-gate break; 167*0Sstevel@tonic-gate 168*0Sstevel@tonic-gate case 'r': 169*0Sstevel@tonic-gate opt_root = optarg; 170*0Sstevel@tonic-gate break; 171*0Sstevel@tonic-gate 172*0Sstevel@tonic-gate case '#': /* dbug args */ 173*0Sstevel@tonic-gate msgp = dbug_push(optarg); 174*0Sstevel@tonic-gate if (msgp) { 175*0Sstevel@tonic-gate printf("dbug_push failed \"%s\"\n", msgp); 176*0Sstevel@tonic-gate dbug_leave("main"); 177*0Sstevel@tonic-gate return (1); 178*0Sstevel@tonic-gate } 179*0Sstevel@tonic-gate ofd = db_getfd(); 180*0Sstevel@tonic-gate break; 181*0Sstevel@tonic-gate 182*0Sstevel@tonic-gate default: 183*0Sstevel@tonic-gate printf(gettext("illegal switch\n")); 184*0Sstevel@tonic-gate dbug_leave("main"); 185*0Sstevel@tonic-gate return (1); 186*0Sstevel@tonic-gate } 187*0Sstevel@tonic-gate } 188*0Sstevel@tonic-gate 189*0Sstevel@tonic-gate /* XXX need some way to prevent multiple daemons from running */ 190*0Sstevel@tonic-gate 191*0Sstevel@tonic-gate dbug_print(("info", "cachefsd started...")); 192*0Sstevel@tonic-gate 193*0Sstevel@tonic-gate if (opt_mt) { 194*0Sstevel@tonic-gate dbug_print(("info", "MT_AUTO mode set")); 195*0Sstevel@tonic-gate mode = RPC_SVC_MT_AUTO; 196*0Sstevel@tonic-gate if (!rpc_control(RPC_SVC_MTMODE_SET, &mode)) { 197*0Sstevel@tonic-gate msgout(gettext("unable to set automatic MT mode.")); 198*0Sstevel@tonic-gate dbug_leave("main"); 199*0Sstevel@tonic-gate return (1); 200*0Sstevel@tonic-gate } 201*0Sstevel@tonic-gate } 202*0Sstevel@tonic-gate 203*0Sstevel@tonic-gate /* 204*0Sstevel@tonic-gate * Enable non-blocking mode and maximum record size checks for 205*0Sstevel@tonic-gate * connection oriented transports. 206*0Sstevel@tonic-gate */ 207*0Sstevel@tonic-gate if (!rpc_control(RPC_SVC_CONNMAXREC_SET, &maxrecsz)) { 208*0Sstevel@tonic-gate msgout(gettext("unable to set max RPC record size")); 209*0Sstevel@tonic-gate } 210*0Sstevel@tonic-gate 211*0Sstevel@tonic-gate /* ignore sigpipe */ 212*0Sstevel@tonic-gate nact.sa_handler = SIG_IGN; 213*0Sstevel@tonic-gate nact.sa_sigaction = NULL; 214*0Sstevel@tonic-gate sigemptyset(&nact.sa_mask); 215*0Sstevel@tonic-gate nact.sa_flags = 0; 216*0Sstevel@tonic-gate xx = sigaction(SIGPIPE, &nact, NULL); 217*0Sstevel@tonic-gate if (xx) { 218*0Sstevel@tonic-gate dbug_print(("error", "sigaction/SIGPIPE failed %d", errno)); 219*0Sstevel@tonic-gate } 220*0Sstevel@tonic-gate 221*0Sstevel@tonic-gate /* catch sigusr1 signals, used to wake up threads */ 222*0Sstevel@tonic-gate nact.sa_handler = NULL; 223*0Sstevel@tonic-gate nact.sa_sigaction = sigusr1_handler; 224*0Sstevel@tonic-gate sigemptyset(&nact.sa_mask); 225*0Sstevel@tonic-gate nact.sa_flags = SA_SIGINFO; 226*0Sstevel@tonic-gate xx = sigaction(SIGUSR1, &nact, NULL); 227*0Sstevel@tonic-gate if (xx) { 228*0Sstevel@tonic-gate dbug_print(("error", "sigaction failed %d", errno)); 229*0Sstevel@tonic-gate } 230*0Sstevel@tonic-gate 231*0Sstevel@tonic-gate /* do not set up rpc services if just taking care of root */ 232*0Sstevel@tonic-gate if (opt_root) { 233*0Sstevel@tonic-gate dbug_print(("info", "handling just root")); 234*0Sstevel@tonic-gate 235*0Sstevel@tonic-gate /* make the fscache object */ 236*0Sstevel@tonic-gate fscache_object_p = 237*0Sstevel@tonic-gate cfsd_fscache_create("rootcache", opt_root, 1); 238*0Sstevel@tonic-gate 239*0Sstevel@tonic-gate /* init the fscache object with mount information */ 240*0Sstevel@tonic-gate fscache_lock(fscache_object_p); 241*0Sstevel@tonic-gate fscache_object_p->i_refcnt++; 242*0Sstevel@tonic-gate fscache_setup(fscache_object_p); 243*0Sstevel@tonic-gate fscache_object_p->i_mounted = 1; 244*0Sstevel@tonic-gate fscache_unlock(fscache_object_p); 245*0Sstevel@tonic-gate 246*0Sstevel@tonic-gate if (fscache_object_p->i_disconnectable && 247*0Sstevel@tonic-gate fscache_object_p->i_mounted) { 248*0Sstevel@tonic-gate pid = fork(); 249*0Sstevel@tonic-gate if (pid < 0) { 250*0Sstevel@tonic-gate perror(gettext("cannot fork")); 251*0Sstevel@tonic-gate cfsd_fscache_destroy(fscache_object_p); 252*0Sstevel@tonic-gate dbug_leave("main"); 253*0Sstevel@tonic-gate return (1); 254*0Sstevel@tonic-gate } 255*0Sstevel@tonic-gate if (pid) { 256*0Sstevel@tonic-gate cfsd_fscache_destroy(fscache_object_p); 257*0Sstevel@tonic-gate dbug_leave("main"); 258*0Sstevel@tonic-gate return (0); 259*0Sstevel@tonic-gate } 260*0Sstevel@tonic-gate (void) fdwalk(void_close, &ofd); 261*0Sstevel@tonic-gate xx = open("/dev/sysmsg", O_RDWR); 262*0Sstevel@tonic-gate (void) dup2(xx, 1); 263*0Sstevel@tonic-gate (void) dup2(xx, 2); 264*0Sstevel@tonic-gate setsid(); 265*0Sstevel@tonic-gate 266*0Sstevel@tonic-gate fscache_process(fscache_object_p); 267*0Sstevel@tonic-gate } else { 268*0Sstevel@tonic-gate /* not disconnectable */ 269*0Sstevel@tonic-gate cfsd_fscache_destroy(fscache_object_p); 270*0Sstevel@tonic-gate dbug_leave("main"); 271*0Sstevel@tonic-gate return (1); 272*0Sstevel@tonic-gate } 273*0Sstevel@tonic-gate cfsd_fscache_destroy(fscache_object_p); 274*0Sstevel@tonic-gate dbug_leave("main"); 275*0Sstevel@tonic-gate return (0); 276*0Sstevel@tonic-gate } 277*0Sstevel@tonic-gate 278*0Sstevel@tonic-gate /* if a inetd started us */ 279*0Sstevel@tonic-gate else if (!ioctl(0, I_LOOK, mname) && 280*0Sstevel@tonic-gate ((strcmp(mname, "sockmod") == 0) || 281*0Sstevel@tonic-gate (strcmp(mname, "timod") == 0))) { 282*0Sstevel@tonic-gate dbug_print(("info", "started by inetd")); 283*0Sstevel@tonic-gate 284*0Sstevel@tonic-gate if (freopen("/dev/null", "w", stderr) == NULL) 285*0Sstevel@tonic-gate return (1); 286*0Sstevel@tonic-gate 287*0Sstevel@tonic-gate /* started from inetd */ 288*0Sstevel@tonic-gate if ((netid = getenv("NLSPROVIDER")) == NULL) 289*0Sstevel@tonic-gate netid = "ticotsord"; 290*0Sstevel@tonic-gate if ((nconf = getnetconfigent(netid)) == NULL) 291*0Sstevel@tonic-gate msgout(gettext("cannot get transport info")); 292*0Sstevel@tonic-gate 293*0Sstevel@tonic-gate if (strcmp(mname, "sockmod") == 0) { 294*0Sstevel@tonic-gate if (ioctl(0, I_POP, 0) || ioctl(0, I_PUSH, "timod")) { 295*0Sstevel@tonic-gate msgout( 296*0Sstevel@tonic-gate gettext("could not get the right module")); 297*0Sstevel@tonic-gate dbug_leave("main"); 298*0Sstevel@tonic-gate return (1); 299*0Sstevel@tonic-gate } 300*0Sstevel@tonic-gate } 301*0Sstevel@tonic-gate if ((transp = svc_tli_create(0, nconf, NULL, 0, 0)) == NULL) { 302*0Sstevel@tonic-gate msgout(gettext("cannot create server handle")); 303*0Sstevel@tonic-gate dbug_leave("main"); 304*0Sstevel@tonic-gate return (1); 305*0Sstevel@tonic-gate } 306*0Sstevel@tonic-gate if (nconf) 307*0Sstevel@tonic-gate freenetconfigent(nconf); 308*0Sstevel@tonic-gate xx = svc_reg(transp, CACHEFSDPROG, CACHEFSDVERS, 309*0Sstevel@tonic-gate cachefsdprog_1, 0); 310*0Sstevel@tonic-gate if (!xx) { 311*0Sstevel@tonic-gate msgout(gettext( 312*0Sstevel@tonic-gate "unable to reg (CACHEFSDPROG, CACHEFSDVERS).")); 313*0Sstevel@tonic-gate dbug_leave("main"); 314*0Sstevel@tonic-gate return (1); 315*0Sstevel@tonic-gate } 316*0Sstevel@tonic-gate } 317*0Sstevel@tonic-gate 318*0Sstevel@tonic-gate /* else if started by hand */ 319*0Sstevel@tonic-gate else { 320*0Sstevel@tonic-gate /* if we should fork */ 321*0Sstevel@tonic-gate if (opt_fork) { 322*0Sstevel@tonic-gate dbug_print(("info", "forking")); 323*0Sstevel@tonic-gate pid = fork(); 324*0Sstevel@tonic-gate if (pid < 0) { 325*0Sstevel@tonic-gate perror(gettext("cannot fork")); 326*0Sstevel@tonic-gate dbug_leave("main"); 327*0Sstevel@tonic-gate return (1); 328*0Sstevel@tonic-gate } 329*0Sstevel@tonic-gate if (pid) { 330*0Sstevel@tonic-gate dbug_leave("main"); 331*0Sstevel@tonic-gate return (0); 332*0Sstevel@tonic-gate } 333*0Sstevel@tonic-gate (void) fdwalk(void_close, &ofd); 334*0Sstevel@tonic-gate xx = open("/dev/sysmsg", 2); 335*0Sstevel@tonic-gate (void) dup2(xx, 1); 336*0Sstevel@tonic-gate (void) dup2(xx, 2); 337*0Sstevel@tonic-gate setsid(); 338*0Sstevel@tonic-gate } 339*0Sstevel@tonic-gate 340*0Sstevel@tonic-gate /* connect to *ANY* local loopback transport provider */ 341*0Sstevel@tonic-gate xx = svc_create(cachefsdprog_1, CACHEFSDPROG, CACHEFSDVERS, 342*0Sstevel@tonic-gate "local"); 343*0Sstevel@tonic-gate if (!xx) { 344*0Sstevel@tonic-gate msgout(gettext("unable to create (CACHEFSDPROG, " 345*0Sstevel@tonic-gate "CACHEFSDVERS) for netpath.")); 346*0Sstevel@tonic-gate dbug_leave("main"); 347*0Sstevel@tonic-gate return (1); 348*0Sstevel@tonic-gate } 349*0Sstevel@tonic-gate } 350*0Sstevel@tonic-gate 351*0Sstevel@tonic-gate /* find existing caches and mounted file systems */ 352*0Sstevel@tonic-gate all_object_p = cfsd_all_create(); 353*0Sstevel@tonic-gate subr_cache_setup(all_object_p); 354*0Sstevel@tonic-gate 355*0Sstevel@tonic-gate /* process requests */ 356*0Sstevel@tonic-gate svc_run(); 357*0Sstevel@tonic-gate 358*0Sstevel@tonic-gate msgout(gettext("svc_run returned")); 359*0Sstevel@tonic-gate cfsd_all_destroy(all_object_p); 360*0Sstevel@tonic-gate dbug_leave("main"); 361*0Sstevel@tonic-gate return (1); 362*0Sstevel@tonic-gate } 363*0Sstevel@tonic-gate 364*0Sstevel@tonic-gate /* 365*0Sstevel@tonic-gate * Callback function for fdwalk() to close all files. 366*0Sstevel@tonic-gate */ 367*0Sstevel@tonic-gate static int 368*0Sstevel@tonic-gate void_close(void *ofdp, int fd) 369*0Sstevel@tonic-gate { 370*0Sstevel@tonic-gate if (fd != *(int *)ofdp) { 371*0Sstevel@tonic-gate if (close(fd) != 0) 372*0Sstevel@tonic-gate dbug_print(("err", 373*0Sstevel@tonic-gate "cannot close fd %d, %d", fd, errno)); 374*0Sstevel@tonic-gate } 375*0Sstevel@tonic-gate return (0); 376*0Sstevel@tonic-gate } 377*0Sstevel@tonic-gate 378*0Sstevel@tonic-gate /* 379*0Sstevel@tonic-gate * ----------------------------------------------------------------- 380*0Sstevel@tonic-gate * msgout 381*0Sstevel@tonic-gate * 382*0Sstevel@tonic-gate * Description: 383*0Sstevel@tonic-gate * Outputs an error message to stderr. 384*0Sstevel@tonic-gate * Arguments: 385*0Sstevel@tonic-gate * msgp 386*0Sstevel@tonic-gate * Returns: 387*0Sstevel@tonic-gate * Preconditions: 388*0Sstevel@tonic-gate * precond(msgp) 389*0Sstevel@tonic-gate */ 390*0Sstevel@tonic-gate 391*0Sstevel@tonic-gate void 392*0Sstevel@tonic-gate msgout(char *msgp) 393*0Sstevel@tonic-gate { 394*0Sstevel@tonic-gate dbug_enter("msgout"); 395*0Sstevel@tonic-gate dbug_precond(msgp); 396*0Sstevel@tonic-gate 397*0Sstevel@tonic-gate (void) fprintf(stderr, "%s\n", msgp); 398*0Sstevel@tonic-gate dbug_leave("msgout"); 399*0Sstevel@tonic-gate } 400*0Sstevel@tonic-gate 401*0Sstevel@tonic-gate 402*0Sstevel@tonic-gate /* 403*0Sstevel@tonic-gate * ----------------------------------------------------------------- 404*0Sstevel@tonic-gate * cachefsdprog_1 405*0Sstevel@tonic-gate * 406*0Sstevel@tonic-gate * Description: 407*0Sstevel@tonic-gate * Arguments: 408*0Sstevel@tonic-gate * rqstp 409*0Sstevel@tonic-gate * transp 410*0Sstevel@tonic-gate * Returns: 411*0Sstevel@tonic-gate * Preconditions: 412*0Sstevel@tonic-gate * precond(rqstp) 413*0Sstevel@tonic-gate * precond(transp) 414*0Sstevel@tonic-gate */ 415*0Sstevel@tonic-gate void 416*0Sstevel@tonic-gate cachefsdprog_1(struct svc_req *rqstp, register SVCXPRT *transp) 417*0Sstevel@tonic-gate { 418*0Sstevel@tonic-gate int index; 419*0Sstevel@tonic-gate struct rpcgen_table *rtp; 420*0Sstevel@tonic-gate void *argumentp = NULL; 421*0Sstevel@tonic-gate void *resultp = NULL; 422*0Sstevel@tonic-gate LOCAL local; 423*0Sstevel@tonic-gate int xx; 424*0Sstevel@tonic-gate 425*0Sstevel@tonic-gate dbug_enter("cachefsdprog_1"); 426*0Sstevel@tonic-gate 427*0Sstevel@tonic-gate dbug_precond(rqstp); 428*0Sstevel@tonic-gate dbug_precond(transp); 429*0Sstevel@tonic-gate 430*0Sstevel@tonic-gate /* make sure a valid command number */ 431*0Sstevel@tonic-gate index = rqstp->rq_proc; 432*0Sstevel@tonic-gate if ((index < 0) || (cachefsdprog_1_nproc <= index)) { 433*0Sstevel@tonic-gate msgout(gettext("bad message")); 434*0Sstevel@tonic-gate svcerr_noproc(transp); 435*0Sstevel@tonic-gate dbug_leave("cachefsdprog_1"); 436*0Sstevel@tonic-gate return; 437*0Sstevel@tonic-gate } 438*0Sstevel@tonic-gate 439*0Sstevel@tonic-gate /* get command information */ 440*0Sstevel@tonic-gate rtp = &cachefsdprog_1_table[index]; 441*0Sstevel@tonic-gate 442*0Sstevel@tonic-gate /* get memory for the arguments */ 443*0Sstevel@tonic-gate if (rtp->len_arg != 0) 444*0Sstevel@tonic-gate argumentp = (void *)cfsd_calloc(rtp->len_arg); 445*0Sstevel@tonic-gate 446*0Sstevel@tonic-gate /* get memory for the results */ 447*0Sstevel@tonic-gate if (rtp->len_res != 0) 448*0Sstevel@tonic-gate resultp = (void *)cfsd_calloc(rtp->len_res); 449*0Sstevel@tonic-gate 450*0Sstevel@tonic-gate /* get the arguments */ 451*0Sstevel@tonic-gate if (rtp->xdr_arg && argumentp) { 452*0Sstevel@tonic-gate if (!svc_getargs(transp, rtp->xdr_arg, (caddr_t)argumentp)) { 453*0Sstevel@tonic-gate svcerr_decode(transp); 454*0Sstevel@tonic-gate cfsd_free(argumentp); 455*0Sstevel@tonic-gate cfsd_free(resultp); 456*0Sstevel@tonic-gate dbug_leave("cachefsdprog_1"); 457*0Sstevel@tonic-gate return; 458*0Sstevel@tonic-gate } 459*0Sstevel@tonic-gate } 460*0Sstevel@tonic-gate 461*0Sstevel@tonic-gate /* call the routine to process the command */ 462*0Sstevel@tonic-gate local = (LOCAL)rtp->proc; 463*0Sstevel@tonic-gate xx = (*local)(argumentp, resultp, rqstp); 464*0Sstevel@tonic-gate 465*0Sstevel@tonic-gate /* if the command could not be processed */ 466*0Sstevel@tonic-gate if (xx == 0) { 467*0Sstevel@tonic-gate svcerr_systemerr(transp); 468*0Sstevel@tonic-gate } 469*0Sstevel@tonic-gate 470*0Sstevel@tonic-gate /* else send the results back to the caller */ 471*0Sstevel@tonic-gate else { 472*0Sstevel@tonic-gate xx = svc_sendreply(transp, rtp->xdr_res, (caddr_t)resultp); 473*0Sstevel@tonic-gate if (!xx) 474*0Sstevel@tonic-gate svcerr_systemerr(transp); 475*0Sstevel@tonic-gate 476*0Sstevel@tonic-gate /* free the results */ 477*0Sstevel@tonic-gate xx = cachefsdprog_1_freeresult(transp, rtp->xdr_res, 478*0Sstevel@tonic-gate (caddr_t)resultp); 479*0Sstevel@tonic-gate if (xx == 0) 480*0Sstevel@tonic-gate msgout(gettext("unable to free results")); 481*0Sstevel@tonic-gate } 482*0Sstevel@tonic-gate 483*0Sstevel@tonic-gate /* free the passed in arguments */ 484*0Sstevel@tonic-gate if (!svc_freeargs(transp, rtp->xdr_arg, (caddr_t)argumentp)) { 485*0Sstevel@tonic-gate msgout(gettext("unable to free arguments")); 486*0Sstevel@tonic-gate abort(); 487*0Sstevel@tonic-gate } 488*0Sstevel@tonic-gate 489*0Sstevel@tonic-gate if (argumentp) 490*0Sstevel@tonic-gate cfsd_free(argumentp); 491*0Sstevel@tonic-gate if (resultp) 492*0Sstevel@tonic-gate cfsd_free(resultp); 493*0Sstevel@tonic-gate dbug_leave("cachefsdprog_1"); 494*0Sstevel@tonic-gate } 495*0Sstevel@tonic-gate 496*0Sstevel@tonic-gate /* 497*0Sstevel@tonic-gate * sigusr1_handler 498*0Sstevel@tonic-gate * 499*0Sstevel@tonic-gate * Description: 500*0Sstevel@tonic-gate * Catches sigusr1 signal so threads wake up. 501*0Sstevel@tonic-gate * Arguments: 502*0Sstevel@tonic-gate * Returns: 503*0Sstevel@tonic-gate * Preconditions: 504*0Sstevel@tonic-gate */ 505*0Sstevel@tonic-gate void 506*0Sstevel@tonic-gate sigusr1_handler(int sig, siginfo_t *sp, void *vp) 507*0Sstevel@tonic-gate { 508*0Sstevel@tonic-gate } 509