slpd.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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* This is a proxy daemon for the real Java slpd. This deamon starts
* at boot time, and listens for any incoming SLP messages only on
* loopback -- this way, only local processes can start the real
* daemon. When a message comes in, the proxy daemon dups the message
* fds onto fds 0, 1, and 2, and execs the real Java slpd. The purpose
* of this approach is for performance: boot time performance is
* not degraded by cranking off the (huge) JVM, and systems take
* the JVM resource hit only if they actually use SLP.
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/byteorder.h>
#include <sys/resource.h>
#include <unistd.h>
#include <slp.h>
#include <fcntl.h>
#include <stdlib.h>
#include <syslog.h>
/* This is an index which points into the args array at the conf file arg */
#define CONF_INDEX 6
/* Location of the Java Virtual Machine */
static char *slpd_args[] = {
"-Xmx128m",
"-classpath",
"com.sun.slp.slpd",
"-f",
0
};
/*
* These are global so they can be easily accessed from a signal
* handler for cleanup.
*/
static void
run_slpd(void)
{
closelog();
closelog();
}
}
/*
* If an alternate config file was specified with -f, make sure slpd
* uses that config file. Also, force libslp.so to use that new config
* file when checking to see if slpd is a DA. If any other arguments
* are given, they are ignored.
*/
static void
{
int c;
switch (c) {
case 'f':
break;
default:
break;
}
char *prefix = "SLP_CONF_FILE=";
int env_size;
char *conf_env;
exit(1);
}
}
}
static void
detachfromtty(void) {
switch (fork()) {
case -1:
perror("slpd: can not fork");
exit(1);
/*NOTREACHED*/
case 0:
break;
default:
exit(0);
}
/*
* standard input, output, and error, and detach from
* controlling terminal.
*/
closefrom(0);
(void) dup(1);
(void) setsid();
}
static void
cleanup_and_exit(int retval)
{
closelog();
}
int
{
struct sockaddr_in bindaddr;
const char *isDA;
const char *proxyReg;
int connfd;
int lfd;
const int on = 1;
/* If slpd has been configured to run as a DA, start it and exit */
run_slpd();
return (1);
}
cleanup_and_exit(1);
}
< 0) {
cleanup_and_exit(1);
}
cleanup_and_exit(1);
}
< 0) {
cleanup_and_exit(1);
}
(void) dup2(0, 1);
(void) dup2(0, 2);
run_slpd();
return (1);
}