mddoors.c revision 80148899834a4078a2bd348504aa2d6de9752837
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <door.h>
#include <locale.h>
#include <meta.h>
#include <strings.h>
#include <syslog.h>
static pid_t enter_daemon_lock(void);
static void exit_daemon_lock(void);
#define DAEMON_LOCK_FILE "/var/run/.mddoors.lock"
static int hold_daemon_lock;
static const char *daemon_lock_file = DAEMON_LOCK_FILE;
static int daemon_lock_fd;
void
{
if (hold_daemon_lock) {
}
}
/*
* Use an advisory lock to ensure that only one daemon process is
* active at any point in time.
*/
static pid_t
enter_daemon_lock(void)
{
if (daemon_lock_fd < 0) {
exit(-1);
}
exit(1);
}
}
}
hold_daemon_lock = 1;
return (getpid());
}
/*
* Drop the advisory daemon lock, close lock file
*/
static void
exit_daemon_lock(void)
{
return;
}
gettext("close(%s) failed - %s\n"),
return;
}
(void) unlink(daemon_lock_file);
}
/*
* Purpose of this routine is to accept a message from the local kernel and
* send this message using rpc to the master node.
* when an ok comes from the master we call door_return()
*/
/* ARGSUSED */
static void
char *argp,
{
int err;
int size;
} else {
if (err == 0) {
if (size > 0) {
/* This is the max data we can transfer, here */
if (size > MDMN_MAX_KRES_DATA) {
}
size);
} else {
kresult.kmmr_res_size = 0;
}
}
}
}
/* ARGSUSED */
int
main(void)
{
int i;
int mdmn_door_handle;
int size;
/*
* Get the locale set up before calling any other routines
* with messages to ouput. Just in case we're not in a build
* environment, make sure that TEXT_DOMAIN gets set to
* something.
*/
#if !defined(TEXT_DOMAIN)
#define TEXT_DOMAIN "SYS_TEST"
#endif
(void) textdomain(TEXT_DOMAIN);
/* here beginneth the daemonizing code */
if (pid < 0) {
exit(1);
}
if (pid) {
exit(0);
}
/*
* Only one daemon can run at a time.
* If another instance is already running, this is not an error.
*/
exit(0);
}
exit(1);
}
for (i = 0; i < size; i++) {
if (i == daemon_lock_fd)
continue;
(void) close(i);
}
(void) dup2(i, 1);
(void) dup2(i, 2);
(void) setsid();
/* here endeth the daemonizing code */
/* Block out the usual signals so we don't get killed unintentionally */
(void) atexit(daemon_cleanup);
/* Resume any previously blocked resync */
/*
* At this point we are single threaded.
* We give mdmn_send_message() a chance to initialize safely.
*/
(void) mdmn_send_message(0, 0, 0, 0, 0, 0, 0, 0);
/* setup the door handle */
if (mdmn_door_handle == -1) {
exit(1);
}
"mddoors") != 0) {
"Couldn't set door handle"));
exit(1);
}
(void) pause();
"Unexpected exit from pause()"));
return (1);
}