rstat_main.c revision 49e7ca4919cec3229f6fab9730bafc7cf24dab23
/*
* 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 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "rstat.h"
#include "rstat_v2.h"
#include <stdio.h>
#include <stdlib.h> /* getenv, exit */
#include <signal.h>
#include <memory.h>
#include <stropts.h>
#include <netconfig.h>
#include <syslog.h>
#ifdef __STDC__
#define SIG_PF void(*)(int)
#endif
#ifdef DEBUG
#define RPC_SVC_FG
#endif
int _rpcpmstart; /* Started by a port monitor ? */
int _rpcfdtype; /* Whether Stream or Datagram ? */
int _rpcsvcdirty; /* Still serving ? */
static void _msgout(/*char *msg*/);
static void closedown();
extern void rstatprog_4(/*struct svc_req *rqstp, SVCXPRT *transp*/);
extern void rstatprog_3(/*struct svc_req *rqstp, SVCXPRT *transp*/);
extern void rstatprog_2(/*struct svc_req *rqstp, SVCXPRT *transp*/);
int
{
int i;
/*
* If stdin looks like a TLI endpoint, we assume
* that we were started by a port monitor. If
* t_getstate fails with TBADF, this is not a
* TLI endpoint.
*/
char *netid;
_rpcpmstart = 1;
#ifdef DEBUG
_msgout("cannot get transport name");
#endif
#ifdef DEBUG
_msgout("cannot get transport info");
#endif
}
_msgout("cannot create server handle");
exit(1);
}
if (nconf)
0)) {
_msgout("unable to register "
"(RSTATPROG, RSTATVERS_VAR).");
exit(1);
}
0)) {
_msgout("unable to register "
"(RSTATPROG, RSTATVERS_TIME).");
exit(1);
}
0)) {
_msgout("unable to register "
"(RSTATPROG, RSTATVERS_SWTCH).");
exit(1);
}
svc_run();
exit(1);
/* NOTREACHED */
} else {
#ifndef RPC_SVC_FG
if (pid < 0) {
perror("cannot fork");
exit(1);
}
if (pid)
exit(0);
closefrom(0);
(void) dup2(i, 1);
(void) dup2(i, 2);
setsid();
#endif
}
_msgout("unable to create (RSTATPROG, RSTATVERS_VAR) "
"for datagram_v.");
exit(1);
}
"datagram_v")) {
_msgout("unable to create (RSTATPROG, RSTATVERS_TIME) "
"for datagram_v.");
exit(1);
}
_msgout("unable to create (RSTATPROG, RSTATVERS_VAR) "
"for circuit_v.");
exit(1);
}
_msgout("unable to create (RSTATPROG, RSTATVERS_TIME) "
"for circuit_v.");
exit(1);
}
/*
* V2 supported on datagram transports *only*
*/
"datagram_v")) {
_msgout("unable to create (RSTATPROG, RSTATVERS_SWTCH) "
"for datagram_v.");
exit(1);
}
svc_run();
_msgout("svc_run returned");
return (1);
}
static void
char *msg;
{
#ifdef RPC_SVC_FG
if (_rpcpmstart)
else
#else
#endif
}