cfsd_main.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1998-2000, 2002 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Main routines for cachefs daemon.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <string.h> /* strcmp */
#include <signal.h>
#include <unistd.h> /* setsid */
#include <memory.h>
#include <stropts.h>
#include <netconfig.h>
#include <libintl.h>
#include <locale.h>
#include <thread.h>
#include <synch.h>
#include <common/cachefsd.h>
#include "cfsd.h"
#include "cfsd_kmod.h"
#include "cfsd_maptbl.h"
#include "cfsd_logfile.h"
#include "cfsd_fscache.h"
#include "cfsd_cache.h"
#include "cfsd_all.h"
#include "cfsd_subr.h"
#define RPCGEN_ACTION(X) X
#include "cachefsd_tbl.i"
#ifndef SIG_PF
#define SIG_PF void(*)(int)
#endif
/* global definitions */
/* forward references */
void sigusr1_handler(int, siginfo_t *, void *);
static int void_close(void *, int);
/*
* -----------------------------------------------------------------
* main
*
* Description:
* main routine for the chart daemon.
* Arguments:
* argc
* argv
* Returns:
* Returns 0 for a normal exit, !0 if an error occurred.
* Preconditions:
* precond(argv)
*/
int
{
int xx;
int opt_fork = 0;
int opt_mt = 0;
int c;
char *msgp;
int size;
int ofd = -1;
char *netid;
int mode;
/* selectable maximum RPC request record size */
int maxrecsz = RPC_MAXDATASIZE;
dbug_enter("main");
dbug_process("cfsadmin");
#if !defined(TEXT_DOMAIN)
#define TEXT_DOMAIN "SYS_TEST"
#endif
(void) textdomain(TEXT_DOMAIN);
/* verify root */
if (getuid() != 0) {
dbug_leave("main");
return (1);
}
/* Increase number of file descriptors to maximum allowable */
if (xx < 0) {
dbug_print(("error",
"getrlimit/RLIMIT_NOFILE failed %d", errno));
dbug_leave("main");
return (1);
}
if (xx < 0) {
dbug_print(("error",
"setrlimit/RLIMIT_NOFILE failed %d", errno));
dbug_leave("main");
return (1);
}
switch (c) {
case 'f':
opt_fork = 1;
break;
case 'm':
/*
* XXX don't use this until race between mount
* and umount is fixed.
*/
opt_mt = 1;
break;
case 'r':
break;
case '#': /* dbug args */
if (msgp) {
dbug_leave("main");
return (1);
}
break;
default:
dbug_leave("main");
return (1);
}
}
/* XXX need some way to prevent multiple daemons from running */
if (opt_mt) {
dbug_leave("main");
return (1);
}
}
/*
* Enable non-blocking mode and maximum record size checks for
* connection oriented transports.
*/
}
/* ignore sigpipe */
if (xx) {
}
/* catch sigusr1 signals, used to wake up threads */
if (xx) {
}
/* do not set up rpc services if just taking care of root */
if (opt_root) {
/* make the fscache object */
/* init the fscache object with mount information */
if (fscache_object_p->i_disconnectable &&
if (pid < 0) {
dbug_leave("main");
return (1);
}
if (pid) {
dbug_leave("main");
return (0);
}
setsid();
} else {
/* not disconnectable */
dbug_leave("main");
return (1);
}
dbug_leave("main");
return (0);
}
/* if a inetd started us */
return (1);
/* started from inetd */
netid = "ticotsord";
gettext("could not get the right module"));
dbug_leave("main");
return (1);
}
}
dbug_leave("main");
return (1);
}
if (nconf)
cachefsdprog_1, 0);
if (!xx) {
"unable to reg (CACHEFSDPROG, CACHEFSDVERS)."));
dbug_leave("main");
return (1);
}
}
/* else if started by hand */
else {
/* if we should fork */
if (opt_fork) {
if (pid < 0) {
dbug_leave("main");
return (1);
}
if (pid) {
dbug_leave("main");
return (0);
}
setsid();
}
/* connect to *ANY* local loopback transport provider */
"local");
if (!xx) {
"CACHEFSDVERS) for netpath."));
dbug_leave("main");
return (1);
}
}
/* find existing caches and mounted file systems */
/* process requests */
svc_run();
dbug_leave("main");
return (1);
}
/*
* Callback function for fdwalk() to close all files.
*/
static int
{
dbug_print(("err",
}
return (0);
}
/*
* -----------------------------------------------------------------
* msgout
*
* Description:
* Outputs an error message to stderr.
* Arguments:
* msgp
* Returns:
* Preconditions:
* precond(msgp)
*/
void
{
dbug_enter("msgout");
dbug_leave("msgout");
}
/*
* -----------------------------------------------------------------
* cachefsdprog_1
*
* Description:
* Arguments:
* rqstp
* transp
* Returns:
* Preconditions:
* precond(rqstp)
* precond(transp)
*/
void
{
int index;
struct rpcgen_table *rtp;
int xx;
dbug_enter("cachefsdprog_1");
/* make sure a valid command number */
dbug_leave("cachefsdprog_1");
return;
}
/* get command information */
/* get memory for the arguments */
/* get memory for the results */
/* get the arguments */
dbug_leave("cachefsdprog_1");
return;
}
}
/* call the routine to process the command */
/* if the command could not be processed */
if (xx == 0) {
}
/* else send the results back to the caller */
else {
if (!xx)
/* free the results */
if (xx == 0)
}
/* free the passed in arguments */
abort();
}
if (argumentp)
if (resultp)
dbug_leave("cachefsdprog_1");
}
/*
* sigusr1_handler
*
* Description:
* Catches sigusr1 signal so threads wake up.
* Arguments:
* Returns:
* Preconditions:
*/
void
{
}