cfsd_main.cc 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 (c) 1994,1998-2000 by Sun Microsystems, Inc.
* All rights reserved.
*/
// -----------------------------------------------------------------
//
// main.cc
//
// Main routines for cachefs daemon.
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h> /* strcmp */
#include <signal.h>
#include <sysent.h> /* getdtablesize, open */
#include <unistd.h> /* setsid */
#include <memory.h>
#include <stropts.h>
#include <netconfig.h>
#include <libintl.h>
#include <locale.h>
#include <synch.h>
#include <common/cachefsd.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 *);
// -----------------------------------------------------------------
//
// 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
{
dbug_enter("main");
dbug_process("cfsadmin");
/* verify root */
if (getuid() != 0) {
return (1);
}
#if !defined(TEXT_DOMAIN)
#define TEXT_DOMAIN "SYS_TEST"
#endif
(void) textdomain(TEXT_DOMAIN);
int opt_fork = 0;
int opt_mt = 0;
int c;
const char *msgp;
switch (c) {
case 'f':
opt_fork = 1;
break;
case 'm':
opt_mt = 1;
break;
case 'r':
break;
case '#': /* dbug args */
if (msgp) {
return (1);
}
break;
default:
printf("illegal switch\n");
return (1);
}
}
int xx;
// XXX need some way to prevent multiple daemons from running
if (opt_mt) {
int mode = RPC_SVC_MT_AUTO;
msgout("unable to set automatic MT mode.");
return (1);
}
}
#if 0
/* XXX change to sigation */
#else
/* ignore sigpipe */
if (xx) {
}
/* catch sigusr1 signals, used to wake up threads */
if (xx) {
}
#endif
// 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
fscachep->fscache_lock();
if (fscachep->fscache_disconnectable() &&
fscachep->fscache_mounted()) {
if (pid < 0) {
perror("cannot fork");
return (1);
}
if (pid)
return (0);
closefrom(0);
setsid();
} else {
// not disconnectable
return (1);
}
return (0);
}
// if a port mapper started us
char *netid;
int pmclose;
/* started from inetd */
pmclose = 1;
} else {
msgout("cannot get transport info");
}
msgout("could not get the right module");
return (1);
}
}
msgout("cannot create server handle");
return (1);
}
if (nconf)
cachefsdprog_1, 0);
if (!xx) {
msgout("unable to reg (CACHEFSDPROG, CACHEFSDVERS).");
return (1);
}
if (pmclose) {
#if 0
#endif
}
}
// else if started by hand
else {
// if we should fork
if (opt_fork) {
if (pid < 0) {
perror("cannot fork");
return (1);
}
if (pid)
return (0);
closefrom(0);
setsid();
}
"tcp");
#if 0
"netpath");
#endif
if (!xx) {
msgout("unable to create (CACHEFSDPROG, CACHEFSDVERS)"
" for netpath.");
return (1);
}
}
// find existing caches and mounted file systems
// process requests
svc_run();
msgout("svc_run returned");
return (1);
}
// -----------------------------------------------------------------
//
// msgout
//
// Description:
// Outputs an error message to stderr.
// Arguments:
// msgp
// Returns:
// Preconditions:
// precond(msgp)
void
{
dbug_enter("msgout");
}
// -----------------------------------------------------------------
//
// closedown
//
// Description:
// Arguments:
// sig
// Returns:
// Preconditions:
// XXX bob: need to shut down daemon if no requests after 5 minutes
// and no chart mounts
#if 0
void
{
if (_rpcsvcstate == _IDLE) {
int size;
int i, openfd;
exit(0);
if (svc_pollfd[i].fd >= 0) {
openfd++;
}
}
if (openfd <= 1) {
msgout("daemon exiting");
exit(0);
}
}
if (_rpcsvcstate == _SERVED)
}
#endif
// -----------------------------------------------------------------
//
// cachefsdprog_1
//
// Description:
// Arguments:
// rqstp
// transp
// Returns:
// Preconditions:
// precond(rqstp)
// precond(transp)
void
{
dbug_enter("cachefsdprog_1");
// make sure a valid command number
msgout("bad message");
return;
}
// get command information
// get memory for the arguments
}
// get memory for the results
// get the arguments
delete argumentp;
delete resultp;
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)
msgout("unable to free results");
}
// free the passed in arguments
msgout("unable to free arguments");
abort();
}
delete argumentp;
delete resultp;
}
//
// sigusr1_handler
//
// Description:
// Catches sigusr1 signal so threads wake up.
// Arguments:
// Returns:
// Preconditions:
void
sigusr1_handler(int, siginfo_t *, void *)
{
}